ATLAS Offline Software
Loading...
Searching...
No Matches
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
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());
28 ATH_CHECK(mode!=ConversionMode::Undefined);
29 ATH_CHECK(m_roiWriteKey.initialize(mode==ConversionMode::Decoding));
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
37StatusCode 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
79StatusCode ExampleL1TriggerByteStreamTool::convertToBS(std::vector<WROBF*>& vrobf,
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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment ROBF
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
SG::ReadHandleKey< xAOD::MuonRoIContainer > m_roiReadKey
virtual StatusCode convertFromBS(const std::vector< const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment * > &vrobf, const EventContext &eventContext) const override
BS->xAOD conversion.
ExampleL1TriggerByteStreamTool(const std::string &type, const std::string &name, const IInterface *parent)
Gaudi::Property< std::vector< uint32_t > > m_robIds
virtual StatusCode convertToBS(std::vector< OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment * > &vrobf, const EventContext &eventContext) override
xAOD->BS conversion
SG::WriteHandleKey< xAOD::MuonRoIContainer > m_roiWriteKey
OFFLINE_FRAGMENTS_NAMESPACE_WRITE::ROBFragment WROBF
eformat::write::ROBFragment ROBFragment
Definition RawEvent.h:33
eformat::ROBFragment< PointerType > ROBFragment
Definition RawEvent.h:27
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
MuonRoI_v1 MuonRoI
Definition MuonRoI.h:15
MsgStream & msg
Definition testRead.cxx:32