ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
TrigT1
Global
GlobalSimulation
src
TOBTextReader.cxx
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3
*/
4
#include "
TOBTextReader.h
"
5
6
#include "
SpecRegistry.h
"
7
8
#include "
xAODCore/AuxContainerBase.h
"
9
#include "
AthContainers/AuxElement.h
"
10
11
#include <fstream>
12
#include <sstream>
13
14
namespace
GlobalSim
{
15
16
StatusCode
TOBTextReader::initialize
() {
17
ATH_CHECK
(
m_outKey
.initialize());
18
19
const
auto
entry =
specRegistry
().find(
m_specName
.value());
20
if
(entry ==
specRegistry
().end()) {
21
ATH_MSG_ERROR
(
"Unknown BitSpec '"
<<
m_specName
.value()
22
<<
"'. Known specs are: "
<<
knownSpecNames
());
23
return
StatusCode::FAILURE;
24
}
25
m_width
= entry->second.width;
26
m_unpack
= entry->second.unpack;
27
28
// The whole file is read here so that execute() can stay const and
29
// reentrant: after this point m_events is only ever read.
30
std::ifstream in(
m_inputFile
.value());
31
if
(!in) {
32
ATH_MSG_ERROR
(
"Could not open input file '"
<<
m_inputFile
.value() <<
"'"
);
33
return
StatusCode::FAILURE;
34
}
35
36
const
std::size_t expected =
m_width
/ 4;
37
std::string line;
38
std::size_t lineNo{0};
39
40
while
(std::getline(in, line)) {
41
++lineNo;
42
std::istringstream
ss
(line);
43
std::string token;
44
std::vector<std::string> tokens;
45
46
while
(
ss
>> token) {
47
// Checked here rather than at decode time: a token of the wrong
48
// length would be silently truncated by std::bitset, which is how a
49
// file written for one spec gets read as another without complaint.
50
if
(token.size() != expected) {
51
ATH_MSG_ERROR
(
"line "
<< lineNo <<
": token '"
<< token <<
"' has "
52
<< token.size() <<
" hex characters, but "
53
<<
m_specName
.value() <<
" needs "
<< expected);
54
return
StatusCode::FAILURE;
55
}
56
tokens.push_back(token);
57
}
58
59
if
(!tokens.empty()) {
m_events
.push_back(std::move(tokens)); }
60
}
61
62
if
(
m_events
.empty()) {
63
ATH_MSG_ERROR
(
"No events read from '"
<<
m_inputFile
.value() <<
"'"
);
64
return
StatusCode::FAILURE;
65
}
66
67
ATH_MSG_INFO
(
"Loaded "
<<
m_events
.size() <<
" events from '"
68
<<
m_inputFile
.value() <<
"' as "
<<
m_specName
.value()
69
<<
", "
<< expected <<
" hex characters per TOB"
);
70
return
StatusCode::SUCCESS;
71
}
72
73
StatusCode
TOBTextReader::execute
(
const
EventContext& ctx)
const
{
74
// event N -> line N, wrapping round if the job runs more events than the
75
// file has lines.
76
const
std::size_t idx = ctx.evt() %
m_events
.size();
77
const
std::vector<std::string>& tokens =
m_events
[idx];
78
79
auto
tobs = std::make_unique<xAOD::BaseContainer>();
80
auto
tobsAux = std::make_unique<xAOD::AuxContainerBase>();
81
tobs->setStore(tobsAux.get());
82
83
// Assigning the whole word fills every field the spec declares, so the
84
// objects carry the flags as well as the kinematics.
85
for
(
const
std::string& token : tokens) {
86
tobs->push_back(std::make_unique<SG::AuxElement>());
87
m_unpack
(*tobs->back(), token);
88
}
89
90
ATH_MSG_INFO
(
"event "
<< ctx.evt() <<
": produced "
<< tobs->size()
91
<<
" TOBs into '"
<<
m_outKey
.key() <<
"'"
);
92
93
SG::WriteHandle<xAOD::BaseContainer>
h
(
m_outKey
, ctx);
94
ATH_CHECK
(
h
.record(std::move(tobs), std::move(tobsAux)));
95
return
StatusCode::SUCCESS;
96
}
97
98
}
// namespace GlobalSim
ATH_CHECK
#define ATH_CHECK
Evaluate an expression and check for errors.
Definition
AthCheckMacros.h:40
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x,...)
Definition
AthMsgStreamMacros.h:47
ATH_MSG_INFO
#define ATH_MSG_INFO(x,...)
Definition
AthMsgStreamMacros.h:45
AuxContainerBase.h
AuxElement.h
Base class for elements of a container that can have aux data.
ss
static Double_t ss
Definition
LArPhysWaveHECTool.cxx:37
SpecRegistry.h
TOBTextReader.h
h
Header file for AthHistogramAlgorithm.
GlobalSim::TOBTextReader::m_outKey
SG::WriteHandleKey< xAOD::BaseContainer > m_outKey
Definition
TOBTextReader.h:49
GlobalSim::TOBTextReader::m_events
std::vector< std::vector< std::string > > m_events
Definition
TOBTextReader.h:59
GlobalSim::TOBTextReader::m_width
std::size_t m_width
Definition
TOBTextReader.h:55
GlobalSim::TOBTextReader::m_specName
Gaudi::Property< std::string > m_specName
Definition
TOBTextReader.h:45
GlobalSim::TOBTextReader::initialize
virtual StatusCode initialize() override
Definition
TOBTextReader.cxx:16
GlobalSim::TOBTextReader::m_inputFile
Gaudi::Property< std::string > m_inputFile
Definition
TOBTextReader.h:41
GlobalSim::TOBTextReader::m_unpack
std::function< void(SG::AuxElement &, const std::string &)> m_unpack
Definition
TOBTextReader.h:54
GlobalSim::TOBTextReader::execute
virtual StatusCode execute(const EventContext &ctx) const override
Definition
TOBTextReader.cxx:73
SG::WriteHandle
Definition
StoreGate/StoreGate/WriteHandle.h:73
GlobalSim
AlgTool to read in LArStripNeighborhoods, and run the BDT Algorithm.
Definition
BitSpec.h:23
GlobalSim::knownSpecNames
std::string knownSpecNames()
Comma-separated list of the known names, for error messages.
Definition
SpecRegistry.cxx:49
GlobalSim::specRegistry
const std::map< std::string, SpecEntry > & specRegistry()
The known specs, by name. Built on first use.
Definition
SpecRegistry.cxx:36
Generated on
for ATLAS Offline Software by
1.17.0