IncidentSvc.h
Go to the documentation of this file.
1 #ifndef IncidentSvc_IncidentSvc_H
2 #define IncidentSvc_IncidentSvc_H
3 // ============================================================================
4 // Include Files
5 // ============================================================================
6 // STD & STL
7 // ============================================================================
8 #include <map>
9 #include <list>
10 // ============================================================================
11 // GaudiKernel
12 // ============================================================================
13 #include "GaudiKernel/Service.h"
15 #include "GaudiKernel/StringKey.h"
16 #include "GaudiKernel/StringKey.h"
17 #include "GaudiKernel/HashMap.h"
19 // ============================================================================
20 // TBB
21 // ============================================================================
22 #include "tbb/concurrent_queue.h"
23 #include "tbb/concurrent_unordered_map.h"
24 // ============================================================================
36 struct isSingleShot_t;
37 
38 class IncidentSvc : public extends<Service,
39  IIncidentSvc>
40 {
41  public:
42  struct Listener final
43  {
45  long priority;
46  bool rethrow;
47  bool singleShot;
48 
49  Listener(IIncidentListener* il, long pri, bool thr=false, bool single=false):
50  iListener(il), priority(pri), rethrow(thr), singleShot(single){}
51  };
52  private:
53 
54  // Typedefs
55  // ListenerList should be a list rather than a vector because handing
56  // a fired incident may result in a call to addListener.
59 
60 public:
61  // Inherited Service overrides:
62  //
63  StatusCode initialize() override;
64  StatusCode finalize() override;
65 
66  // IIncidentSvc interfaces overwrite
67  //
68  void addListener( IIncidentListener* lis ,
69  const std::string& type = "" ,
70  long priority = 0 ,
71  bool rethrow = false ,
72  bool singleShot = false ) override;
73 
74  void removeListener( IIncidentListener* l, const std::string& type = "" ) override;
75  void fireIncident( const Incident& incident) override;
76  void fireIncident( std::unique_ptr<Incident> incident) override;
77  //TODO: return by value instead...
79  const std::string& type = "") const override;
80 
81  // Standard Constructor.
82  IncidentSvc( const std::string& name, ISvcLocator* svc );
83  // Destructor.
84  ~IncidentSvc() override;
86 
87 private:
89  IIncidentListener* item,
90  bool scheduleRemoval);
91  // ==========================================================================
93  void i_fireIncident(const Incident& incident, const std::string& type);
94 
95 
97  ListenerMap m_listenerMap;
98 
102 
105 
108  mutable bool m_timerLock = false ;
109  // ==========================================================================
110  // When TBB supports unique_ptrs in concurrent queue typedef should be changed
111  //typedef tbb::concurrent_queue<std::unique_ptr<Incident>> IncQueue_t;
112  typedef tbb::concurrent_queue<Incident*> IncQueue_t;
113  tbb::concurrent_unordered_map<EventContext,IncQueue_t,EventContextHash,EventContextHash> m_firedIncidents;
114 
115 };
116 // ============================================================================
117 // The END
118 // ============================================================================
119 #endif
120 // ============================================================================
tbb::concurrent_unordered_map< EventContext, IncQueue_t, EventContextHash, EventContextHash > m_firedIncidents
Definition: IncidentSvc.h:113
ChronoEntity m_timer
timer & it&#39;s lock
Definition: IncidentSvc.h:107
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:289
StatusCode finalize() override
Definition: IncidentSvc.cpp:80
a small helper class for implementation of ChronoStatSvc service, It also could be used as some local...
Definition: ChronoEntity.h:21
bool m_timerLock
Definition: IncidentSvc.h:108
void addListener(IIncidentListener *lis, const std::string &type="", long priority=0, bool rethrow=false, bool singleShot=false) override
Definition: IncidentSvc.cpp:94
IIncidentSvc::IncidentPack getIncidents(const EventContext *ctx) override
ListenerMap::iterator removeListenerFromList(ListenerMap::iterator, IIncidentListener *item, bool scheduleRemoval)
std::list< Listener > ListenerList
Definition: IncidentSvc.h:57
This class represents an entry point to all the event specific data.
Definition: EventContext.h:25
IncidentSvc(const std::string &name, ISvcLocator *svc)
Definition: IncidentSvc.cpp:51
~IncidentSvc() override
Definition: IncidentSvc.cpp:55
STL class.
The interface implemented by any class wanting to listen to Incidents.
std::recursive_mutex m_listenerMapMutex
Mutex to synchronize access to m_listenerMap.
Definition: IncidentSvc.h:104
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
void removeListener(IIncidentListener *l, const std::string &type="") override
StatusCode initialize() override
Definition: IncidentSvc.cpp:62
const std::string * m_currentIncidentType
Incident being fired.
Definition: IncidentSvc.h:101
Listener(IIncidentListener *il, long pri, bool thr=false, bool single=false)
Definition: IncidentSvc.h:49
STL class.
IIncidentListener * iListener
Definition: IncidentSvc.h:44
tbb::concurrent_queue< Incident * > IncQueue_t
Definition: IncidentSvc.h:112
dictionary l
Definition: gaudirun.py:421
void getListeners(std::vector< IIncidentListener * > &lis, const std::string &type="") const override
map_type::iterator iterator
Definition: Map.h:99
STL class.
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
void i_fireIncident(const Incident &incident, const std::string &type)
Internal function to allow incidents listening to all events.
Base class for all Incidents (computing events).
Definition: Incident.h:17
Common class providing an architecture-independent hash map.
Definition: HashMap.h:77
void fireIncident(const Incident &incident) override
ListenerMap m_listenerMap
List of auditor names.
Definition: IncidentSvc.h:97
Default implementation of the IIncidentSvc interface.
Definition: IncidentSvc.h:38
GaudiUtils::HashMap< Gaudi::StringKey, std::unique_ptr< ListenerList > > ListenerMap
Definition: IncidentSvc.h:58