Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:51:11

0001 #include <algorithm>
0002 #include <iostream>
0003 #include <set>
0004 
0005 #include "CondFormats/HcalObjects/interface/HcalFrontEndMap.h"
0006 #include "CondFormats/HcalObjects/interface/HcalObjectAddons.h"
0007 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0008 #include "DataFormats/HcalDetId/interface/HcalFrontEndId.h"
0009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0010 
0011 HcalFrontEndMap::HcalFrontEndMap(const HcalFrontEndMapAddons::Helper& helper)
0012     : mPItems(helper.mPItems.begin(), helper.mPItems.end()) {
0013   initialize();
0014 }
0015 
0016 HcalFrontEndMap::~HcalFrontEndMap() {}
0017 
0018 // copy-ctor
0019 HcalFrontEndMap::HcalFrontEndMap(const HcalFrontEndMap& src) : mPItems(src.mPItems), mPItemsById(src.mPItemsById) {}
0020 
0021 // copy assignment operator
0022 HcalFrontEndMap& HcalFrontEndMap::operator=(const HcalFrontEndMap& rhs) {
0023   HcalFrontEndMap temp(rhs);
0024   temp.swap(*this);
0025   return *this;
0026 }
0027 
0028 // public swap function
0029 void HcalFrontEndMap::swap(HcalFrontEndMap& other) {
0030   std::swap(mPItems, other.mPItems);
0031   std::swap(mPItemsById, other.mPItemsById);
0032 }
0033 
0034 // move constructor
0035 HcalFrontEndMap::HcalFrontEndMap(HcalFrontEndMap&& other) : HcalFrontEndMap() { other.swap(*this); }
0036 
0037 const HcalFrontEndMap::PrecisionItem* HcalFrontEndMap::findById(uint32_t fId) const {
0038   PrecisionItem target(fId, 0, "");
0039   return HcalObjectAddons::findByT<PrecisionItem, HcalFrontEndMapAddons::LessById>(&target, mPItemsById);
0040 }
0041 
0042 HcalFrontEndMapAddons::Helper::Helper() {}
0043 
0044 bool HcalFrontEndMapAddons::Helper::loadObject(DetId fId, int rm, std::string rbx) {
0045   HcalFrontEndMap::PrecisionItem target(fId.rawId(), rm, rbx);
0046   auto iter = mPItems.find(target);
0047   if (iter != mPItems.end()) {
0048     edm::LogWarning("HCAL") << "HcalFrontEndMap::loadObject DetId " << HcalDetId(fId) << " already exists with RM "
0049                             << iter->mRM << " RBX " << iter->mRBX << " new values " << rm << " and " << rbx
0050                             << " are ignored";
0051     return false;
0052   } else {
0053     mPItems.insert(target);
0054     return true;
0055   }
0056 }
0057 
0058 const int HcalFrontEndMap::lookupRM(DetId fId) const {
0059   const PrecisionItem* item = findById(fId.rawId());
0060   return (item ? item->mRM : 0);
0061 }
0062 
0063 const int HcalFrontEndMap::lookupRMIndex(DetId fId) const {
0064   const PrecisionItem* item = findById(fId.rawId());
0065   HcalFrontEndId id;
0066   if (item)
0067     id = HcalFrontEndId(item->mRBX, item->mRM, 0, 1, 0, 1, 0);
0068   return id.rmIndex();
0069 }
0070 
0071 const std::string HcalFrontEndMap::lookupRBX(DetId fId) const {
0072   const PrecisionItem* item = findById(fId.rawId());
0073   return (item ? item->mRBX : "");
0074 }
0075 
0076 const int HcalFrontEndMap::lookupRBXIndex(DetId fId) const {
0077   const PrecisionItem* item = findById(fId.rawId());
0078   HcalFrontEndId id;
0079   if (item)
0080     id = HcalFrontEndId(item->mRBX, item->mRM, 0, 1, 0, 1, 0);
0081   return id.rbxIndex();
0082 }
0083 
0084 std::vector<DetId> HcalFrontEndMap::allDetIds() const {
0085   std::vector<DetId> result;
0086   for (std::vector<PrecisionItem>::const_iterator item = mPItems.begin(); item != mPItems.end(); item++)
0087     if (item->mId)
0088       result.push_back(DetId(item->mId));
0089   return result;
0090 }
0091 
0092 std::vector<int> HcalFrontEndMap::allRMs() const {
0093   std::vector<int> result;
0094   for (std::vector<PrecisionItem>::const_iterator item = mPItems.begin(); item != mPItems.end(); item++) {
0095     if (std::find(result.begin(), result.end(), item->mRM) == result.end())
0096       result.push_back(item->mRM);
0097   }
0098   return result;
0099 }
0100 
0101 std::vector<std::string> HcalFrontEndMap::allRBXs() const {
0102   std::vector<std::string> result;
0103   for (std::vector<PrecisionItem>::const_iterator item = mPItems.begin(); item != mPItems.end(); item++) {
0104     if (std::find(result.begin(), result.end(), item->mRBX) == result.end())
0105       result.push_back(item->mRBX);
0106   }
0107   return result;
0108 }
0109 
0110 void HcalFrontEndMap::sortById() {
0111   HcalObjectAddons::sortByT<PrecisionItem, HcalFrontEndMapAddons::LessById>(mPItems, mPItemsById);
0112 }
0113 
0114 void HcalFrontEndMap::initialize() { HcalFrontEndMap::sortById(); }