BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
RootIoSvc Class Reference

Service that implements the IRunable interface, to control the event loop. Based on RootIoSvc of Glast. More...

Inheritance diagram for RootIoSvc:

Public Member Functions

virtual StatusCode run ()
 for the IRunnable interfce
virtual StatusCode initialize ()
 perform initializations for this service.
virtual StatusCode finalize ()
 perform the finalization, as required for a service.
virtual StatusCode queryInterface (const InterfaceID &riid, void **ppvUnknown)
 Query interface.
virtual void handle (const Incident &inc)
 Handles incidents, implementing IIncidentListener interface.
virtual int getEvtMax ()
virtual void setRootEvtMax (unsigned int max)
virtual void setRootTimeMax (unsigned int max)
virtual void registerRootTree (TChain *ch)
virtual bool setIndex (int i)
virtual int index ()
virtual bool setRunEventPair (std::pair< int, int > ids)
virtual std::pair< int, int > runEventPair ()
virtual int getAutoSaveInterval ()
Public Member Functions inherited from IRootIoSvc
 DeclareInterfaceID (IRootIoSvc, 1, 0)
 DeclareInterfaceID (IRootIoSvc, 1, 0)
 DeclareInterfaceID (IRootIoSvc, 1, 0)

Protected Member Functions

 RootIoSvc (const std::string &name, ISvcLocator *al)
 Standard Constructor.
virtual ~RootIoSvc ()
 destructor

Friends

class SvcFactory< RootIoSvc >
 Allow SvcFactory to instantiate the service.

Detailed Description

Service that implements the IRunable interface, to control the event loop. Based on RootIoSvc of Glast.

Definition at line 41 of file RootIoSvc.cxx.

Constructor & Destructor Documentation

◆ RootIoSvc()

RootIoSvc::RootIoSvc ( const std::string & name,
ISvcLocator * al )
protected

Standard Constructor.

Definition at line 117 of file RootIoSvc.cxx.

117 : Service( name, svc ) {
118
119 declareProperty( "EvtMax", m_evtMax = 0 );
120 declareProperty( "StartTime", m_startTime = 0 );
121 declareProperty( "EndTime", m_endTime = 0 );
122 declareProperty( "AutoSaveInterval", m_autoSaveInterval = 1000 );
123 declareProperty( "StartingIndex", m_index = -1 );
124 m_rootEvtMax = 0;
125 // m_index = -1;
126 m_runEventPair = std::pair<int, int>( -1, -1 );
127 m_chainCol.clear();
128}

Referenced by SvcFactory< RootIoSvc >.

◆ ~RootIoSvc()

RootIoSvc::~RootIoSvc ( )
protectedvirtual

destructor

Standard Destructor.

Definition at line 131 of file RootIoSvc.cxx.

131{ m_chainCol.clear(); }

Member Function Documentation

◆ finalize()

StatusCode RootIoSvc::finalize ( )
virtual

perform the finalization, as required for a service.

Definition at line 164 of file RootIoSvc.cxx.

164 {
165 StatusCode status = StatusCode::SUCCESS;
166 return status;
167}

◆ getAutoSaveInterval()

virtual int RootIoSvc::getAutoSaveInterval ( )
inlinevirtual

Implements IRootIoSvc.

Definition at line 78 of file RootIoSvc.cxx.

78{ return m_autoSaveInterval; };

◆ getEvtMax()

virtual int RootIoSvc::getEvtMax ( )
inlinevirtual

Implements IRootIoSvc.

Definition at line 64 of file RootIoSvc.cxx.

64{ return m_evtMax; };

◆ handle()

void RootIoSvc::handle ( const Incident & inc)
virtual

Handles incidents, implementing IIncidentListener interface.

Definition at line 225 of file RootIoSvc.cxx.

225 {
226 if ( inc.type() == "BeginEvent" ) beginEvent();
227 else if ( inc.type() == "EndEvent" ) endEvent();
228}

◆ index()

virtual int RootIoSvc::index ( )
inlinevirtual

Implements IRootIoSvc.

Definition at line 73 of file RootIoSvc.cxx.

73{ return m_index; };

◆ initialize()

StatusCode RootIoSvc::initialize ( )
virtual

perform initializations for this service.

Definition at line 134 of file RootIoSvc.cxx.

134 {
135 StatusCode status = Service::initialize();
136
137 // bind all of the properties for this service
138 // setProperties ();
139
140 // open the message log
141 MsgStream log( msgSvc(), name() );
142
143 status = serviceLocator()->queryInterface( IAppMgrUI::interfaceID(), (void**)&m_appMgrUI );
144
145 // use the incident service to register begin, end events
146 IIncidentSvc* incsvc = 0;
147 status = service( "IncidentSvc", incsvc, true );
148
149 if ( status.isFailure() ) return status;
150
151 incsvc->addListener( this, "BeginEvent", 100 );
152 incsvc->addListener( this, "EndEvent", 0 );
153
154 // Tell ROOT to reset signals to their default behavior
155 gSystem->ResetSignal( kSigBus );
156 gSystem->ResetSignal( kSigSegmentationViolation );
157 gSystem->ResetSignal( kSigIllegalInstruction );
158 gSystem->ResetSignal( kSigFloatingException );
159
160 return StatusCode::SUCCESS;
161}
IMessageSvc * msgSvc()

◆ queryInterface()

StatusCode RootIoSvc::queryInterface ( const InterfaceID & riid,
void ** ppvUnknown )
virtual

Query interface.

Definition at line 170 of file RootIoSvc.cxx.

170 {
171 if ( IID_IRootIoSvc.versionMatch( riid ) ) { *ppvInterface = (IRootIoSvc*)this; }
172 else if ( IRunable::interfaceID().versionMatch( riid ) ) { *ppvInterface = (IRunable*)this; }
173 else if ( IIncidentListener::interfaceID().versionMatch( riid ) )
174 { *ppvInterface = (IIncidentListener*)this; }
175 else { return Service::queryInterface( riid, ppvInterface ); }
176
177 addRef();
178 return StatusCode::SUCCESS;
179}

◆ registerRootTree()

void RootIoSvc::registerRootTree ( TChain * ch)
virtual

Implements IRootIoSvc.

Definition at line 198 of file RootIoSvc.cxx.

198{ m_chainCol.push_back( ch ); }

◆ run()

StatusCode RootIoSvc::run ( )
virtual

for the IRunnable interfce

Definition at line 239 of file RootIoSvc.cxx.

239 {
240 // Purpose and Method: Control the event loop
241
242 StatusCode status = StatusCode::FAILURE;
243 MsgStream log( msgSvc(), name() );
244
245 if ( 0 == m_appMgrUI ) return status;
246
247 IProperty* propMgr = 0;
248 status = serviceLocator()->service( "ApplicationMgr", propMgr );
249 if ( status.isFailure() )
250 {
251 log << MSG::ERROR << "Unable to locate PropertyManager Service" << endmsg;
252 return status;
253 }
254
255 IntegerProperty evtMax( "EvtMax", 0 );
256 status = propMgr->getProperty( &evtMax );
257 if ( status.isFailure() ) return status;
258
259 // Determine if the min number of ROOT events is less than the
260 // requested number of events in the jobOptions file
261 IntegerProperty rootEvtMax( "EvtMax", m_rootEvtMax );
262 if ( rootEvtMax < evtMax ) setProperty( rootEvtMax );
263 else setProperty( evtMax );
264
265 // now find the top alg so we can monitor its error count
266 //
267 IAlgManager* theAlgMgr;
268 status = serviceLocator()->getService( "ApplicationMgr", IAlgManager::interfaceID(),
269 (IInterface*&)theAlgMgr );
270 IAlgorithm* theIAlg;
271 Algorithm* theAlgorithm = 0;
272 IntegerProperty errorProperty( "ErrorCount", 0 );
273
274 status = theAlgMgr->getAlgorithm( "Top", theIAlg );
275 if ( status.isSuccess() )
276 {
277 try
278 { theAlgorithm = dynamic_cast<Algorithm*>( theIAlg ); } catch ( ... )
279 { status = StatusCode::FAILURE; }
280 }
281 if ( status.isFailure() )
282 {
283 log << MSG::WARNING << "Could not find algorithm 'Top'; will not monitor errors" << endmsg;
284 }
285
286 // loop over the events
287
288 int eventNumber = 0;
289 double currentTime = m_startTime;
290
291 {
292 bool noend = true;
293 log << MSG::INFO << "Runable interface starting event loop as :";
294 if ( m_evtMax > 0 )
295 {
296 log << " MaxEvt = " << m_evtMax;
297 noend = false;
298 }
299 if ( m_endTime > 0 )
300 {
301 log << " EndTime= " << m_endTime;
302 noend = false;
303 }
304 log << endmsg;
305
306 if ( noend )
307 {
308 log << MSG::WARNING << "No end condition specified: will not process any events!"
309 << endmsg;
310 }
311 }
312 // Not yet using time as a control on the event loop for ROOT
313 while ( m_evtMax > 0 && eventNumber < m_evtMax || m_endTime > 0 && currentTime < m_endTime )
314 {
315
316 status = m_appMgrUI->nextEvent( 1 ); // currently, always success
317
318 // the single event may have created a failure. Check the ErrorCount propery of the Top
319 // alg.
320 if ( theAlgorithm != 0 ) theAlgorithm->getProperty( &errorProperty );
321 if ( status.isFailure() || errorProperty.value() > 0 ) { status = StatusCode::FAILURE; }
322
323 if ( status.isFailure() ) break;
324 // if(flux!=0){
325 // currentTime = flux->gpsTime();
326 // }
327 eventNumber++;
328 }
329 if ( status.isFailure() )
330 { log << MSG::ERROR << "Terminating RootIoSvc loop due to error" << endmsg; }
331 else if ( m_endTime > 0 && currentTime >= m_endTime )
332 { log << MSG::INFO << "Loop terminated by time " << endmsg; }
333 else { log << MSG::INFO << "Processing loop terminated by event count" << endmsg; }
334 return status;
335}

◆ runEventPair()

virtual std::pair< int, int > RootIoSvc::runEventPair ( )
inlinevirtual

Implements IRootIoSvc.

Definition at line 76 of file RootIoSvc.cxx.

76{ return m_runEventPair; };

◆ setIndex()

bool RootIoSvc::setIndex ( int i)
virtual

Implements IRootIoSvc.

Definition at line 200 of file RootIoSvc.cxx.

200 {
201 if ( i < 0 ) return false;
202 std::vector<TChain*>::iterator it;
203 for ( it = m_chainCol.begin(); it != m_chainCol.end(); it++ )
204 {
205 if ( i >= ( *it )->GetEntries() ) return false;
206 }
207 m_index = i;
208 m_runEventPair = std::pair<int, int>( -1, -1 );
209 return true;
210}

◆ setRootEvtMax()

void RootIoSvc::setRootEvtMax ( unsigned int max)
virtual

Implements IRootIoSvc.

Definition at line 181 of file RootIoSvc.cxx.

181 {
182 // Purpose and Method: Allow users of the RootIoSvc to specify the number
183 // of events found in their ROOT files
184 if ( m_rootEvtMax == 0 )
185 {
186 m_rootEvtMax = max;
187 return;
188 }
189
190 if ( m_rootEvtMax > max ) m_rootEvtMax = max;
191}
#define max(a, b)

◆ setRootTimeMax()

void RootIoSvc::setRootTimeMax ( unsigned int max)
virtual

Implements IRootIoSvc.

Definition at line 193 of file RootIoSvc.cxx.

193 {
194 // Not yet used
195 return;
196}

◆ setRunEventPair()

bool RootIoSvc::setRunEventPair ( std::pair< int, int > ids)
virtual

Implements IRootIoSvc.

Definition at line 212 of file RootIoSvc.cxx.

212 {
213 std::vector<TChain*>::iterator it;
214 for ( it = m_chainCol.begin(); it != m_chainCol.end(); it++ )
215 {
216 int readInd = ( *it )->GetEntryNumberWithIndex( ids.first, ids.second );
217 if ( ( readInd < 0 ) || ( readInd >= ( *it )->GetEntries() ) ) return false;
218 }
219 m_runEventPair = ids;
220 m_index = -1;
221 return true;
222}

◆ SvcFactory< RootIoSvc >

friend class SvcFactory< RootIoSvc >
friend

Allow SvcFactory to instantiate the service.

Definition at line 89 of file RootIoSvc.cxx.


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