The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
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>
18#include <list>
19#include <tbb/concurrent_queue.h>
20#include <tbb/concurrent_unordered_map.h>
21
32
33struct isSingleShot_t;
34
35class IncidentSvc : public extends<Service, IIncidentSvc> {
36private:
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
43public:
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
60private:
61 ListenerMap::iterator removeListenerFromList( ListenerMap::iterator, IIncidentListener* item, bool scheduleRemoval );
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};
a small helper class for implementation of ChronoStatSvc service, It also could be used as some local...
This class represents an entry point to all the event specific data.
Common class providing an architecture-independent hash map.
Definition HashMap.h:80
The interface implemented by any class wanting to listen to Incidents.
std::vector< std::pair< std::unique_ptr< Incident >, std::vector< Listener > > > IncidentPack
List of incidents and their listeners.
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition ISvcLocator.h:42
Base class for all Incidents (computing events).
Definition Incident.h:24
GaudiUtils::HashMap< Gaudi::StringKey, std::unique_ptr< ListenerList > > ListenerMap
Definition IncidentSvc.h:41
void removeListener(IIncidentListener *l, const std::string &type="") override
~IncidentSvc() override
StatusCode finalize() override
tbb::concurrent_queue< std::unique_ptr< Incident > > IncQueue_t
Definition IncidentSvc.h:80
ListenerMap::iterator removeListenerFromList(ListenerMap::iterator, IIncidentListener *item, bool scheduleRemoval)
IIncidentSvc::IncidentPack getIncidents(const EventContext *ctx) override
bool m_timerLock
Definition IncidentSvc.h:77
tbb::concurrent_unordered_map< EventContext::ContextID_t, EventContext::ContextEvt_t > m_slotEvent
Event ID for each slot.
Definition IncidentSvc.h:84
std::list< IIncidentSvc::Listener > ListenerList
Definition IncidentSvc.h:40
tbb::concurrent_unordered_map< EventContext::ContextID_t, IncQueue_t > m_firedIncidents
Definition IncidentSvc.h:81
void addListener(IIncidentListener *lis, const std::string &type="", long priority=0, bool rethrow=false, bool singleShot=false) override
const std::string * m_currentIncidentType
Incident being fired.
Definition IncidentSvc.h:70
ChronoEntity m_timer
timer & it's lock
Definition IncidentSvc.h:76
void i_fireIncident(const Incident &incident, const std::string &type)
Internal function to allow incidents listening to all events.
ListenerMap m_listenerMap
List of auditor names.
Definition IncidentSvc.h:66
std::recursive_mutex m_listenerMapMutex
Mutex to synchronize access to m_listenerMap.
Definition IncidentSvc.h:73
IncidentSvc(const std::string &name, ISvcLocator *svc)
void fireIncident(const Incident &incident) override
void getListeners(std::vector< IIncidentListener * > &lis, const std::string &type="") const override
const std::string & name() const override
Retrieve name of the service.
Definition Service.cpp:333
This class is used for returning status codes from appropriate routines.
Definition StatusCode.h:64
Base class used to extend a class implementing other interfaces.
Definition extends.h:19