CMS 3D CMS Logo

CastorQIEData.cc

Go to the documentation of this file.
00001 
00007 #include <iostream>
00008 
00009 #include "FWCore/Utilities/interface/Exception.h"
00010 #include "CondFormats/CastorObjects/interface/CastorQIEData.h"
00011 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
00012 
00013 namespace {
00014   CastorQIEShape shape_; // use one default set
00015 
00016   int index (int fCapId, int Range) {return fCapId*4+Range;}
00017 
00018   class compareItems {
00019   public:
00020     bool operator () (const CastorQIECoder& first, const CastorQIECoder& second) const {
00021       return first.rawId () < second.rawId ();
00022     }
00023   };
00024 
00025   std::vector<CastorQIECoder>::const_iterator 
00026   find (const std::vector<CastorQIECoder>& container, unsigned long id) {
00027     std::vector<CastorQIECoder>::const_iterator result = container.begin ();
00028     for (; result != container.end (); result++) {
00029       if (result->rawId () == id) break; // found
00030     }
00031     return result;
00032   }
00033 }
00034 
00035 CastorQIEData::CastorQIEData() 
00036   : mSorted (true) {}
00037 
00038 CastorQIEData::CastorQIEData(const CastorQIEData& a) {
00039   //std::cout << "CastorQIEData::CastorQIEData-> from:" << a.mItems.size () << std::endl;
00040   mItems = a.mItems;
00041   mSorted = a.mSorted;
00042   //std::cout << "CastorQIEData::CastorQIEData-> to:" << mItems.size () << std::endl;
00043 }
00044 
00045 CastorQIEData::~CastorQIEData(){}
00046 
00047 const CastorQIEShape& CastorQIEData::getShape () const {
00048   return shape_;
00049 }
00050 
00051 const CastorQIECoder* CastorQIEData::getCoder (DetId fId) const {
00052   CastorQIECoder target (fId.rawId ());
00053   std::vector<CastorQIECoder>::const_iterator cell;
00054   if (sorted ()) {
00055     cell = std::lower_bound (mItems.begin(), mItems.end(), target, compareItems ());
00056   }
00057   else {
00058     std::cerr << "CastorQIEData::getValues-> container is not sorted. Please sort it to search effectively" << std::endl;
00059     cell = find (mItems, target.rawId ());
00060   }
00061   if (cell == mItems.end() || cell->rawId () != fId.rawId ())
00062     throw cms::Exception ("Conditions not found") << "Unavailable QIE data for cell " << HcalGenericDetId(fId);
00063   return &(*cell);
00064 }
00065 
00066 std::vector<DetId> CastorQIEData::getAllChannels () const {
00067   std::vector<DetId> result;
00068   for (std::vector<CastorQIECoder>::const_iterator item = mItems.begin (); item != mItems.end (); item++) {
00069     result.push_back (DetId (item->rawId ()));
00070   }
00071   return result;
00072 }
00073 
00074 bool CastorQIEData::addCoder (DetId fId, const CastorQIECoder& fCoder) {
00075   CastorQIECoder newCoder (fId.rawId ());
00076   for (int range = 0; range < 4; range++) { 
00077     for (int capid = 0; capid < 4; capid++) {
00078       newCoder.setOffset (capid, range, fCoder.offset (capid, range));
00079       newCoder.setSlope (capid, range, fCoder.slope (capid, range));
00080     }
00081   }
00082  mItems.push_back (newCoder);
00083  mSorted = false;
00084  return true; 
00085 }
00086 
00087 void CastorQIEData::sort () {
00088   if (!mSorted) {
00089     std::sort (mItems.begin(), mItems.end(), compareItems ());
00090     mSorted = true;
00091   }
00092 }

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