Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:58:11

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