ATLAS Offline Software
Loading...
Searching...
No Matches
TrigCostSvc.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 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
18
20
22#include "AlgorithmPayload.h"
23#include "TrigCostDataStore.h"
24
35class TrigCostSvc : public extends <AthService, ITrigCostSvc> {
36 public:
37
43 TrigCostSvc(const std::string& name, ISvcLocator* pSvcLocator);
44
48 virtual ~TrigCostSvc();
49
53 virtual StatusCode initialize() override;
54
58 virtual StatusCode finalize() override;
59
66 virtual StatusCode startEvent(const EventContext& context, const bool enableMonitoring = true) override;
67
74 virtual StatusCode processAlg(const EventContext& context, const std::string& caller, const AuditType type) override;
75
81 virtual StatusCode endEvent(const EventContext& context, SG::WriteHandle<xAOD::TrigCompositeContainer>& costOutputHandle) override;
82
87 virtual bool isMonitoredEvent(const EventContext& context, const bool includeMultiSlot = true) const override;
88
94 virtual StatusCode generateTimeoutReport(const EventContext& context, std::string& report) override;
95
96
101 virtual StatusCode discardEvent(const EventContext& context) override;
102
103 private:
104
113 StatusCode monitor(const EventContext& context, const AlgorithmIdentifier& ai, const TrigTimeStamp& now, const AuditType type);
114
120 StatusCode checkSlot(const EventContext& context) const;
121
127 int32_t getROIID(const EventContext& context);
128
134 static size_t hash(const std::thread::id& thread);
135 static bool equal(const std::thread::id& x, const std::thread::id& y);
136 };
137
139 std::unique_ptr< std::atomic<bool>[] > m_eventMonitored;
140 std::unique_ptr< std::shared_mutex[] > m_slotMutex;
141 std::mutex m_globalMutex;
144
145 tbb::concurrent_hash_map<std::thread::id, AlgorithmIdentifier, ThreadHashCompare> m_threadToAlgMap;
146
147 std::unordered_map<uint32_t, uint32_t> m_threadToCounterMap;
149
150
151 Gaudi::Property<bool> m_monitorAllEvents{this, "MonitorAllEvents", false, "Monitor every HLT event, e.g. for offline validation."};
152 Gaudi::Property<bool> m_enableMultiSlot{this, "EnableMultiSlot", false, "Monitored events in the MasterSlot collect data from events running in other slots."};
153 Gaudi::Property<bool> m_saveHashes{this, "SaveHashes", false, "Store a copy of the hash dictionary for easier debugging"};
154 Gaudi::Property<size_t> m_masterSlot{this, "MasterSlot", 0, "The slot responsible for saving MultiSlot data"};
155 Gaudi::Property<std::string> m_costSupervisorAlgName{this, "CostSupervisorAlgName", "TrigCostSupervisorAlg", "The name of cost monitoring supervising algorithm, starting at the begining of the event"};
156 Gaudi::Property<std::string> m_costFinalizeAlgName{this, "CostFinalizeAlgName", "TrigCostFinalizeAlg", "The name of cost monitoring finalize algorithm, starting at the end of the event"};
157
158
159};
160
161#endif // TRIGCOSTMONITOR_TRIGCOSTSVC_H
DataVector adapter that acts like it holds const pointers.
Handle class for recording to StoreGate.
#define y
#define x
Thread safe and multi-slot hash-map to cache PAYLOAD objects/primitives during event execution.
virtual StatusCode processAlg(const EventContext &context, const std::string &caller, const AuditType type) override
Implementation of ITrigCostSvc::processAlg.
Gaudi::Property< bool > m_monitorAllEvents
Gaudi::Property< bool > m_saveHashes
Gaudi::Property< std::string > m_costFinalizeAlgName
std::mutex m_globalMutex
Used to protect all-slot modifications.
TrigCostDataStore< AlgorithmPayload > m_algStartInfo
Thread-safe store of algorithm start payload.
StatusCode checkSlot(const EventContext &context) const
Sanity check that the job is respecting the number of slots which were declared at config time.
TrigCostDataStore< TrigTimeStamp > m_algStopTime
Thread-safe store of algorithm stop times.
Gaudi::Property< bool > m_enableMultiSlot
virtual StatusCode initialize() override
Initialise, create enough storage to store m_eventSlots.
size_t m_eventSlots
Number of concurrent processing slots.
virtual ~TrigCostSvc()
Destructor.
std::unique_ptr< std::shared_mutex[] > m_slotMutex
Used to control and protect whole-table operations.
virtual bool isMonitoredEvent(const EventContext &context, const bool includeMultiSlot=true) const override
std::unique_ptr< std::atomic< bool >[] > m_eventMonitored
Used to cache if the event in a given slot is being monitored.
int32_t getROIID(const EventContext &context)
@breif Internal function to return a RoI from an extended event context context
virtual StatusCode discardEvent(const EventContext &context) override
Discard a cost monitored event.
Gaudi::Property< std::string > m_costSupervisorAlgName
TrigCostSvc(const std::string &name, ISvcLocator *pSvcLocator)
Standard ATLAS Service constructor.
Gaudi::Property< size_t > m_masterSlot
virtual StatusCode finalize() override
Finalize, act on m_saveHashes.
virtual StatusCode generateTimeoutReport(const EventContext &context, std::string &report) override
StatusCode monitor(const EventContext &context, const AlgorithmIdentifier &ai, const TrigTimeStamp &now, const AuditType type)
Internal call to save monitoring data for a given AlgorithmIdentifier.
size_t m_threadCounter
Count how many unique thread ID we have seen.
tbb::concurrent_hash_map< std::thread::id, AlgorithmIdentifier, ThreadHashCompare > m_threadToAlgMap
Keeps track of what is running right now in each thread.
virtual StatusCode endEvent(const EventContext &context, SG::WriteHandle< xAOD::TrigCompositeContainer > &costOutputHandle) override
Implementation of ITrigCostSvc::endEvent.
std::unordered_map< uint32_t, uint32_t > m_threadToCounterMap
Map thread's hash ID to a counting numeral.
virtual StatusCode startEvent(const EventContext &context, const bool enableMonitoring=true) override
Implementation of ITrigCostSvc::startEvent.
utility class to measure time duration in AthenaMT The pattern when it is useful: AlgA tags the begin...
Small structure to hold an algorithm's name and store, plus some details on its EventView.
Static hash and equal members as required by tbb::concurrent_hash_map.
static bool equal(const std::thread::id &x, const std::thread::id &y)
static size_t hash(const std::thread::id &thread)