ATLAS Offline Software
EvtIdModifierSvc.cxx
Go to the documentation of this file.
1 
3 /*
4  Copyright (C) 2002-2022 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 
19 // FrameWork includes
20 #include "StoreGate/StoreGateSvc.h"
21 
22 // EventInfo includes
23 #include "EventInfo/EventID.h"
24 #include "EventInfo/EventInfo.h"
25 
26 namespace {
27 constexpr int prop_per_nplet{6};
28 
29 enum ModFlag {
30  RUNNBR = 1 << 0,
31  EVTNBR = 1 << 1,
32  TIMESTAMP = 1 << 2,
33  LBKNBR = 1 << 3
34 };
35 
37 
38 } // namespace
39 
41 // Public methods:
43 
44 // Constructors
47  ISvcLocator* pSvcLocator)
48  : ::AthService(name, pSvcLocator) {
49  //
50  // Property declaration
51  //
52  // declareProperty( "Property", m_nProperty );
53 
54  declareProperty("Modifiers", m_evtNpletsProp,
55  "A list of n-uplets "
56  "(RunNumber,EvtNbr,TimeStamp,LumiBlock,Nevents,ModBit).");
57 
58  declareProperty("EvtStoreName", m_evtStoreName = "StoreGateSvc",
59  "Name of the event store whose EventIDs will be modified.");
60 
61  declareProperty("SkipEvents", m_firstEvtIdx = 0,
62  "Number of events to skip before modifying EventInfos.");
63  declareProperty("SkippedEvents", m_skippedEvents = 0,
64  "Number of events skipped in the EventSelector.");
65 }
66 
67 // Athena Service's Hooks
70  ATH_MSG_INFO("Initializing " << name() << "...");
71 
72  if (const auto nplets_prop_count = m_evtNpletsProp.size();
73  nplets_prop_count > 0) {
74  // they should be Nplets...
75  if (nplets_prop_count % prop_per_nplet != 0) {
76  ATH_MSG_ERROR("invalid list of n-plets (not divisible by "
77  << prop_per_nplet << ")" << endmsg << "check your joboptions !");
78  return StatusCode::FAILURE;
79  }
80 
81  m_evtNplets.reserve(nplets_prop_count / prop_per_nplet);
82  for (std::size_t i = 0; i < nplets_prop_count; i += prop_per_nplet) {
83  m_evtNplets.push_back({
84  // clang-format off
85  .runnbr = static_cast<number_type>( m_evtNpletsProp[i + 0]),
86  .evtnbr = static_cast<event_number_t>(m_evtNpletsProp[i + 1]),
87  .timestamp = static_cast<number_type>( m_evtNpletsProp[i + 2]),
88  .lbknbr = static_cast<number_type>( m_evtNpletsProp[i + 3]),
89  .nevts = static_cast<event_number_t>(m_evtNpletsProp[i + 4]),
90  .flags = static_cast<int>( m_evtNpletsProp[i + 5])
91  // clang-format on
92  });
93  }
94  }
95 
96  // initialize running total of nevts
97  m_numEvtTotals.clear();
98  event_number_t sum = 0;
99  for (const ItemModifier& elem : m_evtNplets) {
100  sum += elem.nevts;
101  m_numEvtTotals.push_back(sum);
102  }
103 
104  if (msgLvl(MSG::DEBUG)) {
105  msg(MSG::DEBUG) << "store being modified: [" << m_evtStoreName << "]"
106  << endmsg << "evtid-modifiers: [ ";
107  for (const ItemModifier& elem : m_evtNplets) {
108  msg(MSG::DEBUG) << "[" << elem.runnbr << ", " << elem.evtnbr << ", "
109  << elem.timestamp << ", " << elem.lbknbr << ", "
110  << elem.nevts << ", flags=0x" << std::hex << elem.flags
111  << std::dec << "], ";
112  }
113  msg(MSG::DEBUG) << "]" << endmsg;
114  }
115 
116  return StatusCode::SUCCESS;
117 }
118 
119 // Query the interfaces.
120 // Input: riid, Requested interface ID
121 // ppvInterface, Pointer to requested interface
122 // Return: StatusCode indicating SUCCESS or FAILURE.
123 // N.B. Don't forget to release the interface after use!!!
125  void** ppvInterface) {
126  if (IEvtIdModifierSvc::interfaceID().versionMatch(riid)) {
127  *ppvInterface = dynamic_cast<IEvtIdModifierSvc*>(this);
128  } else {
129  // Interface is not directly available : try out a base class
130  return ::AthService::queryInterface(riid, ppvInterface);
131  }
132  addRef();
133  return StatusCode::SUCCESS;
134 }
135 
137 // Const methods:
139 
142 std::vector<number_type> EvtIdModifierSvc::run_number_list() const {
143  std::set<number_type> runs;
144 
145  for (const ItemModifier& elem : m_evtNplets) {
146  if (elem.flags & ModFlag::RUNNBR) {
147  runs.insert(elem.runnbr);
148  }
149  }
150  return std::vector(runs.begin(), runs.end());
151 }
152 
154 // Non-const methods:
156 
160  bool consume_stream) {
161  // Left in to match old observable behaviour:
162  // only when consuming stream is required do we check for a matching
163  // current StoreGate name (ie: typically the case of being called from a T/P
164  // cnv)
165  if (consume_stream) {
167  if (!active) {
168  ATH_MSG_INFO("could not retrieve the active evtstore - bailing out");
169  return;
170  }
171 
172  const std::string& evtStoreName = active->name();
173  ATH_MSG_DEBUG("active store: [" << evtStoreName << "]");
174  if (evtStoreName != m_evtStoreName) {
175  return;
176  }
177  }
178 
179  ATH_MSG_DEBUG("evtid before massaging: " << "(" << evt_id.run_number() << ", "
180  << evt_id.event_number() << ", "
181  << evt_id.time_stamp() << ", "
182  << evt_id.lumi_block() << ")");
183 
184  // event skipping
185  std::int64_t idx =
186  std::int64_t(evt_index) + m_skippedEvents - std::int64_t(m_firstEvtIdx);
187  std::int64_t idx_looped = idx % m_numEvtTotals.back();
188  ATH_MSG_DEBUG("Got event idx " << evt_index << " --(account for skipping)--> "
189  << idx << " --(modulo #modifiers)--> "
190  << idx_looped);
191  if (idx < 0) {
192  ATH_MSG_DEBUG("skip event");
193  return;
194  }
195 
196  // Account for events skipped in
197  std::size_t mod_idx = std::upper_bound(m_numEvtTotals.cbegin(),
198  m_numEvtTotals.cend(), idx_looped) -
199  m_numEvtTotals.cbegin();
200  ItemModifier current = m_evtNplets[mod_idx];
201  ATH_MSG_DEBUG("Unique modifier index " << mod_idx
202  << " (LB: " << current.lbknbr << ")");
203  if (mod_idx >= m_numEvtTotals.size()) {
204  // Shouldn't happen
205  ATH_MSG_ERROR("Somehow run out of modifiers");
206  return;
207  }
208 
209  if (current.flags & ModFlag::RUNNBR) {
210  evt_id.set_run_number(current.runnbr);
211  }
212  if (current.flags & ModFlag::EVTNBR) {
213  evt_id.set_event_number(current.evtnbr);
214  }
215  if (current.flags & ModFlag::TIMESTAMP) {
216  evt_id.set_time_stamp(current.timestamp);
217  }
218  if (current.flags & ModFlag::LBKNBR) {
219  evt_id.set_lumi_block(current.lbknbr);
220  }
221 
222  ATH_MSG_DEBUG("evtid after massaging: " << "(" << evt_id.run_number() << ", "
223  << evt_id.event_number() << ", "
224  << evt_id.time_stamp() << ", "
225  << evt_id.lumi_block() << ")");
226 }
EvtIdModifierSvc::m_evtNplets
std::vector< ItemModifier > m_evtNplets
db of list of ItemModifiers: (run-nbr, evt-nbr, time-stamp, lbk-nbr, nbr-of-events-per-lbk,...
Definition: EvtIdModifierSvc.h:99
ItemModifier
Definition: EvtIdModifierSvc.h:32
fillPileUpNoiseLumi.current
current
Definition: fillPileUpNoiseLumi.py:52
EvtIdModifierSvc::run_number_list
virtual std::vector< number_type > run_number_list() const override
return the (sorted) list of run-numbers which will be modified.
Definition: EvtIdModifierSvc.cxx:142
EvtIdModifierSvc.h
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthenaPoolTestRead.flags
flags
Definition: AthenaPoolTestRead.py:8
EvtIdModifierSvc::EvtIdModifierSvc
EvtIdModifierSvc()
Default constructor:
find_tgc_unfilled_channelids.runs
int runs
Definition: find_tgc_unfilled_channelids.py:10
EvtIdModifierSvc::m_evtStoreName
std::string m_evtStoreName
(prop) Name of the event store whose EventIDs will be modified.
Definition: EvtIdModifierSvc.h:95
AthCommonMsg< Service >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
AtlasMcWeight::number_type
unsigned int number_type
Definition: AtlasMcWeight.h:20
IEvtIdModifierSvc::interfaceID
static const InterfaceID & interfaceID()
Definition: IEvtIdModifierSvc.h:76
EvtIdModifierSvc::m_firstEvtIdx
event_number_t m_firstEvtIdx
(prop) first event number at which we begin to modify event ids
Definition: EvtIdModifierSvc.h:88
IEvtIdModifierSvc::number_type
EventIDBase::number_type number_type
Definition: IEvtIdModifierSvc.h:42
IEvtIdModifierSvc
Definition: IEvtIdModifierSvc.h:37
EvtIdModifierSvc::m_numEvtTotals
std::vector< event_number_t > m_numEvtTotals
Running total of numEvts before each modifier.
Definition: EvtIdModifierSvc.h:102
event_number_t
EventIDBase::event_number_t event_number_t
Definition: IEvtIdModifierSvc.h:30
StoreGateSvc
The Athena Transient Store API.
Definition: StoreGateSvc.h:128
EventID.h
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
convertTimingResiduals.sum
sum
Definition: convertTimingResiduals.py:55
Trk::active
@ active
Definition: Layer.h:48
EvtIdModifierSvc::modify_evtid
virtual void modify_evtid(EventID &evt_id, event_number_t evt_index, bool consume_stream) override
modify an EventID's lumi block content.
Definition: EvtIdModifierSvc.cxx:159
lumiFormat.i
int i
Definition: lumiFormat.py:92
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
AthService
Definition: AthService.h:32
StoreGateSvc::currentStoreGate
static StoreGateSvc * currentStoreGate()
get current StoreGate
Definition: StoreGateSvc.cxx:69
EvtIdModifierSvc::m_evtNpletsProp
std::vector< uint64_t > m_evtNpletsProp
(prop) list of n-plets (run-nbr, evt-nbr, time-stamp, lbk-nbr, nbr-of-events-per-lbk,...
Definition: EvtIdModifierSvc.h:92
EvtIdModifierSvc::m_skippedEvents
event_number_t m_skippedEvents
(prop) number of events skipped in the event selector
Definition: EvtIdModifierSvc.h:86
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
DEBUG
#define DEBUG
Definition: page_access.h:11
AthCommonMsg< Service >::msg
MsgStream & msg() const
Definition: AthCommonMsg.h:24
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
EventID
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
Definition: EventID.h:35
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
StoreGateSvc.h
EvtIdModifierSvc::initialize
virtual StatusCode initialize() override
Gaudi Service Implementation.
Definition: EvtIdModifierSvc.cxx:69
EvtIdModifierSvc::queryInterface
virtual StatusCode queryInterface(const InterfaceID &riid, void **ppvInterface) override
Definition: EvtIdModifierSvc.cxx:124