ATLAS Offline Software
Loading...
Searching...
No Matches
ITkStripsRodDecoder.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 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;
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
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 oldSide {-1};
140 int linkNumber{0}; // Determined from header and may be changed for links using Rx redundancy
141
142 std::array<bool, N_STRIPS_PER_SIDE*N_SIDES> saved{};//defaults to false
143
144 // For MissingLinkHeaderError
146 std::unordered_set<IdentifierHash> foundHashes;
147 struct Hasher {
148 std::size_t operator()(const IdentifierHash &hash) const { return hash.value();}
149 };
150 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.
151 std::unordered_map<IdentifierHash, SCT_RDO_Container::IDC_WriteHandle, Hasher> writeHandleMap;
152
153 bool foundHeader{false};
154
156 writeHandleMap.reserve( 72);
157 rdoCollMap.reserve( 72 );
158 }
159
160 void reset() {
163 oldSide = -1;
164 groupSize = 0;
165 errors = 0;
166 saved.fill(false);
167 errorHit.clear();
168 };
169 void setOld() {
170 oldStrip = strip;
171 oldSide = side;
172 groupSize = 0;
173 }
174 void setSaved(const bool isOld, const int code) {
175 if (isOld) {
177 }
178 else {
179 saved.at( side*N_STRIPS_PER_SIDE + strip) = code;
180 }
181 }
182 bool isSaved(const bool isOld) {
183 if (isOld) {
184 unsigned int idx = static_cast<std::size_t>(oldSide*N_STRIPS_PER_SIDE + oldStrip);
185 return idx < saved.size() ? saved[idx] : true;
186 }
187 else {
188 const unsigned int idx = static_cast<unsigned int>(side*N_STRIPS_PER_SIDE + strip);
189 return idx < saved.size() ? saved[idx] : true;
190 }
191 }
192 bool isStripValid() const {
193 return static_cast<unsigned int>(strip) < N_STRIPS_PER_SIDE;
194 }
195 bool isOldStripValid() const {
196 return static_cast<unsigned int>(oldStrip) < N_STRIPS_PER_SIDE;
197 }
200 }
201 void setCollection(const SCT_ID* sctID,
202 const IdentifierHash& waferHash,
203 SCT_RDO_Container& rdoIDCont,
204 DataPool<SCT3_RawData>* dataItemsPool,
206 linkIDHash = waferHash;
207 collID = sctID->wafer_id(linkIDHash);
208 foundHashes.insert(linkIDHash);
209 if (rdoCollMap.count(linkIDHash)==0) { // The collection is not in the local map.
210 writeHandleMap.insert(std::pair<IdentifierHash, SCT_RDO_Container::IDC_WriteHandle>(linkIDHash, rdoIDCont.getWriteHandle(linkIDHash)));
211 if (writeHandleMap[linkIDHash].alreadyPresent()) { // The collection is already in the container.
212 rdoCollMap[linkIDHash] = nullptr;
213 writeHandleMap.erase(linkIDHash); // lock is released
214 }
215 else { // Create a new collection for linkIDHash
216 std::unique_ptr<SCT_RDO_Collection> rdoColl{std::make_unique<SCT_RDO_Collection>(linkIDHash)};
217 rdoColl->setIdentifier(collID);
218 if(dataItemsPool){
219 //pool will own
220 rdoColl->clear(SG::VIEW_ELEMENTS);
221 }
222 rdoCollMap[linkIDHash] = std::move(rdoColl);
223 errs.noerror(linkIDHash); // make sure the error information is filled for this hash
224 }
225 }
226 }
227 };
228
243 int makeRDO(const bool isOld,
244 SharedData& data,
245 CacheHelper& cache,
246 DataPool<SCT3_RawData>* dataItemsPool) const;
247
256 StatusCode addRODError(uint32_t rodID, SCT_ByteStreamErrors::ErrorType error,
258 const std::unordered_set<IdentifierHash>* foundHashes=nullptr) const;
266 StatusCode addSingleError(const IdentifierHash& hashID,
268 SCT_RodDecoderErrorsHelper& errs) const;
269
282 StatusCode processHeader(const uint16_t inData,
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
305 StatusCode processHccHeader(const uint16_t inData,
306 const uint8_t data8,
307 uint8_t& isHCCHeader,
308 const uint32_t robID,
309 SharedData& data,
310 SCT_RDO_Container& rdoIDCont,
311 DataPool<SCT3_RawData>* dataItemsPool,
312 CacheHelper& cache,
314 bool& hasError,
315 bool& breakNow,
316 const EventContext& ctx) const;
317
327 StatusCode processHits(const uint16_t inData,
328 const uint32_t robID,
329 SharedData& data,
330 SCT_RDO_Container& rdoIDCont,
331 DataPool<SCT3_RawData>* dataItemsPool,
332 CacheHelper& cache,
334 bool& hasError,
335 const EventContext& ctx) const;
336
339 const SCT_ID* m_itkStripsID{nullptr};
340
344
346 ToolHandle<IITkStripCablingTool> m_cabling{this,
347 "ITkStripCablingTool",
348 "ITkStripCablingTool",
349 "Tool to retrieve ITkStrip Cabling"};
350
352 ToolHandle<ISCT_ConfigurationConditionsTool> m_configTool{this,
353 "ConfigTool",
354 "SCT_ConfigurationConditionsTool/InDetSCT_ConfigurationConditionsTool",
355 "Tool to retrieve SCT Configuration Tool"};
356
358 mutable std::atomic_uint m_singleCondHitNumber{0};
359
361 mutable std::atomic_uint m_pairedCondHitNumber{0};
362
364 mutable std::atomic_uint m_firstExpHitNumber{0};
365
367 mutable std::atomic_uint m_evenExpHitNumber{0};
368
370 mutable std::atomic_uint m_lastExpHitNumber{0};
371
373 mutable std::atomic_uint m_headNumber{0};
374
376 mutable std::atomic_uint m_trailerNumber{0};
377
379 mutable std::atomic_uint m_headErrorBCID{0};
380
382 mutable std::atomic_uint m_headErrorLvl1ID{0};
383
385 mutable std::atomic_uint m_headErrorTimeout{0};
386
388 mutable std::atomic_uint m_headErrorFormatter{0};
389
391 mutable std::atomic_uint m_headErrorPreamble{0};
392
394 mutable std::atomic_uint m_trailerErrorOverflow{0};
395
397 mutable std::atomic_uint m_trailerErrorLimit{0};
398
400 mutable std::atomic_uint m_trailerErrorBit{0};
401
403 mutable std::atomic_uint m_configDataBit{0};
404
406 mutable std::atomic_uint m_flagErrorBit{0};
407
409 mutable std::atomic_uint m_condHit1Error{0};
410
412 mutable std::atomic_uint m_condHit2Error{0};
413
415 mutable std::atomic_uint m_chipNumberError{0};
416
418 mutable std::atomic_uint m_unknownDataFormat{0};
419
421 mutable std::atomic_uint m_nHits{0};
422
424 mutable std::atomic_uint m_nRDOs{0};
425
427 mutable std::atomic_uint m_maskedLinkNumber{0};
428
430 mutable std::atomic_uint m_maskedRODNumber{0};
431
433 mutable std::atomic_uint m_rodClockErrorNumber{0};
434
436 mutable std::atomic_uint m_truncatedRODNumber{0};
437
439 mutable std::atomic_uint m_numMissingLinkHeader{0};
440
442 std::vector<bool> m_swapPhiReadoutDirection{};
443};
444
445#endif //ITKSTRIP_RAWDATABYTESTREAM_ITKSTRIP_RODDECODER_H
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
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.
int makeRDO(const bool isOld, SharedData &data, CacheHelper &cache, DataPool< SCT3_RawData > *dataItemsPool) const
Builds RawData RDO and adds to RDO container.
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.
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
void setSaved(const bool isOld, const int code)
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