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