| The Gaudi Framework v28r2p1 (f1a77ff4)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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