ATLAS Offline Software
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());
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
41 StatusCode 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
62 StatusCode L1TopoPhase1ByteStreamTool::convertToBS(std::vector<WROBF*>& , const EventContext& ) {
63  return StatusCode::FAILURE;
64 }
65 
66 StatusCode 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 }
L1TopoPhase1ByteStreamTool::convert
StatusCode convert(const ROBF *rob, const std::unique_ptr< xAOD::L1TopoRawDataContainer > &container) const
Definition: L1TopoPhase1ByteStreamTool.cxx:66
L1TopoPhase1ByteStreamTool::m_topoRawWriteKey
SG::WriteHandleKey< xAOD::L1TopoRawDataContainer > m_topoRawWriteKey
Definition: L1TopoPhase1ByteStreamTool.h:53
Undefined
@ Undefined
Definition: MaterialTypes.h:8
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
PixelByteStreamErrors::Decoding
@ Decoding
Definition: PixelByteStreamErrors.h:14
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
ROBF
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment ROBF
Definition: ByteStreamMergeOutputSvc.cxx:16
OFFLINE_FRAGMENTS_NAMESPACE::PointerType
const DataType * PointerType
Definition: RawEvent.h:25
lumiFormat.i
int i
Definition: lumiFormat.py:92
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
calibdata.exception
exception
Definition: calibdata.py:496
test_pyathena.parent
parent
Definition: test_pyathena.py:15
Error.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
L1Topo::Error::ROD_ERROR
@ ROD_ERROR
L1Topo::Error::SLINK_STATUS_ERROR
@ SLINK_STATUS_ERROR
DataVector::back
const T * back() const
Access the last element in the collection as an rvalue.
L1TopoPhase1ByteStreamTool::m_robIds
Gaudi::Property< std::vector< uint32_t > > m_robIds
Definition: L1TopoPhase1ByteStreamTool.h:50
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
L1TopoPhase1ByteStreamTool::convertFromBS
virtual StatusCode convertFromBS(const std::vector< const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment * > &vrobf, const EventContext &eventContext) const override
BS->xAOD conversion.
Definition: L1TopoPhase1ByteStreamTool.cxx:41
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment
eformat::ROBFragment< PointerType > ROBFragment
Definition: RawEvent.h:27
SG::VarHandleBase::key
virtual const std::string & key() const override final
Return the StoreGate ID for the referenced object.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleBase.cxx:64
L1TopoRawData.h
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
L1TopoPhase1ByteStreamTool::initialize
virtual StatusCode initialize() override
Definition: L1TopoPhase1ByteStreamTool.cxx:26
SG::WriteHandle::record
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment
eformat::write::ROBFragment ROBFragment
Definition: RawEvent.h:33
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
L1Topo::Error::ROB_ERROR
@ ROB_ERROR
WROBF
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment WROBF
Definition: eFexByteStreamTool.cxx:27
L1TopoPhase1ByteStreamTool::convertToBS
virtual StatusCode convertToBS(std::vector< OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment * > &vrobf, const EventContext &eventContext) override
xAOD->BS conversion
Definition: L1TopoPhase1ByteStreamTool.cxx:62
L1TopoPhase1ByteStreamTool::L1TopoPhase1ByteStreamTool
L1TopoPhase1ByteStreamTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: L1TopoPhase1ByteStreamTool.cxx:20
error
Definition: IImpactPoint3dEstimator.h:70
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
L1TopoPhase1ByteStreamTool.h
L1TopoPhase1ByteStreamTool::m_topoRawReadKey
SG::ReadHandleKey< xAOD::L1TopoRawDataContainer > m_topoRawReadKey
Definition: L1TopoPhase1ByteStreamTool.h:56