1 #define GAUDIKERNEL_MINIMALEVENTLOOPMGR_CPP
3 #include "GaudiKernel/SmartIF.h"
4 #include "GaudiKernel/MsgStream.h"
5 #include "GaudiKernel/IAlgorithm.h"
6 #include "GaudiKernel/IAlgManager.h"
7 #include "GaudiKernel/TypeNameString.h"
8 #include "GaudiKernel/GaudiException.h"
9 #include "GaudiKernel/ThreadGaudi.h"
10 #include "GaudiKernel/Incident.h"
11 #include "GaudiKernel/IIncidentListener.h"
12 #include "GaudiKernel/IIncidentSvc.h"
13 #include "GaudiKernel/AppReturnCode.h"
15 #include "GaudiKernel/MinimalEventLoopMgr.h"
20 class AbortEventListener:
public implements1<IIncidentListener> {
22 AbortEventListener(
bool &flag, std::string &source):m_flag(flag),
26 virtual ~AbortEventListener() {}
39 std::string &m_source;
43 #define ON_DEBUG if (UNLIKELY(outputLevel() <= MSG::DEBUG))
44 #define ON_VERBOSE if (UNLIKELY(outputLevel() <= MSG::VERBOSE))
46 #define DEBMSG ON_DEBUG debug()
47 #define VERMSG ON_VERBOSE verbose()
83 error() <<
"Failed to initialize Service Base class." <<
endmsg;
89 error() <<
"Error retrieving AppMgr interface IProperty." <<
endmsg;
104 fatal() <<
"Error retrieving IncidentSvc." <<
endmsg;
121 error() <<
"Failed to initialize Output streams." <<
endmsg;
132 error() <<
"Failed to initialize Top Algorithms streams." <<
endmsg;
137 ListAlg::iterator ita;
141 sc = (*ita)->sysInitialize();
143 error() <<
"Unable to initialize Algorithm: " << (*ita)->name() <<
endmsg;
148 sc = (*ita)->sysInitialize();
150 error() <<
"Unable to initialize Output Stream: " << (*ita)->name() <<
endmsg;
165 ListAlg::iterator ita;
169 sc = (*ita)->sysStart();
171 error() <<
"Unable to start Algorithm: " << (*ita)->name() <<
endmsg;
176 sc = (*ita)->sysStart();
178 error() <<
"Unable to start Output Stream: " << (*ita)->name() <<
endmsg;
191 ListAlg::iterator ita;
195 sc = (*ita)->sysStop();
197 error() <<
"Unable to stop Algorithm: " << (*ita)->name() <<
endmsg;
202 sc = (*ita)->sysStop();
204 error() <<
"Unable to stop Output Stream: " << (*ita)->name() <<
endmsg;
217 ListAlg::iterator ita;
221 sc = (*ita)->sysReinitialize();
223 error() <<
"Unable to reinitialize Algorithm: " << (*ita)->name() <<
endmsg;
228 sc = (*ita)->sysReinitialize();
230 error() <<
"Unable to reinitialize Output Stream: " << (*ita)->name() <<
endmsg;
242 ListAlg::iterator ita;
246 sc = (*ita)->sysRestart();
248 error() <<
"Unable to restart Algorithm: " << (*ita)->name() <<
endmsg;
253 sc = (*ita)->sysRestart();
255 error() <<
"Unable to restart Output Stream: " << (*ita)->name() <<
endmsg;
270 ListAlg::iterator ita;
272 sc = (*ita)->sysFinalize();
275 warning() <<
"Finalization of algorithm " << (*ita)->name() <<
" failed" <<
endmsg;
280 sc = (*ita)->sysFinalize();
283 warning() <<
"Finalization of algorithm " << (*ita)->name() <<
" failed" <<
endmsg;
291 warning() <<
"Problems removing Algorithm " << (*ita)->name() <<
endmsg;
313 error() <<
"Problems finalizing Service base class" <<
endmsg;
323 error() <<
"This method cannot be called on an object of type "
333 ListAlg::iterator ita;
334 bool eventfailed =
false;
338 sc = (*ita)->sysBeginRun();
340 warning() <<
"beginRun() of algorithm " << (*ita)->name() <<
" failed" <<
endmsg;
353 sc = (*ita)->sysEndRun();
355 warning() <<
"endRun() of algorithm " << (*ita)->name() <<
" failed" <<
endmsg;
374 m_appmgr(appmgr), m_retcode(retcode) {}
375 inline void ignore() {
378 inline ~RetCodeGuard() {
392 bool eventfailed =
false;
399 std::for_each( std::begin(allAlgs),
std::end(allAlgs),
412 DEBMSG <<
"AbortEvent incident fired by "
419 sc = (*ita)->sysExecute();
422 fatal() <<
".executeEvent(): Exception with tag=" << Exception.
tag()
423 <<
" thrown by " << (*ita)->name() <<
endmsg;
425 }
catch (
const std::exception& Exception ) {
426 fatal() <<
".executeEvent(): Standard std::exception thrown by "
427 << (*ita)->name() <<
endmsg;
430 fatal() <<
".executeEvent(): UNKNOWN Exception thrown by "
431 << (*ita)->name() <<
endmsg;
435 warning() <<
"Execution of algorithm " << (*ita)->name() <<
" failed" <<
endmsg;
448 (*ito)->resetExecuted();
450 sc = (*ito)->sysExecute();
452 warning() <<
"Execution of output stream " << (*ito)->name() <<
" failed" <<
endmsg;
459 error() <<
"Error processing event loop." <<
endmsg;
471 error() <<
"Could not set return code of the application ("
483 throw GaudiException(
"Failed to initialize Top Algorithms streams.",
484 "MinimalEventLoopMgr::topAlgHandler",
500 for (VectorName::const_iterator it = algNames.begin(); it != algNames.end(); it++) {
504 const bool CREATE =
false;
507 DEBMSG <<
"Top Algorithm " << item_name <<
" already exists" <<
endmsg;
510 DEBMSG <<
"Creating Top Algorithm " << item.
type() <<
" with name " << item_name <<
endmsg;
514 error() <<
"Unable to create Top Algorithm " << item.
type() <<
" with name " << item_name <<
endmsg;
534 "MinimalEventLoopMgr::outStreamHandler",
550 for (VectorName::const_iterator it = algNames.begin(); it != algNames.end(); it++) {
553 const bool CREATE =
false;
563 error() <<
"Unable to create Output Stream " << (*it) <<
endmsg;
virtual ~MinimalEventLoopMgr()
Standard Destructor.
SmartIF< IIncidentSvc > m_incidentSvc
Reference to the incident service.
virtual SmartIF< IAlgorithm > & algorithm(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)=0
Returns a smart pointer to a service.
Define general base for Gaudi exception.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
GAUDI_API std::string getGaudiThreadIDfromName(const std::string &name)
helper function to extract Gaudi Thread ID from thread copy name
virtual StatusCode getProperty(Property *p) const =0
Get the property by property.
virtual StatusCode stopRun()
implementation of IEventProcessor::stopRun( )
const std::string & type() const
Access to the incident type.
virtual StatusCode stop()
Stop (from RUNNING to INITIALIZED).
bool m_scheduledStop
Scheduled stop of event processing.
virtual StatusCode setProperty(const Property &p)
Set the property by property.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
virtual StatusCode initialize()
implementation of IService::initialize
const std::string & source() const
Access to the source of the incident.
bool isSuccess() const
Test for a status code of SUCCESS.
GAUDI_API const std::string typeinfoName(const std::type_info &)
Get platform independent information about the class type.
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
virtual StatusCode nextEvent(int maxevt)
implementation of IEventProcessor::nextEvent
virtual StatusCode start()
implementation of IService::start
void outStreamHandler(Property &p)
Output stream List handler.
virtual const std::vector< IAlgorithm * > & getAlgorithms() const =0
Return the list of Algorithms.
SmartIF< IAppMgrUI > m_appMgrUI
Reference to the IAppMgrUI interface of the application manager.
StatusCode decodeTopAlgs()
decodeTopAlgNameList & topAlgNameListHandler
virtual void resetExecuted()=0
Reset the Algorithm executed state for the current event.
bool isFailure() const
Test for a status code of FAILURE.
const int UnhandledException
const std::string AbortEvent
Stop processing the current event and pass to te next one.
State m_state
State of the object.
virtual StatusCode createAlgorithm(const std::string &algtype, const std::string &algname, IAlgorithm *&alg, bool managed=false)=0
Create an instance of a algorithm type that has been declared beforehand and assigns to it a name...
virtual void declareUpdateHandler(PropertyCallbackFunctor *pf)
set new callback for update
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Base class used to implement the interfaces.
std::string m_abortEventSource
Source of the AbortEvent incident.
Helper class to parse a string of format "type/name".
virtual StatusCode executeEvent(void *par)
implementation of IEventProcessor::executeEvent(void* par)
This class is used for returning status codes from appropriate routines.
virtual const std::string & tag() const
name tag for the exception, or exception type
void topAlgHandler(Property &p)
Top algorithm List handler.
StatusCode setAppReturnCode(SmartIF< IProperty > &appmgr, int value, bool force=false)
Set the application return code.
The IAlgorithm is the interface implemented by the Algorithm base class.
const TYPE & value() const
explicit conversion
virtual StatusCode reinitialize()
implementation of IService::reinitialize
virtual const std::string & name() const
Retrieve name of the service.
virtual StatusCode stop()
implementation of IService::stop
Property base class allowing Property* collections to be "homogeneous".
virtual StatusCode executeRun(int maxevt)
implementation of IEventProcessor::executeRun( )
virtual StatusCode initialize()
Initialization (from CONFIGURED to INITIALIZED).
ListAlg m_outStreamList
List of output streams.
virtual StatusCode restart()
implementation of IService::restart
bool isValid() const
Allow for check if smart pointer is valid.
virtual StatusCode finalize()
implementation of IService::finalize
const std::string & type() const
Base class for all Incidents (computing events).
virtual void addListener(IIncidentListener *lis, const std::string &type="", long priority=0, bool rethrow=false, bool singleShot=false)=0
Add listener.
SmartIF< IIncidentListener > m_abortEventListener
Instance of the incident listener waiting for AbortEvent.
Templated class to add the standard messaging functionalities.
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
std::string m_outStreamType
Out Stream type.
virtual void removeListener(IIncidentListener *lis, const std::string &type="")=0
Remove listener.
const std::string & name() const
StringArrayProperty m_topAlgNames
List of top level algorithms names.
virtual StatusCode start()
Start (from INITIALIZED to RUNNING).
virtual StatusCode removeAlgorithm(IAlgorithm *alg)=0
Remove an algorithm from the list of known algorithms.
StatusCode decodeOutStreams()
decodeOutStreamNameList & outStreamNameListHandler
Property * declareProperty(const std::string &name, T &property, const std::string &doc="none") const
Declare the named property.
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
StringArrayProperty m_outStreamNames
List of output stream names.
virtual StatusCode finalize()
Finalize (from INITIALIZED to CONFIGURED).
MinimalEventLoopMgr(const std::string &nam, ISvcLocator *svcLoc)
Standard Constructor.
ListAlg m_topAlgList
List of top level algorithms.
bool m_abortEvent
Flag signalling that the event being processedhas to be aborted (skip all following top algs)...
SmartIF< ISvcLocator > & serviceLocator() const
Retrieve pointer to service locator.