ATLAS Offline Software
Loading...
Searching...
No Matches
ITkStripsRodDecoder.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef ITKRAWDATABYTESTREAM_ITK_STRIPS_RODDECODER_H
6#define ITKRAWDATABYTESTREAM_ITK_STRIPS_RODDECODER_H
7
10
17
18#include "GaudiKernel/ToolHandle.h"
19
20#include <atomic>
21#include <cstdint>
22#include <string>
23#include <unordered_map>
24#include <unordered_set>
25#include <vector>
26#include <array>
27
28class IdentifierHash;
29
38public:
40 : errorsIDC{ idcContainer } {}
42 for (auto [id, err]: accumulatedErrors) {
43 errorsIDC.setOrDrop(id, err);
44 }
45 }
46 void noerror(const IdentifierHash id) {
47 accumulatedErrors[id]; // this adds 0 (no error) for an ID
48 }
49
53
55 if (accumulatedErrors[id]==0) {
56 accumulatedErrors.erase(id);
57 }
58 }
59
60 std::map<IdentifierHash, IDCInDetBSErrContainer::ErrorCode> accumulatedErrors;
62};
63
64
72class ITkStripsRodDecoder : public extends<AthAlgTool, IITkStripsRodDecoder>
73{
75 struct CacheHelper {
77 const std::vector<IdentifierHash>* vecHash = nullptr;
78 };
79
80 public:
81
82 using base_class::base_class;
83
85 virtual ~ITkStripsRodDecoder() = default;
86
88 virtual StatusCode initialize() override;
89
101 virtual StatusCode fillCollection(const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment& robFrag,
102 SCT_RDO_Container& rdoIDCont,
104 DataPool<SCT3_RawData>* dataItemsPool,
105 const EventContext& ctx,
106 const std::vector<IdentifierHash>* vecHash = nullptr) const override;
107
108 private:
109
118 }; //Check this numbers
119
121 struct SharedData {
122 static constexpr int INVALID_STRIP = N_STRIPS_PER_SIDE;
123
124 bool condensedMode{true}; // Condensed mode or Expanded mode for each link if superCondensedMode is false
125
126 // Variables necessary for makeRDO
128 int groupSize{0};
129 int timeBin{2};
130 IdentifierHash linkIDHash; // Determined from header and changed for links using Rx redundancy (waferHash)
131 Identifier collID; // Determined from linkIDHash (waferID)
132 int errors{0}; // Encodes the errors on the header (bit 4: error in condensed mode 1st hit, bit 5: error in condensed mode 2nd hit)
133 CacheHelper cache{}; // For the trigger
134 std::vector<int> errorHit;
135
136 int side {-1};
137 int linkNumber{0}; // Determined from header and may be changed for links using Rx redundancy
138
139 std::array<bool, N_STRIPS_PER_SIDE*N_SIDES> saved{};//defaults to false
140
141 // For MissingLinkHeaderError
143 std::unordered_set<IdentifierHash> foundHashes;
144 struct Hasher {
145 std::size_t operator()(const IdentifierHash &hash) const { return hash.value();}
146 };
147 std::unordered_map<IdentifierHash, std::unique_ptr<SCT_RDO_Collection>, Hasher> rdoCollMap; // If SCT_RDO_Collection* is nullptr, it means the collection is already present in the container.
148 std::unordered_map<IdentifierHash, SCT_RDO_Container::IDC_WriteHandle, Hasher> writeHandleMap;
149
150 bool foundHeader{false};
151
153 writeHandleMap.reserve( 72);
154 rdoCollMap.reserve( 72 );
155 }
156
157 void reset() {
159 groupSize = 0;
160 timeBin = 2;
161 errors = 0;
162 saved.fill(false);
163 errorHit.clear();
164 };
165 void setSaved(const int code) {
166 saved.at(side*N_STRIPS_PER_SIDE + strip) = code;
167 }
168 bool isSaved() {
169 unsigned int idx = static_cast<std::size_t>(side*N_STRIPS_PER_SIDE + strip);
170 return idx < saved.size() ? saved[idx] : true;
171 }
172 bool isStripValid() const {
173 return static_cast<unsigned int>(strip) < N_STRIPS_PER_SIDE;
174 }
177 }
178 void setCollection(const SCT_ID* sctID,
179 const IdentifierHash& waferHash,
180 SCT_RDO_Container& rdoIDCont,
181 DataPool<SCT3_RawData>* dataItemsPool,
183 linkIDHash = waferHash;
184 collID = sctID->wafer_id(linkIDHash);
185 foundHashes.insert(linkIDHash);
186 if (rdoCollMap.count(linkIDHash)==0) { // The collection is not in the local map.
187 writeHandleMap.insert(std::pair<IdentifierHash, SCT_RDO_Container::IDC_WriteHandle>(linkIDHash, rdoIDCont.getWriteHandle(linkIDHash)));
188 if (writeHandleMap[linkIDHash].alreadyPresent()) { // The collection is already in the container.
189 rdoCollMap[linkIDHash] = nullptr;
190 writeHandleMap.erase(linkIDHash); // lock is released
191 }
192 else { // Create a new collection for linkIDHash
193 std::unique_ptr<SCT_RDO_Collection> rdoColl{std::make_unique<SCT_RDO_Collection>(linkIDHash)};
194 rdoColl->setIdentifier(collID);
195 if(dataItemsPool){
196 //pool will own
197 rdoColl->clear(SG::VIEW_ELEMENTS);
198 }
199 rdoCollMap[linkIDHash] = std::move(rdoColl);
200 errs.noerror(linkIDHash); // make sure the error information is filled for this hash
201 }
202 }
203 }
204 };
205
219 int makeRDO(SharedData& data,
220 CacheHelper& cache,
221 DataPool<SCT3_RawData>* dataItemsPool) const;
222
231 StatusCode addRODError(uint32_t rodID, SCT_ByteStreamErrors::ErrorType error,
233 const std::unordered_set<IdentifierHash>* foundHashes=nullptr) const;
241 StatusCode addSingleError(const IdentifierHash& hashID,
243 SCT_RodDecoderErrorsHelper& errs) const;
244
257 StatusCode processHeader(const uint16_t inData,
258 const uint32_t robID,
259 SharedData& data,
260 SCT_RDO_Container& rdoIDCont,
261 DataPool<SCT3_RawData>* dataItemsPool,
262 CacheHelper& cache,
264 bool& hasError,
265 bool& breakNow,
266 const EventContext& ctx) const;
267
280 StatusCode processHccHeader(const uint16_t inData,
281 const uint8_t data8,
282 uint8_t& isHCCHeader,
283 const uint32_t robID,
284 SharedData& data,
285 SCT_RDO_Container& rdoIDCont,
286 DataPool<SCT3_RawData>* dataItemsPool,
287 CacheHelper& cache,
289 bool& hasError,
290 bool& breakNow,
291 const EventContext& ctx) const;
292
302 StatusCode processHits(const uint16_t inData,
303 const uint32_t robID,
304 SharedData& data,
305 SCT_RDO_Container& rdoIDCont,
306 DataPool<SCT3_RawData>* dataItemsPool,
307 CacheHelper& cache,
309 bool& hasError,
310 const EventContext& ctx) const;
311
314 const SCT_ID* m_itkStripsID{nullptr};
315
319
321 ToolHandle<IITkStripCablingTool> m_cabling{this,
322 "ITkStripCablingTool",
323 "ITkStripCablingTool",
324 "Tool to retrieve ITkStrip Cabling"};
325
327 mutable std::atomic_uint m_singleCondHitNumber{0};
328
330 mutable std::atomic_uint m_pairedCondHitNumber{0};
331
333 mutable std::atomic_uint m_firstExpHitNumber{0};
334
336 mutable std::atomic_uint m_evenExpHitNumber{0};
337
339 mutable std::atomic_uint m_lastExpHitNumber{0};
340
342 mutable std::atomic_uint m_headNumber{0};
343
345 mutable std::atomic_uint m_trailerNumber{0};
346
348 mutable std::atomic_uint m_headErrorBCID{0};
349
351 mutable std::atomic_uint m_headErrorLvl1ID{0};
352
354 mutable std::atomic_uint m_headErrorTimeout{0};
355
357 mutable std::atomic_uint m_headErrorFormatter{0};
358
360 mutable std::atomic_uint m_headErrorPreamble{0};
361
363 mutable std::atomic_uint m_trailerErrorOverflow{0};
364
366 mutable std::atomic_uint m_trailerErrorLimit{0};
367
369 mutable std::atomic_uint m_trailerErrorBit{0};
370
372 mutable std::atomic_uint m_configDataBit{0};
373
375 mutable std::atomic_uint m_flagErrorBit{0};
376
378 mutable std::atomic_uint m_condHit1Error{0};
379
381 mutable std::atomic_uint m_condHit2Error{0};
382
384 mutable std::atomic_uint m_chipNumberError{0};
385
387 mutable std::atomic_uint m_unknownDataFormat{0};
388
390 mutable std::atomic_uint m_nHits{0};
391
393 mutable std::atomic_uint m_nRDOs{0};
394
396 mutable std::atomic_uint m_maskedLinkNumber{0};
397
399 mutable std::atomic_uint m_maskedRODNumber{0};
400
402 mutable std::atomic_uint m_rodClockErrorNumber{0};
403
405 mutable std::atomic_uint m_truncatedRODNumber{0};
406
408 mutable std::atomic_uint m_numMissingLinkHeader{0};
409
411 std::vector<bool> m_swapPhiReadoutDirection{};
412};
413
414#endif //ITKSTRIP_RAWDATABYTESTREAM_ITKSTRIP_RODDECODER_H
interface file for tool that keeps track of errors in the bytestream.
Define SCT byte stream errors and utility methods.
This is an Identifier helper class for the SCT subdetector.
InDetRawDataContainer< InDetRawDataCollection< SCT_RDORawData > > SCT_RDO_Container
a typed memory pool that saves time spent allocation small object.
Definition DataPool.h:63
IDC like storage for BS errors, TODO, customise implementation further so that we store int rather th...
std::atomic_uint m_headErrorTimeout
Total number of timeout errors in the header data.
StatusCode addSingleError(const IdentifierHash &hashID, SCT_ByteStreamErrors::ErrorType error, SCT_RodDecoderErrorsHelper &errs) const
Add single eror.
std::atomic_uint m_lastExpHitNumber
Total number of last consecutive strips with hit decoded in expanded mode.
std::atomic_uint m_headErrorPreamble
Total number of preamble errors in the header data.
virtual ~ITkStripsRodDecoder()=default
Destructor.
std::atomic_uint m_unknownDataFormat
Total number of unknown data formats.
std::atomic_uint m_singleCondHitNumber
Total number of single strips with hit decoded in condensed mode.
std::atomic_uint m_headNumber
Total number of decoded header data.
std::atomic_uint m_chipNumberError
Total number of chip number errors.
int makeRDO(SharedData &data, CacheHelper &cache, DataPool< SCT3_RawData > *dataItemsPool) const
Builds RawData RDO and adds to RDO container.
std::atomic_uint m_truncatedRODNumber
Total number of truncated ROBFragments.
std::atomic_uint m_evenExpHitNumber
Total number of consecutive paired strips with hit decoded in expanded mode.
StatusCode processHeader(const uint16_t inData, const uint32_t robID, SharedData &data, SCT_RDO_Container &rdoIDCont, DataPool< SCT3_RawData > *dataItemsPool, CacheHelper &cache, SCT_RodDecoderErrorsHelper &errs, bool &hasError, bool &breakNow, const EventContext &ctx) const
Process header word.
StatusCode processHits(const uint16_t inData, const uint32_t robID, SharedData &data, SCT_RDO_Container &rdoIDCont, DataPool< SCT3_RawData > *dataItemsPool, CacheHelper &cache, SCT_RodDecoderErrorsHelper &errs, bool &hasError, const EventContext &ctx) const
Process raw data word.
std::atomic_uint m_headErrorFormatter
Total number of formatter errors in the header data.
std::atomic_uint m_condHit2Error
Total number second hit data errors.
virtual StatusCode initialize() override
Initialize.
std::atomic_uint m_trailerErrorBit
Total number of trailer bit errors.
std::atomic_uint m_nRDOs
Total number of SCT RDOs created.
ToolHandle< IITkStripCablingTool > m_cabling
Providing mappings of online and offline identifiers and also serial numbers.
std::atomic_uint m_nHits
Total number of SCT hits in ByteStream.
const SCT_ID * m_itkStripsID
Identifier helper class for the SCT subdetector that creates compact Identifier objects and Identifie...
std::atomic_uint m_maskedLinkNumber
Total number of masked links in the header data.
std::atomic_uint m_flagErrorBit
Total number of flag error data.
std::atomic_uint m_configDataBit
Total number of configuration data for raw data.
std::atomic_uint m_trailerNumber
Total number of decoded trailer data.
std::atomic_uint m_firstExpHitNumber
Total number of first strips with hit decoded in expanded mode.
std::atomic_uint m_headErrorBCID
Total number of BCID errors in the header data.
StatusCode processHccHeader(const uint16_t inData, const uint8_t data8, uint8_t &isHCCHeader, const uint32_t robID, SharedData &data, SCT_RDO_Container &rdoIDCont, DataPool< SCT3_RawData > *dataItemsPool, CacheHelper &cache, SCT_RodDecoderErrorsHelper &errs, bool &hasError, bool &breakNow, const EventContext &ctx) const
Process header word.
virtual StatusCode fillCollection(const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment &robFrag, SCT_RDO_Container &rdoIDCont, IDCInDetBSErrContainer &errs, DataPool< SCT3_RawData > *dataItemsPool, const EventContext &ctx, const std::vector< IdentifierHash > *vecHash=nullptr) const override
Fill SCT RDO Collection with decoded ROB data.
std::atomic_uint m_trailerErrorLimit
Total number of header trailer limit errors in the trailer data.
std::atomic_uint m_headErrorLvl1ID
Total number of Lvl1ID errors in the header data.
std::atomic_uint m_numMissingLinkHeader
Total number of missing link headers.
std::atomic_uint m_maskedRODNumber
Total number of masked RDOs.
std::atomic_uint m_trailerErrorOverflow
Total number of overflow errors in the trailer data.
std::atomic_uint m_pairedCondHitNumber
Total number of paired strips with hit decoded in condensed mode.
IdContext m_contextITk
"Context" of an expanded identifier (ExpandedIdentifier) for compact or hash versions (Identifier32 o...
std::atomic_uint m_rodClockErrorNumber
Total number of ROD clock errors.
ITk_DecoderNumbers
Define frequently used magic numbers.
std::atomic_uint m_condHit1Error
Total number of first hit data errors.
std::vector< bool > m_swapPhiReadoutDirection
Swap phi readout direction.
StatusCode addRODError(uint32_t rodID, SCT_ByteStreamErrors::ErrorType error, SCT_RodDecoderErrorsHelper &errs, const std::unordered_set< IdentifierHash > *foundHashes=nullptr) const
Add an error for each wafer in the problematic ROD.
This class saves the "context" of an expanded identifier (ExpandedIdentifier) for compact or hash ver...
Definition IdContext.h:26
IDC_WriteHandle getWriteHandle(IdentifierHash hash)
This is a "hash" representation of an Identifier.
This is an Identifier helper class for the SCT subdetector.
Definition SCT_ID.h:68
Identifier wafer_id(int barrel_ec, int layer_disk, int phi_module, int eta_module, int side) const
For a single side of module.
Definition SCT_ID.h:459
allows to accumulate errors in one fillColection call
void add(const IdentifierHash id, SCT_ByteStreamErrors::ErrorType etype)
std::map< IdentifierHash, IDCInDetBSErrContainer::ErrorCode > accumulatedErrors
SCT_RodDecoderErrorsHelper(IDCInDetBSErrContainer &idcContainer)
void removeIfEmpty(const IdentifierHash id)
IDCInDetBSErrContainer & errorsIDC
void noerror(const IdentifierHash id)
eformat::ROBFragment< PointerType > ROBFragment
Definition RawEvent.h:27
ErrorType
SCT byte stream error type enums used in SCT_RodDecoder, SCT_ByteStreamErrorsTool,...
void addError(IDCInDetBSErrContainer::ErrorCode &errWord, ErrorType errType)
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Temp object to help with trigger caching.
const std::vector< IdentifierHash > * vecHash
std::size_t operator()(const IdentifierHash &hash) const
std::unordered_map< IdentifierHash, SCT_RDO_Container::IDC_WriteHandle, Hasher > writeHandleMap
std::array< bool, N_STRIPS_PER_SIDE *N_SIDES > saved
void setCollection(const SCT_ID *sctID, const IdentifierHash &waferHash, SCT_RDO_Container &rdoIDCont, DataPool< SCT3_RawData > *dataItemsPool, SCT_RodDecoderErrorsHelper &errs)
std::unordered_set< IdentifierHash > foundHashes
std::unordered_map< IdentifierHash, std::unique_ptr< SCT_RDO_Collection >, Hasher > rdoCollMap