Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
eEmSortSelectCountContainerComparator.cxx
Go to the documentation of this file.
1 
2 /*
3  Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
4 */
5 
7 #include "hexStrToBinStr.h"
8 
9 #include "../../../dump.h"
10 #include "../../../dump.icc"
11 
14 
15 #include <sstream>
16 #include <algorithm>
17 
18 namespace GlobalSim {
19 
21  const std::string& name,
22  const IInterface* parent) :
23  base_class(type, name, parent){
24  }
25 
27 
31 
32  return StatusCode::SUCCESS;
33  }
34 
35  struct TestCounts {
36  std::size_t nInputPorts{0};
37  std::size_t nOutputTobs{0};
38  std::size_t nOutputTobs_pass{0};
39  std::size_t nCounts{0};
40  std::size_t nCounts_pass{0};
41 
42  bool success() const {
43  return nOutputTobs == nOutputTobs_pass and
45  }
46  };
47  std::ostream& operator << (std::ostream& os, const TestCounts& tc) {
48  os << "test counts. nInputPorts: " << tc.nInputPorts
49  << " nOutputTobs: " << tc.nOutputTobs
50  << " nOutputTobs_pass: " << tc.nOutputTobs_pass
51  << " nCounts: " << tc.nCounts
52  << " nCounts_pass: " << tc.nCounts_pass;
53  return os;
54  }
55 
56 
58  eEmSortSelectCountContainerComparator::run(const EventContext& ctx) const {
59  ATH_MSG_DEBUG("run()");
60 
61 
62  // read in input data (a FIFO) for GepAlgoHypothesis from the event store
63 
64  auto fifo =
66  ctx);
67  CHECK(fifo.isValid());
68 
69  ATH_MSG_DEBUG("read in GepAlgoHypothesis fifo ");
70 
71  auto ports_out =
74  ctx);
75  CHECK(ports_out.isValid());
76 
77  auto tcounts = TestCounts();
78  tcounts.nInputPorts = fifo->size();
79  {
80  std::stringstream ss;
81  ss << "eEmTobs from FIFO:\n";
82  for (const auto& i : *fifo) {
83  ss << eEmInputTOBToString(*(i.m_I_eEmTobs)) << '\n';
84  }
85 
86  ATH_MSG_DEBUG(ss.str());
87  }
88 
89  auto expectations =
91 
92  CHECK(expectations.isValid());
93 
94  const auto& exp_tob_bitstr = expectations->m_expected_tob_bits;
95  auto sz = exp_tob_bitstr.size();
96 
97  // break down the bit string into 8 character chunks
98  std::vector<std::bitset<32>> exp_tobs;
99  exp_tobs.reserve(sz/8);
100 
101  std::stringstream ss;
102 
103  for (std::size_t i = 2; i < sz; i += 8) {
104  ss << std::hex
105  << std::string("0x" + std::string(std::cbegin(exp_tob_bitstr)+i,
106  std::cbegin(exp_tob_bitstr)+i+8));
107  unsigned n;
108  ss >> n;
109  exp_tobs.push_back(std::bitset<32>(n));
110  ss.clear();
111 
112  }
113 
114 
115  auto ntobs = exp_tobs.size();
116  if (ntobs != ports_out->m_O_eEmGenTob.size()) {
117  ATH_MSG_ERROR("exp_tobs size " << exp_tobs.size() <<
118  " port tobs size : " << ports_out->m_O_eEmGenTob.size());
119  return StatusCode::FAILURE;
120  }
121 
122  //for some reason the tobs are delivered in reverse order. Fix this.
123  std::reverse(std::begin(exp_tobs), std::end(exp_tobs));
124 
125 
126  {
127 
128  auto fnd_tobs = ports_out->m_O_eEmGenTob;
129 
130  std::size_t idx{0};
131 
132  // compare only sorted TOBS - the the ordering of the unsorted TOBS
133  // may differ in the VHDL code
134  auto ss = std::stringstream();
135  for (;idx != fnd_tobs.size(); ++idx) {
136 
137 
138  const auto& f_tob = fnd_tobs[idx];
139  bool pass{(f_tob->as_bits().to_ulong() == exp_tobs[idx].to_ulong())};
140  ss << '\n' << idx << " found " << f_tob->as_bits() << ' '
141  << std::hex << f_tob->as_bits().to_ulong()
142  << " expected " << exp_tobs[idx] << ' '
143  << exp_tobs[idx].to_ulong()
144  << ' ' << std::boolalpha
145  << pass
146  << '\n';
147  tcounts.nOutputTobs += 1;
148  if (pass) {tcounts.nOutputTobs_pass +=1;}
149  }
150  ATH_MSG_DEBUG(ss.str());
151  }
152 
153 
154  {
155  const auto& mult_bits = ports_out-> m_O_Multiplicity;
156 
157  auto found = mult_bits->to_string();
158  auto exp_str = hexStrToBinStr((*expectations).m_expected_multiplicity_bits);
159  ATH_MSG_DEBUG("\nmultiplicity bits. found: " << found
160  << " expected: "
161  << exp_str);
162 
163  tcounts.nCounts +=1;
164  if (found == exp_str) {
165  tcounts.nCounts_pass +=1;
166  }
167  }
168 
169  if (!tcounts.success()) {
170  ATH_MSG_ERROR ("Count tests fail: " << tcounts);
171  return StatusCode::FAILURE;
172  } else {
173  ATH_MSG_DEBUG ("Count tests succeed: " << tcounts);
174  }
175 
176  return StatusCode::SUCCESS;
177  }
178 
179  std::string
181 
182  std::stringstream ss;
183  ss << "eEmSortSelectCountContainerComparator.name: " << name() << '\n'
184  << m_HypoFIFOReadKey << '\n'
186  << '\n';
187  return ss.str();
188  }
189 }
190 
fitman.sz
sz
Definition: fitman.py:527
GlobalSim::eEmSortSelectCountContainerComparator::eEmSortSelectCountContainerComparator
eEmSortSelectCountContainerComparator(const std::string &type, const std::string &name, const IInterface *parent)
Definition: eEmSortSelectCountContainerComparator.cxx:20
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
GlobalSim::TestCounts::nOutputTobs
std::size_t nOutputTobs
Definition: eEmSortSelectCountContainerComparator.cxx:37
GlobalSim::eEmInputTOBToString
std::string eEmInputTOBToString(const std::bitset< 72 > &bs)
Definition: GepAlgoHypothesisPortsIn.cxx:9
python.ext.silence.fifo
def fifo()
Definition: silence.py:37
GlobalSim::hexStrToBinStr
std::string hexStrToBinStr(std::string s)
Definition: hexStrToBinStr.h:13
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
GlobalSim::TestCounts::nCounts
std::size_t nCounts
Definition: eEmSortSelectCountContainerComparator.cxx:39
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
hexStrToBinStr.h
GlobalSim::TestCounts::nCounts_pass
std::size_t nCounts_pass
Definition: eEmSortSelectCountContainerComparator.cxx:40
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
GlobalSim::TestCounts::nInputPorts
std::size_t nInputPorts
Definition: eEmSortSelectCountContainerComparator.cxx:36
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
DeMoUpdate.reverse
reverse
Definition: DeMoUpdate.py:563
GlobalSim::operator<<
std::ostream & operator<<(std::ostream &os, const TestCounts &tc)
Definition: eEmSortSelectCountContainerComparator.cxx:47
GlobalSim
AlgTool to obtain a selection of eFex RoIs read in from the event store.
Definition: dump.h:8
MonitoredCollection.h
GlobalSim::eEmSortSelectCountContainerComparator::m_portsOutReadKey
SG::ReadHandleKey< GlobalSim::eEmSortSelectCountContainerPortsOut > m_portsOutReadKey
Definition: eEmSortSelectCountContainerComparator.h:62
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:85
beamspotman.n
n
Definition: beamspotman.py:731
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
test_pyathena.parent
parent
Definition: test_pyathena.py:15
GlobalSim::TestCounts::success
bool success() const
Definition: eEmSortSelectCountContainerComparator.cxx:42
GlobalSim::eEmSortSelectCountContainerComparator::initialize
virtual StatusCode initialize() override
Definition: eEmSortSelectCountContainerComparator.cxx:26
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
Monitored.h
Header file to be included by clients of the Monitored infrastructure.
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
GlobalSim::TestCounts::nOutputTobs_pass
std::size_t nOutputTobs_pass
Definition: eEmSortSelectCountContainerComparator.cxx:38
checkTriggerxAOD.found
found
Definition: checkTriggerxAOD.py:328
GlobalSim::eEmSortSelectCountContainerComparator::m_eEmSortSelectCountExpectationsReadKey
SG::ReadHandleKey< GlobalSim::eEmSortSelectCountExpectations > m_eEmSortSelectCountExpectationsReadKey
Definition: eEmSortSelectCountContainerComparator.h:71
LArNewCalib_DelayDump_OFC_Cali.idx
idx
Definition: LArNewCalib_DelayDump_OFC_Cali.py:69
eEmSortSelectCountContainerComparator.h
GlobalSim::eEmSortSelectCountContainerComparator::m_HypoFIFOReadKey
SG::ReadHandleKey< GlobalSim::GepAlgoHypothesisFIFO > m_HypoFIFOReadKey
Definition: eEmSortSelectCountContainerComparator.h:53
GlobalSim::TestCounts
Definition: eEmSortSelectCountContainerComparator.cxx:35
GlobalSim::eEmSortSelectCountContainerComparator::toString
virtual std::string toString() const override
Definition: eEmSortSelectCountContainerComparator.cxx:180
GlobalSim::eEmSortSelectCountContainerComparator::run
virtual StatusCode run(const EventContext &ctx) const override
Definition: eEmSortSelectCountContainerComparator.cxx:58