ATLAS Offline Software
SCT_ByteStreamErrorsTool.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 /*
4  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
5 */
6 
13 #ifndef SCT_ByteStreamErrorsTool_h
14 #define SCT_ByteStreamErrorsTool_h
15 
19 
21 #include "Identifier/IdContext.h"
22 #include "Identifier/Identifier.h"
30 
32 #include "GaudiKernel/EventContext.h"
33 #include "GaudiKernel/EventIDBase.h"
34 
36 #include <array>
37 #include <atomic>
38 #include <functional>
39 #include <unordered_map>
40 #include <vector>
41 
43 class SCT_ID;
44 
64 class SCT_ByteStreamErrorsTool: public extends<AthAlgTool, ISCT_ByteStreamErrorsTool> {
65 
66 public:
67  //@name Tool methods
69  SCT_ByteStreamErrorsTool(const std::string& type, const std::string& name, const IInterface* parent);
70  virtual ~SCT_ByteStreamErrorsTool() = default;
71  virtual StatusCode initialize() override;
72  virtual StatusCode finalize() override;
74 
75  virtual bool canReportAbout(InDetConditions::Hierarchy h) const override;
76 
78  virtual bool isGood(const Identifier& elementId, InDetConditions::Hierarchy h=InDetConditions::DEFAULT) const override;
79  virtual bool isGood(const Identifier& elementId, const EventContext& ctx, InDetConditions::Hierarchy h=InDetConditions::DEFAULT) const override;
80  virtual bool isGood(const IdentifierHash& elementIdHash) const override;
81  virtual bool isGood(const IdentifierHash& elementIdHash, const EventContext& ctx) const override;
82  virtual void getDetectorElementStatus(const EventContext& ctx, InDet::SiDetectorElementStatus &element_status,
84 
85  virtual std::set<IdentifierHash> getErrorSet(int errorType, const EventContext& ctx) const override; // Used by SCTRawDataProviderTool and others
86  virtual std::set<IdentifierHash> getErrorSet(int errorType) const override; // Used by SCTRawDataProviderTool and others
87 
88  virtual unsigned int tempMaskedChips(const Identifier& moduleId, const EventContext& ctx) const override; // Internally used
89  virtual unsigned int tempMaskedChips(const Identifier& moduleId) const override;
90  virtual unsigned int abcdErrorChips(const Identifier& moduleId) const override; // Internally used
91  virtual unsigned int abcdErrorChips(const Identifier& moduleId, const EventContext& ctx) const override; // Internally used
92 
93 
94 private:
96 
97  ToolHandle<ISCT_ConfigurationConditionsTool> m_config{this, "ConfigTool",
98  "SCT_ConfigurationConditionsTool/InDetSCT_ConfigurationConditionsTool", "Tool to retrieve SCT Configuration Tool"};
99 
100  SG::ReadHandleKey<IDCInDetBSErrContainer> m_bsIDCErrContainerName{this, "IDCByteStreamErrContainer", "SCT_ByteStreamErrs", "SCT BS error key for IDC variant"};
101  SG::ReadCondHandleKey<InDetDD::SiDetectorElementCollection> m_SCTDetEleCollKey{this, "SCTDetEleCollKey", "SCT_DetectorElementCollection", "Key of SiDetectorElementCollection for SCT"};
102 
103  const SCT_ID* m_sct_id{nullptr};
106 
108  struct IDCCacheEntry {
109  EventContext::ContextEvt_t eventId{EventContext::INVALID_CONTEXT_EVT}; // invalid event ID for the start
111  // infomations in granularity of Chips
112  // misisng value mean that the map need updating
113  // 0 as the value denotes no error
114  // error encoding is as follows: pattern for a module has length of 6 bits, side 0 is encoded in bits 0-5, side 1 in bits 6-11
115  // so bit 0 is for chip 0 on side 0, bit 1 is for chip 1 on side 0, ..., and bit 11 is for chip 5 on side 1
116  std::unordered_map<size_t, unsigned int> tempMaskedChips;
117  std::unordered_map<size_t, unsigned int> abcdErrorChips;
118 
119 
120  //Record the set number of the idcErrContainer, if the set numbers are the same, skip the fillData process to save time.
121  unsigned int m_set_number = 0;
122 
123  void reset(EventContext::ContextEvt_t evtId, const IDCInDetBSErrContainer_Cache* cache) {
124  eventId = evtId;
125  IDCCache = cache;
126  m_set_number = 0;
127  tempMaskedChips.clear();
128  abcdErrorChips.clear();
129  }
130 
131  bool needsUpdate(const EventContext& ctx) const {
132  return eventId != ctx.evt() or eventId == EventContext::INVALID_CONTEXT_EVT;
133  }
134 
135  };
137 
141  [[nodiscard]] const IDCInDetBSErrContainer* getContainer(const EventContext& ctx) const;
142  mutable std::atomic_uint m_nRetrievalFailure{0};
143 
149  [[nodiscard]] IDCCacheEntry* getCacheEntry(const EventContext& ctx) const;
150 
154  StatusCode fillData(const EventContext& ctx) const;
155 
156  bool isGoodChip(const Identifier& stripId, const EventContext& ctx) const;
157  int getChip(const Identifier& stripId, const EventContext& ctx) const;
158 
159  // For isRODSimulatedData, HVisOn and isCondensedReadout
160  const InDetDD::SiDetectorElement* getDetectorElement(const IdentifierHash& waferHash, const EventContext& ctx) const;
161 
166  std::pair<StatusCode, unsigned int> getErrorCodeWithCacheUpdate(const Identifier& id, const EventContext& ctx, std::unordered_map<size_t, unsigned int>& whereExected) const;
167 
168 };
169 
170 #endif // SCT_ByteStreamErrorsTool_h
ReadHandleKey.h
Property holding a SG store/key/clid from which a ReadHandle is made.
SCT_ByteStreamErrorsTool::m_config
ToolHandle< ISCT_ConfigurationConditionsTool > m_config
Definition: SCT_ByteStreamErrorsTool.h:97
ISCT_ByteStreamErrorsTool.h
SCT_ByteStreamErrorsTool::finalize
virtual StatusCode finalize() override
Finalize.
Definition: SCT_ByteStreamErrorsTool.cxx:52
SCT_ByteStreamErrorsTool::getErrorSet
virtual std::set< IdentifierHash > getErrorSet(int errorType, const EventContext &ctx) const override
The accessor method that can be used by clients to retrieve a set of IdHashes of wafers with a given ...
Definition: SCT_ByteStreamErrorsTool.cxx:331
IDCInDetBSErrContainer
IDC like storage for BS errors, TODO, customise implementation further so that we store int rather th...
Definition: IDCInDetBSErrContainer.h:19
SCT_ByteStreamErrorsTool::abcdErrorChips
virtual unsigned int abcdErrorChips(const Identifier &moduleId) const override
Definition: SCT_ByteStreamErrorsTool.cxx:474
SCT_ByteStreamErrorsTool::isGoodChip
bool isGoodChip(const Identifier &stripId, const EventContext &ctx) const
Definition: SCT_ByteStreamErrorsTool.cxx:268
SCT_ByteStreamErrorsTool::IDCCacheEntry::needsUpdate
bool needsUpdate(const EventContext &ctx) const
Definition: SCT_ByteStreamErrorsTool.h:131
SCT_ByteStreamErrorsTool::getChip
int getChip(const Identifier &stripId, const EventContext &ctx) const
Definition: SCT_ByteStreamErrorsTool.cxx:312
InDetConditions::Hierarchy
Hierarchy
Definition: InDetHierarchy.h:14
SCT_ByteStreamErrorsTool::m_sct_id
const SCT_ID * m_sct_id
Definition: SCT_ByteStreamErrorsTool.h:103
SCT_ByteStreamErrorsTool::tempMaskedChips
virtual unsigned int tempMaskedChips(const Identifier &moduleId, const EventContext &ctx) const override
Definition: SCT_ByteStreamErrorsTool.cxx:435
SG::ReadHandleKey< IDCInDetBSErrContainer >
SCT_ByteStreamErrorsTool::IDCCacheEntry::reset
void reset(EventContext::ContextEvt_t evtId, const IDCInDetBSErrContainer_Cache *cache)
Definition: SCT_ByteStreamErrorsTool.h:123
SCT_ByteStreamErrorsTool::IDCCacheEntry::m_set_number
unsigned int m_set_number
Definition: SCT_ByteStreamErrorsTool.h:121
SCT_ByteStreamErrorsTool::canReportAbout
virtual bool canReportAbout(InDetConditions::Hierarchy h) const override
Used by ConditionsSummayTool to decide whether to call isGood() for a particular detector element.
Definition: SCT_ByteStreamErrorsTool.cxx:67
SCT_ByteStreamErrorsTool::m_badErrorMask
uint64_t m_badErrorMask
Definition: SCT_ByteStreamErrorsTool.h:105
SCT_ByteStreamErrorsTool::IDCCacheEntry
Definition: SCT_ByteStreamErrorsTool.h:108
SCT_ByteStreamErrorsTool::ATLAS_THREAD_SAFE
SG::SlotSpecificObj< std::mutex > m_cacheMutex ATLAS_THREAD_SAFE
Definition: SCT_ByteStreamErrorsTool.h:107
SCT_ByteStreamErrorsTool
Definition: SCT_ByteStreamErrorsTool.h:64
SCT_ByteStreamErrorsTool::m_cntx_sct
IdContext m_cntx_sct
Definition: SCT_ByteStreamErrorsTool.h:104
SCT_ByteStreamErrorsTool::IDCCacheEntry::IDCCache
const IDCInDetBSErrContainer_Cache * IDCCache
Definition: SCT_ByteStreamErrorsTool.h:110
SCT_ByteStreamErrorsTool::isGood
virtual bool isGood(const Identifier &elementId, InDetConditions::Hierarchy h=InDetConditions::DEFAULT) const override
Is the detector element good?
Definition: SCT_ByteStreamErrorsTool.cxx:262
SCT_ByteStreamErrorsTool::IDCCacheEntry::eventId
EventContext::ContextEvt_t eventId
Definition: SCT_ByteStreamErrorsTool.h:109
SG::SlotSpecificObj< std::mutex >
SCT_ByteStreamErrorsTool::getDetectorElementStatus
virtual void getDetectorElementStatus(const EventContext &ctx, InDet::SiDetectorElementStatus &element_status, SG::WriteCondHandle< InDet::SiDetectorElementStatus > *whandle) const override
Definition: SCT_ByteStreamErrorsTool.cxx:162
IdContext.h
InDet::SiDetectorElementStatus
Definition: SiDetectorElementStatus.h:62
SCT_ByteStreamErrorsTool::getErrorCodeWithCacheUpdate
std::pair< StatusCode, unsigned int > getErrorCodeWithCacheUpdate(const Identifier &id, const EventContext &ctx, std::unordered_map< size_t, unsigned int > &whereExected) const
Method that returns BS Error code from the map passed @rag where-Expected If the information is initi...
Definition: SCT_ByteStreamErrorsTool.cxx:479
Identifier
Definition: DetectorDescription/Identifier/Identifier/Identifier.h:32
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SCT_ByteStreamErrorsTool::IDCCacheEntry::abcdErrorChips
std::unordered_map< size_t, unsigned int > abcdErrorChips
Definition: SCT_ByteStreamErrorsTool.h:117
SCT_ByteStreamErrorsTool::N_STRIPS_PER_SIDE
@ N_STRIPS_PER_SIDE
Definition: SCT_ByteStreamErrorsTool.h:95
AthAlgTool.h
test_pyathena.parent
parent
Definition: test_pyathena.py:15
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
InDetHierarchy.h
SCT_ByteStreamErrorsTool::getCacheEntry
IDCCacheEntry * getCacheEntry(const EventContext &ctx) const
Return cache for the current event If, for current slot, the cache is outdated it is retrieved from t...
Definition: SCT_ByteStreamErrorsTool.cxx:94
ReadCondHandleKey.h
SCT_ByteStreamErrorsTool::~SCT_ByteStreamErrorsTool
virtual ~SCT_ByteStreamErrorsTool()=default
SCT_ByteStreamErrorsTool::ATLAS_THREAD_SAFE
SG::SlotSpecificObj< IDCCacheEntry > m_eventCache ATLAS_THREAD_SAFE
Definition: SCT_ByteStreamErrorsTool.h:136
SCT_ByteStreamErrorsTool::initialize
virtual StatusCode initialize() override
Initialize.
Definition: SCT_ByteStreamErrorsTool.cxx:30
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
IdentifierHash.h
SCT_ByteStreamErrorsTool::SCT_ByteStreamErrorsTool
SCT_ByteStreamErrorsTool(const std::string &type, const std::string &name, const IInterface *parent)
header file for this class.
Definition: SCT_ByteStreamErrorsTool.cxx:23
SCT_ByteStreamErrorsTool::fillData
StatusCode fillData(const EventContext &ctx) const
Updates information per module & ABCD chip.
Definition: SCT_ByteStreamErrorsTool.cxx:363
InDetDD::SiDetectorElement
Definition: SiDetectorElement.h:109
SiDetectorElementCollection.h
SCT_ByteStreamErrorsTool::m_bsIDCErrContainerName
SG::ReadHandleKey< IDCInDetBSErrContainer > m_bsIDCErrContainerName
Definition: SCT_ByteStreamErrorsTool.h:100
SCT_ByteStreamErrorsTool::getContainer
const IDCInDetBSErrContainer * getContainer(const EventContext &ctx) const
Obtains container form the SG, if it is missing it will complain (hard-coded 3 times per job) and ret...
Definition: SCT_ByteStreamErrorsTool.cxx:71
ISCT_ConfigurationConditionsTool.h
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection >
SCT_ByteStreamErrorsTool::m_nRetrievalFailure
std::atomic_uint m_nRetrievalFailure
Definition: SCT_ByteStreamErrorsTool.h:142
SCT_ByteStreamErrorsTool::N_STRIPS_PER_CHIP
@ N_STRIPS_PER_CHIP
Definition: SCT_ByteStreamErrorsTool.h:95
h
SCT_ID
Definition: SCT_ID.h:68
IDCInDetBSErrContainer.h
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
SCT_ByteStreamErrorsTool::N_CHIPS_PER_SIDE
@ N_CHIPS_PER_SIDE
Definition: SCT_ByteStreamErrorsTool.h:95
SCT_ByteStreamErrorsTool::m_SCTDetEleCollKey
SG::ReadCondHandleKey< InDetDD::SiDetectorElementCollection > m_SCTDetEleCollKey
Definition: SCT_ByteStreamErrorsTool.h:101
SCT_ByteStreamErrorsTool::N_ELEMENTS
N_ELEMENTS
Definition: SCT_ByteStreamErrorsTool.h:95
SCT_ByteStreamErrorsTool::IDCCacheEntry::tempMaskedChips
std::unordered_map< size_t, unsigned int > tempMaskedChips
Definition: SCT_ByteStreamErrorsTool.h:116
SCT_ByteStreamErrorsTool::getDetectorElement
const InDetDD::SiDetectorElement * getDetectorElement(const IdentifierHash &waferHash, const EventContext &ctx) const
Definition: SCT_ByteStreamErrorsTool.cxx:509
SlotSpecificObj.h
Maintain a set of objects, one per slot.
SCT_ByteStreamErrorsTool::N_SIDES
@ N_SIDES
Definition: SCT_ByteStreamErrorsTool.h:95
IdentifierHash
Definition: IdentifierHash.h:38
InDetConditions::DEFAULT
@ DEFAULT
Definition: InDetHierarchy.h:14
IdContext
class IdContext
Definition: IdContext.h:34
SG::WriteCondHandle
Definition: WriteCondHandle.h:26
IdentifiableValueCache
This class is to provide an event wide MT container for concurrent storing of basic types,...
Definition: IdentifiableValueCache.h:19