LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
LCReader.h
Go to the documentation of this file.
1 #ifndef MT_LCREADER_H
2 #define MT_LCREADER_H 1
3 
4 // -- std headers
5 #include <string>
6 #include <vector>
7 #include <fstream>
8 #include <memory>
9 
10 // -- lcio headers
11 #include "MT/Types.h"
12 #include "MT/LCReaderListener.h"
13 #include "LCIOSTLTypes.h"
14 #include "LCIOTypes.h"
15 #include "EVENT/LCIO.h"
16 
17 // need to make forward declaration to
18 // avoid lcio dependencies to include directly sio headers
19 
20 namespace sio {
21  class buffer ;
22 }
23 
24 namespace SIO {
25  class LCIORandomAccessMgr ;
26  class SIOHandlerMgr ;
27 }
28 
29 namespace MT {
30 
37 class LCReader {
38 private:
39  // No copy
40  LCReader(const LCReader&) = delete;
41  LCReader& operator=(const LCReader&) = delete;
42 
43 public:
45  static constexpr int directAccess = 0x00000001 << 0 ;
47  static constexpr int lazyUnpack = 0x00000002 << 0 ;
48 
49 public:
50  ~LCReader() = default;
51 
57  LCReader( int lcReaderFlag ) ;
58 
61  void open( const std::string & filename );
62 
68  void open( const std::vector<std::string> & filenames ) ;
69 
74  std::unique_ptr<EVENT::LCRunHeader> readNextRunHeader( int accessMode = EVENT::LCIO::READ_ONLY ) ;
75 
80  std::unique_ptr<EVENT::LCEvent> readNextEvent( int accessMode = EVENT::LCIO::READ_ONLY ) ;
81 
86  int getNumberOfEvents() ;
87 
92  int getNumberOfRuns() ;
93 
98  void getRuns( EVENT::IntVec & runs ) ;
99 
106  void getEvents( EVENT::IntVec & events ) ;
107 
112  void setReadCollectionNames( const std::vector<std::string> & colnames ) ;
113 
116  void skipNEvents( int n ) ;
117 
121  std::unique_ptr<EVENT::LCRunHeader> readRunHeader( int runNumber , int accessMode = EVENT::LCIO::READ_ONLY ) ;
122 
126  std::unique_ptr<EVENT::LCEvent> readEvent( int runNumber, int evtNumber , int accessMode = EVENT::LCIO::READ_ONLY ) ;
127 
130  void close() ;
131 
136  void readStream( const LCReaderListenerList & listeners ) ;
137 
142  void readStream( const LCReaderListenerList & listeners , int maxRecord ) ;
143 
148  void readNextRecord( const LCReaderListenerList & listeners ) ;
149 
154  void readStream( LCReaderListener *listener ) ;
155 
160  void readStream( LCReaderListener *listener , int maxRecord ) ;
161 
166  void readNextRecord( LCReaderListener *listener ) ;
167 
168 private:
169  // void readRecord( const sio::record_map &records , sio::record_read_result &readResult ) ;
170  void postProcessEvent( EVENT::LCEvent *evt ) ;
171  void getEventMap() ;
172 
173 private:
177  std::shared_ptr<sio::buffer> _rawBuffer {nullptr} ; //{1*sio::mbyte} ;
179  std::shared_ptr<sio::buffer> _compBuffer {nullptr} ; //{2*sio::mbyte} ;
183  bool _readEventMap {false} ;
185  bool _lazyUnpack {false} ;
191  unsigned int _currentFileIndex {0} ;
196 }; // class
197 
198 } // namespace MT
199 
200 #endif /* ifndef MT_LCREADER_H */
std::size_t _bufferMaxSize
Definition: LCReader.h:195
void readNextRecord(const LCReaderListenerList &listeners)
Reads the input stream and notifies listeners according to the object type found in the stream...
Definition: LCReader.cc:539
void readStream(const LCReaderListenerList &listeners)
Reads the input stream and notifies listeners according to the object type found in the stream...
Definition: LCReader.cc:423
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
bool _readEventMap
Whether to read the event map using the random access manager.
Definition: LCReader.h:183
std::ifstream _stream
The input file stream.
Definition: LCReader.h:175
std::vector< std::string > _myFilenames
The list of files to open and read.
Definition: LCReader.h:187
std::unique_ptr< EVENT::LCEvent > readEvent(int runNumber, int evtNumber, int accessMode=EVENT::LCIO::READ_ONLY)
Reads the specified event from file.
Definition: LCReader.cc:323
std::vector< std::string > _readCollectionNames
A restricted list of collections to read only.
Definition: LCReader.h:189
std::unique_ptr< EVENT::LCRunHeader > readRunHeader(int runNumber, int accessMode=EVENT::LCIO::READ_ONLY)
Reads the specified runHeader from file.
Definition: LCReader.cc:299
STL class.
void skipNEvents(int n)
Skips the next n events from the current position.
Definition: LCReader.cc:274
static constexpr int directAccess
Bit for direct access.
Definition: LCReader.h:45
bool _lazyUnpack
Whether to perform the lazy unpacking of event records.
Definition: LCReader.h:185
~LCReader()=default
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
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
std::shared_ptr< sio::buffer > _rawBuffer
The raw buffer for extracting bytes from the stream.
Definition: LCReader.h:177
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
The main event interface.
Definition: LCEvent.h:31
STL class.
std::shared_ptr< SIO::LCIORandomAccessMgr > _raMgr
The random access manager for event/run random access in the file.
Definition: LCReader.h:193
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
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
static constexpr int lazyUnpack
Bit for lazy unpacking of event records.
Definition: LCReader.h:47
int getNumberOfRuns()
Return the number of runs (run headers) in the file - the file has to be open.
Definition: LCReader.cc:225
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
STL class.
void close()
Closes the output file/stream etc.
Definition: LCReader.cc:416
LCReader & operator=(const LCReader &)=delete