Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

EventLoopMgr.cpp

Go to the documentation of this file.
00001 //===================================================================
00002 //      EventLoopMgr.cpp
00003 //--------------------------------------------------------------------
00004 //
00005 //      Package    : EventLoopMgr ( The LHCb Offline System)
00006 //
00007 //  Description: implementation of the Application's batch mode handler
00008 //
00009 //      Author     : M.Frank
00010 //  History    :
00011 // +---------+----------------------------------------------+---------
00012 // |    Date |                 Comment                      | Who     
00013 // +---------+----------------------------------------------+---------
00014 // | 29/10/98| Initial version                              | MF
00015 // +---------+----------------------------------------------+---------
00016 //
00017 //====================================================================
00018 #define  GAUDISVC_EVENTLOOPMGR_CPP
00019 
00020 #include "GaudiKernel/SmartIF.h"
00021 #include "GaudiKernel/Incident.h"
00022 #include "GaudiKernel/MsgStream.h"
00023 #include "GaudiKernel/SvcFactory.h"
00024 #include "GaudiKernel/DataObject.h"
00025 #include "GaudiKernel/IIncidentSvc.h"
00026 #include "GaudiKernel/IEvtSelector.h"
00027 #include "GaudiKernel/IDataManagerSvc.h"
00028 #include "GaudiKernel/IDataProviderSvc.h"
00029 
00030 #include "EventLoopMgr.h"
00031 
00032 // Instantiation of a static factory class used by clients to create instances of this service
00033 static SvcFactory<EventLoopMgr> s_EventLoopMgrFactory;
00034 const ISvcFactory& EventLoopMgrFactory = s_EventLoopMgrFactory;
00035 
00036 // Standard Constructor
00037 EventLoopMgr::EventLoopMgr(const std::string& nam, ISvcLocator* svcLoc)
00038 : MinimalEventLoopMgr(nam, svcLoc)
00039 {
00040   declareProperty( "EvtSel", m_evtsel );
00041 }
00042 
00043 // Standard Destructor
00044 EventLoopMgr::~EventLoopMgr()   {
00045 }
00046 
00047 // implementation of IAppMgrUI::initalize
00048 StatusCode EventLoopMgr::initialize()    {
00049   StatusCode sc = MinimalEventLoopMgr::initialize();
00050   if ( sc.isSuccess() )   {
00051     MsgStream log(msgSvc(), name());
00052     //--------------------------------------------------------------------------------------------
00053     // Setup access to event data services
00054     //--------------------------------------------------------------------------------------------
00055     sc = serviceLocator()->service("EventDataSvc", m_evtDataMgrSvc);
00056     if( !sc.isSuccess() )  {
00057       log << MSG::FATAL << "Error retrieving EventDataSvc interface IDataManagerSvc." << endreq;
00058       return sc;
00059     }
00060     sc = serviceLocator()->service("EventDataSvc", m_evtDataSvc);
00061     if( !sc.isSuccess() )  {
00062       log << MSG::FATAL << "Error retrieving EventDataSvc interface IDataProviderSvc." << endreq;
00063       return sc;
00064     }
00065     //--------------------------------------------------------------------------------------------
00066     // Get the references to the services that are needed by the ApplicationMgr itself
00067     //--------------------------------------------------------------------------------------------
00068     sc = serviceLocator()->service("IncidentSvc", m_incidentSvc);
00069     if( !sc.isSuccess() )  {
00070       log << MSG::FATAL << "Error retrieving IncidentSvc." << endreq;
00071       return sc;
00072     }
00073     //--------------------------------------------------------------------------------------------
00074     // Setup Event Setector
00075     //--------------------------------------------------------------------------------------------
00076     // We do not expect a Event Selector necessarily being declared
00077     SmartIF<IProperty> prpMgr(IID_IProperty, serviceLocator());
00078     if ( prpMgr.isValid() )   {
00079       setProperty(prpMgr->getProperty("EvtSel"));
00080     }
00081     else {
00082       log << MSG::FATAL << "IProperty interface not found in ApplicationMgr." << endreq;
00083       return StatusCode::FAILURE;
00084     }
00085     if( m_evtsel != "NONE" || m_evtsel.length() == 0) {
00086       sc = serviceLocator()->service( "EventSelector", m_evtSelector, true );
00087       if( sc.isSuccess() )     {
00088         // Setup Event Selector
00089         m_evtIterator = m_evtSelector->begin();
00090       }
00091       else {
00092         log << MSG::FATAL << "EventSelector not found." << endreq;
00093         return StatusCode::FAILURE;
00094       }
00095     }
00096     else {
00097       m_evtSelector = 0;
00098       m_evtIterator = 0;
00099       log << MSG::WARNING << "Unable to locate service \"EventSelector\" " << endreq;    
00100       log << MSG::WARNING << "No events will be processed from external input." << endreq;    
00101     }
00102   }
00103   else    {
00104     MsgStream log(msgSvc(), name());
00105     log << MSG::FATAL << "Error Initializing base class MinimalEventLoopMgr." << endreq;
00106   }
00107   return sc;
00108 }
00109 
00110 // implementation of IAppMgrUI::finalize
00111 StatusCode EventLoopMgr::finalize()    {
00112   m_evtSelector   = releaseInterface(m_evtSelector);
00113   m_incidentSvc   = releaseInterface(m_incidentSvc);
00114   m_evtDataSvc    = releaseInterface(m_evtDataSvc);
00115   m_evtDataMgrSvc = releaseInterface(m_evtDataMgrSvc);
00116   return MinimalEventLoopMgr::finalize();
00117 }
00118 
00119 // executeEvent(void* par)
00120 StatusCode EventLoopMgr::executeEvent(void* par)    {
00121   // Fire BeginEvent "Incident"
00122   m_incidentSvc->fireIncident(Incident(name(),"BeginEvent"));
00123   // Execute Algorithms
00124   StatusCode sc = MinimalEventLoopMgr::executeEvent(par);
00125   // Fire EndEvent "Incident"
00126   m_incidentSvc->fireIncident(Incident(name(),"EndEvent"));
00127   //--------------------------------------------------------------------------------------------
00128   // Check if there was an error processing current event
00129   //--------------------------------------------------------------------------------------------
00130   if( !sc.isSuccess() ){
00131     MsgStream log( msgSvc(), name() );
00132     log << MSG::ERROR << "Terminating event processing loop due to errors" << endreq;
00133   }
00134   return sc;
00135 }
00136 
00137 // implementation of IAppMgrUI::nextEvent
00138 StatusCode EventLoopMgr::nextEvent(int maxevt)   {
00139   static int        total_nevt = 0;
00140   DataObject*       pObject = 0;
00141   StatusCode        sc;
00142   MsgStream log( msgSvc(), name() );
00143 
00144   // Check to see whether a new Event Selector has been specified
00145   SmartIF<IProperty> prpMgr(IID_IProperty, serviceLocator());
00146   if ( prpMgr.isValid() )   {
00147     setProperty(prpMgr->getProperty("EvtSel"));
00148     if( m_evtsel != "NONE" || m_evtsel.length() == 0) {
00149       IEvtSelector* theEvtSel;
00150       sc = serviceLocator()->service( "EventSelector", theEvtSel );
00151       if( sc.isSuccess() && ( theEvtSel != m_evtSelector ) ) {
00152         // Setup Event Selector
00153         m_evtSelector = theEvtSel;
00154         m_evtIterator = m_evtSelector->begin();
00155         Service* theSvc = dynamic_cast< Service* >( theEvtSel );
00156         log << MSG::INFO << "EventSelector service changed to " << theSvc->name( ) << endreq;
00157       }
00158     }
00159   }
00160 
00161 
00162   // loop over events if the maxevt (received as input) is different from -1. 
00163   // if evtmax is -1 it means infinite loop
00164   for( int nevt = 0; (maxevt == -1 ? true : nevt < maxevt);  nevt++, total_nevt++) {
00165     //--------------------------------------------------------------------------------------------
00166     // Clear the event store, if used in the event loop
00167     //--------------------------------------------------------------------------------------------
00168     if( 0 != total_nevt ) {
00169       sc = m_evtDataMgrSvc->clearStore();
00170       if( !sc.isSuccess() )  {
00171         MsgStream log( msgSvc(), name() );
00172         log << MSG::DEBUG << "Clear of Event data store failed" << endreq;
00173       }
00174     }
00175     //--------------------------------------------------------------------------------------------
00176     // Setup event in the event store
00177     //--------------------------------------------------------------------------------------------
00178     if( m_evtIterator ) {
00179       // Only if there is a EventSelector
00180       if( *(m_evtIterator) == *(m_evtSelector->end()) ) {
00181         // This is the end of the loop. No more events in the selection
00182         MsgStream log( msgSvc(), name() );
00183         log << MSG::INFO << "No more events in event selection " << endreq;
00184         break;
00185       }
00186       // Create root address and assign address to data service
00187       IOpaqueAddress* addr = **m_evtIterator;
00188       // Set root clears the event data store first
00189       sc = m_evtDataMgrSvc->setRoot ("/Event", addr);
00190       if( !sc.isSuccess() )  {
00191         MsgStream log( msgSvc(), name() );
00192         log << MSG::WARNING << "Error declaring event root address." << endreq;
00193         continue;
00194       }
00195       sc = m_evtDataSvc->retrieveObject("/Event", pObject);
00196       if( !sc.isSuccess() ) {
00197         MsgStream log( msgSvc(), name() );
00198         log << MSG::WARNING << "Unable to retrieve Event root object" << endreq;
00199         break;
00200       }
00201     }
00202     else {
00203       sc = m_evtDataMgrSvc->setRoot ("/Event", new DataObject());
00204       if( !sc.isSuccess() )  {
00205         MsgStream log( msgSvc(), name() );
00206         log << MSG::WARNING << "Error declaring event root DataObject" << endreq;
00207       } 
00208     }
00209     // Execute event for all required algorithms
00210     sc = executeEvent(NULL);
00211     if( !sc.isSuccess() ){
00212       MsgStream log( msgSvc(), name() );
00213       log << MSG::ERROR << "Terminating event processing loop due to errors" << endreq;
00214       break;
00215     }
00216     //--------------------------------------------------------------------------------------------
00217     // increment event iterator
00218     //--------------------------------------------------------------------------------------------
00219     if (m_evtIterator)  (*m_evtIterator)++;
00220   }
00221   return StatusCode::SUCCESS;
00222 }

Generated at Wed Nov 21 12:22:29 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000