ATLAS Offline Software
Loading...
Searching...
No Matches
HltEventLoopMgr.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 TRIGSERVICES_HLTEVENTLOOPMGR_H
6#define TRIGSERVICES_HLTEVENTLOOPMGR_H
7
8// Local includes
11
12// Trigger includes
20
21// Athena includes
29
30// Gaudi includes
31#include "GaudiKernel/EventIDBase.h" // number_type
32#include "GaudiKernel/IEventProcessor.h"
33#include "GaudiKernel/IEvtSelector.h"
34#include "GaudiKernel/IConversionSvc.h"
35#include "GaudiKernel/IAlgResourcePool.h"
36#include "GaudiKernel/IAlgExecStateSvc.h"
37#include "GaudiKernel/IHiveWhiteBoard.h"
38#include "GaudiKernel/IScheduler.h"
39#include "GaudiKernel/IIoComponentMgr.h"
40#include "GaudiKernel/SmartIF.h"
41#include "Gaudi/Interfaces/IOptionsSvc.h"
42
43// TBB includes
44#include "tbb/concurrent_queue.h"
45#include "tbb/task_group.h"
46
47// System includes
48#include <atomic>
49#include <chrono>
50#include <condition_variable>
51#include <memory>
52
53// Forward declarations
55class IAlgorithm;
56class IIncidentSvc;
57class StoreGateSvc;
59
60namespace coral {
61 class AttributeList;
62}
63namespace HLT {
64 class HLTResultMT;
65}
66
70class HltEventLoopMgr : public extends<AthService, ITrigEventLoopMgr, IEventProcessor>,
72{
73
74public:
75
77 HltEventLoopMgr(const std::string& name, ISvcLocator* svcLoc);
79 virtual ~HltEventLoopMgr() noexcept override;
80
81 // Copy and move not allowed
86
89 virtual StatusCode initialize() override;
90 virtual StatusCode stop() override;
91 virtual StatusCode finalize() override;
93
96 virtual StatusCode prepareForStart (const boost::property_tree::ptree &) override;
97 virtual StatusCode prepareForRun(const boost::property_tree::ptree& pt) override;
98 virtual StatusCode hltUpdateAfterFork(const boost::property_tree::ptree& pt) override;
100
105 virtual StatusCode executeRun(int maxevt=-1) override;
106
111 virtual StatusCode nextEvent(int maxevt=-1) override;
112
117 virtual StatusCode executeEvent( EventContext &&ctx ) override;
118
122 virtual EventContext createEventContext() override;
123
127 virtual StatusCode stopRun() override;
128
129private:
130 // ------------------------- Helper types ------------------------------------
134 std::atomic<bool> eventsAvailable{true};
136 std::atomic<bool> loopEnded{false};
138 std::condition_variable loopEndedCond;
140 std::mutex loopEndedMutex;
142 std::atomic<EventIDBase::number_type> maxLB{0};
144 std::condition_variable coolUpdateCond;
146 std::mutex coolUpdateMutex;
148 bool coolUpdateOngoing{false};
150 StatusCode exitCode{StatusCode::SUCCESS};
151 };
152
153 // ------------------------- Helper methods ----------------------------------
154
156 void updateDFProps();
157
158 // Update internally kept data from new sor
159 void updateMetadataStore(const coral::AttributeList & sor_attrlist) const;
160
162 StatusCode updateMagField(const boost::property_tree::ptree& pt) const;
163
165 StatusCode clearTemporaryStores();
166
168 const coral::AttributeList& getSorAttrList() const;
169
171 void printSORAttrList(const coral::AttributeList& atr) const;
172
174 StatusCode execAtStart(const EventContext& ctx) const;
175
179 StatusCode failedEvent(HLT::OnlineErrorCode errorCode,
180 const EventContext& eventContext);
181
183 void resetEventTimer(const EventContext& eventContext, bool processing);
184
186 StatusCode clearWBSlot(size_t evtSlot) const;
187
191 void inputThreadCallback();
192
195
197 void eventTimerCallback();
199
203 StatusCode startNextEvent();
204
206 StatusCode processFinishedEvent();
208
209 // ------------------------- Handles to required services/tools --------------
210 ServiceHandle<IIncidentSvc> m_incidentSvc{this, "IncidentSvc", "IncidentSvc"};
211 ServiceHandle<Gaudi::Interfaces::IOptionsSvc> m_jobOptionsSvc{this, "JobOptionsSvc", "JobOptionsSvc"};
212 ServiceHandle<StoreGateSvc> m_evtStore{this, "EventStore", "StoreGateSvc"};
213 ServiceHandle<StoreGateSvc> m_detectorStore{this, "DetectorStore", "DetectorStore"};
214 ServiceHandle<StoreGateSvc> m_inputMetaDataStore{this, "InputMetaDataStore", "StoreGateSvc/InputMetaDataStore"};
215 ServiceHandle<IIoComponentMgr> m_ioCompMgr{this, "IoComponentMgr", "IoComponentMgr"};
217 ServiceHandle<IConversionSvc> m_outputCnvSvc{this, "OutputCnvSvc", "OutputCnvSvc"};
218 ServiceHandle<ISchedulerMonSvc> m_schedulerMonSvc{this, "SchedulerMonSvc", "SchedulerMonSvc"};
219 ToolHandle<TrigCOOLUpdateHelper> m_coolHelper{this, "CoolUpdateTool", "TrigCOOLUpdateHelper"};
220 ToolHandle<HLTResultMTMaker> m_hltResultMaker{this, "ResultMaker", "HLTResultMTMaker"};
221 ToolHandle<GenericMonitoringTool> m_monTool{this, "MonTool", "", "Monitoring tool"};
222 ToolHandle<ITrigErrorMonTool> m_errorMonTool{this, "TrigErrorMonTool", "TrigErrorMonTool", "Error monitoring tool"};
223
224 SmartIF<IHiveWhiteBoard> m_whiteboard;
225 SmartIF<IAlgResourcePool> m_algResourcePool;
226 SmartIF<IAlgExecStateSvc> m_aess;
227 SmartIF<IScheduler> m_schedulerSvc;
228
229 std::unique_ptr<TrigSORFromPtreeHelper> m_sorHelper;
230
231 // ------------------------- Other properties --------------------------------------
232 Gaudi::Property<std::string> m_schedulerName{
233 this, "SchedulerSvc", "AvalancheSchedulerSvc", "Name of the scheduler"};
234
235 Gaudi::Property<std::string> m_whiteboardName{
236 this, "WhiteboardSvc", "EventDataSvc", "Name of the Whiteboard"};
237
238 Gaudi::Property<float> m_hardTimeout{
239 this, "HardTimeout", 10*60*1000/*=10min*/, "Hard event processing timeout in milliseconds"};
240
241 Gaudi::Property<float> m_softTimeoutFraction{
242 this, "SoftTimeoutFraction", 0.8, "Fraction of the hard timeout to be set as the soft timeout"};
243
244 Gaudi::Property<unsigned int> m_timeoutThreadIntervalMs{
245 this, "TimeoutThreadIntervalMs", 1000, "How often the timeout thread checks for soft timeout, in milliseconds"};
246
247 Gaudi::Property<bool> m_traceOnTimeout{
248 this, "TraceOnTimeout", true,
249 "Print a stack trace on the first soft timeout (might take a while, holding all threads)"};
250
251 Gaudi::Property<int> m_maxParallelIOTasks{
252 this, "MaxParallelIOTasks", -1,
253 "Maximum number of I/O tasks which can be executed in parallel. "
254 "If <=0 then the number of scheduler threads is used."};
255
256 Gaudi::Property<int> m_maxIOWakeUpIntervalMs{
257 this, "MaxIOWakeUpIntervalMs", 5000,
258 "Maximum time input or output handling thread will sleep unless notified. Negative value (default) means no limit, "
259 "i.e. threads will only wake up on notifications. Zero means threads will never wait for notifications. "
260 "Positive value means the number of milliseconds after which a thread will wake up if it's not notified earlier."};
261
262 Gaudi::Property<int> m_maxFrameworkErrors{
263 this, "MaxFrameworkErrors", 10,
264 "Tolerable number of recovered framework errors before exiting (<0 means all are tolerated)"};
265
266 Gaudi::Property<std::string> m_fwkErrorDebugStreamName{
267 this, "FwkErrorDebugStreamName", "HLTMissingData",
268 "Debug stream name for events with HLT framework errors"};
269
270 Gaudi::Property<std::string> m_algErrorDebugStreamName{
271 this, "AlgErrorDebugStreamName", "HltError",
272 "Debug stream name for events with HLT algorithm errors"};
273
274 Gaudi::Property<std::string> m_timeoutDebugStreamName{
275 this, "TimeoutDebugStreamName", "HltTimeout",
276 "Debug stream name for events with HLT timeout"};
277
278 Gaudi::Property<std::string> m_truncationDebugStreamName{
279 this, "TruncationDebugStreamName", "TruncatedHLTResult",
280 "Debug stream name for events with HLT result truncation"};
281
282 Gaudi::Property<std::string> m_sorPath{
283 this, "SORPath", "/TDAQ/RunCtrl/SOR_Params", "Path to StartOfRun parameters in detector store"};
284
285 Gaudi::Property<std::vector<std::string>> m_execAtStart{
286 this, "execAtStart", {}, "List of algorithms/sequences to execute during prepareForRun"};
287
288 Gaudi::Property<bool> m_setMagFieldFromPtree{
289 this, "setMagFieldFromPtree", true, "Read magnet currents from ptree"};
290
291 Gaudi::Property<unsigned int> m_forceRunNumber{
292 this, "forceRunNumber", 0, "Override run number"};
293
294 Gaudi::Property<unsigned int> m_forceLumiblock{
295 this, "forceLumiblock", 0, "Override lumiblock number"};
296
297 Gaudi::Property<unsigned long long> m_forceSOR_ns{
298 this, "forceStartOfRunTime", 0, "Override SOR time (epoch in nano-seconds)"};
299
300 Gaudi::Property<bool> m_rewriteLVL1{
301 this, "RewriteLVL1", false,
302 "Encode L1 results to ByteStream and write to the output. Possible only with athenaHLT, not online."};
303
304 Gaudi::Property<bool> m_monitorScheduler{
305 this, "MonitorScheduler", false, "Enable SchedulerMonSvc to collect scheduler status data in online histograms"};
306
308 this, "EventContextWHKey", "EventContext", "StoreGate key for recording EventContext"};
309
311 this, "EventInfoRHKey", "EventInfo", "StoreGate key for reading xAOD::EventInfo"};
312
314 this, "L1TriggerResultRHKey", "", "StoreGate key for reading L1TriggerResult for RewriteLVL1"};
315
317 this, "RoIBResultRHKey", "", "StoreGate key for reading RoIBResult for RewriteLVL1 with legacy (Run-2) L1 simulation"};
318
320
321 // ------------------------- Other private members ---------------------------
322
324 EventContext m_currentRunCtx{0,0};
326 std::atomic<size_t> m_localEventNumber{0};
328 IEvtSelector::Context* m_evtSelContext{nullptr};
330 std::vector<std::chrono::steady_clock::time_point> m_eventTimerStartPoint;
332 std::vector<std::chrono::steady_clock::time_point> m_freeSlotStartPoint;
334 std::vector<bool> m_isSlotProcessing; // be aware of vector<bool> specialisation
336 std::atomic<size_t> m_freeSlots{0};
338 std::unique_ptr<HLT::LoopThread> m_inputThread;
340 std::unique_ptr<HLT::LoopThread> m_outputThread;
342 std::unique_ptr<HLT::LoopThread> m_timeoutThread;
344 std::chrono::milliseconds m_softTimeoutValue{0};
346 tbb::task_group m_parallelIOTaskGroup;
348 tbb::concurrent_bounded_queue<bool> m_parallelIOQueue;
350 tbb::concurrent_bounded_queue<EventContext*> m_finishedEventsQueue;
356 std::atomic<int> m_nFrameworkErrors{0};
358 std::string m_applicationName;
363
364};
365
366#endif // TRIGSERVICES_HLTEVENTLOOPMGR_H
Assign a CLID to EventContext.
Header file to be included by clients of the Monitored infrastructure.
Property holding a SG store/key/clid from which a ReadHandle is made.
Property holding a SG store/key/clid from which a WriteHandle is made.
Timeout singleton.
Class to modify timeout flag.
Definition Timeout.h:77
This class is a collection of AttributeLists where each one is associated with a channel number.
A container class for data required to build online output from HLT.
Definition HLTResultMT.h:38
ToolHandle< TrigCOOLUpdateHelper > m_coolHelper
StatusCode clearTemporaryStores()
Clear per-event stores.
ServiceHandle< StoreGateSvc > m_inputMetaDataStore
SG::WriteHandleKey< EventContext > m_eventContextWHKey
ServiceHandle< IIoComponentMgr > m_ioCompMgr
Gaudi::Property< float > m_softTimeoutFraction
virtual StatusCode finalize() override
virtual StatusCode hltUpdateAfterFork(const boost::property_tree::ptree &pt) override
Gaudi::Property< int > m_maxParallelIOTasks
Gaudi::Property< int > m_maxIOWakeUpIntervalMs
StatusCode failedEvent(HLT::OnlineErrorCode errorCode, const EventContext &eventContext)
Handle a failure to process an event.
virtual StatusCode prepareForRun(const boost::property_tree::ptree &pt) override
void printSORAttrList(const coral::AttributeList &atr) const
Print the SOR record.
tbb::concurrent_bounded_queue< bool > m_parallelIOQueue
Queue limiting the number of parallel I/O tasks.
std::unique_ptr< HLT::LoopThread > m_timeoutThread
Timeout thread.
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfoRHKey
ServiceHandle< Gaudi::Interfaces::IOptionsSvc > m_jobOptionsSvc
HltEventLoopMgr & operator=(const HltEventLoopMgr &)=delete
StatusCode execAtStart(const EventContext &ctx) const
Execute optional algs/sequences.
std::unique_ptr< HLT::LoopThread > m_inputThread
Input handling thread (triggers reading new events)
std::atomic< size_t > m_localEventNumber
Event counter used for local bookkeeping; incremental per instance of HltEventLoopMgr,...
virtual StatusCode stop() override
tbb::concurrent_bounded_queue< EventContext * > m_finishedEventsQueue
Queue of events ready for output processing.
HltEventLoopMgr(const HltEventLoopMgr &)=delete
EventLoopStatus m_loopStatus
Object keeping track of the event loop status.
std::unique_ptr< HLT::LoopThread > m_outputThread
Output handling thread (triggers post-processing of finished events)
Gaudi::Property< std::vector< std::string > > m_execAtStart
StatusCode updateMagField(const boost::property_tree::ptree &pt) const
Set magnetic field currents from ptree.
tbb::task_group m_parallelIOTaskGroup
Task group to execute parallel I/O tasks asynchronously.
virtual StatusCode nextEvent(int maxevt=-1) override
Implementation of IEventProcessor::nextEvent which implements the event loop.
SG::ReadHandleKey< xAOD::TrigCompositeContainer > m_l1TriggerResultRHKey
void outputThreadCallback()
The method executed by the output handling thread.
StatusCode processFinishedEvent()
Perform all end-of-event actions for a single event popped out from the scheduler.
virtual StatusCode executeRun(int maxevt=-1) override
Implementation of IEventProcessor::executeRun which calls IEventProcessor::nextEvent.
Gaudi::Property< std::string > m_truncationDebugStreamName
ServiceHandle< StoreGateSvc > m_evtStore
virtual StatusCode initialize() override
Gaudi::Property< unsigned int > m_forceLumiblock
virtual EventContext createEventContext() override
create an Event Context object
std::vector< std::chrono::steady_clock::time_point > m_freeSlotStartPoint
Vector of time stamps telling when each scheduler slot was freed.
ServiceHandle< IEvtSelector > m_evtSelector
HltEventLoopMgr & operator=(HltEventLoopMgr &&)=delete
std::string m_applicationName
Application name.
Gaudi::Property< unsigned int > m_timeoutThreadIntervalMs
SmartIF< IAlgResourcePool > m_algResourcePool
int m_workerID
Worker ID.
StatusCode clearWBSlot(size_t evtSlot) const
Clear an event slot in the whiteboard.
virtual StatusCode executeEvent(EventContext &&ctx) override
Implementation of IEventProcessor::executeEvent which processes a single event.
std::vector< bool > m_isSlotProcessing
Vector of flags to tell if a slot is idle or processing.
SG::ReadHandleKey< ROIB::RoIBResult > m_roibResultRHKey
IEvtSelector::Context * m_evtSelContext
Event selector context.
ServiceHandle< IIncidentSvc > m_incidentSvc
SmartIF< IHiveWhiteBoard > m_whiteboard
bool m_timeoutTraceGenerated
Flag set when a soft timeout produces a stack trace, to avoid producing multiple traces.
Gaudi::Property< std::string > m_timeoutDebugStreamName
virtual StatusCode stopRun() override
Implementation of IEventProcessor::stopRun (obsolete for online runnning)
Gaudi::Property< unsigned long long > m_forceSOR_ns
SmartIF< IScheduler > m_schedulerSvc
StatusCode startNextEvent()
Gaudi::Property< std::string > m_algErrorDebugStreamName
virtual StatusCode prepareForStart(const boost::property_tree::ptree &) override
std::chrono::milliseconds m_softTimeoutValue
Soft timeout value set to HardTimeout*SoftTimeoutFraction at initialisation.
SmartIF< IAlgExecStateSvc > m_aess
void updateDFProps()
Read DataFlow configuration properties.
Gaudi::Property< std::string > m_whiteboardName
std::vector< std::chrono::steady_clock::time_point > m_eventTimerStartPoint
Vector of event start-processing time stamps in each slot.
std::atomic< size_t > m_freeSlots
Number of free slots used to synchronise input/output tasks.
Gaudi::Property< int > m_maxFrameworkErrors
ServiceHandle< IConversionSvc > m_outputCnvSvc
EventContext m_currentRunCtx
"Event" context of current run with dummy event/slot number
void eventTimerCallback()
The method executed by the event timeout monitoring thread.
Gaudi::Property< std::string > m_fwkErrorDebugStreamName
Gaudi::Property< float > m_hardTimeout
ToolHandle< GenericMonitoringTool > m_monTool
std::atomic< int > m_nFrameworkErrors
Counter of framework errors.
HltEventLoopMgr(const std::string &name, ISvcLocator *svcLoc)
Standard constructor.
ToolHandle< HLTResultMTMaker > m_hltResultMaker
void updateMetadataStore(const coral::AttributeList &sor_attrlist) const
ToolHandle< ITrigErrorMonTool > m_errorMonTool
Gaudi::Property< unsigned int > m_forceRunNumber
Gaudi::Property< std::string > m_sorPath
int m_workerPID
Worker PID.
ServiceHandle< ISchedulerMonSvc > m_schedulerMonSvc
Gaudi::Property< bool > m_monitorScheduler
Gaudi::Property< bool > m_traceOnTimeout
Gaudi::Property< std::string > m_schedulerName
const coral::AttributeList & getSorAttrList() const
Extract the single attr list off the SOR CondAttrListCollection.
std::unique_ptr< TrigSORFromPtreeHelper > m_sorHelper
void resetEventTimer(const EventContext &eventContext, bool processing)
Reset the timeout flag and the timer, and mark the slot as busy or idle according to the second argum...
Gaudi::Property< bool > m_setMagFieldFromPtree
SG::ReadHandleKey< HLT::HLTResultMT > m_hltResultRHKey
StoreGate key for reading the HLT result.
virtual ~HltEventLoopMgr() noexcept override
Standard destructor.
Gaudi::Property< bool > m_rewriteLVL1
ServiceHandle< StoreGateSvc > m_detectorStore
HltEventLoopMgr(HltEventLoopMgr &&)=delete
Property holding a SG store/key/clid from which a ReadHandle is made.
Property holding a SG store/key/clid from which a WriteHandle is made.
The Athena Transient Store API.
Tool to perform COOL updates during the run.
It used to be useful piece of code for replacing actual SG with other store of similar functionality ...
Flags and counters steering the main event loop execution.
bool coolUpdateOngoing
COOL update ongoing.
std::mutex coolUpdateMutex
Mutex to synchronize COOL updates.
StatusCode exitCode
Event exit status code.
std::atomic< bool > loopEnded
No more events available and all ongoing processing has finished.
std::mutex loopEndedMutex
Mutex to notify the main thread of the end of the event loop.
std::condition_variable coolUpdateCond
Condition variable to synchronize COOL updates.
std::condition_variable loopEndedCond
Condition variable to notify the main thread of the end of the event loop.
std::atomic< bool > eventsAvailable
Event source has more events.
std::atomic< EventIDBase::number_type > maxLB
Max lumiblock number seen in the loop.