Gaudi Framework, version v21r9

Home   Generated: 3 May 2010

EventLoopMgr Class Reference

Class definition of EventLoopMgr. More...

#include <EventLoopMgr.h>

Inheritance diagram for EventLoopMgr:

Inheritance graph
[legend]
Collaboration diagram for EventLoopMgr:

Collaboration graph
[legend]

List of all members.

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::initialize
virtual StatusCode reinitialize ()
 implementation of IService::reinitialize
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

SmartIF< IDataManagerSvcm_evtDataMgrSvc
 Reference to the Event Data Service's IDataManagerSvc interface.
SmartIF< IDataProviderSvcm_evtDataSvc
 Reference to the Event Data Service's IDataProviderSvc interface.
SmartIF< IEvtSelectorm_evtSelector
 Reference to the Event Selector.
IEvtSelector::Contextm_evtContext
 Event Iterator.
std::string m_evtsel
 Event selector.
SmartIF< IDataManagerSvcm_histoDataMgrSvc
 Reference to the Histogram Data Service.
SmartIF< 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).
bool m_warnings
 Flag to disable warning messages when using external input.


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 39 of file EventLoopMgr.h.


Constructor & Destructor Documentation

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

Standard Constructor.

Definition at line 25 of file EventLoopMgr.cpp.

00026 : MinimalEventLoopMgr(nam, svcLoc)
00027 {
00028   m_histoDataMgrSvc   = 0;
00029   m_histoPersSvc      = 0;
00030   m_evtDataMgrSvc     = 0;
00031   m_evtDataSvc        = 0;
00032   m_evtSelector       = 0;
00033   m_evtContext        = 0;
00034   m_endEventFired     = true;
00035 
00036   // Declare properties
00037   declareProperty("HistogramPersistency", m_histPersName = "");
00038   declareProperty("EvtSel", m_evtsel );
00039   declareProperty("Warnings",m_warnings=true,
00040                   "Set this property to false to suppress warning messages");
00041 }

EventLoopMgr::~EventLoopMgr (  )  [virtual]

Standard Destructor.

Definition at line 46 of file EventLoopMgr.cpp.

00046                               {
00047   if( m_histoDataMgrSvc ) m_histoDataMgrSvc->release();
00048   if( m_histoPersSvc ) m_histoPersSvc->release();
00049   if( m_evtDataMgrSvc ) m_evtDataMgrSvc->release();
00050   if( m_evtDataSvc ) m_evtDataSvc->release();
00051   if( m_evtSelector ) m_evtSelector->release();
00052   if( m_evtContext ) delete m_evtContext;
00053 }


Member Function Documentation

StatusCode EventLoopMgr::getEventRoot ( IOpaqueAddress *&  refpAddr  ) 

Create event address using event selector.

Definition at line 394 of file EventLoopMgr.cpp.

00394                                                                 {
00395   refpAddr = 0;
00396   StatusCode sc = m_evtSelector->next(*m_evtContext);
00397   if ( !sc.isSuccess() )  {
00398     return sc;
00399   }
00400   // Create root address and assign address to data service
00401   sc = m_evtSelector->createAddress(*m_evtContext,refpAddr);
00402   if( !sc.isSuccess() )  {
00403     sc = m_evtSelector->next(*m_evtContext);
00404     if ( sc.isSuccess() )  {
00405       sc = m_evtSelector->createAddress(*m_evtContext,refpAddr);
00406       if ( !sc.isSuccess() )  {
00407         MsgStream log( msgSvc(), name() );
00408         log << MSG::WARNING << "Error creating IOpaqueAddress." << endmsg;
00409       }
00410     }
00411   }
00412   return sc;
00413 }

StatusCode EventLoopMgr::initialize (  )  [virtual]

implementation of IService::initialize

Reimplemented from MinimalEventLoopMgr.

Definition at line 58 of file EventLoopMgr.cpp.

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

StatusCode EventLoopMgr::reinitialize (  )  [virtual]

implementation of IService::reinitialize

Reimplemented from MinimalEventLoopMgr.

Definition at line 134 of file EventLoopMgr.cpp.

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

StatusCode EventLoopMgr::stop (  )  [virtual]

implementation of IService::stop

Reimplemented from MinimalEventLoopMgr.

Definition at line 207 of file EventLoopMgr.cpp.

00207                                  {
00208   if ( ! m_endEventFired ) {
00209     // Fire pending EndEvent incident
00210     m_incidentSvc->fireIncident(Incident(name(),IncidentType::EndEvent));
00211     m_endEventFired = true;
00212   }
00213   return MinimalEventLoopMgr::stop();
00214 }

StatusCode EventLoopMgr::finalize ( void   )  [virtual]

implementation of IService::finalize

Reimplemented from MinimalEventLoopMgr.

Definition at line 219 of file EventLoopMgr.cpp.

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

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

implementation of IService::nextEvent

Reimplemented from MinimalEventLoopMgr.

Definition at line 325 of file EventLoopMgr.cpp.

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

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

implementation of IEventProcessor::executeEvent(void* par)

Reimplemented from MinimalEventLoopMgr.

Definition at line 290 of file EventLoopMgr.cpp.

00290                                                   {
00291 
00292   // Fire BeginEvent "Incident"
00293   m_incidentSvc->fireIncident(Incident(name(),IncidentType::BeginEvent));
00294   // An incident may schedule a stop, in which case is better to exit before the actual execution.
00295   if ( m_scheduledStop ) {
00296     MsgStream  log( msgSvc(), name() );
00297     log << MSG::ALWAYS << "Terminating event processing loop due to a stop scheduled by an incident listener" << endmsg;
00298     return StatusCode::SUCCESS;
00299   }
00300 
00301   // Execute Algorithms
00302   StatusCode sc = MinimalEventLoopMgr::executeEvent(par);
00303 
00304   // Check if there was an error processing current event
00305   if( !sc.isSuccess() ){
00306     MsgStream log( msgSvc(), name() );
00307     log << MSG::ERROR << "Terminating event processing loop due to errors" << endmsg;
00308   }
00309   return sc;
00310 }

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

implementation of IEventProcessor::executeRun()

Reimplemented from MinimalEventLoopMgr.

Definition at line 315 of file EventLoopMgr.cpp.

00315                                                    {
00316   StatusCode  sc;
00317   // initialize the base class
00318   sc = MinimalEventLoopMgr::executeRun(maxevt);
00319   return sc;
00320 }


Member Data Documentation

Reference to the Event Data Service's IDataManagerSvc interface.

Definition at line 44 of file EventLoopMgr.h.

Reference to the Event Data Service's IDataProviderSvc interface.

Definition at line 46 of file EventLoopMgr.h.

Reference to the Event Selector.

Definition at line 48 of file EventLoopMgr.h.

Event Iterator.

Definition at line 50 of file EventLoopMgr.h.

Event selector.

Definition at line 52 of file EventLoopMgr.h.

Reference to the Histogram Data Service.

Definition at line 54 of file EventLoopMgr.h.

Reference to the Histogram Persistency Service.

Definition at line 56 of file EventLoopMgr.h.

Name of the Hist Pers type.

Definition at line 58 of file EventLoopMgr.h.

Property interface of ApplicationMgr.

Definition at line 60 of file EventLoopMgr.h.

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

Definition at line 63 of file EventLoopMgr.h.

Flag to disable warning messages when using external input.

Definition at line 65 of file EventLoopMgr.h.


The documentation for this class was generated from the following files:

Generated at Mon May 3 12:24:09 2010 for Gaudi Framework, version v21r9 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004