ATLAS Offline Software
Loading...
Searching...
No Matches
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
8namespace GlobalSim {
9
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
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
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
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_INFO(x,...)
Gaudi::Property< std::string > m_outFile
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
std::function< std::string(const SG::AuxElement &)> m_pack
SG::ReadHandleKey< xAOD::BaseContainer > m_inKey
virtual StatusCode initialize() override
virtual StatusCode finalize() override
Gaudi::Property< std::string > m_specName
virtual bool isValid() override final
Can the handle be successfully dereferenced?
AlgTool to read in LArStripNeighborhoods, and run the BDT Algorithm.
Definition BitSpec.h:23
std::string knownSpecNames()
Comma-separated list of the known names, for error messages.
const std::map< std::string, SpecEntry > & specRegistry()
The known specs, by name. Built on first use.
AuxElement(SG::AuxVectorData *container, size_t index)
Base class for elements of a container that can have aux data.