Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:50:53

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