LCIO  02.17
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SIOReader.cc
Go to the documentation of this file.
1 #include "SIO/SIOReader.h"
2 
3 // // -- lcio headers
4 // #include "SIO/LCSIO.h"
5 #include "IOIMPL/LCEventIOImpl.h"
7 // #include "Exceptions.h"
8 //
9 // #include <sio/exception.h>
10 // #include <sio/api.h>
11 // #include <sio/compression/zlib.h>
12 //
13 // #include <sys/stat.h>
14 // #include <sstream>
15 // #include <algorithm>
16 #include <limits>
17 // #include <assert.h>
18 
19 namespace SIO {
20 
21 
22  SIOReader::SIOReader( int lcReaderFlag ) :
23  _reader( lcReaderFlag ) {
24  /* nop */
25  }
26 
27  //----------------------------------------------------------------------------
28 
30  /* nop */
31  }
32 
33  //----------------------------------------------------------------------------
34 
36  _reader.setReadCollectionNames( colnames ) ;
37  }
38 
39  //----------------------------------------------------------------------------
40 
41  void SIOReader::open(const std::vector<std::string>& filenames) {
42  _reader.open( filenames ) ;
43  }
44 
45  //----------------------------------------------------------------------------
46 
47  void SIOReader::open(const std::string& filename) {
48  _reader.open( filename ) ;
49  }
50 
51  //----------------------------------------------------------------------------
52 
54  return _reader.getNumberOfEvents() ;
55  }
56 
57  //----------------------------------------------------------------------------
58 
60  return _reader.getNumberOfRuns() ;
61  }
62 
63  //----------------------------------------------------------------------------
64 
66  _reader.getRuns( runs ) ;
67  }
68 
69  //----------------------------------------------------------------------------
70 
72  _reader.getEvents( events ) ;
73  }
74 
75  //----------------------------------------------------------------------------
76 
78  return readNextRunHeader( EVENT::LCIO::READ_ONLY ) ;
79  }
80 
81  //----------------------------------------------------------------------------
82 
84 
85  if( _currentRun != nullptr ){
86  delete _currentRun ;
87  }
88  _currentRun = _reader.readNextRunHeader( accessMode ).release() ;
89 
90  return _currentRun ;
91  }
92 
93  //----------------------------------------------------------------------------
94 
96  return readNextEvent( EVENT::LCIO::READ_ONLY ) ;
97  }
98 
99  //----------------------------------------------------------------------------
100 
102 
103  if( _currentEvent != nullptr ){
104  delete _currentEvent ;
105  }
106  _currentEvent = _reader.readNextEvent( accessMode ).release() ;
107 
108  return _currentEvent ;
109  }
110 
111  //----------------------------------------------------------------------------
112 
113  void SIOReader::skipNEvents( int n ) {
114  _reader.skipNEvents( n ) ;
115  }
116 
117  //----------------------------------------------------------------------------
118 
120  return readRunHeader( runNumber, EVENT::LCIO::READ_ONLY ) ;
121  }
122 
123  //----------------------------------------------------------------------------
124 
125  EVENT::LCRunHeader * SIOReader::readRunHeader(int runNumber, int accessMode) {
126 
127  if( _currentRun != nullptr ){
128  delete _currentRun ;
129  }
130  _currentRun = _reader.readRunHeader( runNumber, accessMode ).release() ;
131 
132  return _currentRun ;
133  }
134 
135  //----------------------------------------------------------------------------
136 
137  EVENT::LCEvent * SIOReader::readEvent(int runNumber, int evtNumber) {
138  return readEvent( runNumber, evtNumber , EVENT::LCIO::READ_ONLY ) ;
139  }
140 
141  //----------------------------------------------------------------------------
142 
143  EVENT::LCEvent * SIOReader::readEvent(int runNumber, int evtNumber, int accessMode) {
144 
145  if( _currentEvent != nullptr ){
146  delete _currentEvent ;
147  }
148  _currentEvent = _reader.readEvent( runNumber, evtNumber, accessMode ).release() ;
149 
150  return _currentEvent ;
151  }
152 
153  //----------------------------------------------------------------------------
154 
156  _reader.close() ;
157  }
158 
159  //----------------------------------------------------------------------------
160 
163  }
164 
165  //----------------------------------------------------------------------------
166 
169  }
170 
171  //----------------------------------------------------------------------------
172 
175  }
176 
177  //----------------------------------------------------------------------------
178 
181  }
182 
183  //----------------------------------------------------------------------------
184 
187  }
188 
189  //----------------------------------------------------------------------------
190 
191  void SIOReader::readStream(int maxRecord) {
192  _reader.readStream( this, maxRecord ) ;
193  }
194 
195  //----------------------------------------------------------------------------
196 
198  auto eventImpl = dynamic_cast<IOIMPL::LCEventIOImpl*>( event.get() ) ;
200  while( iter != _evtListeners.end() ) {
201  eventImpl->setAccessMode( EVENT::LCIO::UPDATE ) ;
202  (*iter)->modifyEvent( eventImpl ) ;
203  eventImpl->setAccessMode( EVENT::LCIO::READ_ONLY ) ; // set the proper acces mode
204  (*iter)->processEvent( eventImpl ) ;
205  iter++ ;
206  }
207  }
208 
209  //----------------------------------------------------------------------------
210 
212  auto hdrImpl = dynamic_cast<IOIMPL::LCRunHeaderIOImpl*>( hdr.get() ) ;
214  while( iter != _runListeners.end() ){
215  hdrImpl->setReadOnly( false ) ;
216  (*iter)->modifyRunHeader( hdrImpl ) ;
217  hdrImpl->setReadOnly( true ) ;
218  (*iter)->processRunHeader( hdrImpl ) ;
219  iter++ ;
220  }
221  }
222 
223 } // namespace
void registerLCRunListener(IO::LCRunListener *ls) override
Registers a listener for reading LCEventsLCRunHeaders from a stream.
Definition: SIOReader.cc:173
Adding stuff needed for io (friend declarations, etc.)
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
Interface for the run header.
Definition: LCRunHeader.h:23
int getNumberOfEvents()
Return the number of events in the file - the file has to be open.
Definition: LCReader.cc:214
EVENT::LCEvent * readEvent(int runNumber, int evtNumber) override
Reads the specified event from file.
Definition: SIOReader.cc:137
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
LCEvent * event
Definition: lsh.cc:80
T end(T...args)
MT::LCReader _reader
The underlying implementation of the LCReader.
Definition: SIOReader.h:207
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::unique_ptr< EVENT::LCRunHeader > readRunHeader(int runNumber, int accessMode=EVENT::LCIO::READ_ONLY)
Reads the specified runHeader from file.
Definition: LCReader.cc:299
SIOReader(int lcReaderFlag=0)
Default constructor.
Definition: SIOReader.cc:22
EVENT::LCRunHeader * readNextRunHeader() override
Reads the next run header from the file.
Definition: SIOReader.cc:77
Listener for the occurence of LCEvents when reading a stream.
STL class.
void skipNEvents(int n)
Skips the next n events from the current position.
Definition: LCReader.cc:274
void getRuns(EVENT::IntVec &runs) override
Return the run numbers of the runs (run headers) in the file - the file has to be open...
Definition: SIOReader.cc:65
void getEvents(EVENT::IntVec &events) override
Return the run and event numbers of the events in the file - the file has to be open.
Definition: SIOReader.cc:71
void removeLCEventListener(IO::LCEventListener *ls) override
Remove a listener for reading LCEvents from a stream.
Definition: SIOReader.cc:167
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
int getNumberOfEvents() override
Return the number of events in the file - the file has to be open.
Definition: SIOReader.cc:53
virtual ~SIOReader()
Destructor.
Definition: SIOReader.cc:29
T erase(T...args)
EVENT::LCRunHeader * readRunHeader(int runNumber) override
Reads the specified runHeader from file.
Definition: SIOReader.cc:119
EVENT::LCEvent * readNextEvent() override
Reads the next event from the file.
Definition: SIOReader.cc:95
void open(const std::vector< std::string > &filenames) override
Opens a list of files for reading (read-only).
Definition: SIOReader.cc:41
Listener for the occurence of LCRunHeader when reading a stream.
Definition: LCRunListener.h:24
void setReadCollectionNames(const std::vector< std::string > &colnames) override
Limit the collection names that are going to be read to the subset given in the vector - all other co...
Definition: SIOReader.cc:35
std::unique_ptr< EVENT::LCEvent > readNextEvent(int accessMode=EVENT::LCIO::READ_ONLY)
Reads the next event from the file.
Definition: LCReader.cc:135
Adding stuff needed for io (friend declarations, etc.)
Definition: LCEventIOImpl.h:26
void registerLCEventListener(IO::LCEventListener *ls) override
Registers a listener for reading LCEvents from a stream.
Definition: SIOReader.cc:161
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 get(T...args)
T insert(T...args)
T find(T...args)
STL class.
The main event interface.
Definition: LCEvent.h:31
void removeLCRunListener(IO::LCRunListener *ls) override
Remove a listener for reading LCRunHeaders from a stream.
Definition: SIOReader.cc:179
EVENT::LCRunHeader * _currentRun
pointer to current RunHeader
Definition: SIOReader.h:215
int getNumberOfRuns() override
Return the number of runs (run headers) in the file - the file has to be open.
Definition: SIOReader.cc:59
T begin(T...args)
void processRunHeader(std::shared_ptr< EVENT::LCRunHeader > hdr) override
Definition: SIOReader.cc:211
void processEvent(std::shared_ptr< EVENT::LCEvent > event) override
Definition: SIOReader.cc:197
EVENT::LCEvent * _currentEvent
pointer to current Event
Definition: SIOReader.h:213
void readStream() override
Reads the input stream and notifies registered listeners according to the object type found in the st...
Definition: SIOReader.cc:185
std::set< IO::LCEventListener * > _evtListeners
The event listeners.
Definition: SIOReader.h:211
void close() override
Closes the output file/stream etc.
Definition: SIOReader.cc:155
int getNumberOfRuns()
Return the number of runs (run headers) in the file - the file has to be open.
Definition: LCReader.cc:225
void skipNEvents(int n) override
Skips the next n events from the current position.
Definition: SIOReader.cc:113
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
void close()
Closes the output file/stream etc.
Definition: LCReader.cc:416
std::set< IO::LCRunListener * > _runListeners
The run listeners.
Definition: SIOReader.h:209