ATLAS Offline Software
HLTResultMTByteStreamDecoderTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Trigger includes
7 
8 // TDAQ includes
9 #include "eformat/StreamTag.h"
10 
12 
13 namespace{
14  // Convert RODMinorVersion to string
15  std::string printRodMinorVersion(const RODMinorVersion v) {
16  return std::to_string(v.first) + "." + std::to_string(v.second);
17  }
18 }
19 
20 // =============================================================================
21 // Standard constructor
22 // =============================================================================
24  const std::string& name,
25  const IInterface* parent)
27 
28 // =============================================================================
29 // Implementation of AthAlgTool::initialize
30 // =============================================================================
32  ATH_MSG_DEBUG("Initialising " << name());
33  return StatusCode::SUCCESS;
34 }
35 
36 // =============================================================================
37 // Implementation of AthAlgTool::finalize
38 // =============================================================================
40  ATH_MSG_DEBUG("Finalising " << name());
41  return StatusCode::SUCCESS;
42 }
43 
44 // =============================================================================
46  const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& vrobf) const {
47 
48  if (vrobf.empty()) {
49  ATH_MSG_ERROR("Empty ROBFragment vector passed to getHltRodMinorVersion, returning invalid version");
50  return {0xff, 0xff};
51  }
52 
53  uint16_t version{0xffff};
54  bool first{true};
55  for (const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment* robf : vrobf) {
56  uint32_t thisRodVersion = robf->rod_version();
57  uint16_t thisRodMinorVersion = (thisRodVersion & 0xffffu);
58  if (thisRodMinorVersion == 0xffffu) {
59  ATH_MSG_WARNING("Invalid HLT ROD minor version 0xffff found in ROBFragment 0x"
60  << MSG::hex << robf->rob_source_id() << MSG::dec);
61  }
62  if (first) {
63  version = thisRodMinorVersion;
64  }
65  else if (thisRodMinorVersion != version) {
66  ATH_MSG_ERROR("Inconsistent HLT ROD minor versions in different ROBFragments, 0x"
67  << MSG::hex << version << " and " << thisRodMinorVersion << MSG::dec
68  << ", getHltRodMinorVersion returning invalid version");
69  return {0xff, 0xff};
70  }
71  first = false;
72  }
73  // Split the version 0xabcd into {0xab, 0xcd}
74  return {((version & 0xff00u) >> 8u), (version & 0x00ffu)};
75 }
76 
77 // =============================================================================
79 
80  if (!rawEvent) {
81  ATH_MSG_ERROR("Decoding requested with nullptr RawEvent");
82  return StatusCode::FAILURE;
83  }
84  ATH_MSG_DEBUG("Decoding HLTResultMT from ByteStream event " << rawEvent->global_id());
85 
86  const RODMinorVersion hltRodMinorVersion = resultToFill.getVersion();
87  ATH_CHECK(checkRodMinorVersion(hltRodMinorVersion));
88 
89  // ---------------------------------------------------------------------------
90  // Read the status words (error codes from online event processing)
91  // ---------------------------------------------------------------------------
92  std::vector<uint32_t> statusWords;
93  // try-catch around eformat calls and raw-pointer operations
94  try {
95  const uint32_t nStatus = rawEvent->nstatus();
96  const uint32_t* rawStatus = rawEvent->status(); // owned by rawEvent
97  //Copy range of data into vector using efficient memmove/memcopy
98  statusWords.assign(rawStatus, rawStatus+nStatus);
99  }
100  catch (const std::exception& ex) {
101  ATH_MSG_ERROR("std::exception caught when reading status words: " << ex.what());
102  return StatusCode::FAILURE;
103  }
104  catch (...) {
105  ATH_MSG_ERROR("Unknown exception caught when reading status words");
106  return StatusCode::FAILURE;
107  }
108  ATH_MSG_DEBUG("Successfully read " << statusWords.size() << " status words");
109  resultToFill.setStatus(std::move(statusWords)); //statusWords is moved so it now empty
110 
111  // ---------------------------------------------------------------------------
112  // Read the stream tags
113  // ---------------------------------------------------------------------------
114  std::vector<eformat::helper::StreamTag> streamTags;
115  // try-catch around eformat calls and raw-pointer operations
116  try {
117  eformat::helper::decode(rawEvent->nstream_tag(),rawEvent->stream_tag(),streamTags);
118  }
119  catch (const std::exception& ex) {
120  ATH_MSG_ERROR("std::exception caught when reading stream tags: " << ex.what());
121  return StatusCode::FAILURE;
122  }
123  catch (...) {
124  ATH_MSG_ERROR("Unknown exception caught when reading stream tags");
125  return StatusCode::FAILURE;
126  }
127  ATH_MSG_DEBUG("Successfully read " << streamTags.size() << " stream tags");
128  ATH_CHECK(resultToFill.setStreamTags(streamTags));
129 
130 
131  // ---------------------------------------------------------------------------
132  // Read the HLT bits
133  // ---------------------------------------------------------------------------
134  std::vector<uint32_t> hltBitWords;
135  // try-catch around eformat calls and raw-pointer operations
136  try {
137  const uint32_t nHltInfo = rawEvent->nhlt_info();
138  const uint32_t* hltInfo = rawEvent->hlt_info(); // owned by rawEvent
139  //Copy range of data into vector using efficient memmove/memcopy
140  hltBitWords.assign(hltInfo, hltInfo+nHltInfo);
141  }
142  catch (const std::exception& ex) {
143  ATH_MSG_ERROR("std::exception caught when reading HLT bits: " << ex.what());
144  return StatusCode::FAILURE;
145  }
146  catch (...) {
147  ATH_MSG_ERROR("Unknown exception caught when reading HLT bits");
148  return StatusCode::FAILURE;
149  }
150 
151  // Version 1.0 includes rerun bits, removed since version 1.1
152  const size_t numBitSets = (hltRodMinorVersion==RODMinorVersion{1,0}) ? 3 : 2;
153 
154  if (hltBitWords.size() % numBitSets != 0) {
155  ATH_MSG_ERROR("Size of hltBitWords=" << hltBitWords.size() << " must be divisible by " << numBitSets
156  << ". Expecting {raw, prescaled" << (numBitSets==3 ? ", rerun" : "") << "} bits.");
157  return StatusCode::FAILURE;
158  }
159  const size_t sizeOfBlock = hltBitWords.size() / numBitSets;
160  auto beginPrescaledIt = hltBitWords.cbegin() + sizeOfBlock;
161  auto endIt = (numBitSets==2) ? hltBitWords.cend() : hltBitWords.cbegin() + 2*sizeOfBlock;
162  resultToFill.setHltBits( {hltBitWords.cbegin(), beginPrescaledIt},
163  {beginPrescaledIt, endIt} );
164  ATH_MSG_DEBUG("Successfully read " << std::distance(hltBitWords.cbegin(), endIt) << " HLT bit words");
165  return StatusCode::SUCCESS;
166 }
167 
168 // =============================================================================
169 StatusCode HLTResultMTByteStreamDecoderTool::decodePayload(const std::vector<const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment*>& vrobf,
170  HLT::HLTResultMT& resultToFill) const {
171  const RODMinorVersion hltRodMinorVersion = resultToFill.getVersion();
172  ATH_CHECK(checkRodMinorVersion(hltRodMinorVersion));
173 
174  for (const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment* robf : vrobf) {
175  eformat::helper::SourceIdentifier sid(robf->rob_source_id());
176  ATH_MSG_DEBUG("Reading ROBFragment " << sid.human());
177 
178  // ---------------------------------------------------------------------------
179  // Read the ROB status words (error codes from online event processing)
180  // ---------------------------------------------------------------------------
181  if (robf->nstatus() > 1) {
182  eformat::helper::Status firstStatusWord(*robf->status());
183  if (firstStatusWord.generic() == eformat::GenericStatus::DATA_CORRUPTION &&
184  *(robf->status()+1) == static_cast<uint32_t>(HLT::OnlineErrorCode::RESULT_TRUNCATION)) {
185  ATH_MSG_DEBUG("Detected truncated ROBFragment " << sid.human());
186  resultToFill.addTruncatedModuleId(sid.module_id());
187  }
188  }
189 
190  // ---------------------------------------------------------------------------
191  // Read the payload
192  // ---------------------------------------------------------------------------
193  std::vector<uint32_t> data;
194  // try-catch around eformat calls and raw-pointer operations
195  try {
196  const uint32_t nRodData = robf->rod_ndata();
197  const uint32_t* rodData = robf->rod_data(); // owned by robf
198  //Copy range of data into vector using efficient memmove
199  data.assign(rodData, rodData+nRodData);
200  }
201  catch (const std::exception& ex) {
202  ATH_MSG_ERROR("std::exception caught when reading HLT result payload: " << ex.what());
203  return StatusCode::FAILURE;
204  }
205  catch (...) {
206  ATH_MSG_ERROR("Unknown exception caught when reading HLT result payload");
207  return StatusCode::FAILURE;
208  }
209  size_t datasize = data.size(); //I need to ask size before moving the vector
210  ATH_CHECK( resultToFill.addSerialisedDataWithCheck(sid.module_id(), std::move(data)) );
211  //Moved "data" so it is now empty vector
212  ATH_MSG_DEBUG("Successfully read " << datasize << " words of HLT result payload for module ID "
213  << sid.module_id());
214  }
215  return StatusCode::SUCCESS;
216 }
217 
218 // =============================================================================
220  if (version == RODMinorVersion{0xff, 0xff}) {
221  ATH_MSG_ERROR("Invalid HLT ROD minor version {0xff, 0xff}");
222  return StatusCode::FAILURE;
223  }
224  if (version.first < 1) {
225  ATH_MSG_ERROR("HLT ROD minor version " << printRodMinorVersion(version) << " is lower than 1.0. "
226  << "This tool is for decoding versions 1.0 or later (i.e. HLT ByteStream from Run 3 or later)");
227  return StatusCode::FAILURE;
228  }
229  ATH_MSG_DEBUG("HLT ROD minor version is " << printRodMinorVersion(version));
230  return StatusCode::SUCCESS;
231 }
AtlasMcWeight::decode
double decode(number_type binnedWeight)
Convert weight from unsigned to double.
Definition: AtlasMcWeight.cxx:32
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::addSerialisedDataWithCheck
StatusCode addSerialisedDataWithCheck(const uint16_t moduleId, std::vector< uint32_t > data)
Add serialised data for a given moduleId.
Definition: HLTResultMT.cxx:180
HLTResultMTByteStreamDecoderTool::decodeHeader
StatusCode decodeHeader(const RawEvent *rawEvent, HLT::HLTResultMT &resultToFill) const
Fills the HLTResultMT object from the ByteStream event header.
Definition: HLTResultMTByteStreamDecoderTool.cxx:78
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
RawEvent
OFFLINE_FRAGMENTS_NAMESPACE::FullEventFragment RawEvent
data type for reading raw event
Definition: RawEvent.h:37
RODMinorVersion
HLT::HLTResultMT::RODMinorVersion RODMinorVersion
Definition: HLTResultMTByteStreamDecoderTool.cxx:11
HLT::HLTResultMT
A container class for data required to build online output from HLT.
Definition: HLTResultMT.h:38
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
HLTResultMTByteStreamDecoderTool::HLTResultMTByteStreamDecoderTool
HLTResultMTByteStreamDecoderTool(const std::string &type, const std::string &name, const IInterface *parent)
Standard constructor.
Definition: HLTResultMTByteStreamDecoderTool.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:93
HLTResultMTByteStreamDecoderTool::finalize
virtual StatusCode finalize() override
Definition: HLTResultMTByteStreamDecoderTool.cxx:39
HLTResultMTByteStreamDecoderTool.h
eformat::ROBFragment
Definition: L1CaloBsDecoderUtil.h:12
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
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
HLTResultMTByteStreamDecoderTool::decodePayload
StatusCode decodePayload(const std::vector< const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment * > &vrobf, HLT::HLTResultMT &resultToFill) const
Fills the HLTResultMT object from vector of ROBFragments.
Definition: HLTResultMTByteStreamDecoderTool.cxx:169
calibdata.exception
exception
Definition: calibdata.py:496
test_pyathena.parent
parent
Definition: test_pyathena.py:15
HLTResultMTByteStreamDecoderTool::checkRodMinorVersion
StatusCode checkRodMinorVersion(const HLT::HLTResultMT::RODMinorVersion version) const
Definition: HLTResultMTByteStreamDecoderTool.cxx:219
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
HLTResultMTByteStreamDecoderTool::getHltRodMinorVersion
HLT::HLTResultMT::RODMinorVersion getHltRodMinorVersion(const std::vector< const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment * > &vrobf) const
Retrieves the HLT ROD minor version from vector of ROBFragments, checking it is the same in all of th...
Definition: HLTResultMTByteStreamDecoderTool.cxx:45
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
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
python.PyAthena.v
v
Definition: PyAthena.py:154
get_generator_info.version
version
Definition: get_generator_info.py:33
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
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
HLTResultMTByteStreamDecoderTool::initialize
virtual StatusCode initialize() override
Definition: HLTResultMTByteStreamDecoderTool.cxx:31
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
DeMoScan.first
bool first
Definition: DeMoScan.py:536
HLT::HLTResultMT::setStatus
void setStatus(std::vector< uint32_t > status)
Replace the full status words with the given data.
Definition: HLTResultMT.cxx:212
HLT::OnlineErrorCode::RESULT_TRUNCATION
@ RESULT_TRUNCATION
AthAlgTool
Definition: AthAlgTool.h:26
Amg::distance
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
Definition: GeoPrimitivesHelpers.h:54