CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/CondFormats/HcalObjects/src/HcalRawGains.cc

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