/search.css" rel="stylesheet" type="text/css"/> /search.js">
00001 #define DYBSVC_DYBEVENTLOOPMGR_CPP 00002 00003 #include "DybEventLoopMgr.h" 00004 00005 #include "GaudiKernel/DataObject.h" 00006 #include "GaudiKernel/IDataManagerSvc.h" 00007 #include "GaudiKernel/IDataProviderSvc.h" 00008 #include "GaudiKernel/IConversionSvc.h" 00009 00010 DybEventLoopMgr::DybEventLoopMgr(const std::string& nam, ISvcLocator* svcLoc) 00011 : MinimalEventLoopMgr(nam, svcLoc) 00012 , m_evtDataMgrSvc(0) 00013 , m_evtDataSvc(0) 00014 , m_evtSelector(0) 00015 , m_evtContext(0) 00016 { 00017 declareProperty("EvtSel", m_evtSelName="NONE", 00018 "Name of Event Selector to use (def: NONE)"); 00019 declareProperty("EventStore", m_evtStoreName="EventDataSvc", 00020 "Name of the Event Store provider (def: EventDataSvc)"); 00021 00022 } 00023 00024 DybEventLoopMgr::~DybEventLoopMgr() 00025 { 00026 } 00027 00028 StatusCode DybEventLoopMgr::initialize() { 00029 // initilaize the base class 00030 MsgStream log(msgSvc(), name()); 00031 00032 StatusCode sc = MinimalEventLoopMgr::initialize(); 00033 00034 if (sc.isFailure()) { 00035 log << MSG::WARNING << "Error Initializing base class MinimalEventLoopMgr." << endreq; 00036 return sc; 00037 } 00038 00039 log << MSG::DEBUG 00040 << "Getting event store service" 00041 << endreq; 00042 // Setup access to event data services 00043 sc = serviceLocator()->service(m_evtStoreName, m_evtDataMgrSvc, true); 00044 if (sc.isFailure()) { 00045 log << MSG::FATAL << "Error retrieving EventDataSvc interface IDataManagerSvc." << endreq; 00046 return sc; 00047 } 00048 sc = serviceLocator()->service(m_evtStoreName, m_evtDataSvc, true); 00049 if (sc.isFailure()) { 00050 log << MSG::FATAL << "Error retrieving EventDataSvc interface IDataProviderSvc." << endreq; 00051 return sc; 00052 } 00053 00054 00055 log << MSG::DEBUG 00056 << "Event selector name: \"" << m_evtSelName << "\"" 00057 << endreq; 00058 00059 if (!m_evtSelName.size() || "NONE" == m_evtSelName) { 00060 log << MSG::INFO << "No event selector to be used" << endreq; 00061 return StatusCode::SUCCESS; 00062 } 00063 00064 sc = serviceLocator()->service(m_evtSelName, m_evtSelector, true); 00065 if (sc.isFailure()) { 00066 log << MSG::FATAL << "Failed to create event selector " 00067 << "\"" << m_evtSelName << "\"" << endreq; 00068 return sc; 00069 } 00070 00071 sc = m_evtSelector->createContext(m_evtContext); 00072 if (sc.isFailure()) { 00073 log << MSG::FATAL << "Can not create the event selector Context." << endreq; 00074 return sc; 00075 } 00076 00077 log << MSG::INFO << "initialized with EvtSel = " << m_evtSelName 00078 << ", Event Store = " << m_evtStoreName << endreq; 00079 00080 return StatusCode::SUCCESS; 00081 } 00082 00083 StatusCode DybEventLoopMgr::reinitialize() { 00084 // reinitilaize the base class 00085 StatusCode sc = MinimalEventLoopMgr::reinitialize(); 00086 if (sc.isFailure()) return sc; 00087 00088 MsgStream log(msgSvc(), name()); 00089 log << MSG::DEBUG << "I'm being reinitialized. Why?" << endreq; 00090 00091 return StatusCode::SUCCESS; 00092 } 00093 00094 StatusCode DybEventLoopMgr::finalize() 00095 { 00096 MsgStream log(msgSvc(), name()); 00097 00098 // Release evemt selector context 00099 if (m_evtSelector && m_evtContext) { 00100 m_evtSelector->releaseContext(m_evtContext).ignore(); 00101 m_evtContext = 0; 00102 } 00103 00104 // Release all interfaces... 00105 m_evtSelector = releaseInterface(m_evtSelector); 00106 m_evtDataSvc = releaseInterface(m_evtDataSvc); 00107 m_evtDataMgrSvc = releaseInterface(m_evtDataMgrSvc); 00108 00109 return MinimalEventLoopMgr::finalize(); 00110 } 00111 00112 // WTF doesn't MinimalEventLoopMgr handle this? 00113 StatusCode DybEventLoopMgr::executeEvent(void* par) 00114 { 00115 MsgStream log(msgSvc(), name()); 00116 00117 if (m_scheduledStop) { 00118 log << MSG::ALWAYS 00119 << "Terminating event processing loop due to a stop scheduled by an incident listener" 00120 << endreq; 00121 return StatusCode::SUCCESS; 00122 } 00123 00124 // Execute Algorithms 00125 StatusCode sc = MinimalEventLoopMgr::executeEvent(par); 00126 if (sc.isFailure()) { 00127 log << MSG::ERROR << "Terminating event processing loop due to errors" << endreq; 00128 } 00129 00130 return sc; 00131 } 00132 00133 StatusCode DybEventLoopMgr::nextEvent(int maxevt) 00134 { 00135 StatusCode sc = StatusCode::SUCCESS; 00136 MsgStream log( msgSvc(), name() ); 00137 00138 // loop over events if the maxevt (received as input) if different from -1. 00139 // if evtmax is -1 it means infinite loop 00140 for (int nevt = 0; (maxevt == -1 ? true : nevt < maxevt); ++nevt) { 00141 00142 log << MSG::DEBUG 00143 << "Executing event loop #" << nevt << endreq; 00144 00145 // Check if there is a scheduled stop issued by some algorithm/sevice 00146 if (m_scheduledStop) { 00147 m_scheduledStop = false; 00148 log << MSG::ALWAYS 00149 << "Terminating event processing loop due to scheduled stop" << endreq; 00150 return StatusCode::SUCCESS; 00151 } 00152 00153 sc = m_evtDataMgrSvc->clearStore(); 00154 if (sc.isFailure()) { 00155 log << MSG::DEBUG << "Clear of Event data store failed" << endreq; 00156 } 00157 00158 // Setup event in the event store 00159 if (m_evtContext) { 00160 IOpaqueAddress* addr = 0; 00161 // Only if there is a EventSelector 00162 sc = getEventRoot(addr); 00163 if (sc.isFailure()) { 00164 log << MSG::INFO << "No more events in event selection " << endreq; 00165 return StatusCode::SUCCESS; 00166 } 00167 00168 // Set root clears the event data store first 00169 sc = m_evtDataMgrSvc->setRoot("/Event", addr); 00170 if (sc.isFailure()) { 00171 log << MSG::WARNING << "Error declaring event root address." << endreq; 00172 continue; // not failure? 00173 } 00174 DataObject* pObject = 0; 00175 sc = m_evtDataSvc->retrieveObject("/Event", pObject); 00176 if( sc.isFailure() ) { 00177 log << MSG::WARNING << "Unable to retrieve Event root object" << endreq; 00178 return StatusCode::FAILURE; 00179 } 00180 } 00181 else { 00182 sc = m_evtDataMgrSvc->setRoot ("/Event", new DataObject()); 00183 if (sc.isFailure() ) { 00184 log << MSG::WARNING << "Error declaring event root DataObject" << endreq; 00185 } 00186 } 00187 // Execute event for all required algorithms 00188 sc = executeEvent(NULL); 00189 if (sc.isFailure()){ 00190 log << MSG::ERROR << "Terminating event processing loop due to errors" << endreq; 00191 return StatusCode::FAILURE; 00192 } 00193 } 00194 return StatusCode::SUCCESS; 00195 } 00196 00198 StatusCode DybEventLoopMgr::getEventRoot(IOpaqueAddress*& refpAddr) 00199 { 00200 refpAddr = 0; 00201 StatusCode sc = m_evtSelector->next(*m_evtContext); 00202 if (sc.isFailure()) { 00203 return sc; 00204 } 00205 00206 // Create root address and assign address to data service 00207 sc = m_evtSelector->createAddress(*m_evtContext,refpAddr); 00208 if (sc.isFailure()) { 00209 sc = m_evtSelector->next(*m_evtContext); 00210 if (sc.isSuccess()) { 00211 sc = m_evtSelector->createAddress(*m_evtContext,refpAddr); 00212 if (sc.isFailure()) { 00213 MsgStream log( msgSvc(), name() ); 00214 log << MSG::WARNING << "Error creating IOpaqueAddress." << endreq; 00215 } 00216 } 00217 } 00218 return sc; 00219 }