ATLAS Offline Software
SCT_MonitorCondData.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 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 
14 namespace {
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
23 {
24  clear();
25 }
26 
27 //----------------------------------------------------------------------
28 // Check if a module has a defect (a list of bad strips). If it does not have defect return false.
29 bool 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 = result;
35  return true;
36 }
37 
38 //----------------------------------------------------------------------
39 // Insert a new defect (a list of bad strips) for a module
40 void 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 
92 std::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 
98 std::size_t SCT_MonitorCondData::nBadStripsForWafer(const IdentifierHash& waferHash) const
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 
105 std::size_t SCT_MonitorCondData::nBadStripsForChip(const IdentifierHash& waferHash, const int strip) const
106 {
107  // 0 <= strip < 768
108  if (strip<0) return false;
109  if (strip>=SCT_ConditionsData::STRIPS_PER_WAFER) 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 
121 bool SCT_MonitorCondData::isBadStrip(const IdentifierHash& waferHash, const int strip) const
122 {
123  // 0 <= strip < 768
124  if (strip<0) return false;
125  if (strip>=SCT_ConditionsData::STRIPS_PER_WAFER) 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 
139 void 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 
151 void 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 
166 const std::string SCT_MonitorCondData::s_separator{"-"};
SCT_MonitorCondData::SCT_MonitorCondData
SCT_MonitorCondData()
Constructor.
Definition: SCT_MonitorCondData.cxx:22
get_generator_info.result
result
Definition: get_generator_info.py:21
SiliconTech::strip
@ strip
SCT_MonitorCondData::m_badModuleArray
std::array< std::size_t, SCT_ConditionsData::NUMBER_OF_MODULES > m_badModuleArray
Definition: SCT_MonitorCondData.h:89
SCT_ConditionsData::NUMBER_OF_MODULES
@ NUMBER_OF_MODULES
Definition: SCT_ConditionsParameters.h:19
SCT_ConditionsData::CHIPS_PER_SIDE
@ CHIPS_PER_SIDE
Definition: SCT_ConditionsParameters.h:20
max
constexpr double max()
Definition: ap_fixedTest.cxx:33
min
constexpr double min()
Definition: ap_fixedTest.cxx:26
SCT_ConditionsData::SIDES_PER_MODULE
@ SIDES_PER_MODULE
Definition: SCT_ConditionsParameters.h:18
SCT_ConditionsData::STRIPS_PER_WAFER
@ STRIPS_PER_WAFER
Definition: SCT_ConditionsParameters.h:21
SCT_MonitorCondData::s_separator
static const std::string s_separator
Definition: SCT_MonitorCondData.h:91
SCT_MonitorCondData::m_defectListArray
std::array< std::string, SCT_ConditionsData::NUMBER_OF_MODULES > m_defectListArray
Store the relation between modules and defects (lists of bad strips).
Definition: SCT_MonitorCondData.h:76
SCT_MonitorCondData::clearModule
void clearModule(const std::size_t moduleIndex)
Definition: SCT_MonitorCondData.cxx:139
SCT_ConditionsData::STRIPS_PER_CHIP
@ STRIPS_PER_CHIP
Definition: SCT_ConditionsParameters.h:21
SCT_MonitorCondData.h
header file for data object for SCT_MonitorCondAlg and SCT_MonitorConditionsTool.
SCT_MonitorCondData::m_badStripArray
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
Definition: SCT_MonitorCondData.h:80
SCT_MonitorCondData::find
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.
Definition: SCT_MonitorCondData.cxx:29
SCT_MonitorCondData::fillBadStrip
void fillBadStrip(const std::size_t moduleIndex, const int strip)
Definition: SCT_MonitorCondData.cxx:151
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
SCT_MonitorCondData::nBadStripsForChip
std::size_t nBadStripsForChip(const IdentifierHash &waferHash, const int strip) const
Get the number of bad strips for the chip, where a strip locates.
Definition: SCT_MonitorCondData.cxx:105
SCT_MonitorCondData::nBadStripsForModule
std::size_t nBadStripsForModule(const IdentifierHash &moduleHash) const
Get the number of bad strips for a module.
Definition: SCT_MonitorCondData.cxx:92
SCT_MonitorCondData::m_badChipArray
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
Definition: SCT_MonitorCondData.h:84
SCT_MonitorCondData::m_badWaferArray
std::array< std::array< std::size_t, SCT_ConditionsData::SIDES_PER_MODULE >, SCT_ConditionsData::NUMBER_OF_MODULES > m_badWaferArray
Definition: SCT_MonitorCondData.h:87
SCT_MonitorCondData::insert
void insert(const IdentifierHash &hash, const std::string &defectList)
Insert a new defect (a list of bad strips) for a module.
Definition: SCT_MonitorCondData.cxx:40
SCT_MonitorCondData::clear
void clear()
Clear m_defectListArray.
Definition: SCT_MonitorCondData.cxx:83
CaloCondBlobAlgs_fillNoiseFromASCII.hash
dictionary hash
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:109
SCT_MonitorCondData::isBadStrip
bool isBadStrip(const IdentifierHash &waferHash, const int strip) const
Check if a strip is bad.
Definition: SCT_MonitorCondData.cxx:121
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
SCT_MonitorCondData::nBadStripsForWafer
std::size_t nBadStripsForWafer(const IdentifierHash &waferHash) const
Get the number of bad strips for a wafer.
Definition: SCT_MonitorCondData.cxx:98