Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:33:50

0001 #include "CalibFormats/CastorObjects/interface/CastorCalibrationWidthsSet.h"
0002 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
0003 #include "FWCore/Utilities/interface/Exception.h"
0004 #include <algorithm>
0005 #include <iostream>
0006 
0007 CastorCalibrationWidthsSet::CastorCalibrationWidthsSet() : sorted_(false) {}
0008 
0009 const CastorCalibrationWidths& CastorCalibrationWidthsSet::getCalibrationWidths(const DetId fId) const {
0010   Item target(fId);
0011   std::vector<Item>::const_iterator cell;
0012   if (sorted_) {
0013     cell = std::lower_bound(mItems.begin(), mItems.end(), target);
0014   } else {
0015     cell = std::find(mItems.begin(), mItems.end(), target);
0016   }
0017   if (cell == mItems.end() || cell->id != fId)
0018     throw cms::Exception("Conditions not found")
0019         << "Unavailable CastorCalibrationWidths for cell " << HcalGenericDetId(fId);
0020   return cell->calib;
0021 }
0022 
0023 void CastorCalibrationWidthsSet::setCalibrationWidths(DetId fId, const CastorCalibrationWidths& ca) {
0024   sorted_ = false;
0025   std::vector<Item>::iterator cell = std::find(mItems.begin(), mItems.end(), Item(fId));  //slow, but guaranteed
0026   if (cell == mItems.end()) {
0027     mItems.push_back(Item(fId));
0028     mItems.at(mItems.size() - 1).calib = ca;
0029     return;
0030   }
0031   cell->calib = ca;
0032 }
0033 void CastorCalibrationWidthsSet::sort() {
0034   if (!sorted_) {
0035     std::sort(mItems.begin(), mItems.end());
0036     sorted_ = true;
0037   }
0038 }
0039 void CastorCalibrationWidthsSet::clear() { mItems.clear(); }