CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/CalibFormats/CastorObjects/src/CastorCalibrationWidthsSet.cc

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