Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:41

0001 #include "CondFormats/SiStripObjects/interface/SiStripDetVOff.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 #include "CondFormats/SiStripObjects/interface/SiStripDetSummary.h"
0004 
0005 #include <algorithm>
0006 
0007 void SiStripDetVOff::setBits(uint32_t& enDetId, const int HVoff, const int LVoff) {
0008   if (LVoff != -1) {
0009     // LVonMask has all bits equal to 1 apart from the last one.
0010     if (LVoff == 0)
0011       enDetId &= LVonMask;
0012     if (LVoff == 1)
0013       enDetId |= LVmask;
0014   }
0015   if (HVoff != -1) {
0016     // HVonMask has all bits equal to 1 apart from the next to last one.
0017     if (HVoff == 0)
0018       enDetId &= HVonMask;
0019     if (HVoff == 1)
0020       enDetId |= HVmask;
0021   }
0022 }
0023 
0024 bool SiStripDetVOff::put(const uint32_t DetId, const int HVoff, const int LVoff) {
0025   // Shift the DetId number of 2 bits to the left to have it in the final format with
0026   // the two additional bits used for HV and LV.
0027   uint32_t enDetId = (DetId << bitShift) & eightBitMask;
0028 
0029   // Binary search to determine if the element is already in the vector
0030   vOffIterator p = std::lower_bound(v_Voff.begin(), v_Voff.end(), enDetId);
0031   if (p != v_Voff.end() && (*p >> bitShift) == DetId) {
0032     // Found a matching entry, insert the HV and LV information.
0033     setBits(*p, HVoff, LVoff);
0034     // Check if the detector has all on, in that case remove it from the list.
0035     if ((~(*p) & allOnMask) == allOnMask)
0036       v_Voff.erase(p);
0037   } else {
0038     // Not found, insert a new entry only if it is not all on
0039     setBits(enDetId, HVoff, LVoff);
0040     if ((~enDetId & allOnMask) != allOnMask)
0041       v_Voff.insert(p, enDetId);
0042   }
0043   return true;
0044 }
0045 
0046 bool SiStripDetVOff::put(std::vector<uint32_t>& DetId, std::vector<int>& HVoff, std::vector<int>& LVoff) {
0047   if (DetId.size() == HVoff.size() && DetId.size() == LVoff.size()) {
0048     constVoffIterator detIdIt = DetId.begin();
0049     constVoffIterator detIdItEnd = DetId.end();
0050     constVboolIterator HVoffIt = HVoff.begin();
0051     constVboolIterator LVoffIt = LVoff.begin();
0052     for (; detIdIt != detIdItEnd; ++detIdIt, ++HVoffIt, ++LVoffIt) {
0053       put(*detIdIt, *HVoffIt, *LVoffIt);
0054     }
0055   } else {
0056     std::cout << "Error: inconsistent sizes of vectors:" << std::endl;
0057     std::cout << "DetId size = " << DetId.size() << ", HVoff size = " << HVoff.size()
0058               << ", LVoff size = " << LVoff.size() << std::endl;
0059     return false;
0060   }
0061   return true;
0062 }
0063 
0064 void SiStripDetVOff::getDetIds(std::vector<uint32_t>& DetIds_) const {
0065   // returns vector of DetIds in map
0066   DetIds_.clear();
0067   // Extract the detId from the bitSet and fill the vector
0068   constVoffIterator bitSetIt = v_Voff.begin();
0069   constVoffIterator bitSetItEnd = v_Voff.end();
0070   for (; bitSetIt != bitSetItEnd; ++bitSetIt) {
0071     DetIds_.push_back((*bitSetIt) >> bitShift);
0072   }
0073 }
0074 
0075 bool SiStripDetVOff::IsModuleVOff(const uint32_t DetId) const {
0076   uint32_t enDetId = (DetId << bitShift) & eightBitMask;
0077   constVoffIterator p = std::lower_bound(v_Voff.begin(), v_Voff.end(), enDetId);
0078   if (p != v_Voff.end() && (*p >> bitShift) == DetId)
0079     return true;
0080   return false;
0081 }
0082 
0083 bool SiStripDetVOff::IsModuleLVOff(const uint32_t DetId) const {
0084   uint32_t enDetId = (DetId << bitShift) & eightBitMask;
0085   constVoffIterator p = std::lower_bound(v_Voff.begin(), v_Voff.end(), enDetId);
0086   if (p != v_Voff.end() && (*p >> bitShift) == DetId && (*p & LVmask))
0087     return true;
0088   return false;
0089 }
0090 
0091 bool SiStripDetVOff::IsModuleHVOff(const uint32_t DetId) const {
0092   uint32_t enDetId = (DetId << bitShift) & eightBitMask;
0093   constVoffIterator p = std::lower_bound(v_Voff.begin(), v_Voff.end(), enDetId);
0094   if (p != v_Voff.end() && (*p >> bitShift) == DetId && (*p & HVmask))
0095     return true;
0096   return false;
0097 }
0098 
0099 void SiStripDetVOff::printDebug(std::stringstream& ss, const TrackerTopology* /*trackerTopo*/) const {
0100   std::vector<uint32_t> detIds;
0101   getDetIds(detIds);
0102   constVoffIterator it = detIds.begin();
0103   ss << "DetId    \t HV \t LV" << std::endl;
0104   for (; it != detIds.end(); ++it) {
0105     ss << *it << "\t";
0106     if (IsModuleHVOff(*it))
0107       ss << "OFF\t";
0108     else
0109       ss << "ON \t";
0110     if (IsModuleLVOff(*it))
0111       ss << "OFF" << std::endl;
0112     else
0113       ss << "ON" << std::endl;
0114   }
0115 }
0116 
0117 int SiStripDetVOff::getLVoffCounts() const {
0118   std::vector<uint32_t> detIds;
0119   getDetIds(detIds);
0120   return std::count_if(std::begin(detIds), std::end(detIds), [this](uint32_t id) -> bool { return IsModuleLVOff(id); });
0121 }
0122 
0123 int SiStripDetVOff::getHVoffCounts() const {
0124   std::vector<uint32_t> detIds;
0125   getDetIds(detIds);
0126   return std::count_if(std::begin(detIds), std::end(detIds), [this](uint32_t id) -> bool { return IsModuleHVOff(id); });
0127 }
0128 
0129 void SiStripDetVOff::printSummary(std::stringstream& ss, const TrackerTopology* trackerTopo) const {
0130   SiStripDetSummary summaryHV{trackerTopo};
0131   SiStripDetSummary summaryLV{trackerTopo};
0132   std::vector<uint32_t> detIds;
0133   getDetIds(detIds);
0134   constVoffIterator it = detIds.begin();
0135   for (; it != detIds.end(); ++it) {
0136     if (IsModuleHVOff(*it))
0137       summaryHV.add(*it);
0138     if (IsModuleLVOff(*it))
0139       summaryLV.add(*it);
0140   }
0141   ss << "Summary of detectors with HV off:" << std::endl;
0142   summaryHV.print(ss, false);
0143   ss << "Summary of detectors with LV off:" << std::endl;
0144   summaryLV.print(ss, false);
0145 }