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 ~AbortEventListener()
override =
default;
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()
71 error() <<
"Failed to initialize Service Base class." <<
endmsg;
75 auto prpMgr = serviceLocator()->as<
IProperty>();
77 error() <<
"Error retrieving AppMgr interface IProperty." <<
endmsg;
81 setProperty(prpMgr->getProperty(
"TopAlg")).ignore();
84 setProperty(prpMgr->getProperty(
"OutStream")).ignore();
90 fatal() <<
"Error retrieving IncidentSvc." <<
endmsg;
107 error() <<
"Failed to initialize Output streams." <<
endmsg;
118 error() <<
"Failed to initialize Top Algorithms streams." <<
endmsg;
126 sc = ita->sysInitialize();
128 error() <<
"Unable to initialize Algorithm: " << ita->name() <<
endmsg;
133 sc = ita->sysInitialize();
135 error() <<
"Unable to initialize Output Stream: " << ita->name() <<
endmsg;
153 sc = ita->sysStart();
155 error() <<
"Unable to start Algorithm: " << ita->name() <<
endmsg;
160 sc = ita->sysStart();
162 error() <<
"Unable to start Output Stream: " << ita->name() <<
endmsg;
180 error() <<
"Unable to stop Algorithm: " << ita->name() <<
endmsg;
187 error() <<
"Unable to stop Output Stream: " << ita->name() <<
endmsg;
203 sc = ita->sysReinitialize();
205 error() <<
"Unable to reinitialize Algorithm: " << ita->name() <<
endmsg;
210 sc = ita->sysReinitialize();
212 error() <<
"Unable to reinitialize Output Stream: " << ita->name() <<
endmsg;
227 sc = ita->sysRestart();
229 error() <<
"Unable to restart Algorithm: " << ita->name() <<
endmsg;
234 sc = ita->sysRestart();
236 error() <<
"Unable to restart Output Stream: " << ita->name() <<
endmsg;
252 sc = ita->sysFinalize();
255 warning() <<
"Finalization of algorithm " << ita->name() <<
" failed" <<
endmsg;
260 sc = ita->sysFinalize();
263 warning() <<
"Finalization of algorithm " << ita->name() <<
" failed" <<
endmsg;
268 for (
auto &ita : m_topAlgList ) {
269 if (algMan->removeAlgorithm(ita).isFailure()) {
271 warning() <<
"Problems removing Algorithm " << ita->name() <<
endmsg;
274 m_topAlgList.
clear();
275 m_outStreamList.clear();
288 error() <<
"Problems finalizing Service base class" <<
endmsg;
298 error() <<
"This method cannot be called on an object of type "
308 bool eventfailed =
false;
312 sc = ita->sysBeginRun();
314 warning() <<
"beginRun() of algorithm " << ita->name() <<
" failed" <<
endmsg;
324 for (
auto& ita : m_topAlgList) {
325 sc = ita->sysEndRun();
327 warning() <<
"endRun() of algorithm " << ita->name() <<
" failed" <<
endmsg;
341 m_appmgr(appmgr), m_retcode(retcode) {}
342 inline void ignore() {
345 inline ~RetCodeGuard() {
359 bool eventfailed =
false;
364 if (
LIKELY(algMan.isValid())) {
373 const auto appmgr = serviceLocator()->as<
IProperty>();
379 DEBMSG <<
"AbortEvent incident fired by "
386 sc = ita->sysExecute();
389 fatal() <<
".executeEvent(): Exception with tag=" << Exception.
tag()
390 <<
" thrown by " << ita->name() <<
endmsg;
391 error() << Exception <<
endmsg;
392 }
catch (
const std::exception& Exception ) {
393 fatal() <<
".executeEvent(): Standard std::exception thrown by "
395 error() << Exception.what() <<
endmsg;
397 fatal() <<
".executeEvent(): UNKNOWN Exception thrown by "
402 warning() <<
"Execution of algorithm " << ita->name() <<
" failed" <<
endmsg;
415 ito->resetExecuted();
417 sc = ito->sysExecute();
419 warning() <<
"Execution of output stream " << ito->name() <<
" failed" <<
endmsg;
426 error() <<
"Error processing event loop." <<
endmsg;
436 auto appmgr = serviceLocator()->as<
IProperty>();
438 error() <<
"Could not set return code of the application ("
450 throw GaudiException(
"Failed to initialize Top Algorithms streams.",
451 "MinimalEventLoopMgr::topAlgHandler",
471 const bool CREATE =
false;
474 DEBMSG <<
"Top Algorithm " << item_name <<
" already exists" <<
endmsg;
477 DEBMSG <<
"Creating Top Algorithm " <<
item.type() <<
" with name " << item_name <<
endmsg;
479 StatusCode sc1 = algMan->createAlgorithm(
item.type(), item_name, ialg);
481 error() <<
"Unable to create Top Algorithm " <<
item.type() <<
" with name " << item_name <<
endmsg;
501 "MinimalEventLoopMgr::outStreamHandler",
519 const bool CREATE =
false;
528 error() <<
"Unable to create Output Stream " << it <<
endmsg;
SmartIF< IIncidentSvc > m_incidentSvc
Reference to the incident service.
StatusCode initialize() override
Base class used to implement the interfaces.
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 stopRun()
implementation of IEventProcessor::stopRun( )
const std::string & type() const
Access to the incident type.
bool m_scheduledStop
Scheduled stop of event processing.
StatusCode finalize() override
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
StatusCode start() override
virtual StatusCode initialize()
implementation of IService::initialize
const std::string & source() const
Access to the source of the incident.
auto begin(reverse_wrapper< T > &w)
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.
virtual StatusCode nextEvent(int maxevt)
implementation of IEventProcessor::nextEvent
The IAlgManager is the interface implemented by the Algorithm Factory in the Application Manager to s...
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 std::string AbortEvent
Stop processing the current event and pass to te next one.
constexpr int ScheduledStop
State m_state
State of the object.
constexpr int UnhandledException
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)
auto end(reverse_wrapper< T > &w)
unsigned long addRef() override
Reference Interface instance.
This class is used for returning status codes from appropriate routines.
void clear(STATE_TYPE _i=std::ios_base::failbit)
bool PyHelper() setProperty(IInterface *p, char *name, char *value)
virtual const std::string & tag() const
name tag for the exception, or exception type
void topAlgHandler(Property &p)
Top algorithm List handler.
StatusCode stop() override
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 StatusCode stop()
implementation of IService::stop
Property base class allowing Property* collections to be "homogeneous".
virtual StatusCode executeRun(int maxevt)
implementation of IEventProcessor::executeRun( )
ListAlg m_outStreamList
List of output streams.
virtual StatusCode restart()
implementation of IService::restart
Base class used to extend a class implementing other interfaces.
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.
virtual void declareUpdateHandler(std::function< void(Property &)> fun)
set new callback for update
std::string m_outStreamType
Out Stream type.
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
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.
StatusCode decodeOutStreams()
decodeOutStreamNameList & outStreamNameListHandler
The IProperty is the basic interface for all components which have properties that can be set or get...
StringArrayProperty m_outStreamNames
List of output stream names.
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)...