Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <algorithm>
0002 #include <set>
0003 #include "CondFormats/HcalObjects/interface/HcalDcsValues.h"
0004 
0005 HcalDcsValues::HcalDcsValues()
0006     : mHBsorted(false), mHEsorted(false), mHO0sorted(false), mHO12sorted(false), mHFsorted(false) {}
0007 
0008 HcalDcsValues::~HcalDcsValues() {}
0009 
0010 bool HcalDcsValues::addValue(HcalDcsValue const& newVal) {
0011   HcalDcsDetId tempId(newVal.DcsId());
0012   switch (tempId.subdet()) {
0013     case HcalDcsBarrel:
0014       mHBValues.push_back(newVal);
0015       mHBsorted = false;
0016       return true;
0017     case HcalDcsEndcap:
0018       mHEValues.push_back(newVal);
0019       mHEsorted = false;
0020       return true;
0021     case HcalDcsOuter:
0022       if (tempId.ring() == 0) {
0023         mHO0Values.push_back(newVal);
0024         mHO0sorted = false;
0025       } else {
0026         mHO12Values.push_back(newVal);
0027         mHO12sorted = false;
0028       }
0029       return true;
0030     case HcalDcsForward:
0031       mHFValues.push_back(newVal);
0032       mHFsorted = false;
0033       return true;
0034     default:
0035       return false;
0036   }
0037 }
0038 
0039 void HcalDcsValues::sortAll() {
0040   mHBsorted = sortList(mHBValues);
0041   mHEsorted = sortList(mHEValues);
0042   mHO0sorted = sortList(mHO0Values);
0043   mHO12sorted = sortList(mHO12Values);
0044   mHFsorted = sortList(mHFValues);
0045 }
0046 
0047 bool HcalDcsValues::exists(HcalDcsDetId const& fid) {
0048   switch (fid.subdet()) {
0049     case HcalDcsBarrel:
0050       if (!mHBsorted)
0051         mHBsorted = sortList(mHBValues);
0052       return foundDcsId(mHBValues, fid);
0053     case HcalDcsEndcap:
0054       if (!mHEsorted)
0055         mHEsorted = sortList(mHEValues);
0056       return foundDcsId(mHEValues, fid);
0057     case HcalDcsOuter:
0058       if (fid.ring() == 0) {
0059         if (!mHO0sorted)
0060           mHO0sorted = sortList(mHO0Values);
0061         return foundDcsId(mHO0Values, fid);
0062       } else {
0063         if (!mHO12sorted)
0064           mHO12sorted = sortList(mHO12Values);
0065         return foundDcsId(mHO12Values, fid);
0066       }
0067     case HcalDcsForward:
0068       if (!mHFsorted)
0069         mHFsorted = sortList(mHFValues);
0070       return foundDcsId(mHBValues, fid);
0071     default:
0072       return false;
0073   }
0074 }
0075 
0076 HcalDcsValues::DcsSet HcalDcsValues::getValues(HcalDcsDetId const& fid) {
0077   DcsSet* valList = nullptr;
0078   switch (fid.subdet()) {
0079     case HcalDcsBarrel:
0080       valList = &mHBValues;
0081       if (!mHBsorted)
0082         mHBsorted = sortList(mHBValues);
0083       break;
0084     case HcalDcsEndcap:
0085       valList = &mHEValues;
0086       if (!mHEsorted)
0087         mHEsorted = sortList(mHEValues);
0088       break;
0089     case HcalDcsOuter:
0090       if (fid.ring() == 0) {
0091         valList = &mHO0Values;
0092         if (!mHO0sorted)
0093           mHO0sorted = sortList(mHO0Values);
0094       } else {
0095         valList = &mHO12Values;
0096         if (!mHO12sorted)
0097           mHO12sorted = sortList(mHO12Values);
0098       }
0099       break;
0100     case HcalDcsForward:
0101       valList = &mHFValues;
0102       if (!mHFsorted)
0103         mHFsorted = sortList(mHFValues);
0104       break;
0105     default:
0106       valList = nullptr;
0107   }
0108 
0109   if (valList) {
0110     HcalDcsValue dummy(fid.rawId(), -1, 0., 0., 0.);
0111     DcsSet::const_iterator lb = lower_bound(valList->begin(), valList->end(), dummy);
0112     if ((lb != valList->end()) && (lb->DcsId() == fid.rawId())) {
0113       DcsSet::const_iterator ub = upper_bound(valList->begin(), valList->end(), dummy);
0114       return DcsSet(lb, ub);
0115     }
0116   }
0117   return DcsSet();
0118 }
0119 
0120 // std::set<uint32_t> HcalDcsValues::getAllIds() const {
0121 //   std::set<uint32_t> chans;
0122 //   std::pair< set<uint32_t>::iterator, bool > retVal;
0123 //   std::set<uint32_t>::iterator currId = 0;
0124 //   DcsSet::const_iterator currRec;
0125 //   for (currRec = mHBValues.begin(); currRec != mHBValues.end(); ++currRec) {
0126 //     if (!currId) {
0127 //       retVal = chans.insert(currRec->DcsId());
0128 //       currId = retVal.first;
0129 //     } else
0130 //       currId = chans.insert(currId, currRec->Dcs());
0131 //   }
0132 //   for (currRec = mHEValues.begin(); currRec != mHEValues.end(); ++currRec) {
0133 //     if (!currId) {
0134 //       retVal = chans.insert(currRec->DcsId());
0135 //       currId = retVal.first;
0136 //     } else
0137 //       currId = chans.insert(currId, currRec->Dcs());
0138 //   }
0139 //   for (currRec = mHO0Values.begin(); currRec != mHO0Values.end(); ++currRec) {
0140 //     if (!currId) {
0141 //       retVal = chans.insert(currRec->DcsId());
0142 //       currId = retVal.first;
0143 //     } else
0144 //       currId = chans.insert(currId, currRec->Dcs());
0145 //   }
0146 //   for (currRec = mHO12Values.begin(); currRec != mHO12Values.end(); ++currRec) {
0147 //     if (!currId) {
0148 //       retVal = chans.insert(currRec->DcsId());
0149 //       currId = retVal.first;
0150 //     } else
0151 //       currId = chans.insert(currId, currRec->Dcs());
0152 //   }
0153 //   for (currRec = mHFValues.begin(); currRec != mHFValues.end(); ++currRec) {
0154 //     if (!currId) {
0155 //       retVal = chans.insert(currRec->DcsId());
0156 //       currId = retVal.first;
0157 //     } else
0158 //       currId = chans.insert(currId, currRec->Dcs());
0159 //   }
0160 //   return chans;
0161 // }
0162 
0163 HcalDcsValues::DcsSet const& HcalDcsValues::getAllSubdetValues(DcsSubDet subd) const {
0164   switch (subd) {
0165     case HcalHB:
0166       return mHBValues;
0167     case HcalHE:
0168       return mHEValues;
0169     case HcalHO0:
0170       return mHO0Values;
0171     case HcalHO12:
0172       return mHO12Values;
0173     case HcalHF:
0174       return mHFValues;
0175   }
0176   return mHBValues;
0177 }
0178 
0179 bool HcalDcsValues::DcsValuesOK(DcsSubDet subd, int LS) {
0180   switch (subd) {
0181     case HcalHB:
0182       if (!mHBsorted)
0183         mHBsorted = sortList(mHBValues);
0184       return subDetOk(mHBValues, LS);
0185     case HcalHE:
0186       if (!mHEsorted)
0187         mHEsorted = sortList(mHEValues);
0188       return subDetOk(mHEValues, LS);
0189     case HcalHO0:
0190       if (!mHO0sorted)
0191         mHO0sorted = sortList(mHO0Values);
0192       return subDetOk(mHO0Values, LS);
0193     case HcalHO12:
0194       if (!mHO12sorted)
0195         mHO12sorted = sortList(mHO12Values);
0196       return subDetOk(mHO12Values, LS);
0197     case HcalHF:
0198       if (!mHFsorted)
0199         mHFsorted = sortList(mHFValues);
0200       return subDetOk(mHFValues, LS);
0201     default:
0202       return false;
0203   }
0204   return false;
0205 }
0206 
0207 bool HcalDcsValues::foundDcsId(DcsSet const& valList, HcalDcsDetId const& fid) const {
0208   HcalDcsValue dummy(fid.rawId(), -1, 0., 0., 0.);
0209   DcsSet::const_iterator lb = lower_bound(valList.begin(), valList.end(), dummy);
0210   if ((lb != valList.end()) && (lb->DcsId() == fid.rawId()))
0211     return true;
0212   return false;
0213 }
0214 
0215 bool HcalDcsValues::subDetOk(DcsSet const& valList, int LS) const {
0216   std::set<uint32_t> badIds;
0217   DcsSet::const_iterator val = valList.begin();
0218   while ((val != valList.end()) && ((LS > -1) ? (val->LS() <= LS) : true)) {
0219     if (!val->isValueGood()) {
0220       badIds.insert(val->DcsId());
0221     } else {
0222       std::set<uint32_t>::iterator fnd = badIds.find(val->DcsId());
0223       if (*fnd == val->DcsId())
0224         badIds.erase(fnd);
0225     }
0226     ++val;
0227   }
0228   return (badIds.empty());
0229 }
0230 
0231 bool HcalDcsValues::sortList(DcsSet& valList) const {
0232   sort(valList.begin(), valList.end());
0233   return true;
0234 }