Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
EFTrackingDataStreamLoaderAlgorithm.cxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3  */
4 
6 
7 #include <optional>
8 #include <vector>
9 
11 
12 namespace {
13 StatusCode getNthEvent(
14  const int eventNumber,
15  const std::vector<unsigned long>& testVector,
16  std::vector<unsigned long>& eventTestVector
17 ) {
18  int eventCounter = 0;
19  std::size_t eventLength = 0;
20  std::size_t wordIndex = 0;
21 
22  while (true) {
23  if (eventCounter >= eventNumber) {
24  break;
25  }
26 
27  if (wordIndex >= testVector.size()) {
28  return StatusCode::FAILURE;
29  }
30 
31  const unsigned long flag = testVector[wordIndex] >> 56;
32 
33  if (flag == 0xCD) {
34  FPGADataFormatUtilities::EVT_FTR_w3 eventFooterWord3 =
35  FPGADataFormatUtilities::get_bitfields_EVT_FTR_w3(testVector[wordIndex + 2]);
36 
37  // The word_count is sometimes reported incorrectly as the total length,
38  // including prior events. This will be fixed but for now don't treat this
39  // as an error. It's still a valid cross check to avoid fake event
40  // footers.
41  if ((eventFooterWord3.word_count == eventLength) ||
42  (eventFooterWord3.word_count == wordIndex)) {
43  eventCounter++;
44  eventLength = 0;
45  wordIndex += 3;
46 
47  continue;
48  }
49  }
50 
51  eventLength++;
52  wordIndex++;
53  }
54 
55  while (true) {
56  if (wordIndex >= testVector.size()) {
57  return StatusCode::FAILURE;
58  }
59 
60  const unsigned long flag = testVector[wordIndex] >> 56;
61 
62  if (flag == 0xCD) {
63  FPGADataFormatUtilities::EVT_FTR_w3 eventFooterWord3 =
64  FPGADataFormatUtilities::get_bitfields_EVT_FTR_w3(testVector[wordIndex + 2]);
65 
66  // The word_count is sometimes reported incorrectly as the total length,
67  // including prior events. This will be fixed but for now don't treat this
68  // as an error. It's still a valid cross check to avoid fake event
69  // footers.
70  if ((eventFooterWord3.word_count == eventLength) ||
71  (eventFooterWord3.word_count == wordIndex)) {
72  eventTestVector.push_back(testVector[wordIndex]);
73  eventTestVector.push_back(testVector[wordIndex + 1]);
74  eventTestVector.push_back(testVector[wordIndex + 2]);
75 
76  break;
77  }
78  }
79 
80  eventTestVector.push_back(testVector[wordIndex]);
81  eventLength++;
82  wordIndex++;
83  }
84 
85  return StatusCode::SUCCESS;
86 }
87 };
88 
90  const std::string& name,
91  ISvcLocator* pSvcLocator
92 ) : AthReentrantAlgorithm(name, pSvcLocator)
93 {}
94 
96  ATH_MSG_INFO("Initializing " << name());
98 
99  return StatusCode::SUCCESS;
100 }
101 
105  ctx
106  );
107 
108  ATH_CHECK(inputDataStream.record(std::make_unique<std::vector<unsigned long>>()));
109  inputDataStream->reserve(m_bufferSize);
110 
111  std::vector<unsigned long> testVector{};
112  ATH_CHECK(m_testVectorTool->prepareTV(m_inputCsvPath, testVector));
113 
114  if (testVector.size() > m_bufferSize) {
115  ATH_MSG_ERROR("Test vector larger than buffer size.");
116 
117  return StatusCode::FAILURE;
118  }
119 
120  {
121  std::lock_guard<std::mutex> lock{m_mutex};
122  ATH_CHECK(getNthEvent(m_eventNumber, testVector, *inputDataStream));
123 
124  m_eventNumber++;
125  }
126 
127  return StatusCode::SUCCESS;
128 }
129 
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
make_unique
std::unique_ptr< T > make_unique(Args &&... args)
Definition: SkimmingToolEXOT5.cxx:23
EFTrackingDataStreamLoaderAlgorithm.h
EFTrackingDataStreamLoaderAlgorithm::m_inputCsvPath
Gaudi::Property< std::string > m_inputCsvPath
Definition: EFTrackingDataStreamLoaderAlgorithm.h:16
EFTrackingDataStreamLoaderAlgorithm::EFTrackingDataStreamLoaderAlgorithm
EFTrackingDataStreamLoaderAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Definition: EFTrackingDataStreamLoaderAlgorithm.cxx:89
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:74
EFTrackingDataStreamLoaderAlgorithm::m_testVectorTool
ToolHandle< TestVectorTool > m_testVectorTool
Definition: EFTrackingDataStreamLoaderAlgorithm.h:37
EFTrackingDataStreamLoaderAlgorithm::execute
StatusCode execute(const EventContext &ctx) const override final
Definition: EFTrackingDataStreamLoaderAlgorithm.cxx:102
FPGADataFormatUtilities::EVT_FTR_w3::word_count
uint64_t word_count
Definition: FPGADataFormatUtilities.h:216
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
master.flag
bool flag
Definition: master.py:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
xAOD::eventNumber
eventNumber
Definition: EventInfo_v1.cxx:124
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
FPGADataFormatUtilities.h
FPGADataFormatUtilities::get_bitfields_EVT_FTR_w3
EVT_FTR_w3 get_bitfields_EVT_FTR_w3(const uint64_t &in)
Definition: FPGADataFormatUtilities.h:234
EFTrackingDataStreamLoaderAlgorithm::initialize
StatusCode initialize() override final
Definition: EFTrackingDataStreamLoaderAlgorithm.cxx:95
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
FPGADataFormatUtilities::EVT_FTR_w3
Definition: FPGADataFormatUtilities.h:215
EFTrackingXrtAlgorithmConfig.inputDataStream
inputDataStream
Definition: EFTrackingXrtAlgorithmConfig.py:75
EFTrackingDataStreamLoaderAlgorithm::m_bufferSize
Gaudi::Property< std::size_t > m_bufferSize
Definition: EFTrackingDataStreamLoaderAlgorithm.h:30
EFTrackingDataStreamLoaderAlgorithm::m_inputDataStreamKey
SG::WriteHandleKey< std::vector< unsigned long > > m_inputDataStreamKey
Definition: EFTrackingDataStreamLoaderAlgorithm.h:23