File indexing completed on 2024-04-06 12:02:15
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
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
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 }