9#include "GaudiKernel/SvcFactory.h"
10#include "GaudiKernel/MsgStream.h"
11#include "GaudiKernel/GaudiException.h"
14#include "GaudiKernel/IAlgManager.h"
15#include "GaudiKernel/Algorithm.h"
16#include "GaudiKernel/IAppMgrUI.h"
17#include "GaudiKernel/IIncidentSvc.h"
18#include "GaudiKernel/IIncidentListener.h"
20#include "CLHEP/Random/Random.h"
33#include "GaudiKernel/Service.h"
34#include "GaudiKernel/IRunable.h"
35#include "GaudiKernel/Property.h"
36#include "RootIO/IRootIoSvc.h"
45 virtual public Service,
46 virtual public IIncidentListener,
48 virtual public IRunable
54 virtual StatusCode
run();
66 virtual StatusCode
queryInterface(
const InterfaceID& riid,
void** ppvUnknown );
69 virtual void handle(
const Incident& inc);
80 virtual int index() {
return m_index; };
83 virtual std::pair<int,int>
runEventPair() {
return m_runEventPair; };
90 RootIoSvc (
const std::string& name, ISvcLocator* al );
104 IAppMgrUI* m_appMgrUI;
105 IntegerProperty m_evtMax;
106 IntegerProperty m_autoSaveInterval;
109 DoubleProperty m_startTime;
110 DoubleProperty m_endTime;
112 unsigned int m_rootEvtMax;
114 std::pair<int, int> m_runEventPair;
115 std::vector<TChain *> m_chainCol;
131 declareProperty(
"EvtMax" , m_evtMax=0);
132 declareProperty(
"StartTime" , m_startTime=0);
133 declareProperty(
"EndTime", m_endTime=0);
134 declareProperty(
"AutoSaveInterval", m_autoSaveInterval=1000);
135 declareProperty(
"StartingIndex", m_index=-1);
138 m_runEventPair = std::pair<int,int>(-1,-1);
153 StatusCode status = Service::initialize ();
159 MsgStream log(
msgSvc(), name() );
161 status = serviceLocator()->queryInterface(IAppMgrUI::interfaceID(), (
void**)&m_appMgrUI);
164 IIncidentSvc* incsvc = 0;
165 status = service (
"IncidentSvc", incsvc,
true);
167 if( status.isFailure() )
return status;
169 incsvc->addListener(
this,
"BeginEvent", 100);
170 incsvc->addListener(
this,
"EndEvent", 0);
173 gSystem->ResetSignal(kSigBus);
174 gSystem->ResetSignal(kSigSegmentationViolation);
175 gSystem->ResetSignal(kSigIllegalInstruction);
176 gSystem->ResetSignal(kSigFloatingException);
178 return StatusCode::SUCCESS;
185 StatusCode status = StatusCode::SUCCESS;
191 if ( IID_IRootIoSvc.versionMatch(riid) ) {
193 }
else if (IRunable::interfaceID().versionMatch(riid) ) {
194 *ppvInterface = (IRunable*)
this;
195 }
else if (IIncidentListener::interfaceID().versionMatch(riid) ) {
196 *ppvInterface = (IIncidentListener*)
this;
198 return Service::queryInterface(riid, ppvInterface);
209 if (m_rootEvtMax == 0) {
214 if (m_rootEvtMax > max) m_rootEvtMax = max;
223 m_chainCol.push_back(ch);
227 if (i < 0)
return false;
228 std::vector<TChain*>::iterator it;
229 for(it = m_chainCol.begin(); it != m_chainCol.end(); it++) {
230 if (i >= (*it)->GetEntries())
return false;
233 m_runEventPair = std::pair<int, int>(-1,-1);
239 std::vector<TChain*>::iterator it;
240 for(it = m_chainCol.begin(); it != m_chainCol.end(); it++) {
241 int readInd = (*it)->GetEntryNumberWithIndex(ids.first, ids.second);
242 if ( (readInd < 0) || (readInd >= (*it)->GetEntries()) )
return false;
244 m_runEventPair = ids;
252 if( inc.type()==
"BeginEvent")beginEvent();
253 else if(inc.type()==
"EndEvent")endEvent();
257void RootIoSvc::beginEvent()
261void RootIoSvc::endEvent()
264 m_runEventPair = std::pair<int, int>(-1,-1);
270 StatusCode status = StatusCode::FAILURE;
271 MsgStream log(
msgSvc(), name() );
273 if ( 0 == m_appMgrUI )
return status;
275 IProperty* propMgr=0;
276 status = serviceLocator()->service(
"ApplicationMgr", propMgr );
277 if( status.isFailure()) {
278 log << MSG::ERROR <<
"Unable to locate PropertyManager Service" << endreq;
282 IntegerProperty evtMax(
"EvtMax",0);
283 status = propMgr->getProperty( &evtMax );
284 if (status.isFailure())
return status;
288 IntegerProperty rootEvtMax(
"EvtMax", m_rootEvtMax);
289 if (rootEvtMax < evtMax) setProperty(rootEvtMax);
290 else setProperty(evtMax);
294 IAlgManager* theAlgMgr;
295 status = serviceLocator( )->getService(
"ApplicationMgr",
296 IAlgManager::interfaceID(),
297 (IInterface*&)theAlgMgr );
299 Algorithm* theAlgorithm=0;
300 IntegerProperty errorProperty(
"ErrorCount",0);
302 status = theAlgMgr->getAlgorithm(
"Top", theIAlg );
303 if ( status.isSuccess( ) ) {
305 theAlgorithm =
dynamic_cast<Algorithm*
>(theIAlg);
307 status = StatusCode::FAILURE;
310 if ( status.isFailure( ) ) {
311 log << MSG::WARNING <<
"Could not find algorithm 'Top'; will not monitor errors" << endreq;
318 double currentTime=m_startTime;
321 log << MSG::INFO <<
"Runable interface starting event loop as :" ;
322 if( m_evtMax>0) { log <<
" MaxEvt = " << m_evtMax; noend=
false; }
323 if( m_endTime>0) { log <<
" EndTime= " << m_endTime; noend=
false; }
327 log << MSG::WARNING <<
"No end condition specified: will not process any events!" << endreq;
331 while( m_evtMax>0 && eventNumber < m_evtMax
332 || m_endTime>0 && currentTime< m_endTime ) {
334 status = m_appMgrUI->nextEvent(1);
337 if( theAlgorithm !=0) theAlgorithm->getProperty(&errorProperty);
338 if( status.isFailure() || errorProperty.value() > 0){
339 status = StatusCode::FAILURE;
342 if( status.isFailure())
break;
348 if( status.isFailure()){
349 log << MSG::ERROR <<
"Terminating RootIoSvc loop due to error" << endreq;
351 }
else if( m_endTime>0 && currentTime >= m_endTime ) {
352 log << MSG::INFO <<
"Loop terminated by time " << endreq;
354 log << MSG::INFO <<
"Processing loop terminated by event count" << endreq;
The RootIoSvc gaudi service interface.
Service that implements the IRunable interface, to control the event loop. Based on RootIoSvc of Glas...
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.