5#ifndef TRIGSERVICES_HLTEVENTLOOPMGR_H
6#define TRIGSERVICES_HLTEVENTLOOPMGR_H
31#include "GaudiKernel/EventIDBase.h"
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"
44#include "tbb/concurrent_queue.h"
45#include "tbb/task_group.h"
50#include <condition_variable>
70class HltEventLoopMgr :
public extends<AthService, ITrigEventLoopMgr, IEventProcessor>,
90 virtual StatusCode
stop()
override;
91 virtual StatusCode
finalize()
override;
96 virtual StatusCode
prepareForStart (
const boost::property_tree::ptree &)
override;
97 virtual StatusCode
prepareForRun(
const boost::property_tree::ptree& pt)
override;
105 virtual StatusCode
executeRun(
int maxevt=-1)
override;
111 virtual StatusCode
nextEvent(
int maxevt=-1)
override;
117 virtual StatusCode
executeEvent( EventContext &&ctx )
override;
127 virtual StatusCode
stopRun()
override;
142 std::atomic<EventIDBase::number_type>
maxLB{0};
162 StatusCode
updateMagField(
const boost::property_tree::ptree& pt)
const;
174 StatusCode
execAtStart(
const EventContext& ctx)
const;
180 const EventContext& eventContext);
183 void resetEventTimer(
const EventContext& eventContext,
bool processing);
219 ToolHandle<TrigCOOLUpdateHelper>
m_coolHelper{
this,
"CoolUpdateTool",
"TrigCOOLUpdateHelper"};
221 ToolHandle<GenericMonitoringTool>
m_monTool{
this,
"MonTool",
"",
"Monitoring tool"};
222 ToolHandle<ITrigErrorMonTool>
m_errorMonTool{
this,
"TrigErrorMonTool",
"TrigErrorMonTool",
"Error monitoring tool"};
233 this,
"SchedulerSvc",
"AvalancheSchedulerSvc",
"Name of the scheduler"};
236 this,
"WhiteboardSvc",
"EventDataSvc",
"Name of the Whiteboard"};
239 this,
"HardTimeout", 10*60*1000,
"Hard event processing timeout in milliseconds"};
242 this,
"SoftTimeoutFraction", 0.8,
"Fraction of the hard timeout to be set as the soft timeout"};
245 this,
"TimeoutThreadIntervalMs", 1000,
"How often the timeout thread checks for soft timeout, in milliseconds"};
248 this,
"TraceOnTimeout",
true,
249 "Print a stack trace on the first soft timeout (might take a while, holding all threads)"};
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."};
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."};
263 this,
"MaxFrameworkErrors", 10,
264 "Tolerable number of recovered framework errors before exiting (<0 means all are tolerated)"};
267 this,
"FwkErrorDebugStreamName",
"HLTMissingData",
268 "Debug stream name for events with HLT framework errors"};
271 this,
"AlgErrorDebugStreamName",
"HltError",
272 "Debug stream name for events with HLT algorithm errors"};
275 this,
"TimeoutDebugStreamName",
"HltTimeout",
276 "Debug stream name for events with HLT timeout"};
279 this,
"TruncationDebugStreamName",
"TruncatedHLTResult",
280 "Debug stream name for events with HLT result truncation"};
283 this,
"SORPath",
"/TDAQ/RunCtrl/SOR_Params",
"Path to StartOfRun parameters in detector store"};
286 this,
"execAtStart", {},
"List of algorithms/sequences to execute during prepareForRun"};
289 this,
"setMagFieldFromPtree",
true,
"Read magnet currents from ptree"};
292 this,
"forceRunNumber", 0,
"Override run number"};
295 this,
"forceLumiblock", 0,
"Override lumiblock number"};
298 this,
"forceStartOfRunTime", 0,
"Override SOR time (epoch in nano-seconds)"};
301 this,
"RewriteLVL1",
false,
302 "Encode L1 results to ByteStream and write to the output. Possible only with athenaHLT, not online."};
305 this,
"MonitorScheduler",
false,
"Enable SchedulerMonSvc to collect scheduler status data in online histograms"};
308 this,
"EventContextWHKey",
"EventContext",
"StoreGate key for recording EventContext"};
311 this,
"EventInfoRHKey",
"EventInfo",
"StoreGate key for reading xAOD::EventInfo"};
314 this,
"L1TriggerResultRHKey",
"",
"StoreGate key for reading L1TriggerResult for RewriteLVL1"};
317 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.
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.
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.
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.
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.