CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/CalibFormats/HcalObjects/src/HcalCalibrationsSet.cc

Go to the documentation of this file.
00001 #include "CalibFormats/HcalObjects/interface/HcalCalibrationsSet.h"
00002 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
00003 #include "FWCore/Utilities/interface/Exception.h"
00004 #include <algorithm>
00005 #include <iostream>
00006 
00007 
00008 HcalCalibrationsSet::HcalCalibrationsSet() 
00009   : sorted_ (false) {}
00010 
00011 const HcalCalibrations& HcalCalibrationsSet::getCalibrations(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 HcalCalibrations for cell " << HcalGenericDetId(fId);
00022   return cell->calib;
00023 }
00024 
00025 void HcalCalibrationsSet::setCalibrations(DetId fId, const HcalCalibrations& 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 HcalCalibrationsSet::sort () {
00037   if (!sorted_) {
00038     std::sort (mItems.begin(), mItems.end());
00039     sorted_ = true;
00040   }
00041 }
00042 void HcalCalibrationsSet::clear() {
00043   mItems.clear();
00044 }