ATLAS Offline Software
Loading...
Searching...
No Matches
L1TopoPhase1ByteStreamTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4
5//author: @asonay
6//email: anil.sonay@cern.ch
7
9
10//L1TopoRDO
11#include "L1TopoRDO/Error.h"
12
13//xAOD
15
18
19
21 const std::string& name,
22 const IInterface* parent)
23 : base_class(type, name, parent) {}
24
25
27
28 ConversionMode topoRawMode = getConversionMode(m_topoRawReadKey, m_topoRawWriteKey, msg());
29 ATH_CHECK(topoRawMode!=ConversionMode::Undefined);
30 ATH_CHECK(m_topoRawWriteKey.initialize(topoRawMode==ConversionMode::Decoding));
31 ATH_CHECK(m_topoRawReadKey.initialize(topoRawMode==ConversionMode::Encoding));
32 ATH_MSG_DEBUG((topoRawMode==ConversionMode::Encoding ? "Encoding" : "Decoding") << " topoRaw ROB IDs: "
33 << std::hex << std::showbase << m_robIds.value() << std::dec);
34
35
36 return StatusCode::SUCCESS;
37
38}
39
40// BS->xAOD conversion
41StatusCode L1TopoPhase1ByteStreamTool::convertFromBS(const std::vector<const ROBF*>& vrobf, const EventContext& ctx) const {
42
43 // prepare container
44 auto l1topoContainer = std::make_unique<xAOD::L1TopoRawDataContainer> ();
45 auto l1topoAuxContainer = std::make_unique<xAOD::L1TopoRawDataAuxContainer> ();
46 l1topoContainer->setStore(l1topoAuxContainer.get());
47
48 // Iterate over ROBFragments to decode
49 for (const ROBF* rob : vrobf) {
50 ATH_CHECK( convert(rob, l1topoContainer) );
51 }
52
54 ATH_CHECK(l1topo_cont.record(std::move(l1topoContainer),std::move(l1topoAuxContainer)));
55 ATH_MSG_DEBUG("Recorded L1TopoRawDataContainer with key " << l1topo_cont.key());
56
57 return StatusCode::SUCCESS;
58}
59
60
61// xAOD->BS conversion
62StatusCode L1TopoPhase1ByteStreamTool::convertToBS(std::vector<WROBF*>& , const EventContext& ) {
63 return StatusCode::FAILURE;
64}
65
66StatusCode L1TopoPhase1ByteStreamTool::convert(const ROBF* rob, const std::unique_ptr<xAOD::L1TopoRawDataContainer> &container) const {
67 ATH_MSG_DEBUG("executing convert() from ROBFragment to xAOD::L1TopoRawData");
68
69 uint32_t rodId = rob->rob_source_id();
70
71 ATH_MSG_DEBUG("ROD sub-detector ID: 0x" << MSG::hex << rodId << MSG::dec);
72
73 // First use ROB & ROD error check methods
74 bool error_rob(false);
75 bool error_rod(false);
76 try {
77 if (rob->check_rob()) {
78 ATH_MSG_VERBOSE("ROB fragment checked ok");
79 }
80 } catch (std::exception const& ex) {
81 ATH_MSG_WARNING("ROB fragment not valid: " << ex.what());
82 error_rob = true;
83 }
84 try {
85 if (rob->check_rod()) {
86 ATH_MSG_VERBOSE("ROD fragment checked ok");
87 }
88 } catch (std::exception const& ex) {
89 ATH_MSG_WARNING("ROD fragment not valid: " << ex.what());
90 error_rod = true;
91 }
92
93 // Print some header info
95 MSG::hex << " \n"
96 << " rod_version 0x" << rob->rod_version() << " \n"
97 << " rod_run_no 0x" << MSG::dec
98 << rob->rod_run_no() << " \n"
99 << " rod_lvl1_id 0x" << MSG::hex
100 << rob->rod_lvl1_id() << " \n"
101 << " rod_bc_id 0x" << rob->rod_bc_id() << " \n"
102 << " rod_lvl1_trigger_type 0x" << rob->rod_lvl1_trigger_type()
103 << " \n"
104 << " nchildren 0x" << rob->nchildren() << " \n"
105 << MSG::dec);
106
107 // print and check status words
108 OFFLINE_FRAGMENTS_NAMESPACE::PointerType it_status = rob->rod_status();
109 const uint32_t nstatus = rob->rod_nstatus();
110 ATH_MSG_VERBOSE("Number of status words: " << nstatus);
111 std::vector<uint32_t> vStatusWords;
112 vStatusWords.reserve(nstatus);
113 ATH_MSG_VERBOSE("Dumping ROD status words:");
114 for (uint32_t i = 0; i < nstatus; ++i, ++it_status) {
115 vStatusWords.push_back(static_cast<uint32_t>(*it_status));
116 ATH_MSG_VERBOSE(" 0x" << MSG::hex << std::setfill('0') << std::setw(8)
117 << *it_status << MSG::dec);
118 }
119 // for definition of first status word see:
120 // - bits 00-15: https://edms.cern.ch/document/445840/5.0a section 5.8
121 // - bits 16-31: bits 16-31:
122 // https://twiki.cern.ch/twiki/bin/viewauth/Atlas/ROBINFragmentErrors
123 // Can do something more specific eventually.
124 bool error_status(false);
125 if (vStatusWords.size() == 0) {
126 ATH_MSG_WARNING("ROD has no status word");
127 }
128 if (vStatusWords.size() > 0 && vStatusWords.at(0) != 0) {
129 ATH_MSG_WARNING("Non-zero first status word, payload may not be valid");
130 error_status = true;
131 }
132
133 // print and interpret data words and save them for RDO
134 OFFLINE_FRAGMENTS_NAMESPACE::PointerType it_data = rob->rod_data();
135 const uint32_t ndata = rob->rod_ndata();
136 ATH_MSG_VERBOSE("Number of data words: " << ndata);
137
138 ATH_MSG_VERBOSE("Dumping L1Topo data words:");
139 std::vector<uint32_t> vDataWords;
140 vDataWords.reserve(ndata);
141 for (uint32_t i = 0; i < ndata; ++i, ++it_data) {
142 vDataWords.push_back(static_cast<uint32_t>(*it_data));
143 ATH_MSG_VERBOSE(" 0x" << MSG::hex << std::setfill('0') << std::setw(8)
144 << *it_data << MSG::dec);
145 }
146
147 //Set Error
148 uint32_t error = 0;
149 if (error_status) {
150 error |= (1 << static_cast<unsigned int>(L1Topo::Error::SLINK_STATUS_ERROR));
151 }
152 if (error_rob) {
153 error |= (1 << static_cast<unsigned int>(L1Topo::Error::ROB_ERROR));
154 }
155 if (error_rod) {
156 error |= (1 << static_cast<unsigned int>(L1Topo::Error::ROD_ERROR));
157 }
158
159 // Fill xAOD
160 container->push_back(std::make_unique<xAOD::L1TopoRawData>());
161 container->back()->initialize(vDataWords,vStatusWords,error,rodId);
162
163 return StatusCode::SUCCESS;
164
165}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment ROBF
virtual StatusCode initialize() override
virtual StatusCode convertToBS(std::vector< OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment * > &vrobf, const EventContext &eventContext) override
xAOD->BS conversion
Gaudi::Property< std::vector< uint32_t > > m_robIds
virtual StatusCode convertFromBS(const std::vector< const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment * > &vrobf, const EventContext &eventContext) const override
BS->xAOD conversion.
L1TopoPhase1ByteStreamTool(const std::string &type, const std::string &name, const IInterface *parent)
SG::WriteHandleKey< xAOD::L1TopoRawDataContainer > m_topoRawWriteKey
SG::ReadHandleKey< xAOD::L1TopoRawDataContainer > m_topoRawReadKey
StatusCode convert(const ROBF *rob, const std::unique_ptr< xAOD::L1TopoRawDataContainer > &container) const
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment WROBF
@ SLINK_STATUS_ERROR
Definition Error.h:16
eformat::write::ROBFragment ROBFragment
Definition RawEvent.h:33
const DataType * PointerType
Definition RawEvent.h:25
eformat::ROBFragment< PointerType > ROBFragment
Definition RawEvent.h:27
MsgStream & msg
Definition testRead.cxx:32