The Gaudi Framework  v41r0 (bdbe7744)
Loading...
Searching...
No Matches
IncidentListenerTest.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\***********************************************************************************/
12
17
19
21
22//=============================================================================
23IncidentListenerTest::IncidentListenerTest( const std::string& name, ISvcLocator* svcloc, long shots )
24 : m_name( name ), m_shots( shots ), m_msgSvc( svcloc ) {
25 if ( !m_msgSvc ) throw GaudiException( "Cannot find MessageSvc", m_name, StatusCode::FAILURE );
26 m_incSvc = svcloc->service( "IncidentSvc" );
27 if ( !m_incSvc ) throw GaudiException( "Cannot find IncidentSvc", m_name, StatusCode::FAILURE );
28}
29
31
32//=============================================================================
33void IncidentListenerTest::handle( const Incident& incident ) {
35 log << MSG::INFO << "Handling incident '" << incident.type() << "'" << endmsg;
36 if ( ( m_shots > 0 ) && ( --m_shots == 0 ) ) {
37 log << MSG::INFO << "deregistering" << endmsg;
38 m_incSvc->removeListener( this, incident.type() );
39 }
40}
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition MsgStream.h:198
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:42
virtual SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)=0
Returns a smart pointer to a service.
Base class for all Incidents (computing events).
Definition Incident.h:24
const std::string & type() const
Access to the incident type.
Definition Incident.h:43
SmartIF< IIncidentSvc > m_incSvc
SmartIF< IMessageSvc > m_msgSvc
IncidentListenerTest(const std::string &name, ISvcLocator *svcloc, long shots=-1)
Constructor.
~IncidentListenerTest() override
Destructor.
void handle(const Incident &incident) override
Reimplements from IIncidentListener.
Definition of the MsgStream class used to transmit messages.
Definition MsgStream.h:29
constexpr static const auto FAILURE
Definition StatusCode.h:100
@ INFO
Definition IMessageSvc.h:22