ATLAS Offline Software
Loading...
Searching...
No Matches
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
18
21
23#include "AlgorithmPayload.h"
24#include "TrigCostDataStore.h"
25
36class 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
148 std::unique_ptr< std::atomic<bool>[] > m_eventMonitored;
149 std::unique_ptr< std::shared_mutex[] > m_slotMutex;
150 std::mutex m_globalMutex;
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
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 StatusCode monitorROS(const EventContext &context, robmonitor::ROBDataMonitorStruct payload) override
Implementation of ITrigCostSvc::monitorROS.
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.
virtual StatusCode endEvent(const EventContext &context, SG::WriteHandle< xAOD::TrigCompositeContainer > &costOutputHandle, SG::WriteHandle< xAOD::TrigCompositeContainer > &rosOutputHandle) override
Implementation of ITrigCostSvc::endEvent.
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
TrigCostDataStore< std::vector< robmonitor::ROBDataMonitorStruct > > m_rosData
Thread-safe store of ROS data.
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.
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...
The structure which is used to monitor the ROB data request in L2 It is created for every addROBData ...
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)