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
18
19#include "GaudiKernel/ToolHandle.h"
20
21#include <atomic>
22#include <cstdint>
23#include <string>
24#include <unordered_map>
25#include <unordered_set>
26#include <vector>
27#include <array>
28
29class IdentifierHash;
30
39public:
41 : errorsIDC{ idcContainer } {}
43 for (auto [id, err]: accumulatedErrors) {
44 errorsIDC.setOrDrop(id, err);
45 }
46 }
47 void noerror(const IdentifierHash id) {
48 accumulatedErrors[id]; // this adds 0 (no error) for an ID
49 }
50
54
56 if (accumulatedErrors[id]==0) {
57 accumulatedErrors.erase(id);
58 }
59 }
60
61 std::map<IdentifierHash, IDCInDetBSErrContainer::ErrorCode> accumulatedErrors;
63};
64
65
73class ITkStripsRodDecoder : public extends<AthAlgTool, IITkStripsRodDecoder>
74{
76 struct CacheHelper {
78 const std::vector<IdentifierHash>* vecHash = nullptr;
79 };
80
81 public:
82
83 using base_class::base_class;
84
86 virtual ~ITkStripsRodDecoder() = default;
87
89 virtual StatusCode initialize() override;
90
102 virtual StatusCode fillCollection(const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment& robFrag,
103 SCT_RDO_Container& rdoIDCont,
105 DataPool<SCT3_RawData>* dataItemsPool,
106 const EventContext& ctx,
107 const std::vector<IdentifierHash>* vecHash = nullptr) const override;
108
109 private:
110
119 }; //Check this numbers
120
122 struct SharedData {
123 static constexpr int INVALID_STRIP = N_STRIPS_PER_SIDE;
124
125 bool condensedMode{true}; // Condensed mode or Expanded mode for each link if superCondensedMode is false
126
127 // Variables necessary for makeRDO
129 int groupSize{0};
130 int timeBin{0};
131 IdentifierHash linkIDHash; // Determined from header and changed for links using Rx redundancy (waferHash)
132 Identifier collID; // Determined from linkIDHash (waferID)
133 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)
134 CacheHelper cache{}; // For the trigger
135 std::vector<int> errorHit;
136
137 int side {-1};
138 int linkNumber{0}; // Determined from header and may be changed for links using Rx redundancy
139
140 std::array<bool, N_STRIPS_PER_SIDE*N_SIDES> saved{};//defaults to false
141
142 // For MissingLinkHeaderError
144 std::unordered_set<IdentifierHash> foundHashes;
145 struct Hasher {
146 std::size_t operator()(const IdentifierHash &hash) const { return hash.value();}
147 };
148 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.
149 std::unordered_map<IdentifierHash, SCT_RDO_Container::IDC_WriteHandle, Hasher> writeHandleMap;
150
151 bool foundHeader{false};
152
154 writeHandleMap.reserve( 72);
155 rdoCollMap.reserve( 72 );
156 }
157
158 void reset() {
160 groupSize = 0;
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 ToolHandle<ISCT_ConfigurationConditionsTool> m_configTool{this,
328 "ConfigTool",
329 "SCT_ConfigurationConditionsTool/InDetSCT_ConfigurationConditionsTool",
330 "Tool to retrieve SCT Configuration Tool"};
331
333 mutable std::atomic_uint m_singleCondHitNumber{0};
334
336 mutable std::atomic_uint m_pairedCondHitNumber{0};
337
339 mutable std::atomic_uint m_firstExpHitNumber{0};
340
342 mutable std::atomic_uint m_evenExpHitNumber{0};
343
345 mutable std::atomic_uint m_lastExpHitNumber{0};
346
348 mutable std::atomic_uint m_headNumber{0};
349
351 mutable std::atomic_uint m_trailerNumber{0};
352
354 mutable std::atomic_uint m_headErrorBCID{0};
355
357 mutable std::atomic_uint m_headErrorLvl1ID{0};
358
360 mutable std::atomic_uint m_headErrorTimeout{0};
361
363 mutable std::atomic_uint m_headErrorFormatter{0};
364
366 mutable std::atomic_uint m_headErrorPreamble{0};
367
369 mutable std::atomic_uint m_trailerErrorOverflow{0};
370
372 mutable std::atomic_uint m_trailerErrorLimit{0};
373
375 mutable std::atomic_uint m_trailerErrorBit{0};
376
378 mutable std::atomic_uint m_configDataBit{0};
379
381 mutable std::atomic_uint m_flagErrorBit{0};
382
384 mutable std::atomic_uint m_condHit1Error{0};
385
387 mutable std::atomic_uint m_condHit2Error{0};
388
390 mutable std::atomic_uint m_chipNumberError{0};
391
393 mutable std::atomic_uint m_unknownDataFormat{0};
394
396 mutable std::atomic_uint m_nHits{0};
397
399 mutable std::atomic_uint m_nRDOs{0};
400
402 mutable std::atomic_uint m_maskedLinkNumber{0};
403
405 mutable std::atomic_uint m_maskedRODNumber{0};
406
408 mutable std::atomic_uint m_rodClockErrorNumber{0};
409
411 mutable std::atomic_uint m_truncatedRODNumber{0};
412
414 mutable std::atomic_uint m_numMissingLinkHeader{0};
415
417 std::vector<bool> m_swapPhiReadoutDirection{};
418};
419
420#endif //ITKSTRIP_RAWDATABYTESTREAM_ITKSTRIP_RODDECODER_H
interface file for tool that keeps track of errors in the bytestream.
interface file for service that keeps track of configuration conditions
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.
ToolHandle< ISCT_ConfigurationConditionsTool > m_configTool
Service that keeps track of configuration conditions.
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