Go to the documentation of this file.00001
00007 #include <iostream>
00008
00009 #include "FWCore/Utilities/interface/Exception.h"
00010 #include "CondFormats/CastorObjects/interface/CastorRawGains.h"
00011 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
00012
00013 namespace {
00014 class compareItems {
00015 public:
00016 bool operator () (const CastorRawGains::Item& first, const CastorRawGains::Item& second) const {
00017 return first.rawId () < second.rawId ();
00018 }
00019 };
00020
00021 CastorRawGains::Container::const_iterator
00022 find (const CastorRawGains::Container& container, unsigned long id) {
00023 CastorRawGains::Container::const_iterator result = container.begin ();
00024 for (; result != container.end (); result++) {
00025 if (result->rawId () == id) break;
00026 }
00027 return result;
00028 }
00029 }
00030
00031 CastorRawGains::CastorRawGains()
00032 : mSorted (false) {}
00033
00034 CastorRawGains::~CastorRawGains(){}
00035
00036 const CastorRawGain* CastorRawGains::getValues (DetId fId) const {
00037 Item target (fId.rawId (), 0, 0, 0, CastorRawGain::BAD);
00038 std::vector<Item>::const_iterator cell;
00039 if (sorted ()) {
00040 cell = std::lower_bound (mItems.begin(), mItems.end(), target, compareItems ());
00041 }
00042 else {
00043 std::cerr << "CastorRawGains::getValues-> container is not sorted. Please sort it to search effectively" << std::endl;
00044 cell = find (mItems, fId.rawId ());
00045 }
00046 if (cell == mItems.end() || cell->rawId () != target.rawId ())
00047 throw cms::Exception ("Conditions not found") << "Unavailable Raw Gains for cell " << HcalGenericDetId(target.rawId());
00048 return &(*cell);
00049 }
00050
00051 std::vector<DetId> CastorRawGains::getAllChannels () const {
00052 std::vector<DetId> result;
00053 for (std::vector<Item>::const_iterator item = mItems.begin (); item != mItems.end (); item++) {
00054 result.push_back (DetId (item->rawId ()));
00055 }
00056 return result;
00057 }
00058
00059
00060 CastorRawGain* CastorRawGains::addItem (DetId fId) {
00061 CastorRawGain item (fId.rawId ());
00062 mItems.push_back (item);
00063 mSorted = false;
00064 return &(mItems.back ());
00065 }
00066
00067 void CastorRawGains::addValues (DetId fId, const CastorRawGain& fValues) {
00068 Item item (fId.rawId (), fValues.getValue(), fValues.getError(), fValues.getVoltage(), fValues.getStatus());
00069 mItems.push_back (item);
00070 mSorted = false;
00071 }
00072
00073
00074 void CastorRawGains::sort () {
00075 if (!mSorted) {
00076 std::sort (mItems.begin(), mItems.end(), compareItems ());
00077 mSorted = true;
00078 }
00079 }