1#include "GaudiKernel/DataObject.h"
2#include "GaudiKernel/EventContext.h"
3#include "GaudiKernel/IAlgorithm.h"
4#include "GaudiKernel/IRegistry.h"
5#include "GaudiKernel/Incident.h"
6#include "GaudiKernel/SmartDataPtr.h"
8#include "EventModel/EventHeader.h"
19 : MinimalEventLoopMgr( name, svcLoc ) {
44 info() <<
"In initialize()" << endmsg;
47 StatusCode sc = MinimalEventLoopMgr::initialize();
48 if ( !sc.isSuccess() )
50 fatal() <<
"Failed to initialize the MinimalEventLoopMgr" << endmsg;
58 fatal() <<
"Failed to get the EventDataSvc" << endmsg;
59 return StatusCode::FAILURE;
65 fatal() <<
"Failed to get the EventDataSvc" << endmsg;
66 return StatusCode::FAILURE;
73 fatal() <<
"Failed to get the IncidentSvc" << endmsg;
74 return StatusCode::FAILURE;
81 fatal() <<
"Failed to get the IProperty of the ApplicationMgr" << endmsg;
82 return StatusCode::FAILURE;
90 warning() <<
"Unable to locate service \"EventSelector\" " << endmsg;
91 warning() <<
"No events will be processed from external input." << endmsg;
99 fatal() <<
"EventSelector not found." << endmsg;
100 return StatusCode::FAILURE;
102 debug() <<
"Found EventSelector" << endmsg;
106 if ( !sc.isSuccess() )
108 fatal() <<
"Can not create the context" << endmsg;
109 return StatusCode::FAILURE;
112 debug() <<
"Context created." << endmsg;
119 fatal() <<
"Failed to get the HistogramDataSvc" << endmsg;
120 return StatusCode::FAILURE;
127 warning() <<
"Histograms cannot not be saved - though required." << endmsg;
128 return StatusCode::FAILURE;
136 case 1: m_progressLevel = MSG::VERBOSE;
break;
137 case 2: m_progressLevel = MSG::DEBUG;
break;
138 case 3: m_progressLevel = MSG::INFO;
break;
139 case 4: m_progressLevel = MSG::WARNING;
break;
140 case 5: m_progressLevel = MSG::ERROR;
break;
141 case 6: m_progressLevel = MSG::FATAL;
break;
142 case 7: m_progressLevel = MSG::ALWAYS;
break;
145 return StatusCode::FAILURE;
150 else { m_skipEvt =
false; }
152 return StatusCode::SUCCESS;
160 info() <<
"In reinitialize()" << endmsg;
163 StatusCode sc = MinimalEventLoopMgr::reinitialize();
164 if ( !sc.isSuccess() )
166 error() <<
"Error Initializing base class MinimalEventLoopMgr." << endmsg;
171 if ( sc = setProperty(
m_appMgrProperty->getProperty(
"EvtSel" ) ); !sc )
return sc;
174 auto theSvc = serviceLocator()->service<IService>(
"EventSelector" );
175 auto theEvtSel = theSvc.as<IEvtSelector>();
176 if ( theEvtSel && ( theEvtSel.get() !=
m_evtSelector.get() ) )
186 if ( theSvc->FSMState() == Gaudi::StateMachine::INITIALIZED )
188 sc = theSvc->reinitialize();
189 if ( !sc.isSuccess() )
191 error() <<
"Failure Reinitializing EventSelector " << theSvc->name() << endmsg;
197 sc = theSvc->sysInitialize();
198 if ( !sc.isSuccess() )
200 error() <<
"Failure Initializing EventSelector " << theSvc->name() << endmsg;
205 if ( !sc.isSuccess() )
207 error() <<
"Can not create Context " << theSvc->name() << endmsg;
210 info() <<
"EventSelector service changed to " << theSvc->name() << endmsg;
220 if ( !sc.isSuccess() )
222 error() <<
"Can not create Context " << theSvc->name() << endmsg;
240 info() <<
"In finalize()" << endmsg;
243 StatusCode sc = MinimalEventLoopMgr::finalize();
244 if ( !sc.isSuccess() )
246 error() <<
"Error finalizing base class" << endmsg;
253 std::vector<DataObject*> objects;
255 DataObject* obj = reg->object();
256 if ( !obj || obj->clID() == CLID_StatisticsFile )
return false;
257 objects.push_back( obj );
260 if ( sc.isSuccess() )
263 sc = std::accumulate( begin( objects ), end( objects ), sc,
264 [&]( StatusCode isc,
auto& i ) {
265 IOpaqueAddress* pAddr =
nullptr;
267 if ( iret.isFailure() )
return iret;
268 i->registry()->setAddress( pAddr );
272 sc = std::accumulate(
273 begin( objects ), end( objects ), sc, [&]( StatusCode isc,
auto& i ) {
274 IRegistry* reg = i->registry();
275 StatusCode iret =
m_histoPersSvc->fillRepRefs( reg->address(), i );
276 return iret.isFailure() ? iret : isc;
279 if ( sc.isSuccess() )
280 { info() <<
"Histograms converted successfully according to request." << endmsg; }
281 else { error() <<
"Error while saving Histograms." << endmsg; }
283 else { error() <<
"Error while traversing Histogram data store" << endmsg; }
301 return StatusCode::SUCCESS;
309 m_incidentSvc->fireIncident( Incident( name(), IncidentType::BeginEvent ) );
313 if ( m_scheduledStop )
316 <<
"Terminating event processing loop due to a stop scheduled by an incident listener"
318 return StatusCode::SUCCESS;
321 SmartDataPtr<Event::EventHeader> evt(
m_evtDataSvc,
"/Event/EventHeader" );
324 error() <<
"Error accessing Event" << endmsg;
325 return StatusCode::FAILURE;
328 int runNo = evt->runNumber();
329 int evtNo = evt->eventNumber();
340 if ( match_evt_no && match_run_no )
342 info() <<
"Reached the requested event " << evtNo <<
" in run " <<
runNo
343 <<
", will start processing from next event." << endmsg;
348 debug() <<
"Skipping event " << evtNo <<
" in run " <<
runNo << endmsg;
349 return StatusCode::SUCCESS;
353 info() <<
"The runNo of current event is " <<
runNo << endmsg;
357 if ( !m_runNoSet ||
runNo != m_runNo )
359 info() <<
"Fire an incident of begin run" << endmsg;
367 m_incidentSvc->fireIncident( Incident( name(), IncidentType::BeginProcessing ) );
368 StatusCode sc = MinimalEventLoopMgr::executeEvent( std::move( ctx ) );
369 m_incidentSvc->fireIncident( Incident( name(), IncidentType::EndProcessing ) );
371 if ( !sc.isSuccess() )
372 error() <<
"Terminating event processing loop due to errors" << endmsg;
374 m_incidentSvc->fireIncident( Incident( name(), IncidentType::EndEvent ) );
383 static int total_nevt = 0;
384 DataObject* pObject = 0;
387 for (
int nevt = 0; maxevt == -1 ||
nevt < maxevt; ++
nevt )
391 { msgStream( m_progressLevel ) <<
"Processing event " <<
nevt << endmsg; }
393 auto ctx = createEventContext();
396 if ( m_scheduledStop )
398 m_scheduledStop =
false;
399 always() <<
"Terminating event processing loop due to scheduled stop" << endmsg;
404 if ( ctx.evt() != 0 )
407 if ( sc.isSuccess() ) debug() <<
"Event data storecleared" << endmsg;
408 else debug() <<
"Failed to clear the store" << endmsg;
414 IOpaqueAddress* addr =
nullptr;
418 if ( !sc.isSuccess() )
420 info() <<
"No more events in event selection" << endmsg;
426 if ( !sc.isSuccess() )
428 warning() <<
"Error declaring event root address." << endmsg;
433 SmartDataPtr<Event::EventHeader> evt(
m_evtDataSvc,
"/Event/EventHeader" );
437 if ( !sc.isSuccess() ) warning() <<
"Error register EventHeader address." << endmsg;
441 if ( !sc.isSuccess() )
443 warning() <<
"Unable to retrieve Event root object" << endmsg;
450 if ( !sc.isSuccess() ) warning() <<
"Error declaring event root DataObject" << endmsg;
455 if ( !sc.isSuccess() )
457 error() <<
"Terminating event processing loop due to errors" << endmsg;
462 return StatusCode::SUCCESS;
472 if ( !sc.isSuccess() )
474 debug() <<
"Failed to get next eventContext [1]" << endmsg;
479 if ( sc.isSuccess() )
481 debug() <<
"Event address created successfully." << endmsg;
486 if ( sc.isFailure() )
488 debug() <<
"Failed to get next eventContext [2]" << endmsg;
493 if ( sc.isFailure() ) { warning() <<
"Error creating IOpaqueAddress." << endmsg; }
494 else debug() <<
"Event address created successfully finally." << endmsg;
DECLARE_COMPONENT(BesBdkRc)
SmartIF< IEvtSelector > m_evtSelector
Reference to the Event Selector.
virtual StatusCode reinitialize()
implementation of IService::reinitalize
IntegerProperty m_startEvtNo
Locate start event number.
virtual StatusCode executeEvent(EventContext &&ctx)
implementation of IEventProcessor::executeEvent(EventContext&&)
SmartIF< IConversionSvc > m_histoPersSvc
Reference to the Histogram Persistency Service.
UnsignedIntegerProperty m_progressLevelSetting
progress level
StatusCode getEventRoot(IOpaqueAddress *&refpAddr)
Create event address using event selector.
UnsignedIntegerProperty m_showProgressInterval
show progress
virtual StatusCode finalize()
implementation of IService::finalize
SmartIF< IDataProviderSvc > m_evtDataSvc
Reference to the Event Data Service's IDataProviderSvc interface.
SmartIF< IProperty > m_appMgrProperty
Property interface of ApplicationMgr.
SmartIF< IDataManagerSvc > m_histoDataMgrSvc
Reference to the Histogram Data Service.
OfflineEventLoopMgr(const std::string &nam, ISvcLocator *svcLoc)
Standard Constructor.
virtual StatusCode initialize()
implementation of IService::initalize
SmartIF< IDataManagerSvc > m_evtDataMgrSvc
Reference to the Event Data Service's IDataManagerSvc interface.
virtual StatusCode nextEvent(int maxevt)
implementation of IService::nextEvent
IEvtSelector::Context * m_evtContext
Event Iterator.
StringProperty m_evtsel
Event selector.
SmartIF< IIncidentSvc > m_incidentSvc
Reference to the indicent service.
virtual ~OfflineEventLoopMgr()
Standard Destructor.
IntegerProperty m_startRunNo