ATLAS Offline Software
HLTResultMT.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
7 #include <algorithm>
8 #include <utility>
9 #include <string_view>
10 
11 // Local constants
12 namespace {
21  constexpr HLT::HLTResultMT::RODMinorVersion s_currentHltRodMinorVersion{1,2};
22 
24  constexpr std::string_view s_contextName{"HLT::HLTResultMT"};
25 }
26 
27 // =============================================================================
28 // Standard constructor
29 // =============================================================================
30 HLT::HLTResultMT::HLTResultMT(std::vector<eformat::helper::StreamTag> streamTags,
31  boost::dynamic_bitset<uint32_t> hltPassRawBits,
32  boost::dynamic_bitset<uint32_t> hltPrescaledBits,
33  std::unordered_map<uint16_t, std::vector<uint32_t> > data)
34 : m_streamTags(std::move(streamTags)),
35  m_hltPassRawBits(std::move(hltPassRawBits)),
36  m_hltPrescaledBits(std::move(hltPrescaledBits)),
37  m_data(std::move(data)),
38  m_version(s_currentHltRodMinorVersion) {}
39 
40 // =============================================================================
41 // Getter/setter methods for stream tags
42 // =============================================================================
43 const std::vector<eformat::helper::StreamTag>& HLT::HLTResultMT::getStreamTags() const {
44  return m_streamTags;
45 }
46 
47 // -----------------------------------------------------------------------------
48 std::vector<eformat::helper::StreamTag>& HLT::HLTResultMT::getStreamTagsNonConst() {
49  return m_streamTags;
50 }
51 
52 // -----------------------------------------------------------------------------
53 StatusCode HLT::HLTResultMT::setStreamTags(const std::vector<eformat::helper::StreamTag>& streamTags) {
54  m_streamTags.clear();
55  for (const auto& st : streamTags) {
56  ATH_CHECK(addStreamTag(st));
57  }
58  return StatusCode::SUCCESS;
59 }
60 
61 // -----------------------------------------------------------------------------
62 StatusCode HLT::HLTResultMT::addStreamTag(const eformat::helper::StreamTag& streamTag) {
63  // Check if a stream tag with the same type and name is already in the result
64  auto compareTypeName = [&streamTag](const eformat::helper::StreamTag& existingStreamTag) {
65  return streamTag.type == existingStreamTag.type && streamTag.name == existingStreamTag.name;
66  };
67  auto p = std::find_if(m_streamTags.begin(), m_streamTags.end(), compareTypeName);
68 
69  // In case of duplicate, merge ROBs and SubDets, otherwise just append the tag to the result
70  if (p != m_streamTags.end()) {
71  if (streamTag.obeys_lumiblock != p->obeys_lumiblock) {
72  ATH_REPORT_ERROR_WITH_CONTEXT(StatusCode::FAILURE, s_contextName.data())
73  << "Stream tags have equal type and name (" << streamTag.type << "/" << streamTag.name
74  << "), but inconsistent obeys_lumiblock flag";
75  return StatusCode::FAILURE;
76  }
77  p->robs.insert(streamTag.robs.begin(), streamTag.robs.end());
78  p->dets.insert(streamTag.dets.begin(), streamTag.dets.end());
79  }
80  else {
81  m_streamTags.push_back(streamTag);
82  }
83 
84  return StatusCode::SUCCESS;
85 }
86 
87 // =============================================================================
88 // Getter/setter methods for trigger bits
89 // =============================================================================
90 const boost::dynamic_bitset<uint32_t>& HLT::HLTResultMT::getHltPassRawBits() const {
91  return m_hltPassRawBits;
92 }
93 
94 // -----------------------------------------------------------------------------
95 const boost::dynamic_bitset<uint32_t>& HLT::HLTResultMT::getHltPrescaledBits() const {
96  return m_hltPrescaledBits;
97 }
98 
99 // -----------------------------------------------------------------------------
100 const std::vector<uint32_t>& HLT::HLTResultMT::getHltBitsAsWords() const {
101  if (m_hltPassRawBits.num_blocks() != m_hltPrescaledBits.num_blocks()) {
102  throw std::runtime_error("Must have the same number of bits in m_hltPassRawBits and m_hltPrescaledBits");
103  }
104  if (m_hltBitWords.size() != m_hltPassRawBits.num_blocks() + m_hltPrescaledBits.num_blocks()) {
105  throw std::runtime_error("m_hltBitWords size differs from the sum of m_hltPassRawBits and m_hltPrescaledBits");
106  }
107  return m_hltBitWords;
108 }
109 
110 // -----------------------------------------------------------------------------
111 void HLT::HLTResultMT::setHltPassRawBits(const boost::dynamic_bitset<uint32_t>& bitset) {
112  // copy assignment
113  m_hltPassRawBits = bitset;
114  updateHltBitWords();
115 }
116 
117 // -----------------------------------------------------------------------------
118 void HLT::HLTResultMT::setHltPrescaledBits(const boost::dynamic_bitset<uint32_t>& bitset) {
119  // copy assignment
120  m_hltPrescaledBits = bitset;
121  updateHltBitWords();
122 }
123 
124 // -----------------------------------------------------------------------------
125 void HLT::HLTResultMT::setHltBits(const boost::dynamic_bitset<uint32_t>& passRawBitset,
126  const boost::dynamic_bitset<uint32_t>& prescaledBitset) {
127  if (passRawBitset.num_blocks() != prescaledBitset.num_blocks()) {
128  throw std::runtime_error("Must have the same number of bits in passRawBitset and prescaledBitset");
129  }
130  // copy assignments
131  m_hltPassRawBits = passRawBitset;
132  m_hltPrescaledBits = prescaledBitset;
133  updateHltBitWords();
134 }
135 
136 // -----------------------------------------------------------------------------
138  m_hltBitWords.clear();
139  m_hltBitWords.resize(m_hltPassRawBits.num_blocks() + m_hltPrescaledBits.num_blocks(), 0);
140  boost::to_block_range(m_hltPassRawBits, m_hltBitWords.begin());
141  boost::to_block_range(m_hltPrescaledBits, m_hltBitWords.begin() + m_hltPassRawBits.num_blocks());
142 }
143 
144 // =============================================================================
145 // Getter/setter methods for serialised data
146 // =============================================================================
147 const std::unordered_map<uint16_t, std::vector<uint32_t> >& HLT::HLTResultMT::getSerialisedData() const {
148  return m_data;
149 }
150 
151 // -----------------------------------------------------------------------------
152 StatusCode HLT::HLTResultMT::getSerialisedData(const uint16_t moduleId, const std::vector<uint32_t>*& data) const {
153  data = nullptr;
154  const auto it = m_data.find(moduleId);
155  if (it==m_data.cend()) {
156  REPORT_MESSAGE_WITH_CONTEXT(MSG::DEBUG, s_contextName.data())
157  << "No data available in the stored map for the requested moduleId=" << moduleId;
158  return StatusCode::FAILURE;
159  }
160  else {
161  data = &(it->second);
162  }
163  return StatusCode::SUCCESS;
164 }
165 
166 // -----------------------------------------------------------------------------
167 void HLT::HLTResultMT::setSerialisedData(std::unordered_map<uint16_t, std::vector<uint32_t> > data) {
168  // WARNING, copying data which may be large - recommend calling this with std::move if appropriate
169  m_data = std::move(data);
170 }
171 
172 // -----------------------------------------------------------------------------
173 void HLT::HLTResultMT::addSerialisedData(const uint16_t moduleId, const std::vector<uint32_t>& data) {
174  std::vector<uint32_t>& v = m_data[moduleId]; // creates new empty vector if the key doesn't exist
175  // WARNING, copying data which may be large
176  v.insert(v.end(),data.begin(),data.end());
177 }
178 
179 // -----------------------------------------------------------------------------
181  if (m_data.find(moduleId)!=m_data.cend()) {
182  ATH_REPORT_ERROR_WITH_CONTEXT(StatusCode::FAILURE, s_contextName.data())
183  << "Trying to add data for a module which already exists in the stored map, moduleId=" << moduleId;
184  return StatusCode::FAILURE;
185  }
186  else {
187  // moving data
188  m_data[moduleId] = std::move(data);
189  }
190  return StatusCode::SUCCESS;
191 }
192 
193 // =============================================================================
194 // Getter/setter methods for status words
195 // =============================================================================
196 const std::vector<uint32_t>& HLT::HLTResultMT::getStatus() const {
197  return m_status;
198 }
199 
200 // -----------------------------------------------------------------------------
201 const std::vector<HLT::OnlineErrorCode> HLT::HLTResultMT::getErrorCodes() const {
202  std::vector<HLT::OnlineErrorCode> errorCodes;
203  if (m_status.size()<2)
204  return errorCodes;
205  for (auto it=m_status.cbegin()+1; it!=m_status.cend(); ++it) {
206  errorCodes.push_back(static_cast<HLT::OnlineErrorCode>(*it));
207  }
208  return errorCodes;
209 }
210 
211 // -----------------------------------------------------------------------------
212 void HLT::HLTResultMT::setStatus(std::vector<uint32_t> status) {
213  // move assignment
214  m_status = std::move(status);
215 }
216 
217 // -----------------------------------------------------------------------------
219  const eformat::helper::Status& firstStatusWord) {
220  if (m_status.empty()) m_status.push_back(firstStatusWord.code());
221  else m_status[0] |= firstStatusWord.code();
222  m_status.push_back(static_cast<uint32_t>(errorCode));
223 }
224 
225 // -----------------------------------------------------------------------------
226 const std::vector<uint32_t>& HLT::HLTResultMT::getRobStatus(uint16_t moduleId) const {
227  const auto it = m_robStatus.find(moduleId);
228  if (it==m_robStatus.end()) {
229  static const std::vector<uint32_t> empty;
230  return empty;
231  }
232  else return it->second;
233 }
234 
235 
236 // =============================================================================
237 // Getter/setter methods for HLT ROD minor version
238 // =============================================================================
240  return m_version;
241 }
242 
243 // -----------------------------------------------------------------------------
245  m_version = version;
246 }
247 
248 // =============================================================================
249 // Getter/setter methods for truncation information
250 // =============================================================================
251 const std::set<uint16_t>& HLT::HLTResultMT::getTruncatedModuleIds() const {
252  return m_truncatedModuleIds;
253 }
254 
255 // -----------------------------------------------------------------------------
256 void HLT::HLTResultMT::addTruncatedModuleId(const uint16_t moduleId, bool severeTruncation) {
257  // decide if event should go to the debug stream
258  m_severeTruncation |= severeTruncation;
259 
260  auto [itr, inserted] = m_truncatedModuleIds.insert(moduleId);
261  // Also update ROB status words
262  if (inserted) {
263  // Note that the per-ROB status requires the specific status bits to be zero
264  // if a problem is detected by the HLT framework. This is different from the
265  // event status where we set PSC_PROBLEM.
266  // See eformat v5.0.2, section 5.8.2 (https://cds.cern.ch/record/683741)
267  eformat::helper::Status firstStatusWord(eformat::GenericStatus::DATA_CORRUPTION);
268  m_robStatus[moduleId] = {firstStatusWord.code(),
270  }
271 }
272 
273 // =============================================================================
274 std::ostream& operator<<(std::ostream& str, const HLT::HLTResultMT& hltResult) {
275  auto printWord = [&str](const uint32_t word, const size_t width=8){
276  str << "0x" << std::hex << std::setw(width) << std::setfill('0') << word << " " << std::dec;
277  };
278  str << "Printing HLTResultMT:" << std::endl;
279 
280  // Status
281  str << "--> Status words = ";
282  for (const uint32_t word : hltResult.getStatus()) {
283  printWord(word);
284  }
285  str << std::endl;
286 
287  // Stream tags
288  str << "--> Stream tags = ";
289  bool first = true;
290  for (const eformat::helper::StreamTag& st : hltResult.getStreamTags()) {
291  if (first) first=false;
292  else str << " ";
293  str << "{" << st.name << ", " << st.type << ", obeysLB=" << st.obeys_lumiblock << ", robs=[";
294  for (const auto& robid : st.robs) printWord(robid);
295  str << "], dets = [";
296  for (const auto& detid : st.dets) printWord(detid,2);
297  str << "]}" << std::endl;
298  }
299  if (hltResult.getStreamTags().empty()) str << std::endl;
300 
301  // HLT bits
302  std::vector<uint32_t> hltPassRawBitWords;
303  std::vector<uint32_t> hltPrescaledBitWords;
304  hltPassRawBitWords.resize(hltResult.getHltPassRawBits().num_blocks());
305  hltPrescaledBitWords.resize(hltResult.getHltPrescaledBits().num_blocks());
306  boost::to_block_range(hltResult.getHltPassRawBits(),hltPassRawBitWords.begin());
307  boost::to_block_range(hltResult.getHltPrescaledBits(),hltPrescaledBitWords.begin());
308  str << "--> HLT bits = ";
309  for (const uint32_t word : hltPassRawBitWords) {
310  printWord(word);
311  }
312  for (const uint32_t word : hltPrescaledBitWords) {
313  printWord(word);
314  }
315  str << std::endl;
316 
317  // Payload size
318  str << "--> Payload size = ";
319  first = true;
320  for (const auto& p : hltResult.getSerialisedData()) {
321  if (first) first=false;
322  else str << " ";
323  str << "{module " << p.first << ": " << p.second.size() << " words}" << std::endl;
324  }
325 
326  // Truncation information
327  if (!hltResult.getTruncatedModuleIds().empty()) {
328  str << "--> Truncated results = ";
329  first = true;
330  for (const uint16_t moduleId : hltResult.getTruncatedModuleIds()) {
331  if (first) first=false;
332  else str << ", ";
333  str << moduleId;
334  }
335  str << std::endl;
336  }
337 
338  return str;
339 }
HLT::HLTResultMT::setHltBits
void setHltBits(const boost::dynamic_bitset< uint32_t > &passRawBitset, const boost::dynamic_bitset< uint32_t > &prescaledBitset)
Replace both HLT pass raw and prescaled bits with the given bitsets.
Definition: HLTResultMT.cxx:125
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
HLT::HLTResultMT::getStreamTags
const std::vector< eformat::helper::StreamTag > & getStreamTags() const
Const-getter for stream tags.
Definition: HLTResultMT.cxx:43
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
AthCheckMacros.h
HLT::HLTResultMT::addSerialisedDataWithCheck
StatusCode addSerialisedDataWithCheck(const uint16_t moduleId, std::vector< uint32_t > data)
Add serialised data for a given moduleId.
Definition: HLTResultMT.cxx:180
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
m_data
std::vector< T > m_data
Definition: TrackTruthMatchingBaseAlg.cxx:660
skel.it
it
Definition: skel.GENtoEVGEN.py:423
HLT::HLTResultMT
A container class for data required to build online output from HLT.
Definition: HLTResultMT.h:38
empty
bool empty(TH1 *h)
Definition: computils.cxx:294
HLT::HLTResultMT::updateHltBitWords
void updateHltBitWords()
Update m_hltBitWords with the contents of m_hltPassRawBits and m_hltPrescaledBits.
Definition: HLTResultMT.cxx:137
HLT::operator<<
MsgStream & operator<<(MsgStream &m, const Navigation &nav)
Definition: Navigation.cxx:168
HLT::HLTResultMT::setSerialisedData
void setSerialisedData(std::unordered_map< uint16_t, std::vector< uint32_t > > data)
Replaces serialised data with a copy of the given data.
Definition: HLTResultMT.cxx:167
HLT::HLTResultMT::addStreamTag
StatusCode addStreamTag(const eformat::helper::StreamTag &streamTag)
Append one stream tag to the stored list.
Definition: HLTResultMT.cxx:62
HLT::HLTResultMT::getRobStatus
const std::vector< uint32_t > & getRobStatus(uint16_t moduleId) const
Status words for ROB with given moduleId.
Definition: HLTResultMT.cxx:226
HLT::HLTResultMT::getErrorCodes
const std::vector< HLT::OnlineErrorCode > getErrorCodes() const
Error codes getter (by value) - strips off the first bit-mask status word.
Definition: HLTResultMT.cxx:201
ATH_REPORT_ERROR_WITH_CONTEXT
#define ATH_REPORT_ERROR_WITH_CONTEXT
Report an error, with an explicitly specified context name.
Definition: AthCheckMacros.h:20
HLT::HLTResultMT::getTruncatedModuleIds
const std::set< uint16_t > & getTruncatedModuleIds() const
Getter for the truncation information.
Definition: HLTResultMT.cxx:251
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:88
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
HLT::HLTResultMT::addTruncatedModuleId
void addTruncatedModuleId(const uint16_t moduleId, bool severeTruncation=true)
Add module ID to the list of truncated results.
Definition: HLTResultMT.cxx:256
HLT::HLTResultMT::addSerialisedData
void addSerialisedData(const uint16_t moduleId, const std::vector< uint32_t > &data)
Append serialised data (copy of input) for a given moduleId, doesn't remove existing data.
Definition: HLTResultMT.cxx:173
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
HLT::HLTResultMT::getVersion
RODMinorVersion getVersion() const
ROD minor version getter.
Definition: HLTResultMT.cxx:239
HLT::HLTResultMT::setStreamTags
StatusCode setStreamTags(const std::vector< eformat::helper::StreamTag > &streamTags)
Replace the stored list of stream tags with the given one.
Definition: HLTResultMT.cxx:53
REPORT_MESSAGE_WITH_CONTEXT
#define REPORT_MESSAGE_WITH_CONTEXT(LVL, CONTEXT_NAME)
Report a message, with an explicitly specified context name.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:345
HLT::HLTResultMT::getSerialisedData
const std::unordered_map< uint16_t, std::vector< uint32_t > > & getSerialisedData() const
Serialised data getter.
Definition: HLTResultMT.cxx:147
HLT::HLTResultMT::getStreamTagsNonConst
std::vector< eformat::helper::StreamTag > & getStreamTagsNonConst()
Non-const-getter for stream tags needed by the result maker to remove disabled ROBs/SubDets.
Definition: HLTResultMT.cxx:48
HLT::HLTResultMT::setHltPrescaledBits
void setHltPrescaledBits(const boost::dynamic_bitset< uint32_t > &bitset)
Replace HLT prescaled bits with the given bitset.
Definition: HLTResultMT.cxx:118
python.PyAthena.v
v
Definition: PyAthena.py:157
get_generator_info.version
version
Definition: get_generator_info.py:33
HLT::OnlineErrorCode
OnlineErrorCode
Definition: OnlineErrorCode.h:15
HLT::HLTResultMT::RODMinorVersion
std::pair< uint8_t, uint8_t > RODMinorVersion
Type to store decoded ROD minor version (16-bit version split into two 8-bit numbers)
Definition: HLTResultMT.h:50
Athena::Status
Status
Athena specific StatusCode values.
Definition: AthStatusCode.h:22
Base_Fragment.width
width
Definition: Sherpa_i/share/common/Base_Fragment.py:59
HLTResultMT.h
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
DeMoScan.first
bool first
Definition: DeMoScan.py:534
HLT::HLTResultMT::setVersion
void setVersion(RODMinorVersion version)
ROD minor version setter.
Definition: HLTResultMT.cxx:244
DEBUG
#define DEBUG
Definition: page_access.h:11
HLT::HLTResultMT::setHltPassRawBits
void setHltPassRawBits(const boost::dynamic_bitset< uint32_t > &bitset)
Replace HLT pass raw bits with the given bitset.
Definition: HLTResultMT.cxx:111
HLT::HLTResultMT::addErrorCode
void addErrorCode(const HLT::OnlineErrorCode &errorCode, const eformat::helper::Status &firstStatusWord={ eformat::GenericStatus::DATA_CORRUPTION, eformat::FullEventStatus::PSC_PROBLEM })
Append an error code.
Definition: HLTResultMT.cxx:218
HLT::HLTResultMT::getStatus
const std::vector< uint32_t > & getStatus() const
Full event status reference getter (1 bit-mask status word + error code words)
Definition: HLTResultMT.cxx:196
HLT::HLTResultMT::getHltPrescaledBits
const boost::dynamic_bitset< uint32_t > & getHltPrescaledBits() const
Const-getter for HLT prescaled bits.
Definition: HLTResultMT.cxx:95
HLT::HLTResultMT::setStatus
void setStatus(std::vector< uint32_t > status)
Replace the full status words with the given data.
Definition: HLTResultMT.cxx:212
str
Definition: BTagTrackIpAccessor.cxx:11
HLT::OnlineErrorCode::RESULT_TRUNCATION
@ RESULT_TRUNCATION
merge.status
status
Definition: merge.py:17
HLT::HLTResultMT::getHltBitsAsWords
const std::vector< uint32_t > & getHltBitsAsWords() const
Const-getter for HLT bits as uint32_t array. Ordering: PassRaw, Prescaled.
Definition: HLTResultMT.cxx:100
HLT::HLTResultMT::HLTResultMT
HLTResultMT(std::vector< eformat::helper::StreamTag > streamTags={}, boost::dynamic_bitset< uint32_t > hltPassRawBits=boost::dynamic_bitset< uint32_t >(), boost::dynamic_bitset< uint32_t > hltPrescaledBits=boost::dynamic_bitset< uint32_t >(), std::unordered_map< uint16_t, std::vector< uint32_t > > data={})
Standard constructor.
Definition: HLTResultMT.cxx:30
HLT::HLTResultMT::getHltPassRawBits
const boost::dynamic_bitset< uint32_t > & getHltPassRawBits() const
Const-getter for HLT pass raw bits.
Definition: HLTResultMT.cxx:90