| The Gaudi Framework v32r1 (f65d50dc)

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 <algorithm>
9 #include <list>
10 #include <map>
11 // ============================================================================
12 // GaudiKernel
13 // ============================================================================
14 #include "GaudiKernel/ChronoEntity.h"
15 #include "GaudiKernel/HashMap.h"
16 #include "GaudiKernel/IIncidentSvc.h"
17 #include "GaudiKernel/Service.h"
18 #include "GaudiKernel/StringKey.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, IIncidentSvc> {
39 public:
40 struct Listener final {
41 IIncidentListener* iListener{nullptr};
42 long priority{0};
43 bool rethrow{false};
44 bool singleShot{false};
45
46 Listener( IIncidentListener* il, long pri, bool thr = false, bool single = false )
47 : iListener( il ), priority( pri ), rethrow( thr ), singleShot( single ) {}
48 };
49
50 private:
51 // Typedefs
52 // ListenerList should be a list rather than a vector because handing
53 // a fired incident may result in a call to addListener.
54 typedef std::list<Listener> ListenerList;
55 typedef GaudiUtils::HashMap<Gaudi::StringKey, std::unique_ptr<ListenerList>> ListenerMap;
56
57 public:
58 // Inherited Service overrides:
59 //
60 StatusCode initialize() override;
61 StatusCode finalize() override;
62
63 // IIncidentSvc interfaces overwrite
64 //
65 void addListener( IIncidentListener* lis, const std::string& type = "", long priority = 0, bool rethrow = false,
66 bool singleShot = false ) override;
67
68 void removeListener( IIncidentListener* l, const std::string& type = "" ) override;
69 void fireIncident( const Incident& incident ) override;
70 void fireIncident( std::unique_ptr<Incident> incident ) override;
71 // TODO: return by value instead...
72 void getListeners( std::vector<IIncidentListener*>& lis, const std::string& type = "" ) const override;
73
74 // Standard Constructor.
75 IncidentSvc( const std::string& name, ISvcLocator* svc );
76 // Destructor.
77 ~IncidentSvc() override;
78 IIncidentSvc::IncidentPack getIncidents( const EventContext* ctx ) override;
79
80 private:
81 ListenerMap::iterator removeListenerFromList( ListenerMap::iterator, IIncidentListener* item, bool scheduleRemoval );
82 // ==========================================================================
84 void i_fireIncident( const Incident& incident, const std::string& type );
85
87 ListenerMap m_listenerMap;
88
91 const std::string* m_currentIncidentType = nullptr;
92
94 mutable std::recursive_mutex m_listenerMapMutex;
95
97 mutable ChronoEntity m_timer;
98 mutable bool m_timerLock = false;
99 // ==========================================================================
100 // When TBB supports unique_ptrs in concurrent queue typedef should be changed
101 // typedef tbb::concurrent_queue<std::unique_ptr<Incident>> IncQueue_t;
102 typedef tbb::concurrent_queue<Incident*> IncQueue_t;
103 tbb::concurrent_unordered_map<EventContext, IncQueue_t, EventContextHash, EventContextHash> m_firedIncidents;
104 };
105 // ============================================================================
106 // The END
107 // ============================================================================
108 #endif
IncidentSvc::m_timer
ChronoEntity m_timer
timer & it's lock
Definition: IncidentSvc.h:97
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
IncidentSvc::finalize
StatusCode finalize() override
Definition: IncidentSvc.cpp:71
ChronoEntity
a small helper class for implementation of ChronoStatSvc service, It also could be used as some local...
Definition: ChronoEntity.h:21
IncidentSvc::m_timerLock
bool m_timerLock
Definition: IncidentSvc.h:98
IncidentSvc::Listener::rethrow
bool rethrow
Definition: IncidentSvc.h:43
IncidentSvc::addListener
void addListener(IIncidentListener *lis, const std::string &type="", long priority=0, bool rethrow=false, bool singleShot=false) override
Definition: IncidentSvc.cpp:91
IncidentSvc::getIncidents
IIncidentSvc::IncidentPack getIncidents(const EventContext *ctx) override
Definition: IncidentSvc.cpp:263
IncidentSvc::removeListenerFromList
ListenerMap::iterator removeListenerFromList(ListenerMap::iterator, IIncidentListener *item, bool scheduleRemoval)
Definition: IncidentSvc.cpp:119
IncidentSvc::ListenerList
std::list< Listener > ListenerList
Definition: IncidentSvc.h:54
IncidentSvc::Listener::singleShot
bool singleShot
Definition: IncidentSvc.h:44
HashMap.h
EventContext
This class represents an entry point to all the event specific data.
Definition: EventContext.h:24
IncidentSvc::IncidentSvc
IncidentSvc(const std::string &name, ISvcLocator *svc)
Definition: IncidentSvc.cpp:49
IncidentSvc::~IncidentSvc
~IncidentSvc() override
Definition: IncidentSvc.cpp:51
std::string
STL class.
Service.h
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:274
IIncidentListener
The interface implemented by any class wanting to listen to Incidents.
Definition: IIncidentListener.h:15
IncidentSvc::m_listenerMapMutex
std::recursive_mutex m_listenerMapMutex
Mutex to synchronize access to m_listenerMap.
Definition: IncidentSvc.h:94
IIncidentSvc.h
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
IncidentSvc::removeListener
void removeListener(IIncidentListener *l, const std::string &type="") override
Definition: IncidentSvc.cpp:137
gaudirun.type
type
Definition: gaudirun.py:142
std::recursive_mutex
IncidentSvc::Listener::priority
long priority
Definition: IncidentSvc.h:42
StringKey.h
IncidentSvc::initialize
StatusCode initialize() override
Definition: IncidentSvc.cpp:55
IncidentSvc::m_currentIncidentType
const std::string * m_currentIncidentType
Incident being fired.
Definition: IncidentSvc.h:91
IIncidentSvc::IncidentPack
Definition: IIncidentSvc.h:49
IncidentSvc::Listener::Listener
Listener(IIncidentListener *il, long pri, bool thr=false, bool single=false)
Definition: IncidentSvc.h:46
std::list
STL class.
IncidentSvc::Listener::iListener
IIncidentListener * iListener
Definition: IncidentSvc.h:41
IncidentSvc::getListeners
void getListeners(std::vector< IIncidentListener * > &lis, const std::string &type="") const override
Definition: IncidentSvc.cpp:246
IncidentSvc::IncQueue_t
tbb::concurrent_queue< Incident * > IncQueue_t
Definition: IncidentSvc.h:102
IncidentSvc::m_firedIncidents
tbb::concurrent_unordered_map< EventContext, IncQueue_t, EventContextHash, EventContextHash > m_firedIncidents
Definition: IncidentSvc.h:103
gaudirun.l
dictionary l
Definition: gaudirun.py:521
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
std::vector
STL class.
std::unique_ptr< Incident >
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
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:157
Incident
Base class for all Incidents (computing events).
Definition: Incident.h:17
IncidentSvc::Listener
Definition: IncidentSvc.h:40
GaudiUtils::HashMap
Common class providing an architecture-independent hash map.
Definition: HashMap.h:73
IncidentSvc::fireIncident
void fireIncident(const Incident &incident) override
Definition: IncidentSvc.cpp:225
IncidentSvc::m_listenerMap
ListenerMap m_listenerMap
List of auditor names.
Definition: IncidentSvc.h:87
IncidentSvc
Default implementation of the IIncidentSvc interface.
Definition: IncidentSvc.h:38
ChronoEntity.h
IncidentSvc::ListenerMap
GaudiUtils::HashMap< Gaudi::StringKey, std::unique_ptr< ListenerList > > ListenerMap
Definition: IncidentSvc.h:55