5#ifndef TRIGCOSTMONITOR_TRIGCOSTSVC_H
6#define TRIGCOSTMONITOR_TRIGCOSTSVC_H
13#include "GaudiKernel/ToolHandle.h"
35class TrigCostSvc :
public extends <AthService, ITrigCostSvc> {
43 TrigCostSvc(
const std::string& name, ISvcLocator* pSvcLocator);
58 virtual StatusCode
finalize()
override;
66 virtual StatusCode
startEvent(
const EventContext& context,
const bool enableMonitoring =
true)
override;
74 virtual StatusCode
processAlg(
const EventContext& context,
const std::string& caller,
const AuditType
type)
override;
87 virtual bool isMonitoredEvent(
const EventContext& context,
const bool includeMultiSlot =
true)
const override;
101 virtual StatusCode
discardEvent(
const EventContext& context)
override;
120 StatusCode
checkSlot(
const EventContext& context)
const;
127 int32_t
getROIID(
const EventContext& context);
134 static size_t hash(
const std::thread::id& thread);
135 static bool equal(
const std::thread::id&
x,
const std::thread::id&
y);
145 tbb::concurrent_hash_map<std::thread::id, AlgorithmIdentifier, ThreadHashCompare>
m_threadToAlgMap;
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"};
DataVector adapter that acts like it holds const pointers.
Handle class for recording to StoreGate.
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)