21#include <boost/algorithm/string/trim.hpp>
27 ISvcLocator* pSvcLocator)
39 return StatusCode::FAILURE;
45 return StatusCode::SUCCESS;
52 return StatusCode::FAILURE;
60 auto expectations = std::make_unique<PU1SuppExpectations>(
"0000",
"0000");
66 return StatusCode::SUCCESS;
76 return StatusCode::FAILURE;
80 return StatusCode::FAILURE;
83 std::string tobLine, rhoLine;
86 while (std::getline(tobFile, tobLine) && std::getline(rhoFile, rhoLine)) {
89 std::string tobStr =
trim(tobLine);
90 std::string rhoStr =
trim(rhoLine);
92 const bool isHex = (tobStr.length() == 64 &&
93 std::all_of(tobStr.begin(), tobStr.end(), ::isxdigit));
96 (tobStr.length() == 256 &&
97 std::all_of(tobStr.begin(), tobStr.end(),
98 [](
char c) { return c ==
'0' || c ==
'1'; }));
100 if (!isHex && !isBinary) {
103 <<
": expected 64 length hex or 256 length bit");
107 auto fifo = std::make_unique<GepAlgoPU1SuppFIFO>();
110 const int chunkSize = isHex ? 16 : 64;
111 std::string_view tobView = tobStr;
112 bool parseError =
false;
114 for (
int i=0; i < 4; ++i) {
115 auto tobWord = tobView.substr(i * chunkSize, chunkSize);
117 auto [ptr, ec] = std::from_chars(
119 tobWord.data() + tobWord.size(),
123 if (ec != std::errc{}) {
125 <<
": failed to parse section " << i);
132 if (parseError)
continue;
134 ports_in.
m_rho =
static_cast<uint16_t
>(std::stoul(rhoStr,
nullptr, 2));
136 fifo->push_back(ports_in);
137 m_fifos.push_back(std::move(fifo));
140 return StatusCode::SUCCESS;
145 std::string result = s;
146 boost::algorithm::trim(result);
#define ATH_MSG_WARNING(x)
#define CHECK(...)
Evaluate an expression and check for errors.
Declares the PU1SuppTestBenchAlg, an Athena algorithm for testing PU1 suppression logic.
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
StatusCode init_from_file()
Populate m_fifos from file.
std::vector< std::unique_ptr< GepAlgoPU1SuppFIFO > > m_fifos
Preloaded list of TOB FIFOs from file.
PU1SuppTestBenchAlg(const std::string &name, ISvcLocator *pSvcLocator)
Constructor.
virtual StatusCode execute() override
Athena execute hook (called once per event).
SG::WriteHandleKey< GepAlgoPU1SuppFIFO > m_suppFIFO_WriteKey
Write handle key for TOB FIFO.
Gaudi::Property< std::string > m_testsFileName
Path to input file containing 256-bit TOBs as 64-character hex strings.
SG::WriteHandleKey< PU1SuppExpectations > m_PU1SuppExpectations_WriteKey
Write handle key for dummy expectations.
std::size_t m_fifo_ptr
Index of next FIFO to write during execution.
Gaudi::Property< std::string > m_rhoFileName
Path to input file containing rho values, one per line.
std::string trim(const std::string &s)
Strip whitespace from both ends of a string.
virtual StatusCode initialize() override
Athena initialize hook.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
AlgTool to read in LArStripNeighborhoods, and run the eRatio Algorithm.
Data structure representing a single PU1 suppression input.
uint16_t m_rho
Rho value as a 16-bit initialized unsigned integer.
std::array< uint64_t, 4 > m_I_PU1TobData
256-bit TOB stored as four 64-bit unsigned integers