The Gaudi Framework  v40r0 (475e45c1)
IncidentSvc.h
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 #pragma once
12 
14 #include <GaudiKernel/HashMap.h>
16 #include <GaudiKernel/Service.h>
17 #include <GaudiKernel/StringKey.h>
18 #include <list>
19 #include <tbb/concurrent_queue.h>
20 #include <tbb/concurrent_unordered_map.h>
21 
33 struct isSingleShot_t;
34 
35 class IncidentSvc : public extends<Service, IIncidentSvc> {
36 private:
37  // Typedefs
38  // ListenerList should be a list rather than a vector because handing
39  // a fired incident may result in a call to addListener.
40  typedef std::list<IIncidentSvc::Listener> ListenerList;
42 
43 public:
44  // Inherited Service overrides:
45  StatusCode finalize() override;
46 
47  void addListener( IIncidentListener* lis, const std::string& type = "", long priority = 0, bool rethrow = false,
48  bool singleShot = false ) override;
49 
50  void removeListener( IIncidentListener* l, const std::string& type = "" ) override;
51  void fireIncident( const Incident& incident ) override;
52  void fireIncident( std::unique_ptr<Incident> incident ) override;
53  // TODO: return by value instead...
54  void getListeners( std::vector<IIncidentListener*>& lis, const std::string& type = "" ) const override;
55 
56  IncidentSvc( const std::string& name, ISvcLocator* svc );
57  ~IncidentSvc() override;
59 
60 private:
63  void i_fireIncident( const Incident& incident, const std::string& type );
64 
67 
70  const std::string* m_currentIncidentType = nullptr;
71 
73  mutable std::recursive_mutex m_listenerMapMutex;
74 
77  mutable bool m_timerLock = false;
78  // When TBB supports unique_ptrs in concurrent queue typedef should be changed
79  // typedef tbb::concurrent_queue<std::unique_ptr<Incident>> IncQueue_t;
80  typedef tbb::concurrent_queue<std::unique_ptr<Incident>> IncQueue_t;
81  tbb::concurrent_unordered_map<EventContext::ContextID_t, IncQueue_t> m_firedIncidents;
82 
84  tbb::concurrent_unordered_map<EventContext::ContextID_t, EventContext::ContextEvt_t> m_slotEvent;
85 };
IncidentSvc::~IncidentSvc
~IncidentSvc() override
Definition: IncidentSvc.cpp:45
ChronoEntity
Definition: ChronoEntity.h:26
IncidentSvc::IncQueue_t
tbb::concurrent_queue< std::unique_ptr< Incident > > IncQueue_t
Definition: IncidentSvc.h:80
ISvcLocator
Definition: ISvcLocator.h:42
IncidentSvc::i_fireIncident
void i_fireIncident(const Incident &incident, const std::string &type)
Internal function to allow incidents listening to all events.
Definition: IncidentSvc.cpp:117
StringKey.h
IncidentSvc::m_firedIncidents
tbb::concurrent_unordered_map< EventContext::ContextID_t, IncQueue_t > m_firedIncidents
Definition: IncidentSvc.h:81
IncidentSvc::m_timerLock
bool m_timerLock
Definition: IncidentSvc.h:77
HashMap.h
IncidentSvc::m_timer
ChronoEntity m_timer
timer & it's lock
Definition: IncidentSvc.h:76
IncidentSvc
Default implementation of the IIncidentSvc interface.
Definition: IncidentSvc.h:35
IIncidentSvc.h
IIncidentListener
Definition: IIncidentListener.h:23
IncidentSvc::ListenerList
std::list< IIncidentSvc::Listener > ListenerList
Definition: IncidentSvc.h:40
GaudiPython.Pythonizations.ctx
ctx
Definition: Pythonizations.py:578
Service::name
const std::string & name() const override
Retrieve name of the service
Definition: Service.cpp:333
StatusCode
Definition: StatusCode.h:64
IncidentSvc::addListener
void addListener(IIncidentListener *lis, const std::string &type="", long priority=0, bool rethrow=false, bool singleShot=false) override
Definition: IncidentSvc.cpp:55
IncidentSvc::removeListenerFromList
ListenerMap::iterator removeListenerFromList(ListenerMap::iterator, IIncidentListener *item, bool scheduleRemoval)
Definition: IncidentSvc.cpp:82
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:19
IncidentSvc::m_slotEvent
tbb::concurrent_unordered_map< EventContext::ContextID_t, EventContext::ContextEvt_t > m_slotEvent
Event ID for each slot.
Definition: IncidentSvc.h:84
IIncidentSvc::IncidentPack
std::vector< std::pair< std::unique_ptr< Incident >, std::vector< Listener > > > IncidentPack
List of incidents and their listeners.
Definition: IIncidentSvc.h:65
IncidentSvc::ListenerMap
GaudiUtils::HashMap< Gaudi::StringKey, std::unique_ptr< ListenerList > > ListenerMap
Definition: IncidentSvc.h:41
Service.h
IncidentSvc::fireIncident
void fireIncident(const Incident &incident) override
Definition: IncidentSvc.cpp:190
gaudirun.type
type
Definition: gaudirun.py:160
ChronoEntity.h
gaudirun.l
dictionary l
Definition: gaudirun.py:583
IncidentSvc::m_listenerMapMutex
std::recursive_mutex m_listenerMapMutex
Mutex to synchronize access to m_listenerMap.
Definition: IncidentSvc.h:73
GaudiUtils::Map< Gaudi::StringKey, std::unique_ptr< ListenerList >, std::unordered_map< Gaudi::StringKey, std::unique_ptr< ListenerList >, Hash< Gaudi::StringKey > > >::iterator
map_type::iterator iterator
Definition: Map.h:97
EventContext
Definition: EventContext.h:34
IncidentSvc::removeListener
void removeListener(IIncidentListener *l, const std::string &type="") override
Definition: IncidentSvc.cpp:99
IncidentSvc::IncidentSvc
IncidentSvc(const std::string &name, ISvcLocator *svc)
Definition: IncidentSvc.cpp:44
GaudiUtils::HashMap
Definition: HashMap.h:80
IncidentSvc::m_currentIncidentType
const std::string * m_currentIncidentType
Incident being fired.
Definition: IncidentSvc.h:70
Incident
Definition: Incident.h:24
IncidentSvc::getIncidents
IIncidentSvc::IncidentPack getIncidents(const EventContext *ctx) override
Definition: IncidentSvc.cpp:241
IncidentSvc::getListeners
void getListeners(std::vector< IIncidentListener * > &lis, const std::string &type="") const override
Definition: IncidentSvc.cpp:226
IncidentSvc::m_listenerMap
ListenerMap m_listenerMap
List of auditor names.
Definition: IncidentSvc.h:66
IncidentSvc::finalize
StatusCode finalize() override
Definition: IncidentSvc.cpp:46