Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
HypoTestBenchAlg.cxx
Go to the documentation of this file.
1 // Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
2 
3 #include "HypoTestBenchAlg.h"
4 #include "AlgoConstants.h"
5 
6 #include <fstream>
7 
8 namespace GlobalSim {
9 
12  std::bitset<72>& bit_tob) const{
13 
14  auto bs = std::bitset<4>();
15 
16  std::size_t ind{s.size()*4};
17 
18  // ensure s is lower case
19  std::transform(s.begin(), s.end(), s.begin(),
20  [](unsigned char c){return std::tolower(c);});
21 
22  for(const char& c : s) {
23  bs = (c >= 'a') ? (c - 'a' + 10) : (c-'0');
24  for (int j = 3; j != -1; --j) {
25  bit_tob[--ind] = bs[j];
26  }
27  if (ind == 0) {break;}
28  }
29 
30  return StatusCode::SUCCESS;
31  }
32 
34  ISvcLocator *pSvcLocator):
35  AthAlgorithm(name, pSvcLocator) {
36  }
37 
39  ATH_MSG_DEBUG("initialising");
42 
43  // initialisation is either from a file of test vectors
44  // or by filling in values by hand in this Algorithm
45 
46  if (m_testsFileName.empty()){
47  ATH_MSG_INFO("Initialisation is manual");
48  CHECK(init_manual());
49  } else {
50  ATH_MSG_INFO("Initialisation is from file " << m_testsFileName);
52  }
53 
54  ATH_MSG_INFO("Number of fifos " << m_fifos.size());
55  for(const auto& fifo : m_fifos) {
56  ATH_MSG_INFO("Fifo size " <<
57  fifo->size());
58  }
59 
60  return StatusCode::SUCCESS;
61  }
62 
63 
65  ATH_MSG_DEBUG("executing");
66 
67  // Write out a FIFO, one per event. Running more events
68  // than FIFOs is an error.
69 
70  if (m_fifo_ptr == m_fifos.size()) {
71  ATH_MSG_ERROR("Attempting to read from an exhausted FIFO vector");
72  return StatusCode::FAILURE;
73  }
74 
75  auto h_write =
77 
78  CHECK(h_write.record(std::move(m_fifos[m_fifo_ptr])));
79 
80  auto expectations = std::make_unique<eEmSortSelectCountExpectations>(
83 
84  auto h_write_exp =
86 
87  CHECK(h_write_exp.record(std::move(expectations)));
88 
89  ++m_fifo_ptr;
90 
91  return StatusCode::SUCCESS;
92  }
93 
96 
97 
98  // build a single GepAlgoHypothesisFIFO that contains
99  // GepAlgoHypothesisPortsIn objects. The PortsIn objects contain
100  // data only for eEmTobs.
101 
102  if (m_testRepeat < 1) {
103  ATH_MSG_ERROR("Invalid repeat of input data requested: " << m_testRepeat);
104  return StatusCode::FAILURE;
105  }
106 
107  for(int i = 0; i != m_testRepeat; ++i) {
109  std::cbegin(m_testVecs_in),
110  std::cend(m_testVecs_in));
111  }
112 
113  auto fifo = std::make_unique<GepAlgoHypothesisFIFO>();
114  for (const auto& tv : m_testVecs) {
115  auto ports_in = GepAlgoHypothesisPortsIn();
116  CHECK(hexTOB2bitsetTOB(tv, *(ports_in.m_I_eEmTobs)));
117  fifo->push_back(ports_in);
118  }
119  m_fifos.push_back(std::move(fifo));
120 
121  m_expected_mults.push_back(m_expMults_in);
122  m_expected_tobs.push_back(m_expTobs_in);
123 
124  return StatusCode::SUCCESS;
125  }
126 
127 
128 
129  std::string trim(std::string s){
130  const char* t = " \t\n\r\f\v";
131 
132  // trim from right
133  auto l_rtrim = [&t](std::string& s){
134  s.erase(s.find_last_not_of(t) + 1);
135  return s;
136  };
137 
138  // trim from left
139  auto l_ltrim = [&t] (std::string& s){
140  s.erase(0, s.find_first_not_of(t));
141  return s;
142  };
143 
144  auto rs = l_rtrim(s);
145  return l_ltrim(rs);
146  }
147 
148  StatusCode
153 
154  if (m_fifos.empty()) {
155  ATH_MSG_ERROR("no fifo data read in");
156  return StatusCode::FAILURE;
157  }
158 
159 
160  if (m_fifos.size() != m_expected_mults.size()) {
161  ATH_MSG_ERROR("no fifo data objs read in "
162  << m_fifos.size()
163  << " != no of expected mults "
164  << m_expected_mults.size());
165  return StatusCode::FAILURE;
166  }
167 
168 
169  if (m_fifos.size() != m_expected_mults.size()) {
170  ATH_MSG_ERROR("no fifo data objs read in "
171  << m_fifos.size()
172  << " != no of expected tobs "
173  << m_expected_tobs.size());
174 
175  return StatusCode::FAILURE;
176  }
177 
178 
179  return StatusCode::SUCCESS;
180  }
181 
182  StatusCode
184 
185 
186  std::ifstream tob_stream(m_testsFileName);
187  if(!tob_stream) {
188  std::stringstream ss;
189  ATH_MSG_FATAL("Failure to open tob file " << m_testsFileName);
190  return StatusCode::FAILURE;
191  }
192 
193  auto padded_line = std::string();
194  auto fifo = std::make_unique<GepAlgoHypothesisFIFO>();
195 
196  while (std::getline(tob_stream, padded_line)) {
197  auto line = trim(padded_line);
198  // filter out entries with only '0' entries.nThis are used
199  // in VHDL to handle special conditions
200  if (std::all_of(std::cbegin(line),
201  std::cend(line),
202  [](const auto& c) {return c == '0';})){
203  continue;
204  }
205 
206  auto ports_in = GepAlgoHypothesisPortsIn();
207  CHECK(hexTOB2bitsetTOB(line, *(ports_in.m_I_eEmTobs)));
208 
209 
210  fifo->push_back(ports_in);
211 
212  // the end of the fifo data is signaled by having the top bit
213  // set on an input tob
214 
215  auto top_ind = (ports_in.m_I_eEmTobs)->size()-1;
216  if ((ports_in.m_I_eEmTobs)->test(top_ind)) {
217  m_fifos.push_back(std::move(fifo));
218  fifo = std::make_unique<GepAlgoHypothesisFIFO>();
219  }
220 
221  }
222 
223  return StatusCode::SUCCESS;
224  }
225 
226 
227  StatusCode
229 
232  return StatusCode::SUCCESS;
233  }
234 
235  StatusCode
237 
240  return StatusCode::SUCCESS;
241  }
242 
243 
244  StatusCode
246  const std::string& fn) {
247 
248 
249  std::ifstream in_stream(fn);
250  if(!in_stream) {
251  std::stringstream ss;
252  ATH_MSG_FATAL("Failure to open expected file " << fn);
253  return StatusCode::FAILURE;
254  }
255 
256  auto padded_line = std::string();
257 
258  while (std::getline(in_stream, padded_line)) {
259  auto line = trim(padded_line);
260  dest.push_back(line);
261  }
262 
263  return StatusCode::SUCCESS;
264  }
265 
266 
267 }
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
checkFileSG.line
line
Definition: checkFileSG.py:75
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
GlobalSim::HypoTestBenchAlg::init_expected_mults_from_file
StatusCode init_expected_mults_from_file()
Definition: HypoTestBenchAlg.cxx:228
GlobalSim::HypoTestBenchAlg::HypoTestBenchAlg
HypoTestBenchAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: HypoTestBenchAlg.cxx:33
python.ext.silence.fifo
def fifo()
Definition: silence.py:37
GlobalSim::HypoTestBenchAlg::m_expectedMults_FileName
Gaudi::Property< std::string > m_expectedMults_FileName
Definition: HypoTestBenchAlg.h:63
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
GlobalSim::HypoTestBenchAlg::init_expected_from_file
StatusCode init_expected_from_file(std::vector< std::string > &, const std::string &)
Definition: HypoTestBenchAlg.cxx:245
GlobalSim::HypoTestBenchAlg::m_testVecs_in
Gaudi::Property< std::vector< std::string > > m_testVecs_in
Definition: HypoTestBenchAlg.h:69
GlobalSim::HypoTestBenchAlg::initialize
virtual StatusCode initialize() override
Definition: HypoTestBenchAlg.cxx:38
perfmonmt-printer.dest
dest
Definition: perfmonmt-printer.py:189
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
GlobalSim::HypoTestBenchAlg::m_fifos
std::vector< std::unique_ptr< GepAlgoHypothesisFIFO > > m_fifos
Definition: HypoTestBenchAlg.h:109
GlobalSim::HypoTestBenchAlg::m_expTobs_in
Gaudi::Property< std::string > m_expTobs_in
Definition: HypoTestBenchAlg.h:90
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
GlobalSim::HypoTestBenchAlg::init_expected_tobs_from_file
StatusCode init_expected_tobs_from_file()
Definition: HypoTestBenchAlg.cxx:236
GlobalSim
AlgTool to obtain a selection of eFex RoIs read in from the event store.
Definition: dump.h:8
GlobalSim::GepAlgoHypothesisPortsIn
Definition: GepAlgoHypothesisPortsIn.h:18
python.getCurrentFolderTag.fn
fn
Definition: getCurrentFolderTag.py:65
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
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
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
GlobalSim::HypoTestBenchAlg::m_testRepeat
Gaudi::Property< int > m_testRepeat
Definition: HypoTestBenchAlg.h:99
GlobalSim::trim
std::string trim(std::string s)
Definition: HypoTestBenchAlg.cxx:129
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
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
HypoTestBenchAlg.h
GlobalSim::HypoTestBenchAlg::init_tests_from_file
StatusCode init_tests_from_file()
Definition: HypoTestBenchAlg.cxx:183
AthAlgorithm
Definition: AthAlgorithm.h:47
GlobalSim::HypoTestBenchAlg::m_expected_tobs
std::vector< std::string > m_expected_tobs
Definition: HypoTestBenchAlg.h:114
GlobalSim::HypoTestBenchAlg::m_hypothesisFIFO_WriteKey
SG::WriteHandleKey< GepAlgoHypothesisFIFO > m_hypothesisFIFO_WriteKey
Definition: HypoTestBenchAlg.h:41
GlobalSim::HypoTestBenchAlg::m_fifo_ptr
std::size_t m_fifo_ptr
Definition: HypoTestBenchAlg.h:110
GlobalSim::HypoTestBenchAlg::m_testsFileName
Gaudi::Property< std::string > m_testsFileName
Definition: HypoTestBenchAlg.h:56
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
GlobalSim::HypoTestBenchAlg::m_testVecs
std::vector< std::string > m_testVecs
Definition: HypoTestBenchAlg.h:106
GlobalSim::HypoTestBenchAlg::execute
virtual StatusCode execute() override
Definition: HypoTestBenchAlg.cxx:64
AlgoConstants.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:73
GlobalSim::HypoTestBenchAlg::m_eEmSortSelectCountExpectations_WriteKey
SG::WriteHandleKey< eEmSortSelectCountExpectations > m_eEmSortSelectCountExpectations_WriteKey
Definition: HypoTestBenchAlg.h:48
GlobalSim::HypoTestBenchAlg::m_expected_mults
std::vector< std::string > m_expected_mults
Definition: HypoTestBenchAlg.h:113
GlobalSim::HypoTestBenchAlg::init_from_file
StatusCode init_from_file()
Definition: HypoTestBenchAlg.cxx:149
GlobalSim::HypoTestBenchAlg::m_expectedTobs_FileName
Gaudi::Property< std::string > m_expectedTobs_FileName
Definition: HypoTestBenchAlg.h:76
GlobalSim::HypoTestBenchAlg::hexTOB2bitsetTOB
StatusCode hexTOB2bitsetTOB(std::string, std::bitset< 72 > &) const
Definition: HypoTestBenchAlg.cxx:11
python.compressB64.c
def c
Definition: compressB64.py:93
GlobalSim::HypoTestBenchAlg::m_expMults_in
Gaudi::Property< std::string > m_expMults_in
Definition: HypoTestBenchAlg.h:82
GlobalSim::HypoTestBenchAlg::init_manual
StatusCode init_manual()
Definition: HypoTestBenchAlg.cxx:95
checkFileSG.ind
list ind
Definition: checkFileSG.py:118