ATLAS Offline Software
TrigCostSvc.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #ifndef TRIGCOSTMONITOR_TRIGCOSTSVC_H
6 #define TRIGCOSTMONITOR_TRIGCOSTSVC_H
7 
8 #include <atomic>
9 #include <shared_mutex>
10 #include <thread>
11 #include <vector>
12 
13 #include "GaudiKernel/ToolHandle.h"
14 
17 #include "StoreGate/WriteHandle.h"
18 
21 
23 #include "AlgorithmPayload.h"
24 #include "TrigCostDataStore.h"
25 
36 class TrigCostSvc : public extends <AthService, ITrigCostSvc> {
37  public:
38 
44  TrigCostSvc(const std::string& name, ISvcLocator* pSvcLocator);
45 
49  virtual ~TrigCostSvc();
50 
54  virtual StatusCode initialize() override;
55 
59  virtual StatusCode finalize() override;
60 
67  virtual StatusCode startEvent(const EventContext& context, const bool enableMonitoring = true) override;
68 
75  virtual StatusCode processAlg(const EventContext& context, const std::string& caller, const AuditType type) override;
76 
83  virtual StatusCode endEvent(const EventContext& context, SG::WriteHandle<xAOD::TrigCompositeContainer>& costOutputHandle, SG::WriteHandle<xAOD::TrigCompositeContainer>& rosOutputHandle) override;
84 
89  virtual bool isMonitoredEvent(const EventContext& context, const bool includeMultiSlot = true) const override;
90 
96  virtual StatusCode monitorROS(const EventContext& context, robmonitor::ROBDataMonitorStruct payload) override;
97 
103  virtual StatusCode generateTimeoutReport(const EventContext& context, std::string& report) override;
104 
105 
110  virtual StatusCode discardEvent(const EventContext& context) override;
111 
112  private:
113 
122  StatusCode monitor(const EventContext& context, const AlgorithmIdentifier& ai, const TrigTimeStamp& now, const AuditType type);
123 
129  StatusCode checkSlot(const EventContext& context) const;
130 
136  int32_t getROIID(const EventContext& context);
137 
143  static size_t hash(const std::thread::id& thread);
144  static bool equal(const std::thread::id& x, const std::thread::id& y);
145  };
146 
147  size_t m_eventSlots;
148  std::unique_ptr< std::atomic<bool>[] > m_eventMonitored;
149  std::unique_ptr< std::shared_mutex[] > m_slotMutex;
154 
155  tbb::concurrent_hash_map<std::thread::id, AlgorithmIdentifier, ThreadHashCompare> m_threadToAlgMap;
156 
157  std::unordered_map<uint32_t, uint32_t> m_threadToCounterMap;
159 
160 
161  Gaudi::Property<bool> m_monitorAllEvents{this, "MonitorAllEvents", false, "Monitor every HLT event, e.g. for offline validation."};
162  Gaudi::Property<bool> m_enableMultiSlot{this, "EnableMultiSlot", false, "Monitored events in the MasterSlot collect data from events running in other slots."};
163  Gaudi::Property<bool> m_saveHashes{this, "SaveHashes", false, "Store a copy of the hash dictionary for easier debugging"};
164  Gaudi::Property<size_t> m_masterSlot{this, "MasterSlot", 0, "The slot responsible for saving MultiSlot data"};
165  Gaudi::Property<std::string> m_costSupervisorAlgName{this, "CostSupervisorAlgName", "TrigCostSupervisorAlg", "The name of cost monitoring supervising algorithm, starting at the begining of the event"};
166  Gaudi::Property<std::string> m_costFinalizeAlgName{this, "CostFinalizeAlgName", "TrigCostFinalizeAlg", "The name of cost monitoring finalize algorithm, starting at the end of the event"};
167 
168 
169 };
170 
171 #endif // TRIGCOSTMONITOR_TRIGCOSTSVC_H
TrigCostSvc::getROIID
int32_t getROIID(const EventContext &context)
@breif Internal function to return a RoI from an extended event context context
Definition: TrigCostSvc.cxx:516
TrigCostSvc::startEvent
virtual StatusCode startEvent(const EventContext &context, const bool enableMonitoring=true) override
Implementation of ITrigCostSvc::startEvent.
Definition: TrigCostSvc.cxx:76
TrigCostSvc::m_threadToAlgMap
tbb::concurrent_hash_map< std::thread::id, AlgorithmIdentifier, ThreadHashCompare > m_threadToAlgMap
Keeps track of what is running right now in each thread.
Definition: TrigCostSvc.h:155
TrigCostSvc::m_threadToCounterMap
std::unordered_map< uint32_t, uint32_t > m_threadToCounterMap
Map thread's hash ID to a counting numeral.
Definition: TrigCostSvc.h:157
TrigCostSvc::ThreadHashCompare
Static hash and equal members as required by tbb::concurrent_hash_map.
Definition: TrigCostSvc.h:142
TrigCostSvc::TrigCostSvc
TrigCostSvc(const std::string &name, ISvcLocator *pSvcLocator)
Standard ATLAS Service constructor.
Definition: TrigCostSvc.cxx:14
robmonitor::ROBDataMonitorStruct
The structure which is used to monitor the ROB data request in L2 It is created for every addROBData ...
Definition: ROBDataMonitor.h:79
TrigCostDataStore.h
AlgorithmIdentifier
Small structure to hold an algorithm's name and store, plus some details on its EventView....
Definition: AlgorithmIdentifier.h:21
ConstDataVector.h
DataVector adapter that acts like it holds const pointers.
TrigCostDataStore< AlgorithmPayload >
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
checkTP.report
report
Definition: checkTP.py:127
TrigCostSvc::~TrigCostSvc
virtual ~TrigCostSvc()
Destructor.
Definition: TrigCostSvc.cxx:31
TrigCostSvc::m_monitorAllEvents
Gaudi::Property< bool > m_monitorAllEvents
Definition: TrigCostSvc.h:161
TrigCostSvc::monitorROS
virtual StatusCode monitorROS(const EventContext &context, robmonitor::ROBDataMonitorStruct payload) override
Implementation of ITrigCostSvc::monitorROS.
Definition: TrigCostSvc.cxx:176
TrigCostSvc::m_eventSlots
size_t m_eventSlots
Number of concurrent processing slots.
Definition: TrigCostSvc.h:147
TrigCostSvc
AthenaMT service to collect trigger cost data from all threads and summarise it at the end of the eve...
Definition: TrigCostSvc.h:36
x
#define x
TrigCostSvc::m_saveHashes
Gaudi::Property< bool > m_saveHashes
Definition: TrigCostSvc.h:163
TrigCostSvc::checkSlot
StatusCode checkSlot(const EventContext &context) const
Sanity check that the job is respecting the number of slots which were declared at config time.
Definition: TrigCostSvc.cxx:506
TrigCostSvc::discardEvent
virtual StatusCode discardEvent(const EventContext &context) override
Discard a cost monitored event.
Definition: TrigCostSvc.cxx:484
TrigCostSvc::m_algStopTime
TrigCostDataStore< TrigTimeStamp > m_algStopTime
Thread-safe store of algorithm stop times.
Definition: TrigCostSvc.h:152
TrigCostSvc::m_threadCounter
size_t m_threadCounter
Count how many unique thread ID we have seen.
Definition: TrigCostSvc.h:158
TrigCostSvc::initialize
virtual StatusCode initialize() override
Initialise, create enough storage to store m_eventSlots.
Definition: TrigCostSvc.cxx:39
TrigCostSvc::generateTimeoutReport
virtual StatusCode generateTimeoutReport(const EventContext &context, std::string &report) override
Definition: TrigCostSvc.cxx:423
WriteHandle.h
Handle class for recording to StoreGate.
python.handimod.now
now
Definition: handimod.py:675
TrigTimeStamp
utility class to measure time duration in AthenaMT The pattern when it is useful: AlgA tags the begin...
Definition: TrigTimeStamp.h:23
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
TrigCostSvc::m_eventMonitored
std::unique_ptr< std::atomic< bool >[] > m_eventMonitored
Used to cache if the event in a given slot is being monitored.
Definition: TrigCostSvc.h:148
TrigCostSvc::ThreadHashCompare::hash
static size_t hash(const std::thread::id &thread)
Definition: TrigCostSvc.cxx:538
ITrigCostSvc.h
TrigCostSvc::processAlg
virtual StatusCode processAlg(const EventContext &context, const std::string &caller, const AuditType type) override
Implementation of ITrigCostSvc::processAlg.
Definition: TrigCostSvc.cxx:105
TrigCompositeContainer.h
TrigCostSvc::finalize
virtual StatusCode finalize() override
Finalize, act on m_saveHashes.
Definition: TrigCostSvc.cxx:65
TrigCostSvc::endEvent
virtual StatusCode endEvent(const EventContext &context, SG::WriteHandle< xAOD::TrigCompositeContainer > &costOutputHandle, SG::WriteHandle< xAOD::TrigCompositeContainer > &rosOutputHandle) override
Implementation of ITrigCostSvc::endEvent.
Definition: TrigCostSvc.cxx:206
TrigCostSvc::m_rosData
TrigCostDataStore< std::vector< robmonitor::ROBDataMonitorStruct > > m_rosData
Thread-safe store of ROS data.
Definition: TrigCostSvc.h:153
id
SG::auxid_t id
Definition: Control/AthContainers/Root/debug.cxx:227
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
TrigCostSvc::m_globalMutex
std::mutex m_globalMutex
Used to protect all-slot modifications.
Definition: TrigCostSvc.h:150
TrigCostSvc::m_costSupervisorAlgName
Gaudi::Property< std::string > m_costSupervisorAlgName
Definition: TrigCostSvc.h:165
TrigCostSvc::ThreadHashCompare::equal
static bool equal(const std::thread::id &x, const std::thread::id &y)
Definition: TrigCostSvc.cxx:544
TrigCostSvc::isMonitoredEvent
virtual bool isMonitoredEvent(const EventContext &context, const bool includeMultiSlot=true) const override
Definition: TrigCostSvc.cxx:526
PixelModuleFeMask_create_db.payload
string payload
Definition: PixelModuleFeMask_create_db.py:69
TrigCostSvc::m_slotMutex
std::unique_ptr< std::shared_mutex[] > m_slotMutex
Used to control and protect whole-table operations.
Definition: TrigCostSvc.h:149
AlgorithmPayload.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
y
#define y
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
AthService.h
TrigCostSvc::m_algStartInfo
TrigCostDataStore< AlgorithmPayload > m_algStartInfo
Thread-safe store of algorithm start payload.
Definition: TrigCostSvc.h:151
TrigCostSvc::m_costFinalizeAlgName
Gaudi::Property< std::string > m_costFinalizeAlgName
Definition: TrigCostSvc.h:166
TrigRoiDescriptorCollection.h
TrigCostSvc::m_masterSlot
Gaudi::Property< size_t > m_masterSlot
Definition: TrigCostSvc.h:164
TrigCostSvc::monitor
StatusCode monitor(const EventContext &context, const AlgorithmIdentifier &ai, const TrigTimeStamp &now, const AuditType type)
Internal call to save monitoring data for a given AlgorithmIdentifier.
Definition: TrigCostSvc.cxx:140
TrigCostSvc::m_enableMultiSlot
Gaudi::Property< bool > m_enableMultiSlot
Definition: TrigCostSvc.h:162