The Gaudi Framework  master (b9786168)
Loading...
Searching...
No Matches
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"
16
18
19namespace {
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
28IncidentProcAlg::IncidentProcAlg( const std::string& name, ISvcLocator* pSvcLocator )
29 : Algorithm( name, pSvcLocator ) {}
30
33 if ( sc.isFailure() ) return sc;
34 m_incSvc = service( "IncidentSvc", true );
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
78}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
#define DECLARE_COMPONENT(type)
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
const SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
This class represents an entry point to all the event specific data.
Algorithm(std::string name, ISvcLocator *svcloc, std::string version=PACKAGE_VERSION)
Constructor.
Definition Algorithm.h:98
StatusCode initialize() override
the default (empty) implementation of IStateful::initialize() method
Definition Algorithm.h:175
const std::string & name() const override
The identifying name of the algorithm object.
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")
Define general base for Gaudi exception.
const char * what() const override
method from std::exception
virtual const std::string & tag() const
name tag for the exception, or exception type
The interface implemented by any class wanting to listen to Incidents.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition ISvcLocator.h:42
SmartIF< IIncidentSvc > m_incSvc
StatusCode initialize() override
StatusCode execute(const EventContext &ctx) const override
IncidentProcAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition of the MsgStream class used to transmit messages.
Definition MsgStream.h:29
Small smart pointer class with automatic reference counting for IInterface.
Definition SmartIF.h:28
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
bool isFailure() const
Definition StatusCode.h:129
constexpr static const auto SUCCESS
Definition StatusCode.h:99
@ DEBUG
Definition IMessageSvc.h:22