00001 #include "CalibFormats/HcalObjects/interface/HcalCalibrationWidthsSet.h" 00002 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h" 00003 #include "FWCore/Utilities/interface/Exception.h" 00004 #include <algorithm> 00005 #include <iostream> 00006 00007 00008 HcalCalibrationWidthsSet::HcalCalibrationWidthsSet() 00009 : sorted_ (false) {} 00010 00011 const HcalCalibrationWidths& HcalCalibrationWidthsSet::getCalibrationWidths(const DetId fId) const { 00012 Item target(fId); 00013 std::vector<Item>::const_iterator cell; 00014 if (sorted_) { 00015 cell = std::lower_bound (mItems.begin(), mItems.end(), target); 00016 } 00017 else { 00018 cell = std::find(mItems.begin(),mItems.end(), target); 00019 } 00020 if (cell == mItems.end() || cell->id != fId) 00021 throw cms::Exception ("Conditions not found") << "Unavailable HcalCalibrationWidths for cell " << HcalGenericDetId(fId); 00022 return cell->calib; 00023 } 00024 00025 void HcalCalibrationWidthsSet::setCalibrationWidths(DetId fId, const HcalCalibrationWidths& ca) { 00026 sorted_=false; 00027 std::vector<Item>::iterator cell=std::find(mItems.begin(),mItems.end(),Item(fId)); //slow, but guaranteed 00028 if (cell==mItems.end()) 00029 { 00030 mItems.push_back(Item(fId)); 00031 mItems.at(mItems.size()-1).calib=ca; 00032 return; 00033 } 00034 cell->calib=ca; 00035 } 00036 void HcalCalibrationWidthsSet::sort () { 00037 if (!sorted_) { 00038 std::sort (mItems.begin(), mItems.end()); 00039 sorted_ = true; 00040 } 00041 } 00042 void HcalCalibrationWidthsSet::clear() { 00043 mItems.clear(); 00044 }