CMS 3D CMS Logo

SiStripDetVOff.cc
Go to the documentation of this file.
4 
5 #include <algorithm>
6 
7 void SiStripDetVOff::setBits(uint32_t& enDetId, const int HVoff, const int LVoff) {
8  if (LVoff != -1) {
9  // LVonMask has all bits equal to 1 apart from the last one.
10  if (LVoff == 0)
11  enDetId &= LVonMask;
12  if (LVoff == 1)
13  enDetId |= LVmask;
14  }
15  if (HVoff != -1) {
16  // HVonMask has all bits equal to 1 apart from the next to last one.
17  if (HVoff == 0)
18  enDetId &= HVonMask;
19  if (HVoff == 1)
20  enDetId |= HVmask;
21  }
22 }
23 
24 bool SiStripDetVOff::put(const uint32_t DetId, const int HVoff, const int LVoff) {
25  // Shift the DetId number of 2 bits to the left to have it in the final format with
26  // the two additional bits used for HV and LV.
27  uint32_t enDetId = (DetId << bitShift) & eightBitMask;
28 
29  // Binary search to determine if the element is already in the vector
30  vOffIterator p = std::lower_bound(v_Voff.begin(), v_Voff.end(), enDetId);
31  if (p != v_Voff.end() && (*p >> bitShift) == DetId) {
32  // Found a matching entry, insert the HV and LV information.
33  setBits(*p, HVoff, LVoff);
34  // Check if the detector has all on, in that case remove it from the list.
35  if ((~(*p) & allOnMask) == allOnMask)
36  v_Voff.erase(p);
37  } else {
38  // Not found, insert a new entry only if it is not all on
39  setBits(enDetId, HVoff, LVoff);
40  if ((~enDetId & allOnMask) != allOnMask)
41  v_Voff.insert(p, enDetId);
42  }
43  return true;
44 }
45 
46 bool SiStripDetVOff::put(std::vector<uint32_t>& DetId, std::vector<int>& HVoff, std::vector<int>& LVoff) {
47  if (DetId.size() == HVoff.size() && DetId.size() == LVoff.size()) {
48  constVoffIterator detIdIt = DetId.begin();
49  constVoffIterator detIdItEnd = DetId.end();
50  constVboolIterator HVoffIt = HVoff.begin();
51  constVboolIterator LVoffIt = LVoff.begin();
52  for (; detIdIt != detIdItEnd; ++detIdIt, ++HVoffIt, ++LVoffIt) {
53  put(*detIdIt, *HVoffIt, *LVoffIt);
54  }
55  } else {
56  std::cout << "Error: inconsistent sizes of vectors:" << std::endl;
57  std::cout << "DetId size = " << DetId.size() << ", HVoff size = " << HVoff.size()
58  << ", LVoff size = " << LVoff.size() << std::endl;
59  return false;
60  }
61  return true;
62 }
63 
64 void SiStripDetVOff::getDetIds(std::vector<uint32_t>& DetIds_) const {
65  // returns vector of DetIds in map
66  DetIds_.clear();
67  // Extract the detId from the bitSet and fill the vector
68  constVoffIterator bitSetIt = v_Voff.begin();
69  constVoffIterator bitSetItEnd = v_Voff.end();
70  for (; bitSetIt != bitSetItEnd; ++bitSetIt) {
71  DetIds_.push_back((*bitSetIt) >> bitShift);
72  }
73 }
74 
75 bool SiStripDetVOff::IsModuleVOff(const uint32_t DetId) const {
76  uint32_t enDetId = (DetId << bitShift) & eightBitMask;
77  constVoffIterator p = std::lower_bound(v_Voff.begin(), v_Voff.end(), enDetId);
78  if (p != v_Voff.end() && (*p >> bitShift) == DetId)
79  return true;
80  return false;
81 }
82 
83 bool SiStripDetVOff::IsModuleLVOff(const uint32_t DetId) const {
84  uint32_t enDetId = (DetId << bitShift) & eightBitMask;
85  constVoffIterator p = std::lower_bound(v_Voff.begin(), v_Voff.end(), enDetId);
86  if (p != v_Voff.end() && (*p >> bitShift) == DetId && (*p & LVmask))
87  return true;
88  return false;
89 }
90 
91 bool SiStripDetVOff::IsModuleHVOff(const uint32_t DetId) const {
92  uint32_t enDetId = (DetId << bitShift) & eightBitMask;
93  constVoffIterator p = std::lower_bound(v_Voff.begin(), v_Voff.end(), enDetId);
94  if (p != v_Voff.end() && (*p >> bitShift) == DetId && (*p & HVmask))
95  return true;
96  return false;
97 }
98 
99 void SiStripDetVOff::printDebug(std::stringstream& ss, const TrackerTopology* /*trackerTopo*/) const {
100  std::vector<uint32_t> detIds;
101  getDetIds(detIds);
102  constVoffIterator it = detIds.begin();
103  ss << "DetId \t HV \t LV" << std::endl;
104  for (; it != detIds.end(); ++it) {
105  ss << *it << "\t";
106  if (IsModuleHVOff(*it))
107  ss << "OFF\t";
108  else
109  ss << "ON \t";
110  if (IsModuleLVOff(*it))
111  ss << "OFF" << std::endl;
112  else
113  ss << "ON" << std::endl;
114  }
115 }
116 
118  std::vector<uint32_t> detIds;
119  getDetIds(detIds);
120  return std::count_if(std::begin(detIds), std::end(detIds), [this](uint32_t id) -> bool { return IsModuleLVOff(id); });
121 }
122 
124  std::vector<uint32_t> detIds;
125  getDetIds(detIds);
126  return std::count_if(std::begin(detIds), std::end(detIds), [this](uint32_t id) -> bool { return IsModuleHVOff(id); });
127 }
128 
129 void SiStripDetVOff::printSummary(std::stringstream& ss, const TrackerTopology* trackerTopo) const {
130  SiStripDetSummary summaryHV{trackerTopo};
131  SiStripDetSummary summaryLV{trackerTopo};
132  std::vector<uint32_t> detIds;
133  getDetIds(detIds);
134  constVoffIterator it = detIds.begin();
135  for (; it != detIds.end(); ++it) {
136  if (IsModuleHVOff(*it))
137  summaryHV.add(*it);
138  if (IsModuleLVOff(*it))
139  summaryLV.add(*it);
140  }
141  ss << "Summary of detectors with HV off:" << std::endl;
142  summaryHV.print(ss, false);
143  ss << "Summary of detectors with LV off:" << std::endl;
144  summaryLV.print(ss, false);
145 }
void getDetIds(std::vector< uint32_t > &DetIds_) const
static const short bitShift
static const unsigned int LVonMask
bool IsModuleLVOff(const uint32_t DetID) const
static const unsigned int allOnMask
bool IsModuleVOff(const uint32_t DetID) const
Returns true if either HV or LV are off.
int getHVoffCounts() const
Returns the total number of modules with HV off.
bool put(const uint32_t DetId, const int HVoff, const int LVoff)
Insert information for a single detId.
std::vector< int >::const_iterator constVboolIterator
std::vector< uint32_t > v_Voff
void printSummary(std::stringstream &ss, const TrackerTopology *) const
void setBits(uint32_t &enDetId, const int HVoff, const int LVoff)
Changes the bits in the stored value according to on/off voltages.
static const unsigned int eightBitMask
static const short HVmask
Definition: DetId.h:17
static const short LVmask
static const unsigned int HVonMask
int getLVoffCounts() const
Returns the total number of modules with LV off.
bool IsModuleHVOff(const uint32_t DetID) const
std::vector< uint32_t >::iterator vOffIterator
std::vector< uint32_t >::const_iterator constVoffIterator
void printDebug(std::stringstream &ss, const TrackerTopology *) const