ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Trigger
TrigT1
Global
GlobalSimulation
src
TOBTextWriter.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 "
TOBTextWriter.h
"
5
6
#include "
SpecRegistry.h
"
7
8
namespace
GlobalSim
{
9
10
StatusCode
TOBTextWriter::initialize
() {
11
ATH_CHECK
(
m_inKey
.initialize());
12
13
const
auto
entry =
specRegistry
().find(
m_specName
.value());
14
if
(entry ==
specRegistry
().end()) {
15
ATH_MSG_ERROR
(
"Unknown BitSpec '"
<<
m_specName
.value()
16
<<
"'. Known specs are: "
<<
knownSpecNames
());
17
return
StatusCode::FAILURE;
18
}
19
m_width
= entry->second.width;
20
m_pack
= entry->second.pack;
21
22
// Opened here rather than in finalize() so that a job which cannot write
23
// its output fails before running the event loop.
24
m_out
.open(
m_outFile
.value());
25
if
(!
m_out
) {
26
ATH_MSG_ERROR
(
"Could not open output file '"
<<
m_outFile
.value() <<
"'"
);
27
return
StatusCode::FAILURE;
28
}
29
30
ATH_MSG_INFO
(
"Writing '"
<<
m_inKey
.key() <<
"' to '"
<<
m_outFile
.value()
31
<<
"' as "
<<
m_specName
.value() <<
", "
<<
m_width
/ 4
32
<<
" hex characters per TOB"
);
33
return
StatusCode::SUCCESS;
34
}
35
36
StatusCode
TOBTextWriter::execute
(
const
EventContext& ctx) {
37
// Lines go out as the events arrive, so the events have to arrive in order.
38
// The first one seen sets the sequence; a gap after that means more than one
39
// event is in flight and the line order can no longer be trusted.
40
if
(
m_nWritten
== 0) {
m_nextEvt
= ctx.evt(); }
41
if
(ctx.evt() !=
m_nextEvt
) {
42
ATH_MSG_ERROR
(
"event "
<< ctx.evt() <<
" arrived out of order (expected "
43
<<
m_nextEvt
<<
"), so line N would no longer be event N. "
44
<<
"Run this job with a single concurrent event."
);
45
return
StatusCode::FAILURE;
46
}
47
48
SG::ReadHandle<xAOD::BaseContainer>
tobs(
m_inKey
, ctx);
49
if
(!tobs.
isValid
()) {
50
ATH_MSG_ERROR
(
"Could not retrieve '"
<<
m_inKey
.key() <<
"'"
);
51
return
StatusCode::FAILURE;
52
}
53
54
// The reference implementation writes a space after every TOB, including
55
// the last one on a line.
56
std::string line;
57
for
(
const
SG::AuxElement
* tob : *tobs) {
58
line +=
m_pack
(*tob);
59
line +=
' '
;
60
}
61
62
// The newline separates lines rather than terminating them. An empty line
63
// denotes an event with no TOBs, so a file ending in a newline could not be
64
// told apart from one with a trailing empty event.
65
if
(
m_nWritten
> 0) {
m_out
<<
'\n'
; }
66
m_out
<< line;
67
68
++
m_nextEvt
;
69
++
m_nWritten
;
70
71
ATH_MSG_INFO
(
"event "
<< ctx.evt() <<
": wrote "
<< tobs->size()
72
<<
" TOBs from '"
<<
m_inKey
.key() <<
"'"
);
73
return
StatusCode::SUCCESS;
74
}
75
76
StatusCode
TOBTextWriter::finalize
() {
77
m_out
.close();
78
if
(!
m_out
) {
79
ATH_MSG_ERROR
(
"Failed writing '"
<<
m_outFile
.value() <<
"'"
);
80
return
StatusCode::FAILURE;
81
}
82
ATH_MSG_INFO
(
"wrote "
<<
m_nWritten
<<
" events to '"
<<
m_outFile
.value() <<
"'"
);
83
return
StatusCode::SUCCESS;
84
}
85
86
}
// 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
SpecRegistry.h
TOBTextWriter.h
GlobalSim::TOBTextWriter::m_outFile
Gaudi::Property< std::string > m_outFile
Definition
TOBTextWriter.h:52
GlobalSim::TOBTextWriter::execute
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
Definition
TOBTextWriter.cxx:36
GlobalSim::TOBTextWriter::m_nWritten
uint64_t m_nWritten
Definition
TOBTextWriter.h:67
GlobalSim::TOBTextWriter::m_pack
std::function< std::string(const SG::AuxElement &)> m_pack
Definition
TOBTextWriter.h:59
GlobalSim::TOBTextWriter::m_out
std::ofstream m_out
Definition
TOBTextWriter.h:62
GlobalSim::TOBTextWriter::m_inKey
SG::ReadHandleKey< xAOD::BaseContainer > m_inKey
Definition
TOBTextWriter.h:45
GlobalSim::TOBTextWriter::m_nextEvt
uint64_t m_nextEvt
Definition
TOBTextWriter.h:66
GlobalSim::TOBTextWriter::m_width
std::size_t m_width
Definition
TOBTextWriter.h:60
GlobalSim::TOBTextWriter::initialize
virtual StatusCode initialize() override
Definition
TOBTextWriter.cxx:10
GlobalSim::TOBTextWriter::finalize
virtual StatusCode finalize() override
Definition
TOBTextWriter.cxx:76
GlobalSim::TOBTextWriter::m_specName
Gaudi::Property< std::string > m_specName
Definition
TOBTextWriter.h:48
SG::ReadHandle
Definition
StoreGate/StoreGate/ReadHandle.h:67
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
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
SG::AuxElement
AuxElement(SG::AuxVectorData *container, size_t index)
Base class for elements of a container that can have aux data.
Generated on
for ATLAS Offline Software by
1.17.0