LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LCReader.cc
Go to the documentation of this file.
1 #include "MT/LCReader.h"
2 
3 // -- lcio headers
4 #include "SIO/LCSIO.h"
6 #include "SIO/LCIORecords.h"
8 #include "IOIMPL/LCEventIOImpl.h"
11 #include "Exceptions.h"
12 #include "SIO/RunEventMap.h"
13 #include "SIO/SIOHandlerMgr.h"
14 
15 // -- sio headers
16 #include "sio/definitions.h"
17 #include "sio/buffer.h"
18 #include <sio/exception.h>
19 #include <sio/api.h>
20 #include <sio/compression/zlib.h>
21 
22 // -- std headers
23 #include <sys/stat.h>
24 #include <assert.h>
25 #include <limits>
26 
28 
29 namespace MT {
30 
31  LCReader::LCReader( int lcReaderFlag ) :
32  _rawBuffer( std::make_shared<sio::buffer>(1*sio::mbyte) ),
33  _compBuffer( std::make_shared<sio::buffer>(2*sio::mbyte) ),
34  _eventHandlerMgr( std::make_shared<SIO::SIOHandlerMgr>() ),
35  _readEventMap( lcReaderFlag & LCReader::directAccess ),
36  _lazyUnpack( lcReaderFlag & LCReader::lazyUnpack ),
37  _raMgr(std::make_shared<SIO::LCIORandomAccessMgr>()) {
38  /* nop */
39  }
40 
41  //----------------------------------------------------------------------------
42 
43  void LCReader::open( const std::string& filename ) {
44  if( _stream.is_open() ) {
45  _stream.close() ;
46  }
47  _stream.open( filename , std::ios::binary ) ;
48  if( not _stream.is_open() ) {
49  SIO_THROW( sio::error_code::not_open, "Couldn't open input stream '" + filename + "'" ) ;
50  }
51  if( _readEventMap ) {
52  getEventMap() ;
53  }
54  // We are in single file mode ...
55  if( _myFilenames.empty() ) {
56  _myFilenames.push_back( filename ) ;
57  }
58  }
59 
60  //----------------------------------------------------------------------------
61 
62  void LCReader::open( const std::vector<std::string>& filenames ) {
63  if( filenames.empty() ) {
64  throw IO::IOException( "[LCReader::open()] Provided file list is empty") ;
65  }
66  struct stat fileinfo ;
67  std::string missing_files ;
68  // JE: first we check if all files exist
69  for(unsigned int i=0 ; i < filenames.size(); i++) {
70  if ( ::stat( filenames[i].c_str(), &fileinfo ) != 0 ) {
71  missing_files += filenames[i] ;
72  missing_files += " " ;
73  }
74  }
75  // JE: if not raise IOException
76  if( missing_files.size() != 0 ) {
77  throw IO::IOException( std::string( "[LCReader::open()] File(s) not found: " + missing_files )) ;
78  }
79  _myFilenames = filenames ;
80  _currentFileIndex = 0 ;
81  open( _myFilenames[0] ) ;
82  }
83 
84  //----------------------------------------------------------------------------
85 
87  std::unique_ptr<EVENT::LCRunHeader> runhdr = nullptr ;
88  auto validator = [&]( const sio::record_info &recinfo ) {
89  // we want a run header record only
90  return ( recinfo._name == SIO::LCSIO::RunRecordName ) ;
91  } ;
92  auto processor = [&]( const sio::record_info &recinfo, const sio::buffer_span& recdata ) {
93  const bool compressed = sio::api::is_compressed( recinfo._options ) ;
94  if( compressed ) {
95  _compBuffer->resize( recinfo._uncompressed_length ) ;
96  sio::zlib_compression compressor ;
97  compressor.uncompress( recdata, *_compBuffer ) ;
98  }
99  auto rundata = compressed ? _compBuffer->span() : recdata ;
100  auto runheader = std::make_unique<IOIMPL::LCRunHeaderIOImpl>() ;
101  SIO::SIORunHeaderRecord::readBlocks( rundata, runheader.get() ) ;
102  runheader->setReadOnly( accessMode == EVENT::LCIO::READ_ONLY ) ;
103  runheader->parameters().setValue( "LCIOFileName" , _myFilenames[ _currentFileIndex ] ) ;
104  runhdr = std::move(runheader) ;
105  return false ; // only one record
106  } ;
107  try {
108  sio::api::read_records( _stream, *_rawBuffer, validator , processor ) ;
109  }
110  catch( sio::exception &e ) {
111  // reached end of file. Need to close the current and open the next if available
112  if( e.code() == sio::error_code::eof ) {
114  close() ;
116  try {
117  return readNextRunHeader(accessMode) ;
118  }
119  catch( sio::exception &e2 ) {
120  if( e2.code() == sio::error_code::eof ) {
121  return nullptr ;
122  }
123  SIO_RETHROW( e2, e2.code(), "Couldn't read next run header!" ) ;
124  }
125  }
126  return nullptr ;
127  }
128  SIO_RETHROW( e, e.code(), "Couldn't read next run header!" ) ;
129  }
130  return runhdr ;
131  }
132 
133  //----------------------------------------------------------------------------
134 
136  IOIMPL::LCEventLazyImpl* lazyEvent = nullptr ;
138  auto validator = [&]( const sio::record_info &recinfo ) {
139  return ( recinfo._name == SIO::LCSIO::HeaderRecordName || recinfo._name == SIO::LCSIO::EventRecordName ) ;
140  } ;
141  auto processor = [&]( const sio::record_info &recinfo, const sio::buffer_span& recdata ) {
142  const bool compressed = sio::api::is_compressed( recinfo._options ) ;
143  // do not run uncompression if we have an event record and lazy unpacking...
144  const bool uncomp = ( compressed && not (recinfo._name == SIO::LCSIO::EventRecordName && _lazyUnpack) ) ;
145  if( uncomp ) {
146  _compBuffer->resize( recinfo._uncompressed_length ) ;
147  sio::zlib_compression compressor ;
148  compressor.uncompress( recdata, *_compBuffer ) ;
149  }
150  auto data = uncomp ? _compBuffer->span() : recdata ;
151  if( recinfo._name == SIO::LCSIO::HeaderRecordName ) {
152  if( _lazyUnpack ) {
153  lazyEvent = new IOIMPL::LCEventLazyImpl() ;
154  event.reset( lazyEvent ) ;
155  }
156  else {
157  event = std::make_unique<IOIMPL::LCEventIOImpl>() ;
158  }
160  return true ;
161  }
162  else if( recinfo._name == SIO::LCSIO::EventRecordName ) {
163  if( nullptr == event ) {
164  throw IO::IOException( "SIOReader::readNextEvent: Event record before an EventHeader record ..." ) ;
165  }
166  if( _lazyUnpack ) {
168  // move the buffer to the event
169  lazyEvent->setBuffer( recinfo, std::move(*_rawBuffer) ) ;
170  // re-allocate a new valid buffer
171  *_rawBuffer = sio::buffer( _bufferMaxSize ) ;
172  }
173  else {
175  }
176  return false ;
177  }
178  return false ;
179  } ;
180  try {
181  sio::api::read_records( _stream, *_rawBuffer, validator, processor ) ;
182  }
183  catch( sio::exception &e ) {
184  // reached end of file. Need to close the current and open the next if available
185  if( e.code() == sio::error_code::eof ) {
187  close() ;
189  try {
190  return readNextEvent(accessMode) ;
191  }
192  catch( sio::exception &e2 ) {
193  if( e2.code() == sio::error_code::eof ) {
194  return nullptr ;
195  }
196  SIO_RETHROW( e2, e2.code(), "Couldn't read next event!" ) ;
197  }
198  }
199  return nullptr ;
200  }
201  SIO_RETHROW( e, e.code(), "Couldn't read next event!" ) ;
202  }
203  if( nullptr != event ) {
204  event->setAccessMode( accessMode ) ;
205  if( not _lazyUnpack ) {
206  postProcessEvent( event.get() ) ;
207  }
208  }
209  return event ;
210  }
211 
212  //----------------------------------------------------------------------------
213 
215  // create the event map if needed (i.e. not opened in direct access mode)
216  if( ! _readEventMap ) {
217  _readEventMap = true ;
218  getEventMap() ;
219  }
220  return _raMgr->getEventMap()->getNumberOfEventRecords() ;
221  }
222 
223  //----------------------------------------------------------------------------
224 
226  // create the event map if needed (i.e. not opened in direct access mode)
227  if( ! _readEventMap ){
228  _readEventMap = true ;
229  getEventMap() ;
230  }
231  return _raMgr->getEventMap()->getNumberOfRunRecords() ;
232  }
233 
234  //----------------------------------------------------------------------------
235 
237  int nRun = this->getNumberOfRuns() ;
238  runs.resize( nRun ) ;
239  auto map = _raMgr->getEventMap() ;
240  auto it = map->begin() ;
241 
242  for(int i=0 ; i <nRun ; ++i, ++it) {
243  runs[i] = it->first.RunNum ;
244  assert( it->first.EvtNum == -1 ) ;
245  }
246  }
247 
248  //----------------------------------------------------------------------------
249 
251  int nRun = this->getNumberOfRuns() ;
252  int nEvt = this->getNumberOfEvents() ;
253  events.resize( 2 * nEvt ) ;
254  auto map = _raMgr->getEventMap() ;
255  auto it = map->begin() ;
256  // This line should be equivalent to the one commented after
257  std::advance( it, nRun );
258  // for(int i=0 ; i <nRun ; ++i , ++it ) ;
259  for(int i=0 ; i < nEvt ; ++i , ++it ) {
260  events[ 2*i ] = it->first.RunNum ;
261  events[ 2*i + 1 ] = it->first.EvtNum ;
262  assert( it->first.EvtNum != -1 ) ;
263  }
264  }
265 
266  //----------------------------------------------------------------------------
267 
269  _readCollectionNames = colnames ;
270  }
271 
272  //----------------------------------------------------------------------------
273 
274  void LCReader::skipNEvents( int n ) {
275  if( n < 1 ) { // nothing to skip
276  return ;
277  }
278  int eventsSkipped = 0 ;
279  try {
280  // we skip n event header records
281  sio::api::skip_records( _stream, [&] ( const sio::record_info &recinfo ) {
282  if( recinfo._name == SIO::LCSIO::HeaderRecordName ) {
283  ++eventsSkipped ;
284  }
285  return ( eventsSkipped < n ) ;
286  } ) ;
287  // we need to skip one more record here which is an event record
288  sio::api::skip_n_records( _stream, 1 ) ;
289  }
290  catch( sio::exception &e ) {
291  if( e.code() != sio::error_code::eof ) {
292  SIO_RETHROW( e, e.code(), "SIOReader::skipNEvents: Couldn't skip events" ) ;
293  }
294  }
295  }
296 
297  //----------------------------------------------------------------------------
298 
299  std::unique_ptr<EVENT::LCRunHeader> LCReader::readRunHeader( int runNumber, int accessMode ) {
300  if( _readEventMap ) {
301  EVENT::long64 pos = _raMgr->getPosition( SIO::RunEvent( runNumber, -1 ) ) ;
302  if( pos != SIO::RunEventMap::npos ) {
303  _stream.seekg( pos ) ;
304  if( not _stream.good() ) {
305  throw IO::IOException( "[SIOReader::readRunHeader()] Can't seek stream to requested position" ) ;
306  }
307  return readNextRunHeader( accessMode ) ;
308  }
309  else {
310  return nullptr ;
311  }
312  }
313  else { // no event map ------------------
314  std::cout << " WARNING : LCReader::readRunHeader(run) called but not in direct access Mode - " << std::endl
315  << " Too avoid this WARNING create the LCReader with: " << std::endl
316  << " LCFactory::getInstance()->createLCReader( IO::LCReader::directAccess ) ; " << std::endl ;
317  }
318  return nullptr ;
319  }
320 
321  //----------------------------------------------------------------------------
322 
323  std::unique_ptr<EVENT::LCEvent> LCReader::readEvent( int runNumber, int evtNumber, int accessMode ) {
324  if( _readEventMap ) {
325  EVENT::long64 pos = _raMgr->getPosition( SIO::RunEvent( runNumber,evtNumber ) ) ;
326  if( pos != SIO::RunEventMap::npos ) {
327  _stream.seekg( pos ) ;
328  if( not _stream.good() ) {
329  throw IO::IOException( "[LCReader::readEvent()] Can't seek stream to requested position" ) ;
330  }
331  return readNextEvent( accessMode ) ;
332  }
333  else {
334  return 0 ;
335  }
336  }
337  else { // no event map ------------------
338  std::cout << " WARNING : LCReader::readEvent(run,evt) called but not in direct access Mode - " << std::endl
339  << " use fast skip mechanism instead ..." << std::endl
340  << " Too avoid this WARNING create the LCReader with: " << std::endl
341  << " LCFactory::getInstance()->createLCReader( IO::LCReader::directAccess ) ; " << std::endl ;
342  // ---- OLD code with fast skip -----------
343  bool evtFound = false ;
344  // look for the specific event in the stream directly. Very slow ...
346  IOIMPL::LCEventLazyImpl* lazyEvent = nullptr ;
347  auto validator = [&]( const sio::record_info &recinfo ) {
348  return ( recinfo._name == SIO::LCSIO::HeaderRecordName || recinfo._name == SIO::LCSIO::EventRecordName ) ;
349  } ;
350  auto processor = [&]( const sio::record_info &recinfo, const sio::buffer_span& recdata ) {
351  const bool compressed = sio::api::is_compressed( recinfo._options ) ;
352  const bool uncomp = ( compressed && not (recinfo._name == SIO::LCSIO::EventRecordName && _lazyUnpack) ) ;
353  if( uncomp ) {
354  _compBuffer->resize( recinfo._uncompressed_length ) ;
355  sio::zlib_compression compressor ;
356  compressor.uncompress( recdata, *_compBuffer ) ;
357  }
358  auto data = uncomp ? _compBuffer->span() : recdata ;
359  if( recinfo._name == SIO::LCSIO::HeaderRecordName ) {
360  if( _lazyUnpack ) {
361  lazyEvent = new IOIMPL::LCEventLazyImpl() ;
362  event.reset( lazyEvent ) ;
363  }
364  else {
365  event = std::make_unique<IOIMPL::LCEventIOImpl>() ;
366  }
367  SIO::SIOEventHeaderRecord::readBlocks( data, event.get(), _readCollectionNames ) ;
368  return true ;
369  }
370  else if( recinfo._name == SIO::LCSIO::EventRecordName ) {
371  if( nullptr == event ) {
372  throw IO::IOException( "SIOReader::readNextEvent: Event record before an EventHeader record ..." ) ;
373  }
374  // if we've found the requested event, we unpack the blocks then
375  if( event->getEventNumber() == evtNumber && event->getRunNumber() == runNumber ) {
376  if( _lazyUnpack ) {
377  _bufferMaxSize = std::max( _bufferMaxSize, _rawBuffer->size() ) ;
378  // move the buffer to the event
379  lazyEvent->setBuffer( recinfo, std::move(*_rawBuffer) ) ;
380  // re-allocate a new valid buffer
381  *_rawBuffer = sio::buffer( _bufferMaxSize ) ;
382  }
383  else {
384  SIO::SIOEventRecord::readBlocks( data, event.get(), *_eventHandlerMgr ) ;
385  }
386  evtFound = true ;
387  // event found ! stop here !
388  return false ;
389  }
390  // not the correct event number, continue looking ...
391  return true ;
392  }
393  return false ;
394  } ;
395  try {
396  sio::api::read_records( _stream, *_rawBuffer, validator, processor ) ;
397  }
398  catch( sio::exception &e ) {
399  if( e.code() != sio::error_code::eof ) {
400  SIO_RETHROW( e, e.code(), "Exception caucht while searching for event!" ) ;
401  }
402  }
403  if( not evtFound ) {
404  return nullptr ;
405  }
406  event->setAccessMode( EVENT::LCIO::READ_ONLY ) ;
407  if( not _lazyUnpack ) {
408  postProcessEvent( event.get() ) ;
409  }
410  return event ;
411  } //-- end fast skip
412  }
413 
414  //----------------------------------------------------------------------------
415 
416  void LCReader::close() {
417  _raMgr->clear() ;
418  _readEventMap = false ;
419  }
420 
421  //----------------------------------------------------------------------------
422 
423  void LCReader::readStream( const LCReaderListenerList & listeners ) {
424  readStream( listeners, std::numeric_limits<int>::max() ) ;
425  }
426 
427  //----------------------------------------------------------------------------
428 
429  void LCReader::readStream( const LCReaderListenerList & listeners, int maxRecord ) {
430  const bool readUntilEOF = (maxRecord == std::numeric_limits<int>::max()) ;
433  std::shared_ptr<IOIMPL::LCEventLazyImpl> lazyEvent = nullptr ;
434  int recordsRead = 0 ;
435  // loop over records in the stream. SIO does it nicely for us
436  auto validator = [&] ( const sio::record_info &recinfo ) {
437  return ( records.find( recinfo._name ) != records.end() ) ;
438  } ;
439  auto processor = [&] ( const sio::record_info &recinfo, const sio::buffer_span& recdata ) {
440  const bool compressed = sio::api::is_compressed( recinfo._options ) ;
441  const bool uncomp = ( compressed && not (recinfo._name == SIO::LCSIO::EventRecordName && _lazyUnpack) ) ;
442  if( uncomp ) {
443  _compBuffer->resize( recinfo._uncompressed_length ) ;
444  sio::zlib_compression compressor ;
445  compressor.uncompress( recdata, *_compBuffer ) ;
446  }
447  auto data = uncomp ? _compBuffer->span() : recdata ;
448  // LCRunHeader case
449  if( recinfo._name == SIO::LCSIO::RunRecordName ) {
450  recordsRead++ ;
451  auto runheader = std::make_shared<IOIMPL::LCRunHeaderIOImpl>() ;
452  SIO::SIORunHeaderRecord::readBlocks( data, runheader.get() ) ;
453  runheader->parameters().setValue( "LCIOFileName" , _myFilenames[ _currentFileIndex ] ) ;
454  auto iter = listeners.begin() ;
455  while( iter != listeners.end() ){
456  runheader->setReadOnly( false ) ;
457  (*iter)->processRunHeader( runheader ) ;
458  iter++ ;
459  }
460  }
461  // Event header case. Setup the event for the next record
462  else if( recinfo._name == SIO::LCSIO::HeaderRecordName ) {
463  if( _lazyUnpack ) {
464  lazyEvent = std::make_shared<IOIMPL::LCEventLazyImpl>() ;
465  event = lazyEvent ;
466  }
467  else {
468  event = std::make_shared<IOIMPL::LCEventIOImpl>() ;
469  }
470  SIO::SIOEventHeaderRecord::readBlocks( data, event.get(), _readCollectionNames ) ;
471  }
472  else if( recinfo._name == SIO::LCSIO::EventRecordName ) {
473  if( nullptr == event ) {
474  throw IO::IOException( "SIOReader::readStream: Event record before an EventHeader record ..." ) ;
475  }
476  recordsRead++ ;
477  if( _lazyUnpack ) {
478  _bufferMaxSize = std::max( _bufferMaxSize, _rawBuffer->size() ) ;
479  // move the buffer to the event
480  lazyEvent->setBuffer( recinfo, std::move(*_rawBuffer) ) ;
481  // re-allocate a new valid buffer
482  *_rawBuffer = sio::buffer( _bufferMaxSize ) ;
483  }
484  else {
485  SIO::SIOEventRecord::readBlocks( data, event.get(), *_eventHandlerMgr ) ;
486  }
487  auto iter = listeners.begin() ;
488  while( iter != listeners.end() ) {
489  if( not _lazyUnpack ) {
490  postProcessEvent( event.get() ) ;
491  }
492  event->setAccessMode( EVENT::LCIO::UPDATE ) ;
493  (*iter)->processEvent( event ) ;
494  iter++ ;
495  }
496  // free ressources here
497  event = nullptr ;
498  }
499  return (recordsRead < maxRecord) ;
500  } ;
501  try {
502  sio::api::read_records( _stream, *_rawBuffer, validator , processor ) ;
503  }
504  catch( sio::exception &e ) {
505  if( e.code() != sio::error_code::eof ) {
506  SIO_RETHROW( e, e.code(), "SIOReader::readStream: Couldn't read stream" ) ;
507  }
508  else {
509  // we caught an eof exception here
510  bool nextFileAvailable = (!_myFilenames.empty() && _currentFileIndex+1 < _myFilenames.size()) ;
511  if( nextFileAvailable ) {
512  close() ;
513  open( _myFilenames[ ++_currentFileIndex ] ) ;
514  if( readUntilEOF ) {
515  // read all
516  readStream( listeners, maxRecord ) ;
517  }
518  else {
519  // read the remaining number of records
520  readStream( listeners, maxRecord - recordsRead ) ;
521  }
522  return ;
523  }
524  else {
525  if( readUntilEOF ) {
526  return ;
527  }
528  std::stringstream message ;
529  message << "SIOReader::readStream(int maxRecord) : EOF before "
530  << maxRecord << " records read from file" << std::ends ;
531  throw IO::EndOfDataException( message.str() ) ;
532  }
533  }
534  }
535  }
536 
537  //----------------------------------------------------------------------------
538 
539  void LCReader::readNextRecord( const LCReaderListenerList & listeners ) {
540  readStream( listeners, 1 );
541  }
542 
543  //----------------------------------------------------------------------------
544 
545  void LCReader::readStream( LCReaderListener *listener ) {
546  readStream( LCReaderListenerList{listener} ) ;
547  }
548 
549  //----------------------------------------------------------------------------
550 
551  void LCReader::readStream( LCReaderListener *listener, int maxRecord ) {
552  readStream( LCReaderListenerList{listener}, maxRecord );
553  }
554 
555  //----------------------------------------------------------------------------
556 
557  void LCReader::readNextRecord( LCReaderListener *listener ) {
558  readNextRecord( LCReaderListenerList{listener} );
559  }
560 
561  //----------------------------------------------------------------------------
562 
563  void LCReader::postProcessEvent( EVENT::LCEvent *evt ) {
564  // restore the daughter relations from the parent relations
566  // check subset collection's pointers
567  char* rColChar = getenv ("LCIO_IGNORE_NULL_IN_SUBSET_COLLECTIONS") ;
568  if( nullptr != rColChar ) {
569  return;
570  }
571  const std::vector< std::string >* strVec = evt->getCollectionNames() ;
572  for( auto name = strVec->begin() ; name != strVec->end() ; name++) {
573  EVENT::LCCollection* col = evt->getCollection( *name ) ;
574  if( col->isSubset() ) {
575  for( int i=0,N=col->getNumberOfElements() ; i<N ; ++i ) {
576  if( col->getElementAt( i ) == 0 ) {
577  std::stringstream sts ;
578  sts << " SIOReader::postProcessEvent: null pointer in subset collection "
579  << *name << " at position: " << i << std::endl ;
580  throw EVENT::Exception( sts.str() ) ;
581  }
582  }
583  }
584  }
585  }
586 
587  //----------------------------------------------------------------------------
588 
589  void LCReader::getEventMap() {
590  _raMgr->createEventMap( _stream ) ;
591  }
592 
593 } // namespace
Base exception class for LCIO - all other exceptions extend this.
Definition: Exceptions.h:21
void setBuffer(const sio::record_info &recinfo, sio::buffer &&recordBuffer)
Set the event record buffer.
T empty(T...args)
static void restoreParentDaughterRelations(EVENT::LCEvent *evt)
Restore the MCParticle parent &lt;-&gt; daughter relations.
T open(T...args)
std::size_t _bufferMaxSize
Definition: LCReader.h:195
void open(const std::string &filename)
Opens a file for reading (read-only).
Definition: LCReader.cc:43
int getNumberOfEvents()
Return the number of events in the file - the file has to be open.
Definition: LCReader.cc:214
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 co...
Definition: LCReader.cc:268
T advance(T...args)
bool _readEventMap
Whether to read the event map using the random access manager.
Definition: LCReader.h:183
T endl(T...args)
static constexpr const char * RunRecordName
Definition: LCSIO.h:23
LCEvent * event
Definition: lsh.cc:80
std::ifstream _stream
The input file stream.
Definition: LCReader.h:175
T end(T...args)
Helper struct that stores run and event positions in the file.
Definition: RunEventMap.h:14
virtual const std::vector< std::string > * getCollectionNames() const =0
Returns the names of the collections in the event.
static void readBlocks(const sio::buffer_span &buffer, EVENT::LCRunHeader *rhdr)
Read the block(s) from the sio buffer and decode a run header.
Definition: LCIORecords.cc:95
std::vector< std::string > _myFilenames
The list of files to open and read.
Definition: LCReader.h:187
std::vector< std::string > _readCollectionNames
A restricted list of collections to read only.
Definition: LCReader.h:189
static void readBlocks(const sio::buffer_span &buffer, EVENT::LCEvent *event, const SIOHandlerMgr &handlerMgr)
Read the blocks (collections) from the sio buffer.
Definition: LCIORecords.cc:70
T resize(T...args)
long long long64
64 bit signed integer,e.g.to be used for timestamps
Definition: LCIOTypes.h:14
virtual LCObject * getElementAt(int index) const =0
Returns pointer to element at index - no range check, use getNumberOfEntries().
STL class.
void skipNEvents(int n)
Skips the next n events from the current position.
Definition: LCReader.cc:274
T push_back(T...args)
bool _lazyUnpack
Whether to perform the lazy unpacking of event records.
Definition: LCReader.h:185
static constexpr const int npos
Definition: RunEventMap.h:46
LCReader(const LCReader &)=delete
void getRuns(EVENT::IntVec &runs)
Return the run numbers of the runs (run headers) in the file - the file has to be open...
Definition: LCReader.cc:236
T close(T...args)
virtual LCCollection * getCollection(const std::string &name) const =0
Returns the collection for the given name.
virtual bool isSubset() const =0
True if the collection holds a subset of objects from other collections.
T str(T...args)
IOException used for reading/writing errors.
Definition: Exceptions.h:92
Implementation of a LCReader for parallel processing use.
Definition: LCReader.h:37
std::unique_ptr< EVENT::LCEvent > readNextEvent(int accessMode=EVENT::LCIO::READ_ONLY)
Reads the next event from the file.
Definition: LCReader.cc:135
T max(T...args)
std::shared_ptr< sio::buffer > _rawBuffer
The raw buffer for extracting bytes from the stream.
Definition: LCReader.h:177
virtual int getNumberOfElements() const =0
Returns the number of elements in the collection.
std::shared_ptr< SIO::SIOHandlerMgr > _eventHandlerMgr
The collection block handler manager for events.
Definition: LCReader.h:181
std::unique_ptr< EVENT::LCRunHeader > readNextRunHeader(int accessMode=EVENT::LCIO::READ_ONLY)
Reads the next run header from the file.
Definition: LCReader.cc:86
T find(T...args)
T size(T...args)
Implementation of the event class with a lazy record unpacking.
The main event interface.
Definition: LCEvent.h:31
STL class.
T ends(T...args)
The generic collection used in LCIO.
Definition: LCCollection.h:29
std::shared_ptr< SIO::LCIORandomAccessMgr > _raMgr
The random access manager for event/run random access in the file.
Definition: LCReader.h:193
T begin(T...args)
void getEventMap()
Definition: LCReader.cc:589
LCReaderListener class Interface for MT::LCReader::readStream() callbacks.
std::shared_ptr< sio::buffer > _compBuffer
The raw buffer for uncompression.
Definition: LCReader.h:179
EndOfDataException for signaling the end of a data stream.
Definition: Exceptions.h:108
static constexpr const char * HeaderRecordName
Definition: LCSIO.h:27
T is_open(T...args)
void postProcessEvent(EVENT::LCEvent *evt)
Definition: LCReader.cc:563
unsigned int _currentFileIndex
The current file list index when opening multiple files.
Definition: LCReader.h:191
int getNumberOfRuns()
Return the number of runs (run headers) in the file - the file has to be open.
Definition: LCReader.cc:225
static constexpr const char * EventRecordName
Definition: LCSIO.h:25
void getEvents(EVENT::IntVec &events)
Return the run and event numbers of the events in the file - the file has to be open.
Definition: LCReader.cc:250
static void readBlocks(const sio::buffer_span &buffer, EVENT::LCEvent *event, const std::vector< std::string > &readCol)
Read an event header record.
Definition: LCIORecords.cc:17
void close()
Closes the output file/stream etc.
Definition: LCReader.cc:416
EVENT::long64 long64
Definition: LCReader.cc:27