Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  master (d98a2936)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
IncidentProcAlg.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 #include "IncidentProcAlg.h"
14 #include <GaudiKernel/Incident.h>
16 
18 
19 namespace {
20  static const std::string s_unknown = "<unknown>";
21  // Helper to get the name of the listener
22  inline const std::string& getListenerName( IIncidentListener* lis ) {
23  SmartIF<INamedInterface> iNamed( lis );
24  return iNamed ? iNamed->name() : s_unknown;
25  }
26 } // namespace
27 
28 IncidentProcAlg::IncidentProcAlg( const std::string& name, ISvcLocator* pSvcLocator )
29  : Algorithm( name, pSvcLocator ) {}
30 
33  if ( sc.isFailure() ) return sc;
34  m_incSvc = service( "IncidentSvc", true );
35  return StatusCode::SUCCESS;
36 }
37 
39  auto incPack = m_incSvc->getIncidents( &ctx );
40  MsgStream log( msgSvc(), name() );
41  if ( msgLevel( MSG::DEBUG ) ) {
42  log << MSG::DEBUG << " Number of Incidents to process = " << incPack.size() << " Context= " << ctx << endmsg;
43  }
44  while ( !incPack.empty() ) {
45  for ( const auto& [inc, listeners] : incPack ) {
46  for ( const auto& l : listeners ) {
47  if ( msgLevel( MSG::DEBUG ) ) {
48  log << MSG::DEBUG << "Calling '" << getListenerName( l.iListener ) << "' for incident [" << inc->type() << "]"
49  << endmsg;
50  }
51 
52  // handle exceptions if they occur
53  try {
54  l.iListener->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  if ( l.rethrow ) { throw exc; }
62  } catch ( const std::exception& exc ) {
63  error() << "Standard std::exception is caught"
64  " handling incident"
65  << inc->type() << endmsg;
66  error() << exc.what() << endmsg;
67  if ( l.rethrow ) { throw exc; }
68  } catch ( ... ) {
69  error() << "UNKNOWN Exception is caught handling incident" << inc->type() << endmsg;
70  if ( l.rethrow ) { throw; }
71  }
72  }
73  }
74  incPack = m_incSvc->getIncidents( &ctx );
75  }
76 
77  return StatusCode::SUCCESS;
78 }
MSG::DEBUG
@ DEBUG
Definition: IMessageSvc.h:22
Gaudi::Algorithm::service
SmartIF< IService > service(std::string_view name, const bool createIf=true, const bool quiet=false) const
Return a pointer to the service identified by name (or "type/name")
Definition: Algorithm.cpp:627
IncidentProcAlg
Definition: IncidentProcAlg.h:18
Gaudi.Configuration.log
log
Definition: Configuration.py:28
Gaudi::Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:524
IncidentProcAlg::initialize
StatusCode initialize() override
Definition: IncidentProcAlg.cpp:31
ISvcLocator
Definition: ISvcLocator.h:42
Gaudi::Algorithm::initialize
StatusCode initialize() override
the default (empty) implementation of IStateful::initialize() method
Definition: Algorithm.h:175
GaudiException
Definition: GaudiException.h:29
Algorithm
Alias for backward compatibility.
Definition: Algorithm.h:58
CommonMessaging< implements< IAlgorithm, IDataHandleHolder, IProperty, IStateful > >::msgLevel
MSG::Level msgLevel() const
get the cached level (originally extracted from the embedded MsgStream)
Definition: CommonMessaging.h:147
AvalancheSchedulerErrorTest.msgSvc
msgSvc
Definition: AvalancheSchedulerErrorTest.py:80
IIncidentSvc.h
IncidentProcAlg.h
IIncidentListener
Definition: IIncidentListener.h:23
IncidentProcAlg::m_incSvc
SmartIF< IIncidentSvc > m_incSvc
Definition: IncidentProcAlg.h:28
GaudiPython.Pythonizations.ctx
ctx
Definition: Pythonizations.py:578
StatusCode
Definition: StatusCode.h:64
IncidentProcAlg::execute
StatusCode execute(const EventContext &ctx) const override
Definition: IncidentProcAlg.cpp:38
SmartIF
Definition: IConverter.h:22
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:198
GaudiException::tag
virtual const std::string & tag() const
name tag for the exception, or exception type
Definition: GaudiException.h:75
MsgStream
Definition: MsgStream.h:29
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
ThreadLocalContext.h
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:99
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
IncidentProcAlg::IncidentProcAlg
IncidentProcAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: IncidentProcAlg.cpp:28
gaudirun.l
dictionary l
Definition: gaudirun.py:583
IIncidentListener.h
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:45
EventContext
Definition: EventContext.h:34
Incident.h