ATLAS Offline Software
Loading...
Searching...
No Matches
HltEventLoopMgr.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef TRIGSERVICES_HLTEVENTLOOPMGR_H
6#define TRIGSERVICES_HLTEVENTLOOPMGR_H
7
8// Local includes
9#include "EventLoopUtils.h"
11
12// Trigger includes
20
21// Athena includes
30
31// Gaudi includes
32#include "GaudiKernel/EventIDBase.h" // number_type
33#include "GaudiKernel/IEventProcessor.h"
34#include "GaudiKernel/IEvtSelector.h"
35#include "GaudiKernel/IConversionSvc.h"
36#include "GaudiKernel/IAlgResourcePool.h"
37#include "GaudiKernel/IAlgExecStateSvc.h"
38#include "GaudiKernel/IHiveWhiteBoard.h"
39#include "GaudiKernel/IScheduler.h"
40#include "GaudiKernel/IIoComponentMgr.h"
41#include "GaudiKernel/SmartIF.h"
42#include "Gaudi/Interfaces/IOptionsSvc.h"
43
44// TBB includes
45#include "tbb/concurrent_queue.h"
46#include "tbb/task_group.h"
47
48// System includes
49#include <atomic>
50#include <chrono>
51#include <condition_variable>
52#include <memory>
53
54// Forward declarations
56class IAlgorithm;
57class IIncidentSvc;
58class StoreGateSvc;
60
61namespace coral {
62 class AttributeList;
63}
64namespace HLT {
65 class HLTResultMT;
66}
67
71class HltEventLoopMgr : public extends<AthService, ITrigEventLoopMgr, IEventProcessor>,
73{
74
75public:
76
78 HltEventLoopMgr(const std::string& name, ISvcLocator* svcLoc);
80 virtual ~HltEventLoopMgr() noexcept override;
81
82 // Copy and move not allowed
87
90 virtual StatusCode initialize() override;
91 virtual StatusCode stop() override;
92 virtual StatusCode finalize() override;
94
97 virtual StatusCode prepareForStart (const boost::property_tree::ptree &) override;
98 virtual StatusCode prepareForRun ATLAS_NOT_THREAD_SAFE (const boost::property_tree::ptree& pt) override;
99 virtual StatusCode hltUpdateAfterFork(const boost::property_tree::ptree& pt) override;
101
106 virtual StatusCode executeRun(int maxevt=-1) override;
107
112 virtual StatusCode nextEvent(int maxevt=-1) override;
113
118 virtual StatusCode executeEvent( EventContext &&ctx ) override;
119
123 virtual EventContext createEventContext() override;
124
128 virtual StatusCode stopRun() override;
129
130private:
131 // ------------------------- Helper types ------------------------------------
135 std::atomic<bool> eventsAvailable{true};
137 std::atomic<bool> loopEnded{false};
139 std::condition_variable loopEndedCond;
141 std::mutex loopEndedMutex;
143 std::atomic<EventIDBase::number_type> maxLB{0};
145 std::condition_variable coolUpdateCond;
147 std::mutex coolUpdateMutex;
149 bool coolUpdateOngoing{false};
151 StatusCode exitCode{StatusCode::SUCCESS};
152 };
153
154 // ------------------------- Helper methods ----------------------------------
155
157 void updateDFProps();
158
159 // Update internally kept data from new sor
160 void updateMetadataStore(const coral::AttributeList & sor_attrlist) const;
161
163 StatusCode updateMagField(const boost::property_tree::ptree& pt) const;
164
166 StatusCode clearTemporaryStores();
167
169 const coral::AttributeList& getSorAttrList() const;
170
172 void printSORAttrList(const coral::AttributeList& atr) const;
173
175 StatusCode execAtStart(const EventContext& ctx) const;
176
180 StatusCode failedEvent(HLT::OnlineErrorCode errorCode,
181 const EventContext& eventContext);
182
184 void resetEventTimer(const EventContext& eventContext, bool processing);
185
187 StatusCode clearWBSlot(size_t evtSlot) const;
188
192 void inputThreadCallback();
193
196
198 void eventTimerCallback();
200
204 StatusCode startNextEvent();
205
207 StatusCode processFinishedEvent();
209
210 // ------------------------- Handles to required services/tools --------------
211 ServiceHandle<IIncidentSvc> m_incidentSvc{this, "IncidentSvc", "IncidentSvc"};
212 ServiceHandle<Gaudi::Interfaces::IOptionsSvc> m_jobOptionsSvc{this, "JobOptionsSvc", "JobOptionsSvc"};
213 ServiceHandle<StoreGateSvc> m_evtStore{this, "EventStore", "StoreGateSvc"};
214 ServiceHandle<StoreGateSvc> m_detectorStore{this, "DetectorStore", "DetectorStore"};
215 ServiceHandle<StoreGateSvc> m_inputMetaDataStore{this, "InputMetaDataStore", "StoreGateSvc/InputMetaDataStore"};
216 ServiceHandle<IIoComponentMgr> m_ioCompMgr{this, "IoComponentMgr", "IoComponentMgr"};
218 ServiceHandle<IConversionSvc> m_outputCnvSvc{this, "OutputCnvSvc", "OutputCnvSvc"};
219 ServiceHandle<ISchedulerMonSvc> m_schedulerMonSvc{this, "SchedulerMonSvc", "SchedulerMonSvc"};
220 ToolHandle<TrigCOOLUpdateHelper> m_coolHelper{this, "CoolUpdateTool", "TrigCOOLUpdateHelper"};
221 ToolHandle<HLTResultMTMaker> m_hltResultMaker{this, "ResultMaker", "HLTResultMTMaker"};
222 ToolHandle<GenericMonitoringTool> m_monTool{this, "MonTool", "", "Monitoring tool"};
223 ToolHandle<ITrigErrorMonTool> m_errorMonTool{this, "TrigErrorMonTool", "TrigErrorMonTool", "Error monitoring tool"};
224
225 SmartIF<IHiveWhiteBoard> m_whiteboard;
226 SmartIF<IAlgResourcePool> m_algResourcePool;
227 SmartIF<IAlgExecStateSvc> m_aess;
228 SmartIF<IScheduler> m_schedulerSvc;
229
230 std::unique_ptr<TrigSORFromPtreeHelper> m_sorHelper;
231
232 // ------------------------- Other properties --------------------------------------
233 Gaudi::Property<std::string> m_schedulerName{
234 this, "SchedulerSvc", "AvalancheSchedulerSvc", "Name of the scheduler"};
235
236 Gaudi::Property<std::string> m_whiteboardName{
237 this, "WhiteboardSvc", "EventDataSvc", "Name of the Whiteboard"};
238
239 Gaudi::Property<float> m_hardTimeout{
240 this, "HardTimeout", 10*60*1000/*=10min*/, "Hard event processing timeout in milliseconds"};
241
242 Gaudi::Property<float> m_softTimeoutFraction{
243 this, "SoftTimeoutFraction", 0.8, "Fraction of the hard timeout to be set as the soft timeout"};
244
245 Gaudi::Property<unsigned int> m_timeoutThreadIntervalMs{
246 this, "TimeoutThreadIntervalMs", 1000, "How often the timeout thread checks for soft timeout, in milliseconds"};
247
248 Gaudi::Property<bool> m_traceOnTimeout{
249 this, "TraceOnTimeout", true,
250 "Print a stack trace on the first soft timeout (might take a while, holding all threads)"};
251
252 Gaudi::Property<int> m_maxParallelIOTasks{
253 this, "MaxParallelIOTasks", -1,
254 "Maximum number of I/O tasks which can be executed in parallel. "
255 "If <=0 then the number of scheduler threads is used."};
256
257 Gaudi::Property<int> m_maxIOWakeUpIntervalMs{
258 this, "MaxIOWakeUpIntervalMs", 5000,
259 "Maximum time input or output handling thread will sleep unless notified. Negative value (default) means no limit, "
260 "i.e. threads will only wake up on notifications. Zero means threads will never wait for notifications. "
261 "Positive value means the number of milliseconds after which a thread will wake up if it's not notified earlier."};
262
263 Gaudi::Property<int> m_maxFrameworkErrors{
264 this, "MaxFrameworkErrors", 10,
265 "Tolerable number of recovered framework errors before exiting (<0 means all are tolerated)"};
266
267 Gaudi::Property<std::string> m_fwkErrorDebugStreamName{
268 this, "FwkErrorDebugStreamName", "HLTMissingData",
269 "Debug stream name for events with HLT framework errors"};
270
271 Gaudi::Property<std::string> m_algErrorDebugStreamName{
272 this, "AlgErrorDebugStreamName", "HltError",
273 "Debug stream name for events with HLT algorithm errors"};
274
275 Gaudi::Property<std::string> m_timeoutDebugStreamName{
276 this, "TimeoutDebugStreamName", "HltTimeout",
277 "Debug stream name for events with HLT timeout"};
278
279 Gaudi::Property<std::string> m_truncationDebugStreamName{
280 this, "TruncationDebugStreamName", "TruncatedHLTResult",
281 "Debug stream name for events with HLT result truncation"};
282
283 Gaudi::Property<std::string> m_sorPath{
284 this, "SORPath", "/TDAQ/RunCtrl/SOR_Params", "Path to StartOfRun parameters in detector store"};
285
286 Gaudi::Property<std::vector<std::string>> m_execAtStart{
287 this, "execAtStart", {}, "List of algorithms/sequences to execute during prepareForRun"};
288
289 Gaudi::Property<bool> m_setMagFieldFromPtree{
290 this, "setMagFieldFromPtree", true, "Read magnet currents from ptree"};
291
292 Gaudi::Property<unsigned int> m_forceRunNumber{
293 this, "forceRunNumber", 0, "Override run number"};
294
295 Gaudi::Property<unsigned int> m_forceLumiblock{
296 this, "forceLumiblock", 0, "Override lumiblock number"};
297
298 Gaudi::Property<unsigned long long> m_forceSOR_ns{
299 this, "forceStartOfRunTime", 0, "Override SOR time (epoch in nano-seconds)"};
300
301 Gaudi::Property<bool> m_rewriteLVL1{
302 this, "RewriteLVL1", false,
303 "Encode L1 results to ByteStream and write to the output. Possible only with athenaHLT, not online."};
304
305 Gaudi::Property<bool> m_monitorScheduler{
306 this, "MonitorScheduler", false, "Enable SchedulerMonSvc to collect scheduler status data in online histograms"};
307
309 this, "EventContextWHKey", "EventContext", "StoreGate key for recording EventContext"};
310
312 this, "EventInfoRHKey", "EventInfo", "StoreGate key for reading xAOD::EventInfo"};
313
315 this, "L1TriggerResultRHKey", "", "StoreGate key for reading L1TriggerResult for RewriteLVL1"};
316
318 this, "RoIBResultRHKey", "", "StoreGate key for reading RoIBResult for RewriteLVL1 with legacy (Run-2) L1 simulation"};
319
321
322 // ------------------------- Other private members ---------------------------
323
325 EventContext m_currentRunCtx{0,0};
327 std::atomic<size_t> m_localEventNumber{0};
329 IEvtSelector::Context* m_evtSelContext{nullptr};
331 std::vector<std::chrono::steady_clock::time_point> m_eventTimerStartPoint;
333 std::vector<std::chrono::steady_clock::time_point> m_freeSlotStartPoint;
335 std::vector<bool> m_isSlotProcessing; // be aware of vector<bool> specialisation
337 std::atomic<size_t> m_freeSlots{0};
339 std::unique_ptr<HLT::LoopThread> m_inputThread;
341 std::unique_ptr<HLT::LoopThread> m_outputThread;
343 std::unique_ptr<HLT::LoopThread> m_timeoutThread;
345 std::chrono::milliseconds m_softTimeoutValue{0};
347 tbb::task_group m_parallelIOTaskGroup;
349 tbb::concurrent_bounded_queue<bool> m_parallelIOQueue;
351 tbb::concurrent_bounded_queue<EventContext*> m_finishedEventsQueue;
357 std::atomic<int> m_nFrameworkErrors{0};
359 std::string m_applicationName;
364
365};
366
367#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.
Define macros for attributes used to control the static checker.
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.
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.
virtual StatusCode prepareForRun ATLAS_NOT_THREAD_SAFE(const boost::property_tree::ptree &pt) override
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.