00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
00033 static SvcFactory<EventLoopMgr> s_EventLoopMgrFactory;
00034 const ISvcFactory& EventLoopMgrFactory = s_EventLoopMgrFactory;
00035
00036
00037 EventLoopMgr::EventLoopMgr(const std::string& nam, ISvcLocator* svcLoc)
00038 : MinimalEventLoopMgr(nam, svcLoc)
00039 {
00040 declareProperty( "EvtSel", m_evtsel );
00041 }
00042
00043
00044 EventLoopMgr::~EventLoopMgr() {
00045 }
00046
00047
00048 StatusCode EventLoopMgr::initialize() {
00049 StatusCode sc = MinimalEventLoopMgr::initialize();
00050 if ( sc.isSuccess() ) {
00051 MsgStream log(msgSvc(), name());
00052
00053
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
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
00075
00076
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
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
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
00120 StatusCode EventLoopMgr::executeEvent(void* par) {
00121
00122 m_incidentSvc->fireIncident(Incident(name(),"BeginEvent"));
00123
00124 StatusCode sc = MinimalEventLoopMgr::executeEvent(par);
00125
00126 m_incidentSvc->fireIncident(Incident(name(),"EndEvent"));
00127
00128
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
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
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
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
00163
00164 for( int nevt = 0; (maxevt == -1 ? true : nevt < maxevt); nevt++, total_nevt++) {
00165
00166
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
00177
00178 if( m_evtIterator ) {
00179
00180 if( *(m_evtIterator) == *(m_evtSelector->end()) ) {
00181
00182 MsgStream log( msgSvc(), name() );
00183 log << MSG::INFO << "No more events in event selection " << endreq;
00184 break;
00185 }
00186
00187 IOpaqueAddress* addr = **m_evtIterator;
00188
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
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
00218
00219 if (m_evtIterator) (*m_evtIterator)++;
00220 }
00221 return StatusCode::SUCCESS;
00222 }