ATLAS Offline Software
Loading...
Searching...
No Matches
EvtIdModifierSvc.cxx
Go to the documentation of this file.
1
2
3/*
4 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
5*/
6
7// EvtIdModifierSvc.cxx
8// Implementation file for class EvtIdModifierSvc
9// Author: S.Binet<binet@cern.ch>
11
12// AthenaServices includes
13#include "EvtIdModifierSvc.h"
14
15// STL includes
16#include <algorithm>
17#include <set>
18#include <print>
19
20// FrameWork includes
22
23// EventInfo includes
24#include "EventInfo/EventID.h"
25
26
27namespace {
28constexpr int prop_per_nplet{6};
29
30enum ModFlag {
31 RUNNBR = 1 << 0,
32 EVTNBR = 1 << 1,
33 TIMESTAMP = 1 << 2,
34 LBKNBR = 1 << 3
35};
36
38
39} // namespace
40
42// Public methods:
44
45// Constructors
47EvtIdModifierSvc::EvtIdModifierSvc(const std::string& name,
48 ISvcLocator* pSvcLocator)
49 : base_class(name, pSvcLocator) {
50
51 declareProperty("Modifiers", m_evtNpletsProp,
52 "A list of n-uplets "
53 "(RunNumber,EvtNbr,TimeStamp,LumiBlock,Nevents,ModBit).");
54
55 declareProperty("EvtStoreName", m_evtStoreName = "StoreGateSvc",
56 "Name of the event store whose EventIDs will be modified.");
57
58 declareProperty("SkipEvents", m_firstEvtIdx = 0,
59 "Number of events to skip before modifying EventIDs.");
60 declareProperty("SkippedEvents", m_skippedEvents = 0,
61 "Number of events skipped in the EventSelector.");
62}
63
64// Athena Service's Hooks
67 ATH_MSG_INFO("Initializing {}...", name());
68
69 if (const auto nplets_prop_count = m_evtNpletsProp.size();
70 nplets_prop_count > 0) {
71 // they should be Nplets...
72 if (nplets_prop_count % prop_per_nplet != 0) {
73 ATH_MSG_ERROR("invalid list of n-plets (not divisible by {})\ncheck your joboptions !",
74 prop_per_nplet);
75 return StatusCode::FAILURE;
76 }
77
78 m_evtNplets.reserve(nplets_prop_count / prop_per_nplet);
79 for (std::size_t i = 0; i < nplets_prop_count; i += prop_per_nplet) {
80 m_evtNplets.push_back({
81 // clang-format off
82 .runnbr = static_cast<number_type>( m_evtNpletsProp[i + 0]),
83 .evtnbr = static_cast<event_number_t>(m_evtNpletsProp[i + 1]),
84 .timestamp = static_cast<number_type>( m_evtNpletsProp[i + 2]),
85 .lbknbr = static_cast<number_type>( m_evtNpletsProp[i + 3]),
86 .nevts = static_cast<event_number_t>(m_evtNpletsProp[i + 4]),
87 .flags = static_cast<int>( m_evtNpletsProp[i + 5])
88 // clang-format on
89 });
90 }
91 }
92
93 // initialize running total of nevts
94 m_numEvtTotals.clear();
95 event_number_t sum = 0;
96 for (const ItemModifier& elem : m_evtNplets) {
97 sum += elem.nevts;
98 m_numEvtTotals.push_back(sum);
99 }
100
101 if (msgLvl(MSG::DEBUG)) {
102 ATH_MSG_DEBUG( "store being modified: [{}]", m_evtStoreName);
103 std::ostringstream mods;
104 for (const ItemModifier& elem : m_evtNplets) {
105 std::print (mods, "[{}, {}, {}, {}, {}, flags={:#x}], ",
106 elem.runnbr, elem.evtnbr, elem.timestamp, elem.lbknbr,
107 elem.nevts, elem.flags);
108 }
109 ATH_MSG_DEBUG( "evtid-modifiers: [ {} ]", mods.str() );
110 }
111
112 return StatusCode::SUCCESS;
113}
114
116// Const methods:
118
121std::vector<number_type> EvtIdModifierSvc::run_number_list() const {
122 std::set<number_type> runs;
123
124 for (const ItemModifier& elem : m_evtNplets) {
125 if (elem.flags & ModFlag::RUNNBR) {
126 runs.insert(elem.runnbr);
127 }
128 }
129 return std::vector(runs.begin(), runs.end());
130}
131
133// Non-const methods:
135
139 bool consume_stream) {
140 // Left in to match old observable behaviour:
141 // only when consuming stream is required do we check for a matching
142 // current StoreGate name (ie: typically the case of being called from a T/P
143 // cnv)
144 if (consume_stream) {
146 if (!active) {
147 ATH_MSG_INFO("could not retrieve the active evtstore - bailing out");
148 return;
149 }
150
151 const std::string& evtStoreName = active->name();
152 ATH_MSG_DEBUG("active store: [{}]", evtStoreName);
153 if (evtStoreName != m_evtStoreName) {
154 return;
155 }
156 }
157
158 ATH_MSG_DEBUG("evtid before massaging: ({}, {}, {}, {})",
159 evt_id.run_number(), evt_id.event_number(), evt_id.time_stamp(),
160 evt_id.lumi_block());
161
162 // event skipping
163 std::int64_t idx =
164 std::int64_t(evt_index) + m_skippedEvents - std::int64_t(m_firstEvtIdx);
165 std::int64_t idx_looped = idx % m_numEvtTotals.back();
166 ATH_MSG_DEBUG("Got event idx {} --(account for skipping)--> {} --(modulo #modifiers)--> {}",
167 evt_index, idx, idx_looped);
168 if (idx < 0) {
169 ATH_MSG_DEBUG("skip event");
170 return;
171 }
172
173 // Account for events skipped in
174 std::size_t mod_idx = std::upper_bound(m_numEvtTotals.cbegin(),
175 m_numEvtTotals.cend(), idx_looped) -
176 m_numEvtTotals.cbegin();
177 ItemModifier current = m_evtNplets[mod_idx];
178 ATH_MSG_DEBUG("Unique modifier index {} (LB: {})", mod_idx, current.lbknbr);
179 if (mod_idx >= m_numEvtTotals.size()) {
180 // Shouldn't happen
181 ATH_MSG_ERROR("Somehow run out of modifiers");
182 return;
183 }
184
185 if (current.flags & ModFlag::RUNNBR) {
186 evt_id.set_run_number(current.runnbr);
187 }
188 if (current.flags & ModFlag::EVTNBR) {
189 evt_id.set_event_number(current.evtnbr);
190 }
191 if (current.flags & ModFlag::TIMESTAMP) {
192 evt_id.set_time_stamp(current.timestamp);
193 }
194 if (current.flags & ModFlag::LBKNBR) {
195 evt_id.set_lumi_block(current.lbknbr);
196 }
197
198 ATH_MSG_DEBUG("evtid after massaging: ({}, {}, {}, {})",
199 evt_id.run_number(), evt_id.event_number(), evt_id.time_stamp(),
200 evt_id.lumi_block());
201}
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_INFO(x,...)
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
EventIDBase::event_number_t event_number_t
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
Definition EventID.h:34
event_number_t m_firstEvtIdx
(prop) first event number at which we begin to modify event ids
EvtIdModifierSvc()
Default constructor:
event_number_t m_skippedEvents
(prop) number of events skipped in the event selector
virtual void modify_evtid(EventID &evt_id, event_number_t evt_index, bool consume_stream) override
modify an EventID's lumi block content.
std::vector< uint64_t > m_evtNpletsProp
(prop) list of n-plets (run-nbr, evt-nbr, time-stamp, lbk-nbr, nbr-of-events-per-lbk,...
std::vector< event_number_t > m_numEvtTotals
Running total of numEvts before each modifier.
virtual StatusCode initialize() override
Gaudi Service Implementation.
std::vector< ItemModifier > m_evtNplets
db of list of ItemModifiers: (run-nbr, evt-nbr, time-stamp, lbk-nbr, nbr-of-events-per-lbk,...
std::string m_evtStoreName
(prop) Name of the event store whose EventIDs will be modified.
virtual std::vector< number_type > run_number_list() const override
return the (sorted) list of run-numbers which will be modified.
EventIDBase::number_type number_type
The Athena Transient Store API.
static StoreGateSvc * currentStoreGate()
get current StoreGate
unsigned int number_type