CMS 3D CMS Logo

CastorPedestals.cc

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

Generated on Tue Jun 9 17:26:18 2009 for CMSSW by  doxygen 1.5.4