CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_13_patch3/src/CalibFormats/CastorObjects/src/CastorCalibrationsSet.cc

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