LCIO
02.17
|
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::LCEvent > | readNextEvent (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::LCEvent > | readEvent (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 | |
LCReader & | operator= (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} |
Implementation of a LCReader for parallel processing use.
Definition at line 37 of file LCReader.h.
|
privatedelete |
|
default |
MT::LCReader::LCReader | ( | int | lcReaderFlag | ) |
Constructor.
lcReaderFlag | flag for reader options |
Definition at line 31 of file LCReader.cc.
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().
|
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 | ) |
Opens a file for reading (read-only).
Definition at line 43 of file LCReader.cc.
References _myFilenames, _readEventMap, _stream, std::ifstream::close(), std::vector< T >::empty(), getEventMap(), std::ifstream::is_open(), std::ifstream::open(), and std::vector< T >::push_back().
Referenced by main(), SIO::SIOReader::open(), open(), readNextEvent(), and readNextRunHeader().
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().
|
private |
Definition at line 563 of file LCReader.cc.
References std::vector< T >::begin(), std::vector< T >::end(), std::endl(), EVENT::LCEvent::getCollection(), EVENT::LCEvent::getCollectionNames(), EVENT::LCCollection::getElementAt(), EVENT::LCCollection::getNumberOfElements(), EVENT::LCCollection::isSubset(), SIO::SIOParticleHandler::restoreParentDaughterRelations(), and std::stringstream::str().
Referenced by readNextEvent().
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 | ) |
Reads the next event from the file.
Returns NULL if 'EOF' read. Note that this method is not thread safe !
Definition at line 135 of file LCReader.cc.
References _bufferMaxSize, _compBuffer, _currentFileIndex, _eventHandlerMgr, _lazyUnpack, _myFilenames, _rawBuffer, _readCollectionNames, _stream, close(), std::vector< T >::empty(), event, SIO::LCSIO::EventRecordName, SIO::LCSIO::HeaderRecordName, std::max(), open(), postProcessEvent(), SIO::SIOEventHeaderRecord::readBlocks(), SIO::SIOEventRecord::readBlocks(), IOIMPL::LCEventLazyImpl::setBuffer(), and std::vector< T >::size().
Referenced by main(), and SIO::SIOReader::readNextEvent().
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().
|
private |
Definition at line 195 of file LCReader.h.
Referenced by readNextEvent().
|
private |
The raw buffer for uncompression.
Definition at line 179 of file LCReader.h.
Referenced by readNextEvent(), and readNextRunHeader().
|
private |
The current file list index when opening multiple files.
Definition at line 191 of file LCReader.h.
Referenced by open(), readNextEvent(), and readNextRunHeader().
|
private |
The collection block handler manager for events.
Definition at line 181 of file LCReader.h.
Referenced by readNextEvent().
|
private |
Whether to perform the lazy unpacking of event records.
Definition at line 185 of file LCReader.h.
Referenced by readNextEvent().
|
private |
The list of files to open and read.
Definition at line 187 of file LCReader.h.
Referenced by open(), readNextEvent(), and readNextRunHeader().
|
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().
|
private |
The raw buffer for extracting bytes from the stream.
Definition at line 177 of file LCReader.h.
Referenced by readNextEvent(), and readNextRunHeader().
|
private |
A restricted list of collections to read only.
Definition at line 189 of file LCReader.h.
Referenced by readNextEvent(), and setReadCollectionNames().
|
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().
|
private |
The input file stream.
Definition at line 175 of file LCReader.h.
Referenced by open(), readNextEvent(), readNextRunHeader(), and skipNEvents().
|
static |
|
static |
Bit for lazy unpacking of event records.
Definition at line 47 of file LCReader.h.
Referenced by main().