ATLAS Offline Software
Loading...
Searching...
No Matches
STGC_RawDataProviderTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5
8#include "eformat/SourceIdentifier.h"
9using eformat::helper::SourceIdentifier;
10
11using namespace OFFLINE_FRAGMENTS_NAMESPACE;
12
13
14//==============================================================================
16
17
18 ATH_CHECK(m_idHelperSvc.retrieve());
19 ATH_CHECK(m_decoder.retrieve());
20 ATH_CHECK(m_robDataProvider.retrieve()); // ROBDataProviderSvc
21 ATH_CHECK(m_rdoContainerKey.initialize());
22
23 m_maxhashtoUse = m_idHelperSvc->stgcIdHelper().module_hash_max();
24 // generate all the Source Identifiers to request the fragments.
25 // assume 16 RODs per side (one per sector) and that ROB ID = ROD ID.
26 for (uint32_t detID : {eformat::MUON_STGC_ENDCAP_A_SIDE, eformat::MUON_STGC_ENDCAP_C_SIDE}) { //0x6D, 0x6E
27 for (uint8_t sectorID(0); sectorID < 16; ++sectorID) {
28 // for now lets build all the possible ROB ids of all possible readout configurations
29 // maybe later we can come up with a smart way to detect which readout sheme is running and only request the relevant ROB ids from the ROBDataProviderSvc
30 // reference: slide 6 of https://indico.cern.ch/event/1260377/contributions/5294286/attachments/2603399/4495810/NSW-SwRod-Felix-v3.pdf
31
32 uint16_t moduleID = (0x0 << 8) | sectorID; // combined/single ROB
33 SourceIdentifier sid(static_cast<eformat::SubDetector>(detID), moduleID);
34 m_allRobIds.push_back(sid.simple_code());
35
36 moduleID = (0x1 << 8) | sectorID; // full device ROB (split configuration)
37 sid = SourceIdentifier(static_cast<eformat::SubDetector>(detID), moduleID);
38 m_allRobIds.push_back(sid.simple_code());
39
40 moduleID = (0x2 << 8) | sectorID; // shared device ROB (split configuration)
41 sid = SourceIdentifier(static_cast<eformat::SubDetector>(detID), moduleID);
42 m_allRobIds.push_back(sid.simple_code());
43
44 moduleID = (0x3 << 8) | sectorID; // spare device ROB (split configuration)
45 sid = SourceIdentifier(static_cast<eformat::SubDetector>(detID), moduleID);
46 m_allRobIds.push_back(sid.simple_code());
47 }
48 }
49
51 return StatusCode::SUCCESS;
52}
53
54
55//==============================================================================
57 const ROBFragmentList& vecRobs,
58 const std::vector<IdentifierHash>& rdoIdhVect,
59 STGC_RawDataContainer& stgcRdoContainer) const
60{
61 // Since there can be multiple ROBFragments contributing to the same RDO collection a temporary cache is setup and passed to fillCollection by reference. Once all ROBFragments are processed the collections are added into the rdo container
62 // const sTgcIdHelper& idH
63 std::vector<std::unique_ptr<STGC_RawDataCollection>> rdo_map{};
64
65
66 // Loop on the passed ROB fragments, and call the decoder for each one to fill the RDO container.
67 for (const ROBFragment* fragment : vecRobs)
68 ATH_CHECK( m_decoder->fillCollection(ctx, *fragment, rdoIdhVect, rdo_map) ); // always returns StatusCode::SUCCESS
69
70
71 // error counters
72 int nerr_duplicate{0};
73
74 // add the RDO collections created from the data of this ROB into the identifiable container.
75 for (std::uint32_t hash = 0 ; hash < rdo_map.size(); ++hash) {
76 auto& collection = rdo_map[hash];
77 if ((!collection) or collection->empty()) continue; // skip empty collections
78
80
81 if (lock.alreadyPresent()) {
82 ++nerr_duplicate;
83 } else{
84 ATH_CHECK(lock.addOrDelete(std::move(collection)));
85 }
86 }
87
88
89 // error summary (to reduce the number of messages)
90 if (nerr_duplicate) {
91 ATH_MSG_WARNING(nerr_duplicate << " elinks skipped since the same module hash has been added by a previous ROB fragment");
92 }
93
94 ATH_MSG_DEBUG("Size of sTgcRdoContainer is " << stgcRdoContainer.size());
95 return StatusCode::SUCCESS;
96}
97
98
99//==============================================================================
100StatusCode Muon::STGC_RawDataProviderTool::initRdoContainer(const EventContext& ctx, STGC_RawDataContainer*& rdoContainer) const
101{
102 // Create the identifiable RdoContainer in StoreGate to be filled with decoded fragment contents.
103 SG::WriteHandle rdoContainerHandle(m_rdoContainerKey, ctx);
104
105 const bool externalCacheRDO = !m_rdoContainerCacheKey.key().empty();
106 if(!externalCacheRDO){
107 ATH_CHECK(rdoContainerHandle.record(std::make_unique<STGC_RawDataContainer>(m_maxhashtoUse)));
108 ATH_MSG_DEBUG("Created STGC RDO container");
109 } else {
111 ATH_CHECK(update.isValid());
112 ATH_CHECK(rdoContainerHandle.record(std::make_unique<STGC_RawDataContainer>(update.ptr())));
113 ATH_MSG_DEBUG("Created STGC RDO container using cache for " << m_rdoContainerCacheKey.key());
114 }
115
116 // this should never happen, but since we dereference the pointer, we should check
117 if (!(rdoContainer = rdoContainerHandle.ptr())) {
118 ATH_MSG_ERROR("The STGC RDO container is null, cannot decode STGC data");
119 return StatusCode::FAILURE;
120 }
121
122 return StatusCode::SUCCESS;
123}
124
125
126//==============================================================================
127StatusCode Muon::STGC_RawDataProviderTool::convert(const std::vector<IdentifierHash>& rdoIdhVect, const EventContext& ctx) const
128{
129 // method for RoI-seeded mode. we don't let empty hash containers reach the decoder,
130 // since an empty container means unseeded mode (decode everything).
131
132 STGC_RawDataContainer* rdoContainer{nullptr};
133 ATH_CHECK(initRdoContainer(ctx, rdoContainer));
134
135 if (rdoIdhVect.empty() || m_skipDecoding) return StatusCode::SUCCESS;
136
137 ROBFragmentList vecRobf;
138 m_robDataProvider->getROBData(ctx, m_allRobIds, vecRobf);
139
140 return convertIntoContainer(ctx, vecRobf, rdoIdhVect, *rdoContainer);
141}
142
143
144//==============================================================================
145StatusCode Muon::STGC_RawDataProviderTool::convert(const EventContext& ctx) const {
146 // method for unseeded mode. just decode everything.
147
148 STGC_RawDataContainer* rdoContainer{nullptr};
149 ATH_CHECK(initRdoContainer(ctx, rdoContainer));
150 if(m_skipDecoding) return StatusCode::SUCCESS;
151
152 ROBFragmentList vecRobf;
153 m_robDataProvider->getROBData(ctx, m_allRobIds, vecRobf);
154
155 // dummy hashID vector for the decoder (empty = unseeded mode)
156 const std::vector<IdentifierHash> rdoIdhVect;
157
158 return convertIntoContainer(ctx, vecRobf, rdoIdhVect, *rdoContainer);
159}
160
161StatusCode Muon::STGC_RawDataProviderTool::convert(const std::vector<uint32_t>& robIds, const EventContext& ctx) const
162{
163 STGC_RawDataContainer* rdoContainer{nullptr};
164 ATH_CHECK(initRdoContainer(ctx, rdoContainer));
165
166 if (robIds.empty() || m_skipDecoding) return StatusCode::SUCCESS;
167
168 ROBFragmentList vecRobf;
169
170 m_robDataProvider->getROBData(ctx, robIds, vecRobf);
171
172 // pass empty list of ID hashes, every ROB ID in list will be decoded
173 const std::vector<IdentifierHash> hashIDList;
174
175 return convertIntoContainer(ctx, vecRobf, hashIDList, *rdoContainer);
176
177}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
virtual void lock()=0
Interface to allow an object to lock itself when made const in SG.
IDC_WriteHandle getWriteHandle(IdentifierHash hash)
size_t size() const
Duplicate of fullSize for backwards compatability.
This is a "hash" representation of an Identifier.
StatusCode convertIntoContainer(const EventContext &ctx, const ROBFragmentList &fragements, const std::vector< IdentifierHash > &chamberHashes, STGC_RawDataContainer &target) const
Method that converts the ROBFragments into the passed container.
SG::WriteHandleKey< STGC_RawDataContainer > m_rdoContainerKey
RDO container key.
Gaudi::Property< bool > m_skipDecoding
Flag to skip decoding and write empty container.
StatusCode initRdoContainer(const EventContext &, STGC_RawDataContainer *&) const
ToolHandle< ISTGC_ROD_Decoder > m_decoder
Decoder for ROB fragment RDO conversion.
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
The ID helper.
virtual StatusCode initialize() override
Standard AlgTool method.
SG::UpdateHandleKey< STGC_RawDataCollection_Cache > m_rdoContainerCacheKey
virtual StatusCode convert(const EventContext &ctx) const override
ServiceHandle< IROBDataProviderSvc > m_robDataProvider
Rob Data Provider handle.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
pointer_type ptr()
Dereference the pointer.
eformat::ROBFragment< PointerType > ROBFragment
Definition RawEvent.h:27