ATLAS Offline Software
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 
5 #include <fstream> // For Csv.
6 
8 
10  const std::string& name,
11  ISvcLocator* pSvcLocator
12 ) : AthReentrantAlgorithm(name, pSvcLocator)
13 {}
14 
16  ATH_MSG_INFO("Initializing " << name());
18 
19  return StatusCode::SUCCESS;
20 }
21 
25  ctx
26  );
27 
28  ATH_CHECK(inputDataStream.record(std::make_unique<std::vector<unsigned long>>()));
29  inputDataStream->reserve(m_bufferSize);
30 
31  std::ifstream inputFile(m_inputCsvPath);
32 
33  if (!inputFile.is_open()) {
34  ATH_MSG_ERROR("Failed to read " << m_inputCsvPath);
35 
36  return StatusCode::FAILURE;
37  }
38 
39  while (!inputFile.eof()) {
40  if (inputDataStream->size() >= m_bufferSize) {
41  ATH_MSG_ERROR("Input csv is too large, " <<
43  ", consider increasing buffer size");
44 
45  return StatusCode::FAILURE;
46  }
47 
48  const auto word = [&inputFile]->std::optional<unsigned long> {
49  std::string word{};
50  std::getline(inputFile, word);
51 
52  // (8 ascii character) x (2 char per ascii character)
53  if (word.size() != 16) {
54  return std::nullopt;
55  }
56 
57  return {std::stoul(word.c_str(), nullptr, 16)};
58  }();
59 
60  if (word == std::nullopt) {
61  ATH_MSG_ERROR("Failed to read " <<
62  m_inputCsvPath <<
63  ", check for trailing characters");
64 
65  return StatusCode::FAILURE;
66  }
67 
68  inputDataStream->push_back(*word);
69  }
70 
71  return StatusCode::SUCCESS;
72 }
73 
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:13
EFTrackingDataStreamLoaderAlgorithm::EFTrackingDataStreamLoaderAlgorithm
EFTrackingDataStreamLoaderAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Definition: EFTrackingDataStreamLoaderAlgorithm.cxx:9
AthReentrantAlgorithm
An algorithm that can be simultaneously executed in multiple threads.
Definition: AthReentrantAlgorithm.h:83
EFTrackingDataStreamLoaderAlgorithm::execute
StatusCode execute(const EventContext &ctx) const override final
Definition: EFTrackingDataStreamLoaderAlgorithm.cxx:22
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
CaloCondBlobAlgs_fillNoiseFromASCII.inputFile
string inputFile
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:17
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
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
EFTrackingDataStreamLoaderAlgorithm::initialize
StatusCode initialize() override final
Definition: EFTrackingDataStreamLoaderAlgorithm.cxx:15
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
EFTrackingXrtAlgorithmConfig.inputDataStream
inputDataStream
Definition: EFTrackingXrtAlgorithmConfig.py:55
EFTrackingDataStreamLoaderAlgorithm::m_bufferSize
Gaudi::Property< std::size_t > m_bufferSize
Definition: EFTrackingDataStreamLoaderAlgorithm.h:27
EFTrackingDataStreamLoaderAlgorithm::m_inputDataStreamKey
SG::WriteHandleKey< std::vector< unsigned long > > m_inputDataStreamKey
Definition: EFTrackingDataStreamLoaderAlgorithm.h:20