The Gaudi Framework  master (37c0b60a)
IncidentSvc.h
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 #ifndef IncidentSvc_IncidentSvc_H
12 #define IncidentSvc_IncidentSvc_H
13 // ============================================================================
14 // Include Files
15 // ============================================================================
16 // STD & STL
17 // ============================================================================
18 #include <algorithm>
19 #include <list>
20 #include <map>
21 // ============================================================================
22 // GaudiKernel
23 // ============================================================================
25 #include <GaudiKernel/HashMap.h>
27 #include <GaudiKernel/Service.h>
28 #include <GaudiKernel/StringKey.h>
29 // ============================================================================
30 // TBB
31 // ============================================================================
32 #include <tbb/concurrent_queue.h>
33 #include <tbb/concurrent_unordered_map.h>
34 // ============================================================================
46 struct isSingleShot_t;
47 
48 class IncidentSvc : public extends<Service, IIncidentSvc> {
49 private:
50  // Typedefs
51  // ListenerList should be a list rather than a vector because handing
52  // a fired incident may result in a call to addListener.
55 
56 public:
57  // Inherited Service overrides:
58  StatusCode finalize() override;
59 
60  // IIncidentSvc interfaces overwrite
61  //
62  void addListener( IIncidentListener* lis, const std::string& type = "", long priority = 0, bool rethrow = false,
63  bool singleShot = false ) override;
64 
65  void removeListener( IIncidentListener* l, const std::string& type = "" ) override;
66  void fireIncident( const Incident& incident ) override;
67  void fireIncident( std::unique_ptr<Incident> incident ) override;
68  // TODO: return by value instead...
69  void getListeners( std::vector<IIncidentListener*>& lis, const std::string& type = "" ) const override;
70 
71  // Standard Constructor.
72  IncidentSvc( const std::string& name, ISvcLocator* svc );
73  // Destructor.
74  ~IncidentSvc() override;
76 
77 private:
79  // ==========================================================================
81  void i_fireIncident( const Incident& incident, const std::string& type );
82 
85 
89 
92 
95  mutable bool m_timerLock = false;
96  // ==========================================================================
97  // When TBB supports unique_ptrs in concurrent queue typedef should be changed
98  // typedef tbb::concurrent_queue<std::unique_ptr<Incident>> IncQueue_t;
99  typedef tbb::concurrent_queue<std::unique_ptr<Incident>> IncQueue_t;
100  tbb::concurrent_unordered_map<EventContext::ContextID_t, IncQueue_t> m_firedIncidents;
101 
103  tbb::concurrent_unordered_map<EventContext::ContextID_t, EventContext::ContextEvt_t> m_slotEvent;
104 };
105 // ============================================================================
106 // The END
107 // ============================================================================
108 #endif
IncidentSvc::~IncidentSvc
~IncidentSvc() override
Definition: IncidentSvc.cpp:61
std::string
STL class.
ChronoEntity
Definition: ChronoEntity.h:31
std::list
STL class.
IncidentSvc::IncQueue_t
tbb::concurrent_queue< std::unique_ptr< Incident > > IncQueue_t
Definition: IncidentSvc.h:99
std::vector
STL class.
ISvcLocator
Definition: ISvcLocator.h:46
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:141
std::recursive_mutex
STL class.
StringKey.h
IncidentSvc::m_firedIncidents
tbb::concurrent_unordered_map< EventContext::ContextID_t, IncQueue_t > m_firedIncidents
Definition: IncidentSvc.h:100
IncidentSvc::m_timerLock
bool m_timerLock
Definition: IncidentSvc.h:95
HashMap.h
IncidentSvc::m_timer
ChronoEntity m_timer
timer & it's lock
Definition: IncidentSvc.h:94
IncidentSvc
Default implementation of the IIncidentSvc interface.
Definition: IncidentSvc.h:48
IIncidentSvc.h
IIncidentListener
Definition: IIncidentListener.h:25
IncidentSvc::ListenerList
std::list< IIncidentSvc::Listener > ListenerList
Definition: IncidentSvc.h:53
GaudiPython.Pythonizations.ctx
ctx
Definition: Pythonizations.py:578
Service::name
const std::string & name() const override
Retrieve name of the service
Definition: Service.cpp:332
StatusCode
Definition: StatusCode.h:65
IncidentSvc::addListener
void addListener(IIncidentListener *lis, const std::string &type="", long priority=0, bool rethrow=false, bool singleShot=false) override
Definition: IncidentSvc.cpp:75
IncidentSvc::removeListenerFromList
ListenerMap::iterator removeListenerFromList(ListenerMap::iterator, IIncidentListener *item, bool scheduleRemoval)
Definition: IncidentSvc.cpp:103
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:20
IncidentSvc::m_slotEvent
tbb::concurrent_unordered_map< EventContext::ContextID_t, EventContext::ContextEvt_t > m_slotEvent
Event ID for each slot.
Definition: IncidentSvc.h:103
IncidentSvc::ListenerMap
GaudiUtils::HashMap< Gaudi::StringKey, std::unique_ptr< ListenerList > > ListenerMap
Definition: IncidentSvc.h:54
Service.h
IncidentSvc::fireIncident
void fireIncident(const Incident &incident) override
Definition: IncidentSvc.cpp:215
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:91
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:107
EventContext
Definition: EventContext.h:34
IncidentSvc::removeListener
void removeListener(IIncidentListener *l, const std::string &type="") override
Definition: IncidentSvc.cpp:121
IncidentSvc::IncidentSvc
IncidentSvc(const std::string &name, ISvcLocator *svc)
Definition: IncidentSvc.cpp:59
GaudiUtils::HashMap
Definition: HashMap.h:83
IncidentSvc::m_currentIncidentType
const std::string * m_currentIncidentType
Incident being fired.
Definition: IncidentSvc.h:88
Incident
Definition: Incident.h:27
std::unique_ptr
STL class.
IncidentSvc::getIncidents
IIncidentSvc::IncidentPack getIncidents(const EventContext *ctx) override
Definition: IncidentSvc.cpp:270
IncidentSvc::getListeners
void getListeners(std::vector< IIncidentListener * > &lis, const std::string &type="") const override
Definition: IncidentSvc.cpp:253
IncidentSvc::m_listenerMap
ListenerMap m_listenerMap
List of auditor names.
Definition: IncidentSvc.h:84
IncidentSvc::finalize
StatusCode finalize() override
Definition: IncidentSvc.cpp:63