Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#include "CalibFormats/CastorObjects/interface/CastorCalibrationsSet.h"
#include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
#include "FWCore/Utilities/interface/Exception.h"
#include <algorithm>

CastorCalibrationsSet::CastorCalibrationsSet() : sorted_(false) {}

const CastorCalibrations& CastorCalibrationsSet::getCalibrations(const DetId fId) const {
  Item target(fId);
  std::vector<Item>::const_iterator cell;
  if (sorted_) {
    cell = std::lower_bound(mItems.begin(), mItems.end(), target);
  } else {
    cell = std::find(mItems.begin(), mItems.end(), target);
  }
  if (cell == mItems.end() || cell->id != fId)
    throw cms::Exception("Conditions not found") << "Unavailable CastorCalibrations for cell " << HcalGenericDetId(fId);
  return cell->calib;
}

void CastorCalibrationsSet::setCalibrations(DetId fId, const CastorCalibrations& ca) {
  sorted_ = false;
  std::vector<Item>::iterator cell = std::find(mItems.begin(), mItems.end(), Item(fId));  //slow, but guaranteed
  if (cell == mItems.end()) {
    mItems.push_back(Item(fId));
    mItems.at(mItems.size() - 1).calib = ca;
    return;
  }

  cell->calib = ca;
}
void CastorCalibrationsSet::sort() {
  if (!sorted_) {
    std::sort(mItems.begin(), mItems.end());
    sorted_ = true;
  }
}
void CastorCalibrationsSet::clear() { mItems.clear(); }