LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
MT::LCReader Class Reference

Implementation of a LCReader for parallel processing use. More...

#include <LCReader.h>

Public Member Functions

 ~LCReader ()=default
 
 LCReader (int lcReaderFlag)
 Constructor. More...
 
void open (const std::string &filename)
 Opens a file for reading (read-only). More...
 
void open (const std::vector< std::string > &filenames)
 Opens a list of files for reading (read-only). More...
 
std::unique_ptr
< EVENT::LCRunHeader
readNextRunHeader (int accessMode=EVENT::LCIO::READ_ONLY)
 Reads the next run header from the file. More...
 
std::unique_ptr< EVENT::LCEventreadNextEvent (int accessMode=EVENT::LCIO::READ_ONLY)
 Reads the next event from the file. More...
 
int getNumberOfEvents ()
 Return the number of events in the file - the file has to be open. More...
 
int getNumberOfRuns ()
 Return the number of runs (run headers) in the file - the file has to be open. More...
 
void getRuns (EVENT::IntVec &runs)
 Return the run numbers of the runs (run headers) in the file - the file has to be open. More...
 
void getEvents (EVENT::IntVec &events)
 Return the run and event numbers of the events in the file - the file has to be open. More...
 
void setReadCollectionNames (const std::vector< std::string > &colnames)
 Limit the collection names that are going to be read to the subset given in the vector - all other collection will be ignored. More...
 
void skipNEvents (int n)
 Skips the next n events from the current position. More...
 
std::unique_ptr
< EVENT::LCRunHeader
readRunHeader (int runNumber, int accessMode=EVENT::LCIO::READ_ONLY)
 Reads the specified runHeader from file. More...
 
std::unique_ptr< EVENT::LCEventreadEvent (int runNumber, int evtNumber, int accessMode=EVENT::LCIO::READ_ONLY)
 Reads the specified event from file. More...
 
void close ()
 Closes the output file/stream etc. More...
 
void readStream (const LCReaderListenerList &listeners)
 Reads the input stream and notifies listeners according to the object type found in the stream. More...
 
void readStream (const LCReaderListenerList &listeners, int maxRecord)
 Reads maxRecord from the input stream and notifies listeners according to the object type found in the stream. More...
 
void readNextRecord (const LCReaderListenerList &listeners)
 Reads the input stream and notifies listeners according to the object type found in the stream. More...
 
void readStream (LCReaderListener *listener)
 Reads the input stream and notifies the listener according to the object type found in the stream. More...
 
void readStream (LCReaderListener *listener, int maxRecord)
 Reads maxRecord from the input stream and notifies listener according to the object type found in the stream. More...
 
void readNextRecord (LCReaderListener *listener)
 Reads the input stream and notifies listener according to the object type found in the stream. More...
 

Static Public Attributes

static constexpr int directAccess = 0x00000001 << 0
 Bit for direct access. More...
 
static constexpr int lazyUnpack = 0x00000002 << 0
 Bit for lazy unpacking of event records. More...
 

Private Member Functions

 LCReader (const LCReader &)=delete
 
LCReaderoperator= (const LCReader &)=delete
 
void postProcessEvent (EVENT::LCEvent *evt)
 
void getEventMap ()
 

Private Attributes

std::ifstream _stream {}
 The input file stream. More...
 
std::shared_ptr< sio::buffer > _rawBuffer {nullptr}
 The raw buffer for extracting bytes from the stream. More...
 
std::shared_ptr< sio::buffer > _compBuffer {nullptr}
 The raw buffer for uncompression. More...
 
std::shared_ptr
< SIO::SIOHandlerMgr
_eventHandlerMgr {nullptr}
 The collection block handler manager for events. More...
 
bool _readEventMap {false}
 Whether to read the event map using the random access manager. More...
 
bool _lazyUnpack {false}
 Whether to perform the lazy unpacking of event records. More...
 
std::vector< std::string_myFilenames {}
 The list of files to open and read. More...
 
std::vector< std::string_readCollectionNames {}
 A restricted list of collections to read only. More...
 
unsigned int _currentFileIndex {0}
 The current file list index when opening multiple files. More...
 
std::shared_ptr
< SIO::LCIORandomAccessMgr
_raMgr {nullptr}
 The random access manager for event/run random access in the file. More...
 
std::size_t _bufferMaxSize {0}
 

Detailed Description

Implementation of a LCReader for parallel processing use.

See Also
EXAMPLE/lcio_parallel_processing.cc
Author
rete
Version
Feb 14, 2019

Definition at line 37 of file LCReader.h.

Constructor & Destructor Documentation

MT::LCReader::LCReader ( const LCReader )
privatedelete
MT::LCReader::~LCReader ( )
default
MT::LCReader::LCReader ( int  lcReaderFlag)

Constructor.

Parameters
lcReaderFlagflag for reader options

Definition at line 31 of file LCReader.cc.

Member Function Documentation

void MT::LCReader::close ( )

Closes the output file/stream etc.

Definition at line 416 of file LCReader.cc.

Referenced by SIO::SIOReader::close(), main(), readNextEvent(), and readNextRunHeader().

void MT::LCReader::getEventMap ( )
private

Definition at line 589 of file LCReader.cc.

Referenced by getNumberOfEvents(), getNumberOfRuns(), and open().

void MT::LCReader::getEvents ( EVENT::IntVec events)

Return the run and event numbers of the events in the file - the file has to be open.

In case several input files are specified in the open() method - the run and event numbers of the events in the file that is currently open are returned. The size of the vector events will be twice the number of events, where i-th run number will be in events[2*i] and the i-th event number in events[2*i+].

Definition at line 250 of file LCReader.cc.

References _raMgr, std::advance(), getNumberOfEvents(), getNumberOfRuns(), and std::vector< T >::resize().

Referenced by SIO::SIOReader::getEvents().

int MT::LCReader::getNumberOfEvents ( )

Return the number of events in the file - the file has to be open.

In case several input files are specified in the open() method - the number of events in the file that is currently open is returned.

Definition at line 214 of file LCReader.cc.

References _raMgr, _readEventMap, and getEventMap().

Referenced by getEvents(), and SIO::SIOReader::getNumberOfEvents().

int MT::LCReader::getNumberOfRuns ( )

Return the number of runs (run headers) in the file - the file has to be open.

In case several input files are specified in the open() method - the number of runs (run headers) in the file that is currently open is returned.

Definition at line 225 of file LCReader.cc.

References _raMgr, _readEventMap, and getEventMap().

Referenced by getEvents(), SIO::SIOReader::getNumberOfRuns(), and getRuns().

void MT::LCReader::getRuns ( EVENT::IntVec runs)

Return the run numbers of the runs (run headers) in the file - the file has to be open.

In case several input files are specified in the open() method - the run numbers of the runs (run headers) in the file that is currently open is returned.

Definition at line 236 of file LCReader.cc.

References _raMgr, getNumberOfRuns(), and std::vector< T >::resize().

Referenced by SIO::SIOReader::getRuns().

void MT::LCReader::open ( const std::string filename)
void MT::LCReader::open ( const std::vector< std::string > &  filenames)

Opens a list of files for reading (read-only).

All subsequent read operations will operate on the list, i.e. if an EOF is encountered the next file in the list will be opened and read transparently to the user.

Definition at line 62 of file LCReader.cc.

References _currentFileIndex, _myFilenames, std::vector< T >::empty(), open(), and std::vector< T >::size().

LCReader& MT::LCReader::operator= ( const LCReader )
privatedelete
void MT::LCReader::postProcessEvent ( EVENT::LCEvent evt)
private
std::unique_ptr< EVENT::LCEvent > MT::LCReader::readEvent ( int  runNumber,
int  evtNumber,
int  accessMode = EVENT::LCIO::READ_ONLY 
)

Reads the specified event from file.

Returns NULL if the specified event hasn't been found in the file.

Definition at line 323 of file LCReader.cc.

References std::endl(), event, SIO::LCSIO::EventRecordName, SIO::LCSIO::HeaderRecordName, std::max(), SIO::RunEventMap::npos, SIO::SIOEventHeaderRecord::readBlocks(), SIO::SIOEventRecord::readBlocks(), and IOIMPL::LCEventLazyImpl::setBuffer().

Referenced by SIO::SIOReader::readEvent().

std::unique_ptr< EVENT::LCEvent > MT::LCReader::readNextEvent ( int  accessMode = EVENT::LCIO::READ_ONLY)
void MT::LCReader::readNextRecord ( const LCReaderListenerList listeners)

Reads the input stream and notifies listeners according to the object type found in the stream.

Definition at line 539 of file LCReader.cc.

Referenced by main().

void MT::LCReader::readNextRecord ( LCReaderListener listener)

Reads the input stream and notifies listener according to the object type found in the stream.

Definition at line 557 of file LCReader.cc.

std::unique_ptr< EVENT::LCRunHeader > MT::LCReader::readNextRunHeader ( int  accessMode = EVENT::LCIO::READ_ONLY)

Reads the next run header from the file.

Returns NULL if 'EOF' read. Note that this method is not thread safe !

Definition at line 86 of file LCReader.cc.

References _compBuffer, _currentFileIndex, _myFilenames, _rawBuffer, _stream, close(), std::vector< T >::empty(), open(), SIO::SIORunHeaderRecord::readBlocks(), SIO::LCSIO::RunRecordName, and std::vector< T >::size().

Referenced by SIO::SIOReader::readNextRunHeader().

std::unique_ptr< EVENT::LCRunHeader > MT::LCReader::readRunHeader ( int  runNumber,
int  accessMode = EVENT::LCIO::READ_ONLY 
)

Reads the specified runHeader from file.

Returns NULL if the specified runHeader hasn't been found in the file.

Definition at line 299 of file LCReader.cc.

References std::endl(), and SIO::RunEventMap::npos.

Referenced by SIO::SIOReader::readRunHeader().

void MT::LCReader::readStream ( const LCReaderListenerList listeners)

Reads the input stream and notifies listeners according to the object type found in the stream.

Definition at line 423 of file LCReader.cc.

Referenced by SIO::SIOReader::readStream().

void MT::LCReader::readStream ( const LCReaderListenerList listeners,
int  maxRecord 
)

Reads maxRecord from the input stream and notifies listeners according to the object type found in the stream.

An exception is thrown if less than maxRecord where read from the file.

Definition at line 429 of file LCReader.cc.

References std::unordered_set< K >::begin(), std::set< K >::end(), std::unordered_set< K >::end(), std::ends(), event, SIO::LCSIO::EventRecordName, std::set< K >::find(), SIO::LCSIO::HeaderRecordName, std::max(), std::numeric_limits::max(), SIO::SIOEventHeaderRecord::readBlocks(), SIO::SIOEventRecord::readBlocks(), SIO::SIORunHeaderRecord::readBlocks(), SIO::LCSIO::RunRecordName, and std::stringstream::str().

void MT::LCReader::readStream ( LCReaderListener listener)

Reads the input stream and notifies the listener according to the object type found in the stream.

Definition at line 545 of file LCReader.cc.

void MT::LCReader::readStream ( LCReaderListener listener,
int  maxRecord 
)

Reads maxRecord from the input stream and notifies listener according to the object type found in the stream.

An exception is thrown if less than maxRecord where read from the file.

Definition at line 551 of file LCReader.cc.

void MT::LCReader::setReadCollectionNames ( const std::vector< std::string > &  colnames)

Limit the collection names that are going to be read to the subset given in the vector - all other collection will be ignored.

This might improve the reading performance considerably in cases where only a small subset of the collections in the event is needed.

Definition at line 268 of file LCReader.cc.

References _readCollectionNames.

Referenced by SIO::SIOReader::setReadCollectionNames().

void MT::LCReader::skipNEvents ( int  n)

Skips the next n events from the current position.

Definition at line 274 of file LCReader.cc.

References _stream, and SIO::LCSIO::HeaderRecordName.

Referenced by SIO::SIOReader::skipNEvents().

Member Data Documentation

std::size_t MT::LCReader::_bufferMaxSize {0}
private

Definition at line 195 of file LCReader.h.

Referenced by readNextEvent().

std::shared_ptr<sio::buffer> MT::LCReader::_compBuffer {nullptr}
private

The raw buffer for uncompression.

Definition at line 179 of file LCReader.h.

Referenced by readNextEvent(), and readNextRunHeader().

unsigned int MT::LCReader::_currentFileIndex {0}
private

The current file list index when opening multiple files.

Definition at line 191 of file LCReader.h.

Referenced by open(), readNextEvent(), and readNextRunHeader().

std::shared_ptr<SIO::SIOHandlerMgr> MT::LCReader::_eventHandlerMgr {nullptr}
private

The collection block handler manager for events.

Definition at line 181 of file LCReader.h.

Referenced by readNextEvent().

bool MT::LCReader::_lazyUnpack {false}
private

Whether to perform the lazy unpacking of event records.

Definition at line 185 of file LCReader.h.

Referenced by readNextEvent().

std::vector<std::string> MT::LCReader::_myFilenames {}
private

The list of files to open and read.

Definition at line 187 of file LCReader.h.

Referenced by open(), readNextEvent(), and readNextRunHeader().

std::shared_ptr<SIO::LCIORandomAccessMgr> MT::LCReader::_raMgr {nullptr}
private

The random access manager for event/run random access in the file.

Definition at line 193 of file LCReader.h.

Referenced by getEvents(), getNumberOfEvents(), getNumberOfRuns(), and getRuns().

std::shared_ptr<sio::buffer> MT::LCReader::_rawBuffer {nullptr}
private

The raw buffer for extracting bytes from the stream.

Definition at line 177 of file LCReader.h.

Referenced by readNextEvent(), and readNextRunHeader().

std::vector<std::string> MT::LCReader::_readCollectionNames {}
private

A restricted list of collections to read only.

Definition at line 189 of file LCReader.h.

Referenced by readNextEvent(), and setReadCollectionNames().

bool MT::LCReader::_readEventMap {false}
private

Whether to read the event map using the random access manager.

Definition at line 183 of file LCReader.h.

Referenced by getNumberOfEvents(), getNumberOfRuns(), and open().

std::ifstream MT::LCReader::_stream {}
private

The input file stream.

Definition at line 175 of file LCReader.h.

Referenced by open(), readNextEvent(), readNextRunHeader(), and skipNEvents().

constexpr int MT::LCReader::directAccess = 0x00000001 << 0
static

Bit for direct access.

Definition at line 45 of file LCReader.h.

Referenced by main().

constexpr int MT::LCReader::lazyUnpack = 0x00000002 << 0
static

Bit for lazy unpacking of event records.

Definition at line 47 of file LCReader.h.

Referenced by main().


The documentation for this class was generated from the following files: