| The Gaudi Framework v32r1 (f65d50dc)

IncidentProcAlg.cpp
Go to the documentation of this file.
1 #include "IncidentProcAlg.h"
2 #include "GaudiKernel/IIncidentListener.h"
3 #include "GaudiKernel/IIncidentSvc.h"
4 #include "GaudiKernel/Incident.h"
5 #include "GaudiKernel/ThreadLocalContext.h"
6 DECLARE_COMPONENT( IncidentProcAlg )
7
8 #define ON_DEBUG if ( msgLevel( MSG::DEBUG ) )
9 #define ON_VERBOSE if ( msgLevel( MSG::VERBOSE ) )
10
11 #define DEBMSG ON_DEBUG debug()
12 #define VERMSG ON_VERBOSE verbose()
13
14 namespace {
15 // ==========================================================================
16 static const std::string s_unknown = "<unknown>";
17 // Helper to get the name of the listener
18 inline const std::string& getListenerName( IIncidentListener* lis ) {
19 SmartIF<INamedInterface> iNamed( lis );
20 return iNamed ? iNamed->name() : s_unknown;
21 }
22 // ==========================================================================
23 } // namespace
24
25 IncidentProcAlg::IncidentProcAlg( const std::string& name, ISvcLocator* pSvcLocator )
26 : Algorithm( name, pSvcLocator ) {}
27
28 StatusCode IncidentProcAlg::initialize() {
29 StatusCode sc = Algorithm::initialize();
30 if ( sc.isFailure() ) return sc;
31 m_incSvc = service( "IncidentSvc", true );
32 return StatusCode::SUCCESS;
33 }
34
35 //=============================================================================
36 StatusCode IncidentProcAlg::execute() {
37 const EventContext& context = Gaudi::Hive::currentContext();
38 auto incPack = m_incSvc->getIncidents( &context );
39 MsgStream log( msgSvc(), name() );
40 log << MSG::DEBUG << " Number of Incidents to process = " << incPack.incidents.size()
41 << " Context= " << Gaudi::Hive::currentContext() << endmsg;
42 while ( incPack.incidents.size() ) {
43 if ( incPack.incidents.size() != incPack.listeners.size() ) {
44 log << MSG::WARNING << " Size of fired incidents and listeners do not match!" << endmsg;
45 }
46 for ( size_t t = 0; t < incPack.incidents.size(); t++ ) {
47 auto& inc = incPack.incidents.at( t );
48 auto& lis = incPack.listeners.at( t );
49 for ( auto& l : lis ) {
50 log << MSG::DEBUG << "Calling '" << getListenerName( l ) << "' for incident [" << inc->type() << "]" << endmsg;
51
52 // handle exceptions if they occur
53 try {
54 l->handle( *inc );
55 } catch ( const GaudiException& exc ) {
56 error() << "Exception with tag=" << exc.tag()
57 << " is caught"
58 " handling incident"
59 << inc->type() << endmsg;
60 error() << exc << endmsg;
61 } catch ( const std::exception& exc ) {
62 error() << "Standard std::exception is caught"
63 " handling incident"
64 << inc->type() << endmsg;
65 error() << exc.what() << endmsg;
66 } catch ( ... ) { error() << "UNKNOWN Exception is caught handling incident" << inc->type() << endmsg; }
67 // check wheter one of the listeners is singleShot
68 }
69 }
70 incPack = m_incSvc->getIncidents( &context );
71 }
72
73 return StatusCode::SUCCESS;
74 }
75
76 //=============================================================================
77 StatusCode IncidentProcAlg::finalize() {
78 info() << "Finalize" << endmsg;
79 return Algorithm::finalize();
80 }
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
SmartIF< INamedInterface >
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:21
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
CommonMessagingBase::msgSvc
const SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
Definition: CommonMessaging.h:68
gaudiComponentHelp.name
name
Definition: gaudiComponentHelp.py:41
IIncidentSvc::getIncidents
virtual IIncidentSvc::IncidentPack getIncidents(const EventContext *ctx)=0
IncidentProcAlg.h
ThreadLocalContext.h
MSG::DEBUG
Definition: IMessageSvc.h:15
GaudiException::tag
virtual const std::string & tag() const
name tag for the exception, or exception type
Definition: GaudiException.h:67
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:85
CommonMessagingBase::info
MsgStream & info() const
shortcut for the method msgStream(MSG::INFO)
Definition: CommonMessaging.h:104
EventContext
This class represents an entry point to all the event specific data.
Definition: EventContext.h:24
IncidentProcAlg::initialize
StatusCode initialize() override
Definition: IncidentProcAlg.cpp:28
IncidentProcAlg::finalize
StatusCode finalize() override
Definition: IncidentProcAlg.cpp:77
INamedInterface::name
virtual const std::string & name() const =0
Retrieve the name of the instance.
std::string
STL class.
Incident.h
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
Gaudi::Algorithm::initialize
StatusCode initialize() override
the default (empty) implementation of IStateful::initialize() method
Definition: Algorithm.h:180
CommonMessagingBase::error
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
Definition: CommonMessaging.h:98
IIncidentListener
The interface implemented by any class wanting to listen to Incidents.
Definition: IIncidentListener.h:15
std::exception::what
T what(T... args)
Gaudi::Algorithm::service
StatusCode service(const std::string &name, T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
Definition: Algorithm.h:215
IIncidentSvc.h
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
IncidentProcAlg::IncidentProcAlg
IncidentProcAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructor(s)
Definition: IncidentProcAlg.cpp:25
IncidentProcAlg::m_incSvc
SmartIF< IIncidentSvc > m_incSvc
Definition: IncidentProcAlg.h:30
Gaudi::Algorithm::finalize
StatusCode finalize() override
the default (empty) implementation of IStateful::finalize() method
Definition: Algorithm.h:186
Gaudi::Hive::currentContext
GAUDI_API const EventContext & currentContext()
Definition: ThreadLocalContext.cpp:20
IncidentProcAlg::execute
StatusCode execute() override
Definition: IncidentProcAlg.cpp:36
std::exception
STL class.
gaudirun.l
dictionary l
Definition: gaudirun.py:521
Algorithm
Alias for backward compatibility.
Definition: Algorithm.h:56
IIncidentListener.h
MSG::WARNING
Definition: IMessageSvc.h:15
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:130
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:192
IncidentProcAlg
Definition: IncidentProcAlg.h:9
Gaudi::Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:645
Gaudi.Configuration.log
log
Definition: Configuration.py:13