The Gaudi Framework  v33r1 (b1225454)
IncidentSvc.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2019 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 public:
50  struct Listener final {
52  long priority{0};
53  bool rethrow{false};
54  bool singleShot{false};
55 
56  Listener( IIncidentListener* il, long pri, bool thr = false, bool single = false )
57  : iListener( il ), priority( pri ), rethrow( thr ), singleShot( single ) {}
58  };
59 
60 private:
61  // Typedefs
62  // ListenerList should be a list rather than a vector because handing
63  // a fired incident may result in a call to addListener.
66 
67 public:
68  // Inherited Service overrides:
69  //
70  StatusCode initialize() override;
71  StatusCode finalize() override;
72 
73  // IIncidentSvc interfaces overwrite
74  //
75  void addListener( IIncidentListener* lis, const std::string& type = "", long priority = 0, bool rethrow = false,
76  bool singleShot = false ) override;
77 
78  void removeListener( IIncidentListener* l, const std::string& type = "" ) override;
79  void fireIncident( const Incident& incident ) override;
80  void fireIncident( std::unique_ptr<Incident> incident ) override;
81  // TODO: return by value instead...
82  void getListeners( std::vector<IIncidentListener*>& lis, const std::string& type = "" ) const override;
83 
84  // Standard Constructor.
85  IncidentSvc( const std::string& name, ISvcLocator* svc );
86  // Destructor.
87  ~IncidentSvc() override;
89 
90 private:
92  // ==========================================================================
94  void i_fireIncident( const Incident& incident, const std::string& type );
95 
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 // The END
117 // ============================================================================
118 #endif
ChronoEntity m_timer
timer & it'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:35
StatusCode finalize() override
Definition: IncidentSvc.cpp:81
a small helper class for implementation of ChronoStatSvc service, It also could be used as some local...
Definition: ChronoEntity.h:31
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
IIncidentSvc::IncidentPack getIncidents(const EventContext *ctx) override
ListenerMap::iterator removeListenerFromList(ListenerMap::iterator, IIncidentListener *item, bool scheduleRemoval)
std::list< Listener > ListenerList
Definition: IncidentSvc.h:64
This class represents an entry point to all the event specific data.
Definition: EventContext.h:34
IncidentSvc(const std::string &name, ISvcLocator *svc)
Definition: IncidentSvc.cpp:59
~IncidentSvc() override
Definition: IncidentSvc.cpp:61
STL class.
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:284
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:61
void removeListener(IIncidentListener *l, const std::string &type="") override
StatusCode initialize() override
Definition: IncidentSvc.cpp:65
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:56
STL class.
IIncidentListener * iListener
Definition: IncidentSvc.h:51
void getListeners(std::vector< IIncidentListener * > &lis, const std::string &type="") const override
tbb::concurrent_queue< Incident * > IncQueue_t
Definition: IncidentSvc.h:112
tbb::concurrent_unordered_map< EventContext, IncQueue_t, EventContextHash, EventContextHash > m_firedIncidents
Definition: IncidentSvc.h:113
dictionary l
Definition: gaudirun.py:543
STL class.
Base class used to extend a class implementing other interfaces.
Definition: extends.h:20
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:27
Common class providing an architecture-independent hash map.
Definition: HashMap.h:83
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:48
GaudiUtils::HashMap< Gaudi::StringKey, std::unique_ptr< ListenerList > > ListenerMap
Definition: IncidentSvc.h:65