ATLAS Offline Software
Loading...
Searching...
No Matches
SCT_RodDecoder.h
Go to the documentation of this file.
1// -*- C++ -*-
2
3/*
4 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
5*/
6
7#ifndef INDETRAWDATABYTESTREAM_SCT_RODDECODER_H
8#define INDETRAWDATABYTESTREAM_SCT_RODDECODER_H
9
12
20
21#include "GaudiKernel/ToolHandle.h"
22
23#include <atomic>
24#include <cstdint>
25#include <string>
26#include <unordered_map>
27#include <unordered_set>
28#include <vector>
29#include <array>
30
31class IdentifierHash;
32
33
42public:
44 : errorsIDC{ idcContainer } {}
46 for (auto [id, err]: accumulatedErrors) {
47 errorsIDC.setOrDrop(id, err);
48 }
49 }
50 void noerror(const IdentifierHash id) {
51 accumulatedErrors[id]; // this adds 0 (no error) for an ID
52 }
53
57
59 if (accumulatedErrors[id]==0) {
60 accumulatedErrors.erase(id);
61 }
62 }
63
64 std::map<IdentifierHash, IDCInDetBSErrContainer::ErrorCode> accumulatedErrors;
66};
67
68
76class SCT_RodDecoder : public extends<AthAlgTool, ISCT_RodDecoder>
77{
79 struct CacheHelper {
81 const std::vector<IdentifierHash>* vecHash;
82 };
83
84 public:
85
87 SCT_RodDecoder(const std::string& type, const std::string& name, const IInterface* parent);
88
90 virtual ~SCT_RodDecoder() = default;
91
93 virtual StatusCode initialize() override;
94
96 virtual StatusCode finalize() override;
97
109 virtual StatusCode fillCollection(const OFFLINE_FRAGMENTS_NAMESPACE::ROBFragment& robFrag,
110 SCT_RDO_Container& rdoIDCont,
112 DataPool<SCT3_RawData>* dataItemsPool,
113 const EventContext& ctx,
114 const std::vector<IdentifierHash>* vecHash = nullptr) const override;
115
116 private:
117
126 };
127
129 struct SharedData {
130 static constexpr int INVALID_STRIP = N_STRIPS_PER_SIDE;
131
132 bool condensedMode{true}; // Condensed mode or Expanded mode for each link if superCondensedMode is false
133
134 // Variables necessary for makeRDO
136 int groupSize{0};
137 int timeBin{0};
138 IdentifierHash linkIDHash; // Determined from header and changed for links using Rx redundancy (waferHash)
139 Identifier collID; // Determined from linkIDHash (waferID)
140 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)
141 CacheHelper cache{}; // For the trigger
142 std::vector<int> errorHit;
143
144 int side {-1};
145 int oldSide {-1};
147 int linkNumber{0}; // Determined from header and may be changed for links using Rx redundancy
148
149 std::array<bool, N_STRIPS_PER_SIDE*N_SIDES> saved{};//defaults to false
150
151 // For MissingLinkHeaderError
153 std::unordered_set<IdentifierHash> foundHashes;
154 struct Hasher {
155 std::size_t operator()(const IdentifierHash &hash) const { return hash.value();}
156 };
157 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.
158 std::unordered_map<IdentifierHash, SCT_RDO_Container::IDC_WriteHandle, Hasher> writeHandleMap;
159
160 bool foundHeader{false};
161
163 writeHandleMap.reserve( 72);
164 rdoCollMap.reserve( 72 );
165 }
166
167 void reset() {
170 oldSide = -1;
171 groupSize = 0;
172 errors = 0;
173 saved.fill(false);
174 errorHit.clear();
175 };
176 void setOld() {
177 oldStrip = strip;
178 oldSide = side;
179 groupSize = 0;
180 }
181 void setSaved(const bool isOld, const int code) {
182 if (isOld) {
184 }
185 else {
186 saved.at( side*N_STRIPS_PER_SIDE + strip) = code;
187 }
188 }
189 bool isSaved(const bool isOld) {
190 if (isOld) {
191 unsigned int idx = static_cast<std::size_t>(oldSide*N_STRIPS_PER_SIDE + oldStrip);
192 return idx < saved.size() ? saved[idx] : true;
193 }
194 else {
195 const unsigned int idx = static_cast<unsigned int>(side*N_STRIPS_PER_SIDE + strip);
196 return idx < saved.size() ? saved[idx] : true;
197 }
198 }
199 bool isStripValid() const {
200 return static_cast<unsigned int>(strip) < N_STRIPS_PER_SIDE;
201 }
202 bool isOldStripValid() const {
203 return static_cast<unsigned int>(oldStrip) < N_STRIPS_PER_SIDE;
204 }
207 }
208 void setCollection(const SCT_ID* sctID,
209 const IdentifierHash& waferHash,
210 SCT_RDO_Container& rdoIDCont,
211 DataPool<SCT3_RawData>* dataItemsPool,
213 linkIDHash = waferHash;
214 collID = sctID->wafer_id(linkIDHash);
215 foundHashes.insert(linkIDHash);
216 if (rdoCollMap.count(linkIDHash)==0) { // The collection is not in the local map.
217 writeHandleMap.insert(std::pair<IdentifierHash, SCT_RDO_Container::IDC_WriteHandle>(linkIDHash, rdoIDCont.getWriteHandle(linkIDHash)));
218 if (writeHandleMap[linkIDHash].alreadyPresent()) { // The collection is already in the container.
219 rdoCollMap[linkIDHash] = nullptr;
220 writeHandleMap.erase(linkIDHash); // lock is released
221 }
222 else { // Create a new collection for linkIDHash
223 std::unique_ptr<SCT_RDO_Collection> rdoColl{std::make_unique<SCT_RDO_Collection>(linkIDHash)};
224 rdoColl->setIdentifier(collID);
225 if(dataItemsPool){
226 //pool will own
227 rdoColl->clear(SG::VIEW_ELEMENTS);
228 }
229 rdoCollMap[linkIDHash] = std::move(rdoColl);
230 errs.noerror(linkIDHash); // make sure the error information is filled for this hash
231 }
232 }
233 }
234 };
235
250 int makeRDO(const bool isOld,
251 SharedData& data,
252 CacheHelper& cache,
253 DataPool<SCT3_RawData>* dataItemsPool) const;
254
263 StatusCode addRODError(uint32_t rodID, SCT_ByteStreamErrors::ErrorType error,
265 const std::unordered_set<IdentifierHash>* foundHashes=nullptr) const;
273 StatusCode addSingleError(const IdentifierHash& hashID,
275 SCT_RodDecoderErrorsHelper& errs) const;
276
284 StatusCode setFirstTempMaskedChip(const IdentifierHash& hashID,
285 unsigned int firstTempMaskedChip,
286 SCT_RodDecoderErrorsHelper& errs) const;
287
300 StatusCode processHeader(const uint16_t inData,
301 const uint32_t robID,
302 SharedData& data,
303 SCT_RDO_Container& rdoIDCont,
304 DataPool<SCT3_RawData>* dataItemsPool,
305 CacheHelper& cache,
307 bool& hasError,
308 bool& breakNow,
309 const EventContext& ctx) const;
310
322 StatusCode processSuperCondensedHit(const uint16_t inData,
323 const uint32_t robID,
324 SharedData& data,
325 SCT_RDO_Container& rdoIDCont,
326 DataPool<SCT3_RawData>* dataItemsPool,
327 CacheHelper& cache,
329 bool& hasError,
330 const EventContext& ctx) const;
331
343 StatusCode processCondensedHit(const uint16_t inData,
344 const uint32_t robID,
345 SharedData& data,
346 SCT_RDO_Container& rdoIDCont,
347 DataPool<SCT3_RawData>* dataItemsPool,
348 CacheHelper& cache,
350 bool& hasError,
351 const EventContext& ctx) const;
352
364 StatusCode processExpandedHit(const uint16_t inData,
365 const uint32_t robID,
366 SharedData& data,
367 SCT_RDO_Container& rdoIDCont,
368 DataPool<SCT3_RawData>* dataItemsPool,
369 CacheHelper& cache,
371 bool& hasError,
372 const EventContext& ctx) const;
373
383 StatusCode processABCDError(const uint16_t inData,
384 const uint32_t robID,
385 SharedData& data,
387 bool& hasError) const;
388
398 StatusCode processRawData(const uint16_t inData,
399 const uint32_t robID,
400 SharedData& data,
402 bool& hasError) const;
403
413 StatusCode processTrailer(const uint16_t inData,
414 const uint32_t robID,
415 SharedData& data,
417 bool& hasError) const;
418
421 const SCT_ID* m_sctID{nullptr};
422
426
428 ToolHandle<ISCT_CablingTool> m_cabling{this,
429 "SCT_CablingTool",
430 "SCT_CablingTool",
431 "Tool to retrieve SCT Cabling"};
432
434 ToolHandle<ISCT_ConfigurationConditionsTool> m_configTool{this,
435 "ConfigTool",
436 "SCT_ConfigurationConditionsTool/InDetSCT_ConfigurationConditionsTool",
437 "Tool to retrieve SCT Configuration Tool"};
438
440 mutable std::atomic_uint m_singleCondHitNumber{0};
441
443 mutable std::atomic_uint m_pairedCondHitNumber{0};
444
446 mutable std::atomic_uint m_firstExpHitNumber{0};
447
449 mutable std::atomic_uint m_evenExpHitNumber{0};
450
452 mutable std::atomic_uint m_lastExpHitNumber{0};
453
455 mutable std::atomic_uint m_headNumber{0};
456
458 mutable std::atomic_uint m_trailerNumber{0};
459
461 mutable std::atomic_uint m_headErrorBCID{0};
462
464 mutable std::atomic_uint m_headErrorLvl1ID{0};
465
467 mutable std::atomic_uint m_headErrorTimeout{0};
468
470 mutable std::atomic_uint m_headErrorFormatter{0};
471
473 mutable std::atomic_uint m_headErrorPreamble{0};
474
476 mutable std::atomic_uint m_trailerErrorOverflow{0};
477
479 mutable std::atomic_uint m_trailerErrorLimit{0};
480
482 mutable std::atomic_uint m_trailerErrorBit{0};
483
485 mutable std::atomic_uint m_configDataBit{0};
486
488 mutable std::atomic_uint m_flagErrorBit{0};
489
491 mutable std::atomic_uint m_condHit1Error{0};
492
494 mutable std::atomic_uint m_condHit2Error{0};
495
497 mutable std::atomic_uint m_chipNumberError{0};
498
500 mutable std::atomic_uint m_unknownDataFormat{0};
501
503 mutable std::atomic_uint m_nHits{0};
504
506 mutable std::atomic_uint m_nRDOs{0};
507
509 mutable std::atomic_uint m_maskedLinkNumber{0};
510
512 mutable std::atomic_uint m_maskedRODNumber{0};
513
515 mutable std::atomic_uint m_rodClockErrorNumber{0};
516
518 mutable std::atomic_uint m_truncatedRODNumber{0};
519
521 mutable std::atomic_uint m_numMissingLinkHeader{0};
522
524 std::vector<bool> m_swapPhiReadoutDirection{};
525};
526
527#endif //SCT_RAWDATABYTESTREAM_SCT_RODDECODER_H
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
interface file for tool that keeps track of errors in the bytestream.
Header file for abstract interface to SCT cabling tool.
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...
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)
std::atomic_uint m_firstExpHitNumber
Total number of first strips with hit decoded in expanded mode.
StatusCode addSingleError(const IdentifierHash &hashID, SCT_ByteStreamErrors::ErrorType error, SCT_RodDecoderErrorsHelper &errs) const
Add single eror.
std::atomic_uint m_singleCondHitNumber
Total number of single strips with hit decoded in condensed mode.
std::atomic_uint m_nHits
Total number of SCT hits in ByteStream.
StatusCode processRawData(const uint16_t inData, const uint32_t robID, SharedData &data, SCT_RodDecoderErrorsHelper &errs, bool &hasError) const
Process raw data word.
ToolHandle< ISCT_ConfigurationConditionsTool > m_configTool
Service that keeps track of configuration conditions.
SCT_DecoderNumbers
Define frequently used magic numbers.
std::atomic_uint m_pairedCondHitNumber
Total number of paired strips with hit decoded in condensed mode.
StatusCode processCondensedHit(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 hit word in Condensed mode.
std::atomic_uint m_headNumber
Total number of decoded header data.
StatusCode setFirstTempMaskedChip(const IdentifierHash &hashID, unsigned int firstTempMaskedChip, SCT_RodDecoderErrorsHelper &errs) const
Set first temporarily masked chip information from byte stream trailer.
IdContext m_contextSCT
"Context" of an expanded identifier (ExpandedIdentifier) for compact or hash versions (Identifier32 o...
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.
std::atomic_uint m_headErrorFormatter
Total number of formatter errors in the header data.
std::atomic_uint m_headErrorLvl1ID
Total number of Lvl1ID errors in the header data.
StatusCode processSuperCondensedHit(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 hit word in Super-Condensed mode.
std::atomic_uint m_truncatedRODNumber
Total number of truncated ROBFragments.
std::atomic_uint m_flagErrorBit
Total number of flag error data.
std::atomic_uint m_maskedRODNumber
Total number of masked RDOs.
std::atomic_uint m_headErrorTimeout
Total number of timeout errors in the header data.
std::atomic_uint m_trailerErrorBit
Total number of trailer bit errors.
StatusCode processABCDError(const uint16_t inData, const uint32_t robID, SharedData &data, SCT_RodDecoderErrorsHelper &errs, bool &hasError) const
Process ABCD error.
SCT_RodDecoder(const std::string &type, const std::string &name, const IInterface *parent)
Constructor.
std::atomic_uint m_rodClockErrorNumber
Total number of ROD clock errors.
std::atomic_uint m_trailerErrorOverflow
Total number of overflow errors in the trailer data.
const SCT_ID * m_sctID
Identifier helper class for the SCT subdetector that creates compact Identifier objects and Identifie...
std::atomic_uint m_headErrorPreamble
Total number of preamble errors in the header data.
std::vector< bool > m_swapPhiReadoutDirection
Swap phi readout direction.
std::atomic_uint m_condHit1Error
Total number of first hit data errors.
virtual StatusCode finalize() override
Finalize.
std::atomic_uint m_chipNumberError
Total number of chip number errors.
virtual StatusCode initialize() override
Initialize.
StatusCode processTrailer(const uint16_t inData, const uint32_t robID, SharedData &data, SCT_RodDecoderErrorsHelper &errs, bool &hasError) const
Process trailer word.
std::atomic_uint m_maskedLinkNumber
Total number of masked links in the header data.
StatusCode processExpandedHit(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 hit word in Expanded mode.
std::atomic_uint m_nRDOs
Total number of SCT RDOs created.
std::atomic_uint m_unknownDataFormat
Total number of unknown data formats.
std::atomic_uint m_headErrorBCID
Total number of BCID errors in the header data.
std::atomic_uint m_lastExpHitNumber
Total number of last consecutive strips with hit decoded in expanded mode.
ToolHandle< ISCT_CablingTool > m_cabling
Providing mappings of online and offline identifiers and also serial numbers.
std::atomic_uint m_trailerNumber
Total number of decoded trailer data.
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.
std::atomic_uint m_configDataBit
Total number of configuration data for raw data.
virtual ~SCT_RodDecoder()=default
Destructor.
int makeRDO(const bool isOld, SharedData &data, CacheHelper &cache, DataPool< SCT3_RawData > *dataItemsPool) const
Builds RawData RDO and adds to RDO container.
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_evenExpHitNumber
Total number of consecutive paired strips with hit decoded in expanded mode.
std::atomic_uint m_numMissingLinkHeader
Total number of missing link headers.
std::atomic_uint m_trailerErrorLimit
Total number of header trailer limit errors in the trailer data.
std::atomic_uint m_condHit2Error
Total number second hit data errors.
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::vector< int > errorHit
void setSaved(const bool isOld, const int code)
std::array< bool, N_STRIPS_PER_SIDE *N_SIDES > saved
std::unordered_set< IdentifierHash > foundHashes
std::unordered_map< IdentifierHash, SCT_RDO_Container::IDC_WriteHandle, Hasher > writeHandleMap
bool isSaved(const bool isOld)
std::unordered_map< IdentifierHash, std::unique_ptr< SCT_RDO_Collection >, Hasher > rdoCollMap
static constexpr int INVALID_STRIP
void setCollection(const SCT_ID *sctID, const IdentifierHash &waferHash, SCT_RDO_Container &rdoIDCont, DataPool< SCT3_RawData > *dataItemsPool, SCT_RodDecoderErrorsHelper &errs)