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