ATLAS Offline Software
ExampleL1TriggerByteStreamTool.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 // Local includes
7 
8 // Trigger includes
9 #include "xAODTrigger/MuonRoI.h"
11 
12 
13 // TDAQ includes
14 #include "eformat/SourceIdentifier.h"
15 #include "eformat/Status.h"
16 #include <span>
17 
20 
22  const std::string& name,
23  const IInterface* parent)
24 : base_class(type, name, parent) {}
25 
27  ConversionMode mode = getConversionMode(m_roiReadKey, m_roiWriteKey, msg());
30  ATH_CHECK(m_roiReadKey.initialize(mode==ConversionMode::Encoding));
31  ATH_MSG_DEBUG((mode==ConversionMode::Encoding ? "Encoding" : "Decoding") << " ROB IDs: "
32  << MSG::hex << m_robIds.value() << MSG::dec);
33  return StatusCode::SUCCESS;
34 }
35 
36 // BS->xAOD conversion
37 StatusCode ExampleL1TriggerByteStreamTool::convertFromBS(const std::vector<const ROBF*>& vrobf,
38  const EventContext& eventContext) const {
39  if (m_roiWriteKey.empty()) {
40  ATH_MSG_ERROR("Conversion from BS to xAOD RoI requested but RoI WriteHandleKey is empty");
41  return StatusCode::FAILURE;
42  }
43 
44  // Create and record the RoI container
45  auto handle = SG::makeHandle(m_roiWriteKey, eventContext);
46  auto cont = std::make_unique<xAOD::MuonRoIContainer>();
47  auto auxcont = std::make_unique<xAOD::MuonRoIAuxContainer>();
48  cont->setStore(auxcont.get());
49  ATH_CHECK(handle.record(std::move(cont), std::move(auxcont)));
50  ATH_MSG_DEBUG("Recorded MuonRoIContainer with key " << m_roiWriteKey.key());
51 
52  // Find the ROB fragment to decode
53  const eformat::helper::SourceIdentifier sid(m_robIds.value().at(0));
54  auto it = std::find_if(vrobf.begin(), vrobf.end(), [&sid](const ROBF* rob){return rob->rob_source_id() == sid.code();});
55  if (it == vrobf.end()) {
56  ATH_MSG_DEBUG("No MUCTPI ROB fragment with ID 0x" << std::hex << sid.code() << std::dec
57  << " was found, MuonRoIContainer will be empty");
58  return StatusCode::SUCCESS;
59  }
60 
61  // Iterate over ROD words and decode
62  const ROBF* rob = *it;
63  const uint32_t ndata = rob->rod_ndata();
64  const uint32_t* data = rob->rod_data();
65  ATH_MSG_DEBUG("Starting to decode " << ndata << " ROD words");
66  for (const uint32_t word : std::span{data, ndata}) {
67  ATH_MSG_DEBUG("Muon RoI raw word: 0x" << std::hex << word << std::dec);
68  // Here comes the decoding
69  // Using some dummy values as this is not real decoding, just an example
70  handle->push_back(new xAOD::MuonRoI);
71  handle->back()->initialize(word, 99, 99, "DummyThreshold", 99);
72  }
73 
74  ATH_MSG_DEBUG("Decoded " << handle->size() << " Muon RoIs");
75  return StatusCode::SUCCESS;
76 }
77 
80  const EventContext& eventContext) {
81  // Retrieve the RoI container
82  auto muonRoIs = SG::makeHandle(m_roiReadKey, eventContext);
83  ATH_CHECK(muonRoIs.isValid());
84 
85  // Clear BS data cache
86  clearCache(eventContext);
87 
88  // Create raw ROD data words
89  ATH_MSG_DEBUG("Converting " << muonRoIs->size() << " L1 Muon RoIs to ByteStream");
90  uint32_t* data = newRodData(eventContext, muonRoIs->size());
91  for (size_t i=0; i<muonRoIs->size(); ++i) {
92  data[i] = muonRoIs->at(i)->roiWord();
93  }
94 
95  // Create ROBFragment containing the ROD words
96  const eformat::helper::SourceIdentifier sid(m_robIds.value().at(0));
97  vrobf.push_back(newRobFragment(eventContext, sid.code(), muonRoIs->size(), data));
98 
99  return StatusCode::SUCCESS;
100 }
data
char data[hepevt_bytes_allocation_ATLAS]
Definition: HepEvt.cxx:11
CxxUtils::span
span(T *ptr, std::size_t sz) -> span< T >
A couple needed deduction guides.
Undefined
@ Undefined
Definition: MaterialTypes.h:8
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
MuonRoIAuxContainer.h
skel.it
it
Definition: skel.GENtoEVGEN.py:423
PixelByteStreamErrors::Decoding
@ Decoding
Definition: PixelByteStreamErrors.h:14
SG::makeHandle
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
Definition: ReadCondHandle.h:270
ROBF
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment ROBF
Definition: ByteStreamMergeOutputSvc.cxx:16
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
lumiFormat.i
int i
Definition: lumiFormat.py:92
ExampleL1TriggerByteStreamTool::m_roiReadKey
SG::ReadHandleKey< xAOD::MuonRoIContainer > m_roiReadKey
Definition: ExampleL1TriggerByteStreamTool.h:55
ExampleL1TriggerByteStreamTool.h
ExampleL1TriggerByteStreamTool::initialize
virtual StatusCode initialize() override
Definition: ExampleL1TriggerByteStreamTool.cxx:26
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
xAOD::MuonRoI_v1
Class describing a LVL1 muon region of interest.
Definition: MuonRoI_v1.h:33
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ExampleL1TriggerByteStreamTool::m_roiWriteKey
SG::WriteHandleKey< xAOD::MuonRoIContainer > m_roiWriteKey
Definition: ExampleL1TriggerByteStreamTool.h:52
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
ExampleL1TriggerByteStreamTool::ExampleL1TriggerByteStreamTool
ExampleL1TriggerByteStreamTool(const std::string &type, const std::string &name, const IInterface *parent)
Definition: ExampleL1TriggerByteStreamTool.cxx:21
Preparation.mode
mode
Definition: Preparation.py:95
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment
eformat::ROBFragment< PointerType > ROBFragment
Definition: RawEvent.h:27
ExampleL1TriggerByteStreamTool::convertFromBS
virtual StatusCode convertFromBS(const std::vector< const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment * > &vrobf, const EventContext &eventContext) const override
BS->xAOD conversion.
Definition: ExampleL1TriggerByteStreamTool.cxx:37
ExampleL1TriggerByteStreamTool::convertToBS
virtual StatusCode convertToBS(std::vector< OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment * > &vrobf, const EventContext &eventContext) override
xAOD->BS conversion
Definition: ExampleL1TriggerByteStreamTool.cxx:79
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment
eformat::write::ROBFragment ROBFragment
Definition: RawEvent.h:33
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
WROBF
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment WROBF
Definition: eFexByteStreamTool.cxx:27
MuonRoI.h
python.AutoConfigFlags.msg
msg
Definition: AutoConfigFlags.py:7
ExampleL1TriggerByteStreamTool::m_robIds
Gaudi::Property< std::vector< uint32_t > > m_robIds
Definition: ExampleL1TriggerByteStreamTool.h:48