ATLAS Offline Software
Loading...
Searching...
No Matches
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
9
10#include <chrono>
11#include <mutex>
12#include <vector>
13
14TrigExISPublishing::TrigExISPublishing(const std::string& name, ISvcLocator* svcLoc) :
15 AthReentrantAlgorithm(name, svcLoc)
16{}
17
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
47StatusCode 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}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_DEBUG(x)
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
An algorithm that can be simultaneously executed in multiple threads.
std::atomic< long > m_nEvents
Number of events processed so far.
std::shared_ptr< hltinterface::GenericHLTContainer > m_IsObject
virtual StatusCode execute(const EventContext &ctx) const override
TrigExISPublishing(const std::string &name, ISvcLocator *svcLoc)
virtual StatusCode initialize() override