Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:02:16

0001 /** 
0002 \class HcalRawGains
0003 \author Fedor Ratnikov (UMd)
0004 POOL object to store Gain values 4xCapId
0005 $Author: ratnikov
0006 $Date: 2007/01/09 22:49:21 $
0007 $Revision: 1.3 $
0008 */
0009 
0010 #include <iostream>
0011 
0012 #include "FWCore/Utilities/interface/Exception.h"
0013 #include "CondFormats/HcalObjects/interface/HcalRawGains.h"
0014 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
0015 
0016 namespace {
0017   class compareItems {
0018   public:
0019     bool operator()(const HcalRawGains::Item& first, const HcalRawGains::Item& second) const {
0020       return first.rawId() < second.rawId();
0021     }
0022   };
0023 
0024   HcalRawGains::Container::const_iterator find(const HcalRawGains::Container& container, unsigned long id) {
0025     HcalRawGains::Container::const_iterator result = container.begin();
0026     for (; result != container.end(); result++) {
0027       if (result->rawId() == id)
0028         break;  // found
0029     }
0030     return result;
0031   }
0032 }  // namespace
0033 
0034 HcalRawGains::HcalRawGains() : mSorted(false) {}
0035 
0036 HcalRawGains::~HcalRawGains() {}
0037 
0038 const HcalRawGain* HcalRawGains::getValues(DetId fId) const {
0039   Item target(fId.rawId(), 0, 0, 0, HcalRawGain::BAD);
0040   std::vector<Item>::const_iterator cell;
0041   if (sorted()) {
0042     cell = std::lower_bound(mItems.begin(), mItems.end(), target, compareItems());
0043   } else {
0044     std::cerr << "HcalRawGains::getValues-> container is not sorted. Please sort it to search effectively" << std::endl;
0045     cell = find(mItems, fId.rawId());
0046   }
0047   if (cell == mItems.end() || cell->rawId() != target.rawId())
0048     throw cms::Exception("Conditions not found")
0049         << "Unavailable Raw Gains for cell " << HcalGenericDetId(target.rawId());
0050   return &(*cell);
0051 }
0052 
0053 std::vector<DetId> HcalRawGains::getAllChannels() const {
0054   std::vector<DetId> result;
0055   for (std::vector<Item>::const_iterator item = mItems.begin(); item != mItems.end(); item++) {
0056     result.push_back(DetId(item->rawId()));
0057   }
0058   return result;
0059 }
0060 
0061 HcalRawGain* HcalRawGains::addItem(DetId fId) {
0062   HcalRawGain item(fId.rawId());
0063   mItems.push_back(item);
0064   mSorted = false;
0065   return &(mItems.back());
0066 }
0067 
0068 void HcalRawGains::addValues(DetId fId, const HcalRawGain& fValues) {
0069   Item item(fId.rawId(), fValues.getValue(), fValues.getError(), fValues.getVoltage(), fValues.getStatus());
0070   mItems.push_back(item);
0071   mSorted = false;
0072 }
0073 
0074 void HcalRawGains::sort() {
0075   if (!mSorted) {
0076     std::sort(mItems.begin(), mItems.end(), compareItems());
0077     mSorted = true;
0078   }
0079 }