5#ifndef TRIGSERVICES_HLTEVENTLOOPMGR_H
6#define TRIGSERVICES_HLTEVENTLOOPMGR_H
32#include "GaudiKernel/EventIDBase.h"
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"
45#include "tbb/concurrent_queue.h"
46#include "tbb/task_group.h"
51#include <condition_variable>
71class HltEventLoopMgr :
public extends<AthService, ITrigEventLoopMgr, IEventProcessor>,
91 virtual StatusCode
stop()
override;
92 virtual StatusCode
finalize()
override;
97 virtual StatusCode
prepareForStart (
const boost::property_tree::ptree &)
override;
106 virtual StatusCode
executeRun(
int maxevt=-1)
override;
112 virtual StatusCode
nextEvent(
int maxevt=-1)
override;
118 virtual StatusCode
executeEvent( EventContext &&ctx )
override;
128 virtual StatusCode
stopRun()
override;
143 std::atomic<EventIDBase::number_type>
maxLB{0};
163 StatusCode
updateMagField(
const boost::property_tree::ptree& pt)
const;
175 StatusCode
execAtStart(
const EventContext& ctx)
const;
181 const EventContext& eventContext);
184 void resetEventTimer(
const EventContext& eventContext,
bool processing);
220 ToolHandle<TrigCOOLUpdateHelper>
m_coolHelper{
this,
"CoolUpdateTool",
"TrigCOOLUpdateHelper"};
222 ToolHandle<GenericMonitoringTool>
m_monTool{
this,
"MonTool",
"",
"Monitoring tool"};
223 ToolHandle<ITrigErrorMonTool>
m_errorMonTool{
this,
"TrigErrorMonTool",
"TrigErrorMonTool",
"Error monitoring tool"};
234 this,
"SchedulerSvc",
"AvalancheSchedulerSvc",
"Name of the scheduler"};
237 this,
"WhiteboardSvc",
"EventDataSvc",
"Name of the Whiteboard"};
240 this,
"HardTimeout", 10*60*1000,
"Hard event processing timeout in milliseconds"};
243 this,
"SoftTimeoutFraction", 0.8,
"Fraction of the hard timeout to be set as the soft timeout"};
246 this,
"TimeoutThreadIntervalMs", 1000,
"How often the timeout thread checks for soft timeout, in milliseconds"};
249 this,
"TraceOnTimeout",
true,
250 "Print a stack trace on the first soft timeout (might take a while, holding all threads)"};
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."};
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."};
264 this,
"MaxFrameworkErrors", 10,
265 "Tolerable number of recovered framework errors before exiting (<0 means all are tolerated)"};
268 this,
"FwkErrorDebugStreamName",
"HLTMissingData",
269 "Debug stream name for events with HLT framework errors"};
272 this,
"AlgErrorDebugStreamName",
"HltError",
273 "Debug stream name for events with HLT algorithm errors"};
276 this,
"TimeoutDebugStreamName",
"HltTimeout",
277 "Debug stream name for events with HLT timeout"};
280 this,
"TruncationDebugStreamName",
"TruncatedHLTResult",
281 "Debug stream name for events with HLT result truncation"};
284 this,
"SORPath",
"/TDAQ/RunCtrl/SOR_Params",
"Path to StartOfRun parameters in detector store"};
287 this,
"execAtStart", {},
"List of algorithms/sequences to execute during prepareForRun"};
290 this,
"setMagFieldFromPtree",
true,
"Read magnet currents from ptree"};
293 this,
"forceRunNumber", 0,
"Override run number"};
296 this,
"forceLumiblock", 0,
"Override lumiblock number"};
299 this,
"forceStartOfRunTime", 0,
"Override SOR time (epoch in nano-seconds)"};
302 this,
"RewriteLVL1",
false,
303 "Encode L1 results to ByteStream and write to the output. Possible only with athenaHLT, not online."};
306 this,
"MonitorScheduler",
false,
"Enable SchedulerMonSvc to collect scheduler status data in online histograms"};
309 this,
"EventContextWHKey",
"EventContext",
"StoreGate key for recording EventContext"};
312 this,
"EventInfoRHKey",
"EventInfo",
"StoreGate key for reading xAOD::EventInfo"};
315 this,
"L1TriggerResultRHKey",
"",
"StoreGate key for reading L1TriggerResult for RewriteLVL1"};
318 this,
"RoIBResultRHKey",
"",
"StoreGate key for reading RoIBResult for RewriteLVL1 with legacy (Run-2) L1 simulation"};
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.
Define macros for attributes used to control the static checker.
Class to modify timeout flag.
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.
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.
void inputThreadCallback()
ServiceHandle< IEvtSelector > m_evtSelector
HltEventLoopMgr & operator=(HltEventLoopMgr &&)=delete
std::string m_applicationName
Application name.
Gaudi::Property< unsigned int > m_timeoutThreadIntervalMs
SmartIF< IAlgResourcePool > m_algResourcePool
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.