ATLAS Offline Software
Loading...
Searching...
No Matches
SCT_MonitorCondData.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5//----------------------------------------------------------------------
6// Implementation file for the data object class for SCT_MonitorConditionsSvc
7//----------------------------------------------------------------------
8
10
11#include <iterator>
12#include <utility>
13
14namespace {
15 bool doesNotHaveNumbers(const std::string& numberString) {
16 return (numberString.empty() or numberString.find_first_of("0123456789") == std::string::npos);
17 }
18}
19
20//----------------------------------------------------------------------
21// Constructor
26
27//----------------------------------------------------------------------
28// Check if a module has a defect (a list of bad strips). If it does not have defect return false.
29bool SCT_MonitorCondData::find(const IdentifierHash& hash, std::string& defectList) const
30{
31 std::size_t moduleIndex{static_cast<std::size_t>(hash/SCT_ConditionsData::SIDES_PER_MODULE)};
32 std::string result{m_defectListArray[moduleIndex]};
33 if (result.empty()) return false;
34 defectList = std::move(result);
35 return true;
36}
37
38//----------------------------------------------------------------------
39// Insert a new defect (a list of bad strips) for a module
40void SCT_MonitorCondData::insert(const IdentifierHash& hash, const std::string& defectList)
41{
42 std::size_t moduleIndex{static_cast<std::size_t>(hash/SCT_ConditionsData::SIDES_PER_MODULE)};
43 m_defectListArray[moduleIndex] = defectList;
44
45 // Set all strips, chips, wafers and module itself of this module good.
46 clearModule(moduleIndex);
47
48 if (doesNotHaveNumbers(defectList)) return;
49
50 // Fill bad strips
51 std::istringstream is{defectList};
52 std::istream_iterator<std::string> readString{is};
53 std::istream_iterator<std::string> endOfString; //relies on default constructor to produce eof
54 for (; readString != endOfString; ++readString) {
55 const std::string& stringRange{*readString};
56 std::string::size_type p{stringRange.find(s_separator)};
57 if (p!=std::string::npos) { //its a range
58 std::string::size_type len1{p++};
59 std::string::size_type len2{stringRange.size()-p};
60 int min{std::stoi(stringRange.substr(0, len1))};
61 int max{std::stoi(stringRange.substr(p, len2))};
62 for (int strip{min}; strip<=max; strip++) {
63 fillBadStrip(moduleIndex, strip);
64 }
65 } else { //assume its a single number
66 int strip{std::stoi(*readString)};
67 fillBadStrip(moduleIndex, strip);
68 }
69 }
70
71 // Fill the number of defects in chips, wafers, module
72 for (std::size_t waferIndex{0}; waferIndex<SCT_ConditionsData::SIDES_PER_MODULE; waferIndex++) {
73 for (std::size_t chipIndex{0}; chipIndex<SCT_ConditionsData::CHIPS_PER_SIDE; chipIndex++) {
74 m_badChipArray[moduleIndex][waferIndex][chipIndex] = m_badStripArray[moduleIndex][waferIndex][chipIndex].count();
75 m_badWaferArray[moduleIndex][waferIndex] += m_badChipArray[moduleIndex][waferIndex][chipIndex];
76 }
77 m_badModuleArray[moduleIndex] += m_badWaferArray[moduleIndex][waferIndex];
78 }
79}
80
81//----------------------------------------------------------------------
82// Clear m_defectListMap
84{
85 m_defectListArray.fill("");
86
87 for (std::size_t moduleIndex{0}; moduleIndex<SCT_ConditionsData::NUMBER_OF_MODULES; moduleIndex++) {
88 clearModule(moduleIndex);
89 }
90}
91
92std::size_t SCT_MonitorCondData::nBadStripsForModule(const IdentifierHash& moduleHash) const
93{
94 std::size_t moduleIndex{static_cast<std::size_t>(moduleHash/SCT_ConditionsData::SIDES_PER_MODULE)};
95 return m_badModuleArray[moduleIndex];
96}
97
99{
100 std::size_t moduleIndex{static_cast<std::size_t>(waferHash/SCT_ConditionsData::SIDES_PER_MODULE)};
101 std::size_t waferIndex{static_cast<std::size_t>(waferHash%SCT_ConditionsData::SIDES_PER_MODULE)};
102 return m_badWaferArray[moduleIndex][waferIndex];
103}
104
105std::size_t SCT_MonitorCondData::nBadStripsForChip(const IdentifierHash& waferHash, const int strip) const
106{
107 // 0 <= strip < 768
108 if (strip<0) return false;
110
111 // 0 to 4087
112 std::size_t moduleIndex{static_cast<std::size_t>(waferHash/SCT_ConditionsData::SIDES_PER_MODULE)};
113 // 0 to 1
114 std::size_t waferIndex{static_cast<std::size_t>(waferHash%SCT_ConditionsData::SIDES_PER_MODULE)};
115 // 0 to 5
116 std::size_t chipIndex{static_cast<std::size_t>(strip/SCT_ConditionsData::STRIPS_PER_CHIP)};
117
118 return m_badChipArray[moduleIndex][waferIndex][chipIndex];
119}
120
121bool SCT_MonitorCondData::isBadStrip(const IdentifierHash& waferHash, const int strip) const
122{
123 // 0 <= strip < 768
124 if (strip<0) return false;
126
127 // 0 to 4087
128 std::size_t moduleIndex{static_cast<std::size_t>(waferHash/SCT_ConditionsData::SIDES_PER_MODULE)};
129 // 0 to 1
130 std::size_t waferIndex{static_cast<std::size_t>(waferHash%SCT_ConditionsData::SIDES_PER_MODULE)};
131 // 0 to 5
132 std::size_t chipIndex{static_cast<std::size_t>(strip/SCT_ConditionsData::STRIPS_PER_CHIP)};
133 // 0 to 127
134 std::size_t stripIndex{static_cast<std::size_t>(strip%SCT_ConditionsData::STRIPS_PER_CHIP)};
135
136 return m_badStripArray[moduleIndex][waferIndex][chipIndex].test(stripIndex);
137}
138
139void SCT_MonitorCondData::clearModule(const std::size_t moduleIndex) {
140 // std::array is not automatically initialized.
141 for (std::size_t waferIndex{0}; waferIndex<SCT_ConditionsData::SIDES_PER_MODULE; waferIndex++) {
142 for (std::size_t chipIndex{0}; chipIndex<SCT_ConditionsData::CHIPS_PER_SIDE; chipIndex++) {
143 m_badStripArray[moduleIndex][waferIndex][chipIndex].reset();
144 m_badChipArray[moduleIndex][waferIndex][chipIndex] = 0;
145 }
146 m_badWaferArray[moduleIndex][waferIndex] = 0;
147 }
148 m_badModuleArray[moduleIndex] = 0;
149}
150
151void SCT_MonitorCondData::fillBadStrip(const std::size_t moduleIndex, const int strip) {
152 // 0 <= strip < 1536
153 if (strip<0) return;
155
156 // 0 or 1
157 std::size_t waferIndex{static_cast<std::size_t>(strip/SCT_ConditionsData::STRIPS_PER_WAFER)};
158 // 0 to 5
159 std::size_t chipIndex{static_cast<std::size_t>(strip/SCT_ConditionsData::STRIPS_PER_CHIP)%SCT_ConditionsData::CHIPS_PER_SIDE};
160 // 0 to 127
161 std::size_t stripIndex{static_cast<std::size_t>(strip%SCT_ConditionsData::STRIPS_PER_CHIP)};
162 // Set the strip as bad
163 m_badStripArray[moduleIndex][waferIndex][chipIndex].set(stripIndex);
164}
165
166const std::string SCT_MonitorCondData::s_separator{"-"};
header file for data object for SCT_MonitorCondAlg and SCT_MonitorConditionsTool.
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41
This is a "hash" representation of an Identifier.
std::size_t nBadStripsForModule(const IdentifierHash &moduleHash) const
Get the number of bad strips for a module.
void clear()
Clear m_defectListArray.
void insert(const IdentifierHash &hash, const std::string &defectList)
Insert a new defect (a list of bad strips) for a module.
bool find(const IdentifierHash &hash, std::string &defectList) const
Check if a module has a defect (a list of bad strips). If it does not have defect return false.
bool isBadStrip(const IdentifierHash &waferHash, const int strip) const
Check if a strip is bad.
std::array< std::array< std::array< std::bitset< SCT_ConditionsData::STRIPS_PER_CHIP >, SCT_ConditionsData::CHIPS_PER_SIDE >, SCT_ConditionsData::SIDES_PER_MODULE >, SCT_ConditionsData::NUMBER_OF_MODULES > m_badStripArray
SCT_MonitorCondData()
Constructor.
std::array< std::array< std::size_t, SCT_ConditionsData::SIDES_PER_MODULE >, SCT_ConditionsData::NUMBER_OF_MODULES > m_badWaferArray
void fillBadStrip(const std::size_t moduleIndex, const int strip)
std::array< std::size_t, SCT_ConditionsData::NUMBER_OF_MODULES > m_badModuleArray
std::size_t nBadStripsForChip(const IdentifierHash &waferHash, const int strip) const
Get the number of bad strips for the chip, where a strip locates.
std::size_t nBadStripsForWafer(const IdentifierHash &waferHash) const
Get the number of bad strips for a wafer.
std::array< std::string, SCT_ConditionsData::NUMBER_OF_MODULES > m_defectListArray
Store the relation between modules and defects (lists of bad strips).
void clearModule(const std::size_t moduleIndex)
std::array< std::array< std::array< std::size_t, SCT_ConditionsData::CHIPS_PER_SIDE >, SCT_ConditionsData::SIDES_PER_MODULE >, SCT_ConditionsData::NUMBER_OF_MODULES > m_badChipArray
static const std::string s_separator