ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
HLT
Trigger
TrigControl
TrigExamples
src
TrigExISPublishing.cxx
Go to the documentation of this file.
1
/*
2
Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
5
#include "hltinterface/ContainerFactory.h"
6
#include "hltinterface/IInfoRegister.h"
7
8
#include "
TrigExISPublishing.h
"
9
10
#include <chrono>
11
#include <mutex>
12
#include <vector>
13
14
TrigExISPublishing::TrigExISPublishing
(
const
std::string& name, ISvcLocator* svcLoc) :
15
AthReentrantAlgorithm
(name, svcLoc)
16
{}
17
18
StatusCode
TrigExISPublishing::initialize
()
19
{
20
// construct the LAr noise burst container and register it
21
auto
cfact = hltinterface::ContainerFactory::getInstance();
22
if
(cfact) {
23
try
{
24
const
std::string ISname =
"LArISInfo_NoiseBurstAlg"
;
25
const
std::string IStype =
"LArNoiseBurstCandidates"
;
26
m_IsObject
= cfact->constructContainer(ISname, IStype);
27
m_evntPos
= cfact->addIntVector(
m_IsObject
,
"Flag"
,
28
hltinterface::GenericHLTContainer::LASTVALUE);
29
m_timeTagPos
= cfact->addIntVector(
m_IsObject
,
"TimeStamp"
,
30
hltinterface::GenericHLTContainer::LASTVALUE);
31
m_timeTagPosns
= cfact->addIntVector(
m_IsObject
,
"TimeStamp_ns"
,
32
hltinterface::GenericHLTContainer::LASTVALUE);
33
ATH_MSG_DEBUG
(
"Registering container in IS with name /HLTObjects/"
<< ISname);
34
hltinterface::IInfoRegister::instance()->registerObject(
"/HLTObjects/"
,
m_IsObject
);
35
}
36
catch
(std::exception& ex) {
37
ATH_MSG_ERROR
(
"Cannot publish to IS: "
<< ex.what());
38
}
39
}
40
else
{
41
ATH_MSG_INFO
(
"IS publishing not available"
);
42
}
43
44
return
StatusCode::SUCCESS;
45
}
46
47
StatusCode
TrigExISPublishing::execute
(
const
EventContext& ctx)
const
48
{
49
auto
* reg = hltinterface::IInfoRegister::instance();
50
51
if
(
m_IsObject
&& reg) {
52
// Time-varying values, to see at a glance that publication is alive.
53
const
long
n =
m_nEvents
.fetch_add(1, std::memory_order_relaxed) + 1;
54
const
auto
now = std::chrono::system_clock::now().time_since_epoch();
55
const
long
sec = std::chrono::duration_cast<std::chrono::seconds>(now).count();
56
const
long
nsec = std::chrono::duration_cast<std::chrono::nanoseconds>(now).count() % 1000000000L;
57
58
boost::property_tree::ptree event_tree;
59
event_tree.put(
"eventNumber"
, ctx.eventID().event_number());
60
event_tree.put(
"LBNumber"
, ctx.eventID().lumi_block());
61
62
// Take the publication mutex offered by the service.
63
// endEvent() serialises every registered container, not just ours, so a private
64
// lock would not stop another producer writing its container while our endEvent() reads it.
65
// The lock must therefore span both the update and the endEvent() call.
66
std::lock_guard<std::mutex>
lock
(reg->getPublicationMutex());
67
try
{
68
reg->beginEvent(event_tree);
69
70
m_IsObject
->appendField(
m_evntPos
, std::vector<long>{n % 256});
71
m_IsObject
->appendField(
m_timeTagPos
, std::vector<long>{sec});
72
m_IsObject
->appendField(
m_timeTagPosns
, std::vector<long>{nsec});
73
74
constexpr
size_t
maxEntries = 100;
75
for
(
const
size_t
pos : {
m_evntPos
,
m_timeTagPos
,
m_timeTagPosns
}) {
76
std::vector<long>& v =
m_IsObject
->getIntVecField(pos);
77
if
(v.size() > maxEntries) {
78
v.erase(v.begin(), v.end() - maxEntries);
79
}
80
}
81
82
reg->endEvent(event_tree);
83
}
84
catch
(
const
std::exception& ex) {
85
ATH_MSG_INFO
(
"Caught exception during IS publication: "
<< ex.what());
86
}
87
}
88
89
return
StatusCode::SUCCESS;
90
}
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition
AthMsgStreamMacros.h:33
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition
AthMsgStreamMacros.h:31
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition
AthMsgStreamMacros.h:29
lock
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
TrigExISPublishing.h
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition
AthReentrantAlgorithm.h:74
TrigExISPublishing::m_timeTagPosns
size_t m_timeTagPosns
Definition
TrigExISPublishing.h:37
TrigExISPublishing::m_timeTagPos
size_t m_timeTagPos
Definition
TrigExISPublishing.h:36
TrigExISPublishing::m_nEvents
std::atomic< long > m_nEvents
Number of events processed so far.
Definition
TrigExISPublishing.h:40
TrigExISPublishing::m_IsObject
std::shared_ptr< hltinterface::GenericHLTContainer > m_IsObject
Definition
TrigExISPublishing.h:33
TrigExISPublishing::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition
TrigExISPublishing.cxx:47
TrigExISPublishing::TrigExISPublishing
TrigExISPublishing(const std::string &name, ISvcLocator *svcLoc)
Definition
TrigExISPublishing.cxx:14
TrigExISPublishing::m_evntPos
size_t m_evntPos
Definition
TrigExISPublishing.h:35
TrigExISPublishing::initialize
virtual StatusCode initialize() override
Definition
TrigExISPublishing.cxx:18
Generated on
for ATLAS Offline Software by
1.17.0