The Gaudi Framework  master (37c0b60a)
IncidentProcAlg.cpp
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 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>
17 
18 namespace {
19  // ==========================================================================
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  // ==========================================================================
27 } // namespace
28 
30  : Algorithm( name, pSvcLocator ) {}
31 
34  if ( sc.isFailure() ) return sc;
35  m_incSvc = service( "IncidentSvc", true );
36  return StatusCode::SUCCESS;
37 }
38 
39 //=============================================================================
41  auto incPack = m_incSvc->getIncidents( &ctx );
42  MsgStream log( msgSvc(), name() );
43  if ( msgLevel( MSG::DEBUG ) ) {
44  log << MSG::DEBUG << " Number of Incidents to process = " << incPack.size() << " Context= " << ctx << endmsg;
45  }
46  while ( !incPack.empty() ) {
47  for ( const auto& [inc, listeners] : incPack ) {
48  for ( const auto& l : listeners ) {
49  if ( msgLevel( MSG::DEBUG ) ) {
50  log << MSG::DEBUG << "Calling '" << getListenerName( l.iListener ) << "' for incident [" << inc->type() << "]"
51  << endmsg;
52  }
53 
54  // handle exceptions if they occur
55  try {
56  l.iListener->handle( *inc );
57  } catch ( const GaudiException& exc ) {
58  error() << "Exception with tag=" << exc.tag()
59  << " is caught"
60  " handling incident"
61  << inc->type() << endmsg;
62  error() << exc << endmsg;
63  if ( l.rethrow ) { throw exc; }
64  } catch ( const std::exception& exc ) {
65  error() << "Standard std::exception is caught"
66  " handling incident"
67  << inc->type() << endmsg;
68  error() << exc.what() << endmsg;
69  if ( l.rethrow ) { throw exc; }
70  } catch ( ... ) {
71  error() << "UNKNOWN Exception is caught handling incident" << inc->type() << endmsg;
72  if ( l.rethrow ) { throw; }
73  }
74  }
75  }
76  incPack = m_incSvc->getIncidents( &ctx );
77  }
78 
79  return StatusCode::SUCCESS;
80 }
MSG::DEBUG
@ DEBUG
Definition: IMessageSvc.h:25
std::string
STL class.
IncidentProcAlg
Definition: IncidentProcAlg.h:19
std::exception
STL class.
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:526
IncidentProcAlg::initialize
StatusCode initialize() override
Definition: IncidentProcAlg.cpp:32
ISvcLocator
Definition: ISvcLocator.h:46
Gaudi::Algorithm::initialize
StatusCode initialize() override
the default (empty) implementation of IStateful::initialize() method
Definition: Algorithm.h:178
GaudiException
Definition: GaudiException.h:31
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:148
AvalancheSchedulerErrorTest.msgSvc
msgSvc
Definition: AvalancheSchedulerErrorTest.py:80
IIncidentSvc.h
IncidentProcAlg.h
IIncidentListener
Definition: IIncidentListener.h:25
IncidentProcAlg::m_incSvc
SmartIF< IIncidentSvc > m_incSvc
Definition: IncidentProcAlg.h:39
GaudiPython.Pythonizations.ctx
ctx
Definition: Pythonizations.py:578
StatusCode
Definition: StatusCode.h:65
IncidentProcAlg::execute
StatusCode execute(const EventContext &ctx) const override
Definition: IncidentProcAlg.cpp:40
SmartIF
Definition: IConverter.h:25
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:202
GaudiException::tag
virtual const std::string & tag() const
name tag for the exception, or exception type
Definition: GaudiException.h:77
MsgStream
Definition: MsgStream.h:33
StatusCode::isFailure
bool isFailure() const
Definition: StatusCode.h:129
ThreadLocalContext.h
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition: StatusCode.h:100
ConditionsStallTest.name
name
Definition: ConditionsStallTest.py:77
IncidentProcAlg::IncidentProcAlg
IncidentProcAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructor(s)
Definition: IncidentProcAlg.cpp:29
gaudirun.l
dictionary l
Definition: gaudirun.py:583
IIncidentListener.h
DECLARE_COMPONENT
#define DECLARE_COMPONENT(type)
Definition: PluginServiceV1.h:46
Gaudi::Algorithm::service
StatusCode service(std::string_view name, T *&psvc, bool createIf=true) const
Access a service by name, creating it if it doesn't already exist.
Definition: Algorithm.h:206
EventContext
Definition: EventContext.h:34
Incident.h
std::exception::what
T what(T... args)