Gaudi Framework, version v20r2

Generated: 18 Jul 2008

EventLoopMgr Class Reference

#include <EventLoopMgr.h>

Inheritance diagram for EventLoopMgr:

Inheritance graph
[legend]
Collaboration diagram for EventLoopMgr:

Collaboration graph
[legend]
List of all members.

Detailed Description

Class definition of EventLoopMgr.

This is the default processing manager of the application manager. This object handles the minimal requirements needed by the application manager. It also handles the default user configuration setup for standard event processing.

History:

    +---------+----------------------------------------------+---------+
    |    Date |                 Comment                      | Who     |
    +---------+----------------------------------------------+---------+
    |13/12/00 | Initial version                              | M.Frank |
    +---------+----------------------------------------------+---------+
    
Author:
Markus Frank
Version:
1.0

Definition at line 36 of file EventLoopMgr.h.

Public Member Functions

 EventLoopMgr (const std::string &nam, ISvcLocator *svcLoc)
 Standard Constructor.
virtual ~EventLoopMgr ()
 Standard Destructor.
StatusCode getEventRoot (IOpaqueAddress *&refpAddr)
 Create event address using event selector.
virtual StatusCode initialize ()
 implementation of IService::initalize
virtual StatusCode reinitialize ()
 implementation of IService::reinitalize
virtual StatusCode stop ()
 implementation of IService::stop
virtual StatusCode finalize ()
 implementation of IService::finalize
virtual StatusCode nextEvent (int maxevt)
 implementation of IService::nextEvent
virtual StatusCode executeEvent (void *par)
 implementation of IEventProcessor::executeEvent(void* par)
virtual StatusCode executeRun (int maxevt)
 implementation of IEventProcessor::executeRun()

Protected Attributes

IDataManagerSvcm_evtDataMgrSvc
 Reference to the Event Data Service's IDataManagerSvc interface.
IDataProviderSvcm_evtDataSvc
 Reference to the Event Data Service's IDataProviderSvc interface.
IEvtSelectorm_evtSelector
 Reference to the Event Selector.
IEvtSelector::Contextm_evtContext
 Event Iterator.
std::string m_evtsel
 Event selector.
IDataManagerSvcm_histoDataMgrSvc
 Reference to the Histogram Data Service.
IConversionSvcm_histoPersSvc
 Reference to the Histogram Persistency Service.
std::string m_histPersName
 Name of the Hist Pers type.
IPropertym_appMgrProperty
 Property interface of ApplicationMgr.
bool m_endEventFired
 Flag to avoid to fire the EnvEvent incident twice in a row (and also not before the first event).


Constructor & Destructor Documentation

EventLoopMgr::EventLoopMgr ( const std::string nam,
ISvcLocator svcLoc 
)

Standard Constructor.

Definition at line 24 of file EventLoopMgr.cpp.

00025 : MinimalEventLoopMgr(nam, svcLoc)
00026 {
00027   m_histoDataMgrSvc   = 0;
00028   m_histoPersSvc      = 0;
00029   m_evtDataMgrSvc     = 0;
00030   m_evtDataSvc        = 0;
00031   m_evtSelector       = 0;
00032   m_evtContext        = 0;
00033   m_endEventFired     = true;
00034   
00035   // Declare properties
00036   declareProperty("HistogramPersistency", m_histPersName = "");
00037   declareProperty( "EvtSel", m_evtsel );
00038 }

EventLoopMgr::~EventLoopMgr (  )  [virtual]

Standard Destructor.

Definition at line 43 of file EventLoopMgr.cpp.

References m_evtContext, m_evtDataMgrSvc, m_evtDataSvc, m_evtSelector, m_histoDataMgrSvc, m_histoPersSvc, and IInterface::release().


Member Function Documentation

StatusCode EventLoopMgr::getEventRoot ( IOpaqueAddress *&  refpAddr  ) 

Create event address using event selector.

Definition at line 383 of file EventLoopMgr.cpp.

References IEvtSelector::createAddress(), endreq(), StatusCode::isSuccess(), m_evtContext, m_evtSelector, Service::msgSvc(), Service::name(), IEvtSelector::next(), and MSG::WARNING.

Referenced by nextEvent().

00383                                                                 {
00384   refpAddr = 0;
00385   StatusCode sc = m_evtSelector->next(*m_evtContext);
00386   if ( !sc.isSuccess() )  {
00387     return sc;
00388   }
00389   // Create root address and assign address to data service
00390   sc = m_evtSelector->createAddress(*m_evtContext,refpAddr);
00391   if( !sc.isSuccess() )  {
00392     sc = m_evtSelector->next(*m_evtContext);
00393     if ( sc.isSuccess() )  {
00394       sc = m_evtSelector->createAddress(*m_evtContext,refpAddr);
00395       if ( !sc.isSuccess() )  {
00396         MsgStream log( msgSvc(), name() );
00397         log << MSG::WARNING << "Error creating IOpaqueAddress." << endreq;
00398       }
00399     }
00400   }
00401   return sc;
00402 }

StatusCode EventLoopMgr::initialize (  )  [virtual]

implementation of IService::initalize

Reimplemented from MinimalEventLoopMgr.

Definition at line 55 of file EventLoopMgr.cpp.

References IEvtSelector::createContext(), MSG::DEBUG, endreq(), StatusCode::FAILURE, MSG::FATAL, IProperty::getProperty(), IID_IProperty, MinimalEventLoopMgr::initialize(), StatusCode::isSuccess(), SmartIFBase< TYPE >::isValid(), std::basic_string< _CharT, _Traits, _Alloc >::length(), m_appMgrProperty, m_evtContext, m_evtDataMgrSvc, m_evtDataSvc, m_evtsel, m_evtSelector, m_histoDataMgrSvc, m_histoPersSvc, Service::msgSvc(), Service::name(), ISvcLocator::service(), Service::serviceLocator(), Service::setProperty(), StatusCode::SUCCESS, and MSG::WARNING.

00055                                        {
00056   MsgStream log(msgSvc(), name());
00057 
00058   // initilaize the base class
00059   StatusCode sc = MinimalEventLoopMgr::initialize();
00060   if( !sc.isSuccess() ) {
00061     log << MSG::DEBUG << "Error Initializing base class MinimalEventLoopMgr." << endreq;
00062     return sc;
00063   }
00064 
00065   // Setup access to event data services
00066   sc = serviceLocator()->service("EventDataSvc", m_evtDataMgrSvc, true);
00067   if( !sc.isSuccess() )  {
00068     log << MSG::FATAL << "Error retrieving EventDataSvc interface IDataManagerSvc." << endreq;
00069     return sc;
00070   }
00071   sc = serviceLocator()->service("EventDataSvc", m_evtDataSvc, true);
00072   if( !sc.isSuccess() )  {
00073     log << MSG::FATAL << "Error retrieving EventDataSvc interface IDataProviderSvc." << endreq;
00074     return sc;
00075   }
00076 
00077   // Obtain the IProperty of the ApplicationMgr
00078   SmartIF<IProperty> prpMgr(IID_IProperty, serviceLocator());
00079   if ( ! prpMgr.isValid() )   {
00080     log << MSG::FATAL << "IProperty interface not found in ApplicationMgr." << endreq;
00081     return StatusCode::FAILURE;
00082   }
00083   else {
00084     m_appMgrProperty = prpMgr;
00085   }
00086 
00087   // We do not expect a Event Selector necessarily being declared
00088   setProperty(m_appMgrProperty->getProperty("EvtSel")).ignore();
00089 
00090   if( m_evtsel != "NONE" || m_evtsel.length() == 0) {
00091     sc = serviceLocator()->service( "EventSelector", m_evtSelector, true );
00092     if( sc.isSuccess() )     {
00093       // Setup Event Selector
00094       sc=m_evtSelector->createContext(m_evtContext);
00095       if( !sc.isSuccess() )   {
00096         log << MSG::FATAL << "Can not create the event selector Context." << endreq;
00097         return sc;
00098       }
00099     }
00100     else {
00101       log << MSG::FATAL << "EventSelector not found." << endreq;
00102       return sc;
00103     }
00104   }
00105   else {
00106     m_evtSelector = 0;
00107     m_evtContext = 0;
00108     log << MSG::WARNING << "Unable to locate service \"EventSelector\" " << endreq;    
00109     log << MSG::WARNING << "No events will be processed from external input." << endreq;    
00110   }
00111 
00112   // Setup access to histogramming services
00113   sc = serviceLocator()->service("HistogramDataSvc", m_histoDataMgrSvc, true);
00114   if( !sc.isSuccess() )  {
00115     log << MSG::FATAL << "Error retrieving HistogramDataSvc." << endreq;
00116     return sc;
00117   }
00118   // Setup histogram persistency
00119   sc = serviceLocator()->service("HistogramPersistencySvc", m_histoPersSvc, true );
00120   if( !sc.isSuccess() ) {
00121     log << MSG::WARNING << "Histograms cannot not be saved - though required." << endreq;
00122     return sc;
00123   }
00124   return StatusCode::SUCCESS;
00125 }

StatusCode EventLoopMgr::reinitialize (  )  [virtual]

implementation of IService::reinitalize

Reimplemented from MinimalEventLoopMgr.

Definition at line 129 of file EventLoopMgr.cpp.

References IEvtSelector::createContext(), MSG::DEBUG, endreq(), MSG::ERROR, IService::FSMState(), IProperty::getProperty(), MSG::INFO, Gaudi::StateMachine::INITIALIZED, StatusCode::isSuccess(), std::basic_string< _CharT, _Traits, _Alloc >::length(), m_appMgrProperty, m_evtContext, m_evtsel, m_evtSelector, Service::msgSvc(), INamedInterface::name(), Service::name(), IService::reinitialize(), MinimalEventLoopMgr::reinitialize(), IEvtSelector::releaseContext(), ISvcLocator::service(), Service::serviceLocator(), Service::setProperty(), StatusCode::SUCCESS, and IService::sysInitialize().

00129                                       {
00130   MsgStream log(msgSvc(), name());
00131   
00132   // initilaize the base class
00133   StatusCode sc = MinimalEventLoopMgr::reinitialize();
00134   if( !sc.isSuccess() ) {
00135     log << MSG::DEBUG << "Error Initializing base class MinimalEventLoopMgr." << endreq;
00136     return sc;
00137   }
00138 
00139   // Check to see whether a new Event Selector has been specified
00140   setProperty(m_appMgrProperty->getProperty("EvtSel"));
00141   if( m_evtsel != "NONE" || m_evtsel.length() == 0) {
00142     IEvtSelector* theEvtSel;
00143     IService*     theSvc;
00144     sc = serviceLocator()->service( "EventSelector", theEvtSel );
00145     sc = serviceLocator()->service( "EventSelector", theSvc );
00146     if( sc.isSuccess() && ( theEvtSel != m_evtSelector ) ) {
00147       // Setup Event Selector
00148       m_evtSelector = theEvtSel;
00149       if (theSvc->FSMState() == Gaudi::StateMachine::INITIALIZED) {
00150         sc = theSvc->reinitialize();
00151         if( !sc.isSuccess() ) {
00152           log << MSG::ERROR << "Failure Reinitializing EventSelector "
00153               << theSvc->name( ) << endreq;
00154           return sc;
00155         }
00156       } 
00157       else {
00158         sc = theSvc->sysInitialize();
00159         if( !sc.isSuccess() ) {
00160           log << MSG::ERROR << "Failure Initializing EventSelector "
00161               << theSvc->name( ) << endreq;
00162           return sc;
00163         }
00164       }
00165       sc = m_evtSelector->createContext(m_evtContext);
00166       if( !sc.isSuccess() ) {
00167         log << MSG::ERROR << "Can not create Context "
00168             << theSvc->name( ) << endreq;
00169         return sc;
00170       }
00171       log << MSG::INFO << "EventSelector service changed to "
00172           << theSvc->name( ) << endreq;
00173     }
00174     else if ( m_evtSelector && m_evtContext )   {
00175       m_evtSelector->releaseContext(m_evtContext);
00176       m_evtContext = 0;
00177       sc = m_evtSelector->createContext(m_evtContext);
00178       if( !sc.isSuccess() ) {
00179         log << MSG::ERROR << "Can not create Context "
00180             << theSvc->name( ) << endreq;
00181         return sc;
00182       }
00183     }
00184   }
00185   else if ( m_evtSelector && m_evtContext )   {
00186     m_evtSelector->releaseContext(m_evtContext);
00187     m_evtSelector = 0;
00188     m_evtContext = 0;
00189   }
00190   return StatusCode::SUCCESS;
00191 }

StatusCode EventLoopMgr::stop (  )  [virtual]

implementation of IService::stop

Reimplemented from MinimalEventLoopMgr.

Definition at line 197 of file EventLoopMgr.cpp.

References IncidentType::EndEvent, IIncidentSvc::fireIncident(), m_endEventFired, MinimalEventLoopMgr::m_incidentSvc, Service::name(), and MinimalEventLoopMgr::stop().

00197                                  {
00198   if ( ! m_endEventFired ) {
00199     // Fire pending EndEvent incident
00200     m_incidentSvc->fireIncident(Incident(name(),IncidentType::EndEvent));
00201     m_endEventFired = true;
00202   }
00203   return MinimalEventLoopMgr::stop();
00204 }

StatusCode EventLoopMgr::finalize (  )  [virtual]

implementation of IService::finalize

Reimplemented from MinimalEventLoopMgr.

Definition at line 209 of file EventLoopMgr.cpp.

References IConverter::createRep(), endreq(), MSG::ERROR, IConverter::fillRepRefs(), MinimalEventLoopMgr::finalize(), StatusCode::ignore(), MSG::INFO, StatusCode::isSuccess(), m_evtContext, m_evtDataMgrSvc, m_evtDataSvc, m_evtSelector, m_histoDataMgrSvc, m_histoPersSvc, Service::msgSvc(), Service::name(), IEvtSelector::releaseContext(), MinimalEventLoopMgr::releaseInterface(), HistogramAgent::selectedObjects(), StatusCode::SUCCESS, and IDataManagerSvc::traverseTree().

00209                                      {
00210   StatusCode sc;
00211   MsgStream log(msgSvc(), name());
00212   
00213   // Finalize base class
00214   sc = MinimalEventLoopMgr::finalize();
00215   if (! sc.isSuccess()) {
00216     log << MSG::ERROR << "Error finalizing base class" << endreq;
00217     return sc;
00218   }
00219 
00220   // Save Histograms Now
00221   if ( 0 != m_histoPersSvc )    {
00222     HistogramAgent agent;
00223     sc = m_histoDataMgrSvc->traverseTree( &agent );
00224     if( sc.isSuccess() )   {
00225       IDataSelector* objects = agent.selectedObjects();
00226       // skip /stat entry!
00227       if ( objects->size() > 0 )    {
00228         IDataSelector::iterator i;
00229         for ( i = objects->begin(); i != objects->end(); i++ )    {
00230           IOpaqueAddress* pAddr = 0;
00231           StatusCode iret = m_histoPersSvc->createRep(*i, pAddr);
00232           if ( iret.isSuccess() )     {
00233             (*i)->registry()->setAddress(pAddr);
00234           }
00235           else  {
00236             sc = iret;
00237           }
00238         }
00239         for ( i = objects->begin(); i != objects->end(); i++ )    {
00240           IRegistry* reg = (*i)->registry();
00241           StatusCode iret = m_histoPersSvc->fillRepRefs(reg->address(), *i);
00242           if ( !iret.isSuccess() )    {
00243             sc = iret;
00244           }
00245         }
00246       }
00247       if ( sc.isSuccess() )    {
00248         log << MSG::INFO << "Histograms converted successfully according to request." << endreq;
00249       }
00250       else  {
00251         log << MSG::ERROR << "Error while saving Histograms." << endreq;
00252       }
00253     }
00254     else {
00255       log << MSG::ERROR << "Error while traversing Histogram data store" << endreq;
00256     }
00257   }
00258 
00259   // Release evemt selector context
00260   if ( m_evtSelector && m_evtContext )   {
00261     m_evtSelector->releaseContext(m_evtContext).ignore();
00262     m_evtContext = 0;
00263   }
00264 
00265   // Release all interfaces...
00266   m_histoDataMgrSvc = releaseInterface(m_histoDataMgrSvc);
00267   m_histoPersSvc    = releaseInterface(m_histoPersSvc);
00268 
00269   m_evtSelector     = releaseInterface(m_evtSelector);
00270   m_evtDataSvc      = releaseInterface(m_evtDataSvc);
00271   m_evtDataMgrSvc   = releaseInterface(m_evtDataMgrSvc);
00272 
00273   return StatusCode::SUCCESS;
00274 }

StatusCode EventLoopMgr::nextEvent ( int  maxevt  )  [virtual]

implementation of IService::nextEvent

Reimplemented from MinimalEventLoopMgr.

Definition at line 315 of file EventLoopMgr.cpp.

References MSG::ALWAYS, IDataManagerSvc::clearStore(), MSG::DEBUG, IncidentType::EndEvent, endreq(), MSG::ERROR, executeEvent(), IIncidentSvc::fireIncident(), getEventRoot(), MSG::INFO, StatusCode::isSuccess(), m_endEventFired, m_evtContext, m_evtDataMgrSvc, m_evtDataSvc, MinimalEventLoopMgr::m_incidentSvc, MinimalEventLoopMgr::m_scheduledStop, Service::msgSvc(), Service::name(), IDataProviderSvc::retrieveObject(), IDataManagerSvc::setRoot(), StatusCode::SUCCESS, and MSG::WARNING.

00315                                                {
00316   static int        total_nevt = 0;
00317   DataObject*       pObject = 0;
00318   StatusCode        sc;
00319   MsgStream         log( msgSvc(), name() );
00320 
00321   // loop over events if the maxevt (received as input) if different from -1. 
00322   // if evtmax is -1 it means infinite loop
00323   for( int nevt = 0; (maxevt == -1 ? true : nevt < maxevt);  nevt++, total_nevt++) {
00324     // Check if there is a scheduled stop issued by some algorithm/sevice
00325     if ( m_scheduledStop ) {
00326       m_scheduledStop = false;
00327       log << MSG::ALWAYS << "Terminating event processing loop due to scheduled stop" << endreq;
00328       break;
00329     }
00330     // Clear the event store, if used in the event loop
00331     if( 0 != total_nevt ) {
00332       
00333       if ( ! m_endEventFired ) {
00334         // Fire EndEvent "Incident" (it is considered part of the clearsing of the TS)
00335         m_incidentSvc->fireIncident(Incident(name(),IncidentType::EndEvent));
00336         m_endEventFired = true;
00337       }
00338       sc = m_evtDataMgrSvc->clearStore();
00339       if( !sc.isSuccess() )  {
00340         log << MSG::DEBUG << "Clear of Event data store failed" << endreq;
00341       }
00342     }
00343 
00344     // Setup event in the event store
00345     if( m_evtContext ) {
00346       IOpaqueAddress* addr = 0;
00347       // Only if there is a EventSelector
00348       sc = getEventRoot(addr);
00349       if( !sc.isSuccess() )  {
00350         log << MSG::INFO << "No more events in event selection " << endreq;
00351         break;
00352       }
00353       // Set root clears the event data store first
00354       sc = m_evtDataMgrSvc->setRoot ("/Event", addr);
00355       if( !sc.isSuccess() )  {
00356         log << MSG::WARNING << "Error declaring event root address." << endreq;
00357         continue;
00358       }
00359       sc = m_evtDataSvc->retrieveObject("/Event", pObject);
00360       if( !sc.isSuccess() ) {
00361         log << MSG::WARNING << "Unable to retrieve Event root object" << endreq;
00362         break;
00363       }
00364     }
00365     else {
00366       sc = m_evtDataMgrSvc->setRoot ("/Event", new DataObject());
00367       if( !sc.isSuccess() )  {
00368         log << MSG::WARNING << "Error declaring event root DataObject" << endreq;
00369       } 
00370     }
00371     // Execute event for all required algorithms
00372     sc = executeEvent(NULL);
00373     m_endEventFired = false;
00374     if( !sc.isSuccess() ){
00375       log << MSG::ERROR << "Terminating event processing loop due to errors" << endreq;
00376       break;
00377     }
00378   }
00379   return StatusCode::SUCCESS;
00380 }

StatusCode EventLoopMgr::executeEvent ( void *  par  )  [virtual]

implementation of IEventProcessor::executeEvent(void* par)

Reimplemented from MinimalEventLoopMgr.

Definition at line 280 of file EventLoopMgr.cpp.

References MSG::ALWAYS, IncidentType::BeginEvent, endreq(), MSG::ERROR, MinimalEventLoopMgr::executeEvent(), IIncidentSvc::fireIncident(), StatusCode::isSuccess(), MinimalEventLoopMgr::m_incidentSvc, MinimalEventLoopMgr::m_scheduledStop, Service::msgSvc(), Service::name(), and StatusCode::SUCCESS.

Referenced by nextEvent().

00280                                                   {
00281 
00282   // Fire BeginEvent "Incident"
00283   m_incidentSvc->fireIncident(Incident(name(),IncidentType::BeginEvent));
00284   // An incident may schedule a stop, in which case is better to exit before the actual execution.
00285   if ( m_scheduledStop ) {
00286     MsgStream  log( msgSvc(), name() );
00287     log << MSG::ALWAYS << "Terminating event processing loop due to a stop scheduled by an incident listener" << endreq;
00288     return StatusCode::SUCCESS;
00289   }
00290 
00291   // Execute Algorithms
00292   StatusCode sc = MinimalEventLoopMgr::executeEvent(par);
00293 
00294   // Check if there was an error processing current event
00295   if( !sc.isSuccess() ){
00296     MsgStream log( msgSvc(), name() );
00297     log << MSG::ERROR << "Terminating event processing loop due to errors" << endreq;
00298   }
00299   return sc;
00300 }

StatusCode EventLoopMgr::executeRun ( int  maxevt  )  [virtual]

implementation of IEventProcessor::executeRun()

Reimplemented from MinimalEventLoopMgr.

Definition at line 305 of file EventLoopMgr.cpp.

References MinimalEventLoopMgr::executeRun().

00305                                                    {
00306   StatusCode  sc;
00307   // initialize the base class
00308   sc = MinimalEventLoopMgr::executeRun(maxevt);
00309   return sc;
00310 }


Member Data Documentation

IDataManagerSvc* EventLoopMgr::m_evtDataMgrSvc [protected]

Reference to the Event Data Service's IDataManagerSvc interface.

Definition at line 41 of file EventLoopMgr.h.

Referenced by finalize(), initialize(), nextEvent(), and ~EventLoopMgr().

IDataProviderSvc* EventLoopMgr::m_evtDataSvc [protected]

Reference to the Event Data Service's IDataProviderSvc interface.

Definition at line 43 of file EventLoopMgr.h.

Referenced by finalize(), initialize(), nextEvent(), and ~EventLoopMgr().

IEvtSelector* EventLoopMgr::m_evtSelector [protected]

Reference to the Event Selector.

Definition at line 45 of file EventLoopMgr.h.

Referenced by finalize(), getEventRoot(), initialize(), reinitialize(), and ~EventLoopMgr().

IEvtSelector::Context* EventLoopMgr::m_evtContext [protected]

Event Iterator.

Definition at line 47 of file EventLoopMgr.h.

Referenced by finalize(), getEventRoot(), initialize(), nextEvent(), reinitialize(), and ~EventLoopMgr().

std::string EventLoopMgr::m_evtsel [protected]

Event selector.

Definition at line 49 of file EventLoopMgr.h.

Referenced by initialize(), and reinitialize().

IDataManagerSvc* EventLoopMgr::m_histoDataMgrSvc [protected]

Reference to the Histogram Data Service.

Definition at line 51 of file EventLoopMgr.h.

Referenced by finalize(), initialize(), and ~EventLoopMgr().

IConversionSvc* EventLoopMgr::m_histoPersSvc [protected]

Reference to the Histogram Persistency Service.

Definition at line 53 of file EventLoopMgr.h.

Referenced by finalize(), initialize(), and ~EventLoopMgr().

std::string EventLoopMgr::m_histPersName [protected]

Name of the Hist Pers type.

Definition at line 55 of file EventLoopMgr.h.

IProperty* EventLoopMgr::m_appMgrProperty [protected]

Property interface of ApplicationMgr.

Definition at line 57 of file EventLoopMgr.h.

Referenced by initialize(), and reinitialize().

bool EventLoopMgr::m_endEventFired [protected]

Flag to avoid to fire the EnvEvent incident twice in a row (and also not before the first event).

Definition at line 60 of file EventLoopMgr.h.

Referenced by nextEvent(), and stop().


The documentation for this class was generated from the following files:
Generated at Fri Jul 18 12:07:12 2008 for Gaudi Framework, version v20r2 by Doxygen version 1.5.1 written by Dimitri van Heesch, © 1997-2004