4#include "GaudiKernel/SmartIF.h"
5#include "GaudiKernel/Incident.h"
6#include "GaudiKernel/MsgStream.h"
7#include "GaudiKernel/SvcFactory.h"
8#include "GaudiKernel/DataObject.h"
9#include "GaudiKernel/IIncidentSvc.h"
10#include "GaudiKernel/IEvtSelector.h"
11#include "GaudiKernel/IDataManagerSvc.h"
12#include "GaudiKernel/IDataProviderSvc.h"
13#include "GaudiKernel/IConversionSvc.h"
14#include "GaudiKernel/SmartDataPtr.h"
15#include "GaudiKernel/IAlgorithm.h"
16#include "ApplicationMgr/HistogramAgent.h"
17#include "OfflineEventLoopMgr/OfflineEventLoopMgr.h"
18#include "EventModel/EventModel.h"
19#include "EventModel/Event.h"
20#include "EventModel/EventHeader.h"
31: MinimalEventLoopMgr(nam, svcLoc)
43 declareProperty(
"EvtSel",
m_evtsel );
63 MsgStream log(
msgSvc(), name());
66 StatusCode sc = MinimalEventLoopMgr::initialize();
67 if( !sc.isSuccess() ) {
68 log << MSG::DEBUG <<
"Error Initializing base class MinimalEventLoopMgr." << endreq;
74 if( !sc.isSuccess() ) {
75 log << MSG::FATAL <<
"Error retrieving EventDataSvc interface IDataManagerSvc." << endreq;
78 sc = serviceLocator()->service(
"EventDataSvc",
m_evtDataSvc,
true);
79 if( !sc.isSuccess() ) {
80 log << MSG::FATAL <<
"Error retrieving EventDataSvc interface IDataProviderSvc." << endreq;
85 sc = serviceLocator()->service(
"IncidentSvc",
m_incidentSvc,
true);
86 if( !sc.isSuccess() ) {
87 log << MSG::FATAL <<
"Error retrieving IncidentSvc." << endreq;
93 SmartIF<IProperty> prpMgr(serviceLocator());
94 if ( ! prpMgr.isValid() ) {
95 log << MSG::FATAL <<
"IProperty interface not found in ApplicationMgr." << endreq;
96 return StatusCode::FAILURE;
106 sc = serviceLocator()->service(
"EventSelector",
m_evtSelector,
true );
107 if( sc.isSuccess() ) {
110 if( !sc.isSuccess() ) {
111 log << MSG::FATAL <<
"Can not create the event selector Context." << endreq;
116 log << MSG::FATAL <<
"EventSelector not found." << endreq;
123 log << MSG::WARNING <<
"Unable to locate service \"EventSelector\" " << endreq;
124 log << MSG::WARNING <<
"No events will be processed from external input." << endreq;
129 if( !sc.isSuccess() ) {
130 log << MSG::FATAL <<
"Error retrieving HistogramDataSvc." << endreq;
134 sc = serviceLocator()->service(
"HistogramPersistencySvc",
m_histoPersSvc,
true );
135 if( !sc.isSuccess() ) {
136 log << MSG::WARNING <<
"Histograms cannot not be saved - though required." << endreq;
140 return StatusCode::SUCCESS;
146 MsgStream log(
msgSvc(), name());
149 StatusCode sc = MinimalEventLoopMgr::reinitialize();
150 if( !sc.isSuccess() ) {
151 log << MSG::DEBUG <<
"Error Initializing base class MinimalEventLoopMgr." << endreq;
158 IEvtSelector* theEvtSel;
160 sc = serviceLocator()->service(
"EventSelector", theEvtSel );
161 sc = serviceLocator()->service(
"EventSelector", theSvc );
166 if (theSvc->FSMState() == Gaudi::StateMachine::INITIALIZED) {
167 sc = theSvc->reinitialize();
168 if( !sc.isSuccess() ) {
169 log << MSG::ERROR <<
"Failure Reinitializing EventSelector "
170 << theSvc->name( ) << endreq;
175 sc = theSvc->initialize();
176 if( !sc.isSuccess() ) {
177 log << MSG::ERROR <<
"Failure Initializing EventSelector "
178 << theSvc->name( ) << endreq;
183 if( !sc.isSuccess() ) {
184 log << MSG::ERROR <<
"Can not create Context "
185 << theSvc->name( ) << endreq;
188 log << MSG::INFO <<
"EventSelector service changed to "
189 << theSvc->name( ) << endreq;
195 if( !sc.isSuccess() ) {
196 log << MSG::ERROR <<
"Can not create Context "
197 << theSvc->name( ) << endreq;
207 return StatusCode::SUCCESS;
215 MsgStream log(
msgSvc(), name());
218 MinimalEventLoopMgr::finalize();
222 HistogramAgent agent;
224 if( sc.isSuccess() ) {
225 IDataSelector* objects = agent.selectedObjects();
227 if ( objects->size() > 0 ) {
228 IDataSelector::iterator i;
229 for ( i = objects->begin(); i != objects->end(); i++ ) {
230 IOpaqueAddress* pAddr = 0;
232 if ( iret.isSuccess() ) {
233 (*i)->registry()->setAddress(pAddr);
239 for ( i = objects->begin(); i != objects->end(); i++ ) {
240 IRegistry* reg = (*i)->registry();
241 StatusCode iret =
m_histoPersSvc->fillRepRefs(reg->address(), *i);
242 if ( !iret.isSuccess() ) {
247 if ( sc.isSuccess() ) {
248 log << MSG::INFO <<
"Histograms converted successfully according to request." << endreq;
251 log << MSG::ERROR <<
"Error while saving Histograms." << endreq;
255 log << MSG::ERROR <<
"Error while traversing Histogram data store" << endreq;
274 return StatusCode::SUCCESS;
282 MsgStream log(
msgSvc(), name());
284 m_incidentSvc->fireIncident(Incident(name(),IncidentType::BeginEvent));
286 SmartDataPtr<Event::EventHeader> evt(
m_evtDataSvc,
"/Event/EventHeader");
288 runNo = evt -> runNumber();
289 log << MSG::INFO <<
"The runNumber of current event is "<<
runNo<<endreq;
293 log << MSG::ERROR <<
"Error accessing Event" <<endreq;
294 return StatusCode::FAILURE;
297 log << MSG::INFO <<
"fireIncident of begin run"<<endreq;
300 ListAlg::iterator it_topAlg = m_topAlgList.begin();
301 for (;it_topAlg!=m_topAlgList.end();it_topAlg++){
302 (*it_topAlg)->beginRun();}
308 StatusCode sc = MinimalEventLoopMgr::executeEvent(par);
310 m_incidentSvc->fireIncident(Incident(name(),IncidentType::EndEvent));
313 if( !sc.isSuccess() ){
314 MsgStream log(
msgSvc(), name() );
315 log << MSG::ERROR <<
"Terminating event processing loop due to errors" << endreq;
327 sc = MinimalEventLoopMgr::executeRun(maxevt);
335 static int total_nevt = 0;
336 DataObject* pObject = 0;
338 MsgStream log(
msgSvc(), name() );
349 for(
int nevt = 0; (maxevt == -1 ?
true :
nevt < maxevt);
nevt++, total_nevt++) {
351 if ( m_scheduledStop ) {
352 m_scheduledStop =
false;
353 log << MSG::ALWAYS <<
"Terminating event processing loop due to scheduled stop" << endreq;
357 if( 0 != total_nevt ) {
359 if( !sc.isSuccess() ) {
360 log << MSG::DEBUG <<
"Clear of Event data store failed" << endreq;
366 IOpaqueAddress* addr = 0;
369 if( !sc.isSuccess() ) {
370 log << MSG::INFO <<
"No more events in event selection " << endreq;
375 if( !sc.isSuccess() ) {
376 log << MSG::WARNING <<
"Error declaring event root address." << endreq;
380 SmartDataPtr<Event::EventHeader> evt(
m_evtDataSvc,
"/Event/EventHeader");
383 if( !sc.isSuccess() ) {
384 log << MSG::WARNING <<
"Error register EventHeader address." << endreq;
388 if( !sc.isSuccess() ) {
389 log << MSG::WARNING <<
"Unable to retrieve Event root object" << endreq;
395 if( !sc.isSuccess() ) {
396 log << MSG::WARNING <<
"Error declaring event root DataObject" << endreq;
404 if( !sc.isSuccess() ){
405 log << MSG::ERROR <<
"Terminating event processing loop due to errors" << endreq;
411 ListAlg::iterator it_topAlg = m_topAlgList.begin();
412 for (;it_topAlg!=m_topAlgList.end();it_topAlg++){
413 (*it_topAlg)->endRun();
416 return StatusCode::SUCCESS;
423 if ( !sc.isSuccess() ) {
428 if( !sc.isSuccess() ) {
430 if ( sc.isSuccess() ) {
432 if ( !sc.isSuccess() ) {
433 MsgStream log(
msgSvc(), name() );
434 log << MSG::WARNING <<
"Error creating IOpaqueAddress." << endreq;
virtual StatusCode reinitialize()
implementation of IService::reinitalize
IDataManagerSvc * m_histoDataMgrSvc
Reference to the Histogram Data Service.
virtual StatusCode executeEvent(void *par)
implementation of IEventProcessor::executeEvent(void* par)
virtual StatusCode executeRun(int maxevt)
implementation of IEventProcessor::executeRun()
IProperty * m_appMgrProperty
Property interface of ApplicationMgr.
IDataManagerSvc * m_evtDataMgrSvc
Reference to the Event Data Service's IDataManagerSvc interface.
StatusCode getEventRoot(IOpaqueAddress *&refpAddr)
Create event address using event selector.
std::string m_evtsel
Event selector.
virtual StatusCode finalize()
implementation of IService::finalize
IEvtSelector * m_evtSelector
Reference to the Event Selector.
IIncidentSvc * m_incidentSvc
Reference to the indicent service.
OfflineEventLoopMgr(const std::string &nam, ISvcLocator *svcLoc)
Standard Constructor.
virtual StatusCode initialize()
implementation of IService::initalize
IEvtSelector::Context * m_evtContext
Event Iterator.
std::string m_histPersName
Name of the Hist Pers type.
IConversionSvc * m_histoPersSvc
Reference to the Histogram Persistency Service.
virtual StatusCode nextEvent(int maxevt)
implementation of IService::nextEvent
IDataProviderSvc * m_evtDataSvc
Reference to the Event Data Service's IDataProviderSvc interface.
virtual ~OfflineEventLoopMgr()
Standard Destructor.