Go to the documentation of this file.00001 #include <algorithm>
00002 #include <set>
00003 #include "CondFormats/HcalObjects/interface/HcalDcsValues.h"
00004
00005 HcalDcsValues::HcalDcsValues() :
00006 mHBsorted(false),mHEsorted(false),mHO0sorted(false), mHO12sorted(false),
00007 mHFsorted(false) {
00008 }
00009
00010 HcalDcsValues::~HcalDcsValues() {
00011 }
00012
00013 bool HcalDcsValues::addValue(HcalDcsValue const& newVal) {
00014 HcalDcsDetId tempId( newVal.DcsId() );
00015 switch (tempId.subdet()) {
00016 case HcalDcsBarrel :
00017 mHBValues.push_back(newVal);
00018 mHBsorted=false;
00019 return true;
00020 case HcalDcsEndcap :
00021 mHEValues.push_back(newVal);
00022 mHEsorted=false;
00023 return true;
00024 case HcalDcsOuter :
00025 if (tempId.ring() == 0) {
00026 mHO0Values.push_back(newVal);
00027 mHO0sorted=false;
00028 } else {
00029 mHO12Values.push_back(newVal);
00030 mHO12sorted=false;
00031 }
00032 return true;
00033 case HcalDcsForward :
00034 mHFValues.push_back(newVal);
00035 mHFsorted=false;
00036 return true;
00037 default :
00038 return false;
00039 }
00040 }
00041
00042 void HcalDcsValues::sortAll() {
00043 mHBsorted = sortList(mHBValues);
00044 mHEsorted = sortList(mHEValues);
00045 mHO0sorted = sortList(mHO0Values);
00046 mHO12sorted = sortList(mHO12Values);
00047 mHFsorted = sortList(mHFValues);
00048 }
00049
00050 bool HcalDcsValues::exists(HcalDcsDetId const& fid) {
00051 switch (fid.subdet()) {
00052 case HcalDcsBarrel :
00053 if (!mHBsorted) mHBsorted = sortList(mHBValues);
00054 return foundDcsId(mHBValues, fid);
00055 case HcalDcsEndcap :
00056 if (!mHEsorted) mHEsorted = sortList(mHEValues);
00057 return foundDcsId(mHEValues, fid);
00058 case HcalDcsOuter :
00059 if (fid.ring() == 0) {
00060 if (!mHO0sorted) mHO0sorted = sortList(mHO0Values);
00061 return foundDcsId(mHO0Values, fid);
00062 } else {
00063 if (!mHO12sorted) mHO12sorted = sortList(mHO12Values);
00064 return foundDcsId(mHO12Values, fid);
00065 }
00066 case HcalDcsForward :
00067 if (!mHFsorted) mHFsorted = sortList(mHFValues);
00068 return foundDcsId(mHBValues, fid);
00069 default : return false;
00070 }
00071 }
00072
00073 HcalDcsValues::DcsSet HcalDcsValues::getValues(HcalDcsDetId const& fid) {
00074 DcsSet * valList = 0;
00075 switch(fid.subdet()) {
00076 case HcalDcsBarrel :
00077 valList = &mHBValues;
00078 if (!mHBsorted) mHBsorted = sortList(mHBValues);
00079 break;
00080 case HcalDcsEndcap :
00081 valList = &mHEValues;
00082 if (!mHEsorted) mHEsorted = sortList(mHEValues);
00083 break;
00084 case HcalDcsOuter :
00085 if (fid.ring() == 0) {
00086 valList = &mHO0Values;
00087 if (!mHO0sorted) mHO0sorted = sortList(mHO0Values);
00088 } else {
00089 valList = &mHO12Values;
00090 if (!mHO12sorted) mHO12sorted = sortList(mHO12Values);
00091 }
00092 break;
00093 case HcalDcsForward :
00094 valList = &mHFValues;
00095 if (!mHFsorted) mHFsorted = sortList(mHFValues);
00096 break;
00097 default : valList = 0;
00098 }
00099
00100 if (valList) {
00101 HcalDcsValue dummy(fid.rawId(), -1, 0., 0., 0.);
00102 DcsSet::const_iterator lb = lower_bound(valList->begin(), valList->end(), dummy);
00103 if ((lb != valList->end()) && (lb->DcsId() == fid.rawId())) {
00104 DcsSet::const_iterator ub = upper_bound(valList->begin(), valList->end(), dummy);
00105 return DcsSet(lb, ub) ;
00106 }
00107 }
00108 return DcsSet() ;
00109 }
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 HcalDcsValues::DcsSet const & HcalDcsValues::getAllSubdetValues(DcsSubDet subd) const {
00156 switch (subd) {
00157 case HcalHB : return mHBValues;
00158 case HcalHE : return mHEValues;
00159 case HcalHO0 : return mHO0Values;
00160 case HcalHO12 : return mHO12Values;
00161 case HcalHF : return mHFValues;
00162 }
00163 return mHBValues;
00164 }
00165
00166 bool HcalDcsValues::DcsValuesOK(DcsSubDet subd, int LS) {
00167 switch (subd) {
00168 case HcalHB :
00169 if (!mHBsorted) mHBsorted = sortList(mHBValues);
00170 return subDetOk(mHBValues, LS);
00171 case HcalHE :
00172 if (!mHEsorted) mHEsorted = sortList(mHEValues);
00173 return subDetOk(mHEValues, LS);
00174 case HcalHO0 :
00175 if (!mHO0sorted) mHO0sorted = sortList(mHO0Values);
00176 return subDetOk(mHO0Values, LS);
00177 case HcalHO12 :
00178 if (!mHO12sorted) mHO12sorted = sortList(mHO12Values);
00179 return subDetOk(mHO12Values, LS);
00180 case HcalHF :
00181 if (!mHFsorted) mHFsorted = sortList(mHFValues);
00182 return subDetOk(mHFValues, LS);
00183 default : return false;
00184 }
00185 return false;
00186 }
00187
00188 bool HcalDcsValues::foundDcsId(DcsSet const& valList,
00189 HcalDcsDetId const& fid) const {
00190 HcalDcsValue dummy(fid.rawId(), -1, 0., 0., 0.);
00191 DcsSet::const_iterator lb = lower_bound(valList.begin(), valList.end(), dummy);
00192 if ((lb != valList.end()) && (lb->DcsId() == fid.rawId()))
00193 return true;
00194 return false;
00195 }
00196
00197 bool HcalDcsValues::subDetOk(DcsSet const& valList, int LS) const {
00198 std::set<uint32_t> badIds;
00199 DcsSet::const_iterator val = valList.begin();
00200 while ( (val != valList.end()) &&
00201 ( (LS>-1) ? (val->LS()<=LS) : true) ) {
00202 if (!val->isValueGood()) {
00203 badIds.insert(val->DcsId());
00204 } else {
00205 std::set<uint32_t>::iterator fnd = badIds.find(val->DcsId());
00206 if (*fnd == val->DcsId()) badIds.erase(fnd);
00207 }
00208 ++val;
00209 }
00210 return (badIds.size()==0);
00211 }
00212
00213 bool HcalDcsValues::sortList(DcsSet& valList) const {
00214 sort(valList.begin(), valList.end());
00215 return true;
00216 }