Go to the documentation of this file.00001 #include "CondFormats/SiStripObjects/interface/SiStripDetVOff.h"
00002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00003 #include "CondFormats/SiStripObjects/interface/SiStripDetSummary.h"
00004
00005 #include <algorithm>
00006
00007 void SiStripDetVOff::setBits( uint32_t & enDetId, const int HVoff, const int LVoff )
00008 {
00009 if( LVoff != -1 ) {
00010
00011 if( LVoff == 0 ) enDetId &= LVonMask;
00012 if( LVoff == 1 ) enDetId |= LVmask;
00013 }
00014 if( HVoff != -1 ) {
00015
00016 if( HVoff == 0 ) enDetId &= HVonMask;
00017 if( HVoff == 1 ) enDetId |= HVmask;
00018 }
00019 }
00020
00021 bool SiStripDetVOff::put(const uint32_t DetId, const int HVoff, const int LVoff)
00022 {
00023
00024
00025 uint32_t enDetId = (DetId << bitShift) & eightBitMask;
00026
00027
00028 vOffIterator p = std::lower_bound(v_Voff.begin(), v_Voff.end(), enDetId);
00029 if( p != v_Voff.end() && (*p >> bitShift) == DetId) {
00030
00031 setBits(*p, HVoff, LVoff);
00032
00033 if( (~(*p) & allOnMask) == allOnMask ) v_Voff.erase(p);
00034 }
00035 else {
00036
00037 setBits(enDetId, HVoff, LVoff);
00038 if( (~enDetId & allOnMask) != allOnMask ) v_Voff.insert(p, enDetId);
00039 }
00040 return true;
00041 }
00042
00043 bool SiStripDetVOff::put(std::vector<uint32_t>& DetId, std::vector<int>& HVoff, std::vector<int>& LVoff)
00044 {
00045 if( DetId.size() == HVoff.size() && DetId.size() == LVoff.size() ) {
00046 constVoffIterator detIdIt = DetId.begin();
00047 constVoffIterator detIdItEnd = DetId.end();
00048 constVboolIterator HVoffIt = HVoff.begin();
00049 constVboolIterator LVoffIt = LVoff.begin();
00050 for( ; detIdIt != detIdItEnd; ++detIdIt, ++HVoffIt, ++LVoffIt ) {
00051 put( *detIdIt, *HVoffIt, *LVoffIt );
00052 }
00053 }
00054 else {
00055 std::cout << "Error: inconsistent sizes of vectors:" << std::endl;
00056 std::cout << "DetId size = " << DetId.size() << ", HVoff size = " << HVoff.size() << ", LVoff size = " << LVoff.size() << std::endl;
00057 return false;
00058 }
00059 return true;
00060 }
00061
00062 void SiStripDetVOff::getDetIds(std::vector<uint32_t>& DetIds_) const
00063 {
00064
00065 DetIds_.clear();
00066
00067 constVoffIterator bitSetIt = v_Voff.begin();
00068 constVoffIterator bitSetItEnd = v_Voff.end();
00069 for( ; bitSetIt != bitSetItEnd; ++bitSetIt ) {
00070 DetIds_.push_back( (*bitSetIt) >> bitShift );
00071 }
00072 }
00073
00074 bool SiStripDetVOff::IsModuleVOff(const uint32_t DetId) const
00075 {
00076 uint32_t enDetId = (DetId << bitShift) & eightBitMask;
00077 constVoffIterator p = std::lower_bound(v_Voff.begin(), v_Voff.end(), enDetId);
00078 if( p != v_Voff.end() && (*p >> bitShift) == DetId) return true;
00079 return false;
00080 }
00081
00082 bool SiStripDetVOff::IsModuleLVOff(const uint32_t DetId) const
00083 {
00084 uint32_t enDetId = (DetId << bitShift) & eightBitMask;
00085 constVoffIterator p = std::lower_bound(v_Voff.begin(), v_Voff.end(), enDetId);
00086 if( p != v_Voff.end() && (*p >> bitShift) == DetId && (*p & LVmask) ) return true;
00087 return false;
00088 }
00089
00090 bool SiStripDetVOff::IsModuleHVOff(const uint32_t DetId) const
00091 {
00092 uint32_t enDetId = (DetId << bitShift) & eightBitMask;
00093 constVoffIterator p = std::lower_bound(v_Voff.begin(), v_Voff.end(), enDetId);
00094 if( p != v_Voff.end() && (*p >> bitShift) == DetId && (*p & HVmask) ) return true;
00095 return false;
00096 }
00097
00098 void SiStripDetVOff::printDebug(std::stringstream & ss) const
00099 {
00100 std::vector<uint32_t> detIds;
00101 getDetIds(detIds);
00102 constVoffIterator it = detIds.begin();
00103 ss << "DetId \t HV \t LV" << std::endl;
00104 for( ; it!=detIds.end(); ++it ) {
00105 ss << *it << "\t";
00106 if( IsModuleHVOff(*it)) ss << "OFF\t";
00107 else ss << "ON \t";
00108 if( IsModuleLVOff(*it)) ss << "OFF" << std::endl;
00109 else ss << "ON" << std::endl;
00110 }
00111 }
00112
00113 int SiStripDetVOff::getLVoffCounts() const
00114 {
00115 SiStripDetSummary summaryLV;
00116 std::vector<uint32_t> detIds;
00117 getDetIds(detIds);
00118 constVoffIterator it = detIds.begin();
00119 for( ; it!=detIds.end(); ++it ) {
00120 if( IsModuleLVOff(*it)) summaryLV.add(*it);
00121 }
00122 int totalCount = 0;
00123 std::map<unsigned int, SiStripDetSummary::Values> counts = summaryLV.getCounts();
00124 std::map<unsigned int, SiStripDetSummary::Values>::const_iterator mapIt = counts.begin();
00125 for( ; mapIt != counts.end(); ++mapIt ) {
00126 totalCount += mapIt->second.count;
00127 }
00128 return totalCount;
00129 }
00130
00131 int SiStripDetVOff::getHVoffCounts() const
00132 {
00133 SiStripDetSummary summaryHV;
00134 std::vector<uint32_t> detIds;
00135 getDetIds(detIds);
00136 constVoffIterator it = detIds.begin();
00137 for( ; it!=detIds.end(); ++it ) {
00138 if( IsModuleHVOff(*it)) summaryHV.add(*it);
00139 }
00140 int totalCount = 0;
00141 std::map<unsigned int, SiStripDetSummary::Values> counts = summaryHV.getCounts();
00142 std::map<unsigned int, SiStripDetSummary::Values>::const_iterator mapIt = counts.begin();
00143 for( ; mapIt != counts.end(); ++mapIt ) {
00144 totalCount += mapIt->second.count;
00145 }
00146 return totalCount;
00147 }
00148
00149 void SiStripDetVOff::printSummary(std::stringstream & ss) const
00150 {
00151 SiStripDetSummary summaryHV;
00152 SiStripDetSummary summaryLV;
00153 std::vector<uint32_t> detIds;
00154 getDetIds(detIds);
00155 constVoffIterator it = detIds.begin();
00156 for( ; it!=detIds.end(); ++it ) {
00157 if( IsModuleHVOff(*it)) summaryHV.add(*it);
00158 if( IsModuleLVOff(*it)) summaryLV.add(*it);
00159 }
00160 ss << "Summary of detectors with HV off:" << std::endl;
00161 summaryHV.print(ss, false);
00162 ss << "Summary of detectors with LV off:" << std::endl;
00163 summaryLV.print(ss, false);
00164 }