9#include "GaudiKernel/Algorithm.h"
10#include "GaudiKernel/GaudiException.h"
11#include "GaudiKernel/IAlgManager.h"
12#include "GaudiKernel/IAppMgrUI.h"
13#include "GaudiKernel/IIncidentListener.h"
14#include "GaudiKernel/IIncidentSvc.h"
15#include "GaudiKernel/MsgStream.h"
17#include "CLHEP/Random/Random.h"
30#include "Gaudi/Property.h"
31#include "GaudiKernel/IRunable.h"
32#include "GaudiKernel/Service.h"
35#include "RootIoSvc/IRootIoSvc.h"
42 virtual public IIncidentListener,
44 virtual public IRunable {
47 virtual StatusCode
run();
59 virtual StatusCode
queryInterface(
const InterfaceID& riid,
void** ppvUnknown );
62 virtual void handle(
const Incident& inc );
73 virtual int index() {
return m_index; };
76 virtual std::pair<int, int>
runEventPair() {
return m_runEventPair; };
82 RootIoSvc(
const std::string& name, ISvcLocator* al );
95 IAppMgrUI* m_appMgrUI;
96 IntegerProperty m_evtMax;
97 IntegerProperty m_autoSaveInterval;
100 DoubleProperty m_startTime;
101 DoubleProperty m_endTime;
103 unsigned int m_rootEvtMax;
105 std::pair<int, int> m_runEventPair;
106 std::vector<TChain*> m_chainCol;
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 );
126 m_runEventPair = std::pair<int, int>( -1, -1 );
135 StatusCode status = Service::initialize();
141 MsgStream log(
msgSvc(), name() );
143 status = serviceLocator()->queryInterface( IAppMgrUI::interfaceID(), (
void**)&m_appMgrUI );
146 IIncidentSvc* incsvc = 0;
147 status = service(
"IncidentSvc", incsvc,
true );
149 if ( status.isFailure() )
return status;
151 incsvc->addListener(
this,
"BeginEvent", 100 );
152 incsvc->addListener(
this,
"EndEvent", 0 );
155 gSystem->ResetSignal( kSigBus );
156 gSystem->ResetSignal( kSigSegmentationViolation );
157 gSystem->ResetSignal( kSigIllegalInstruction );
158 gSystem->ResetSignal( kSigFloatingException );
160 return StatusCode::SUCCESS;
165 StatusCode status = StatusCode::SUCCESS;
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 ); }
178 return StatusCode::SUCCESS;
184 if ( m_rootEvtMax == 0 )
190 if ( m_rootEvtMax >
max ) m_rootEvtMax =
max;
201 if ( i < 0 )
return false;
202 std::vector<TChain*>::iterator it;
203 for ( it = m_chainCol.begin(); it != m_chainCol.end(); it++ )
205 if ( i >= ( *it )->GetEntries() )
return false;
208 m_runEventPair = std::pair<int, int>( -1, -1 );
213 std::vector<TChain*>::iterator it;
214 for ( it = m_chainCol.begin(); it != m_chainCol.end(); it++ )
216 int readInd = ( *it )->GetEntryNumberWithIndex( ids.first, ids.second );
217 if ( ( readInd < 0 ) || ( readInd >= ( *it )->GetEntries() ) )
return false;
219 m_runEventPair = ids;
226 if ( inc.type() ==
"BeginEvent" ) beginEvent();
227 else if ( inc.type() ==
"EndEvent" ) endEvent();
230void RootIoSvc::beginEvent()
233void RootIoSvc::endEvent()
236 m_runEventPair = std::pair<int, int>( -1, -1 );
242 StatusCode status = StatusCode::FAILURE;
243 MsgStream log(
msgSvc(), name() );
245 if ( 0 == m_appMgrUI )
return status;
247 IProperty* propMgr = 0;
248 status = serviceLocator()->service(
"ApplicationMgr", propMgr );
249 if ( status.isFailure() )
251 log << MSG::ERROR <<
"Unable to locate PropertyManager Service" << endmsg;
255 IntegerProperty evtMax(
"EvtMax", 0 );
256 status = propMgr->getProperty( &evtMax );
257 if ( status.isFailure() )
return status;
261 IntegerProperty rootEvtMax(
"EvtMax", m_rootEvtMax );
262 if ( rootEvtMax < evtMax ) setProperty( rootEvtMax );
263 else setProperty( evtMax );
267 IAlgManager* theAlgMgr;
268 status = serviceLocator()->getService(
"ApplicationMgr", IAlgManager::interfaceID(),
269 (IInterface*&)theAlgMgr );
271 Algorithm* theAlgorithm = 0;
272 IntegerProperty errorProperty(
"ErrorCount", 0 );
274 status = theAlgMgr->getAlgorithm(
"Top", theIAlg );
275 if ( status.isSuccess() )
278 { theAlgorithm =
dynamic_cast<Algorithm*
>( theIAlg ); }
catch ( ... )
279 { status = StatusCode::FAILURE; }
281 if ( status.isFailure() )
283 log << MSG::WARNING <<
"Could not find algorithm 'Top'; will not monitor errors" << endmsg;
289 double currentTime = m_startTime;
293 log << MSG::INFO <<
"Runable interface starting event loop as :";
296 log <<
" MaxEvt = " << m_evtMax;
301 log <<
" EndTime= " << m_endTime;
308 log << MSG::WARNING <<
"No end condition specified: will not process any events!"
313 while ( m_evtMax > 0 && eventNumber < m_evtMax || m_endTime > 0 && currentTime < m_endTime )
316 status = m_appMgrUI->nextEvent( 1 );
320 if ( theAlgorithm != 0 ) theAlgorithm->getProperty( &errorProperty );
321 if ( status.isFailure() || errorProperty.value() > 0 ) { status = StatusCode::FAILURE; }
323 if ( status.isFailure() )
break;
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; }
virtual bool setRunEventPair(std::pair< int, int > ids)
virtual std::pair< int, int > runEventPair()
virtual void registerRootTree(TChain *ch)
virtual StatusCode run()
for the IRunnable interfce
virtual StatusCode initialize()
perform initializations for this service.
virtual void setRootEvtMax(unsigned int max)
virtual void setRootTimeMax(unsigned int max)
RootIoSvc(const std::string &name, ISvcLocator *al)
Standard Constructor.
virtual bool setIndex(int i)
virtual StatusCode finalize()
perform the finalization, as required for a service.
virtual int getAutoSaveInterval()
virtual void handle(const Incident &inc)
Handles incidents, implementing IIncidentListener interface.
virtual ~RootIoSvc()
destructor
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvUnknown)
Query interface.
Forward and external declarations.