Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /** 
0002 \class HcalDcsMap
0003 \author Gena Kukartsev
0004 POOL object to store map between detector ID and DCS ID
0005 Inspired by HcalElectronicsMap
0006 $Author: kukartse
0007 $Date: 2010/02/22 21:08:07 $
0008 $Revision: 1.1 $
0009 */
0010 
0011 #include <iostream>
0012 #include <set>
0013 
0014 #include "CondFormats/HcalObjects/interface/HcalDcsMap.h"
0015 #include "CondFormats/HcalObjects/interface/HcalObjectAddons.h"
0016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0017 
0018 HcalDcsMap::HcalDcsMap(const HcalDcsMapAddons::Helper& helper) : mItems(helper.mItems.begin(), helper.mItems.end()) {
0019   initialize();
0020 }
0021 
0022 HcalDcsMap::~HcalDcsMap() {}
0023 // copy-ctor
0024 HcalDcsMap::HcalDcsMap(const HcalDcsMap& src)
0025     : mItems(src.mItems), mItemsById(src.mItemsById), mItemsByDcsId(src.mItemsByDcsId) {}
0026 // copy assignment operator
0027 HcalDcsMap& HcalDcsMap::operator=(const HcalDcsMap& rhs) {
0028   HcalDcsMap temp(rhs);
0029   temp.swap(*this);
0030   return *this;
0031 }
0032 // public swap function
0033 void HcalDcsMap::swap(HcalDcsMap& other) {
0034   std::swap(mItems, other.mItems);
0035   std::swap(mItemsById, other.mItemsById);
0036   std::swap(mItemsByDcsId, other.mItemsByDcsId);
0037 }
0038 // move constructor
0039 HcalDcsMap::HcalDcsMap(HcalDcsMap&& other) : HcalDcsMap() { other.swap(*this); }
0040 
0041 HcalDcsMap::const_iterator HcalDcsMap::beginById(void) const {
0042   const_iterator _iter;
0043   _iter.fIter = mItemsById.begin();
0044   return _iter;
0045 }
0046 
0047 HcalDcsMap::const_iterator HcalDcsMap::beginByDcsId(void) const {
0048   const_iterator _iter;
0049   _iter.fIter = mItemsByDcsId.begin();
0050   return _iter;
0051 }
0052 
0053 HcalDcsMap::const_iterator HcalDcsMap::endById(void) const {
0054   const_iterator _iter;
0055   _iter.fIter = mItemsById.end();
0056   return _iter;
0057 }
0058 
0059 HcalDcsMap::const_iterator HcalDcsMap::endByDcsId(void) const {
0060   const_iterator _iter;
0061   _iter.fIter = mItemsByDcsId.end();
0062   return _iter;
0063 }
0064 
0065 // iterator methods
0066 bool HcalDcsMap::const_iterator::operator!=(const HcalDcsMap::const_iterator& other) {
0067   if (fIter != other.fIter)
0068     return true;
0069   else
0070     return false;
0071 }
0072 
0073 HcalDcsMap::const_iterator HcalDcsMap::const_iterator::operator++() {
0074   ++fIter;
0075   return *this;
0076 }
0077 
0078 HcalDcsMap::const_iterator HcalDcsMap::const_iterator::operator++(int) {
0079   const_iterator i = *this;
0080   ++fIter;
0081   return i;
0082 }
0083 
0084 void HcalDcsMap::const_iterator::next(void) { ++fIter; }
0085 
0086 HcalDcsDetId HcalDcsMap::const_iterator::getHcalDcsDetId(void) { return (*fIter)->mDcsId; }
0087 
0088 HcalDetId HcalDcsMap::const_iterator::getHcalDetId(void) { return (*fIter)->mId; }
0089 
0090 const HcalDcsMap::Item* HcalDcsMap::findById(unsigned long fId) const {
0091   Item target(fId, 0);
0092   return HcalObjectAddons::findByT<Item, HcalDcsMapAddons::LessById>(&target, mItemsById);
0093 }
0094 
0095 const HcalDcsMap::Item* HcalDcsMap::findByDcsId(unsigned long fDcsId) const {
0096   Item target(0, fDcsId);
0097   return HcalObjectAddons::findByT<Item, HcalDcsMapAddons::LessByDcsId>(&target, mItemsByDcsId);
0098 }
0099 
0100 HcalDetId HcalDcsMap::lookup(HcalDcsDetId fId) const {
0101   // DCS type is a part of DcsDetId but it does not make sense to keep
0102   // duplicate records in the map for DCS channels where only type is different.
0103   // Hence, the type in HcalDcsDetId is always forced to DCSUNKNOWN
0104   HcalDcsDetId fDcsId_notype(fId.subdet(),
0105                              fId.ring(),  // side is already included
0106                              fId.slice(),
0107                              HcalDcsDetId::DCSUNKNOWN,
0108                              fId.subchannel());
0109   auto item = HcalDcsMap::findByDcsId(fDcsId_notype.rawId());
0110   return item ? item->mId : 0;
0111 }
0112 
0113 HcalDcsDetId HcalDcsMap::lookup(HcalDetId fId, HcalDcsDetId::DcsType type) const {
0114   auto item = HcalDcsMap::findById(fId.rawId());
0115   HcalDcsDetId _id(item ? item->mId : 0);
0116   return HcalDcsDetId(_id.subdet(), _id.zside() * _id.ring(), _id.slice(), type, _id.subchannel());
0117 }
0118 
0119 //FIXME: remove duplicates
0120 std::vector<HcalDcsDetId> HcalDcsMap::allHcalDcsDetId() const {
0121   std::vector<HcalDcsDetId> result;
0122   for (std::vector<Item>::const_iterator item = mItems.begin(); item != mItems.end(); item++)
0123     if (item->mDcsId)
0124       result.push_back(HcalDcsDetId(item->mDcsId));
0125   return result;
0126 }
0127 
0128 // FIXME: remove duplicates
0129 std::vector<HcalGenericDetId> HcalDcsMap::allHcalDetId() const {
0130   std::vector<HcalGenericDetId> result;
0131   std::set<unsigned long> allIds;
0132   for (std::vector<Item>::const_iterator item = mItems.begin(); item != mItems.end(); item++)
0133     if (item->mId)
0134       allIds.insert(item->mId);
0135   for (std::set<unsigned long>::const_iterator channel = allIds.begin(); channel != allIds.end(); channel++) {
0136     result.push_back(HcalGenericDetId(*channel));
0137   }
0138   return result;
0139 }
0140 
0141 HcalDcsMapAddons::Helper::Helper() {}
0142 
0143 bool HcalDcsMapAddons::Helper::mapGeomId2DcsId(HcalDetId fId, HcalDcsDetId fDcsId) {
0144   // DCS type is a part of DcsDetId but it does not make sense to keep
0145   // duplicate records in the map for DCS channels where only type is different.
0146   // Hence, the type in HcalDcsDetId is always forced to DCSUNKNOWN
0147   HcalDcsDetId fDcsId_notype(fDcsId.subdet(),
0148                              fDcsId.ring(),  // side is included
0149                              fDcsId.slice(),
0150                              HcalDcsDetId::DCSUNKNOWN,
0151                              fDcsId.subchannel());
0152   HcalDcsMap::Item target(fId, fDcsId_notype);
0153   auto iter = mItems.find(target);
0154   if (iter != mItems.end() and iter->mId == fId) {
0155     edm::LogWarning("HCAL") << "HcalDcsMap::mapGeomId2DcsId-> Geom channel " << fId << " already mapped to DCS channel "
0156                             << fDcsId_notype;
0157     return false;  // element already exists
0158   }
0159   mItems.insert(target);
0160 
0161   return true;
0162 }
0163 
0164 void HcalDcsMap::sortById() { HcalObjectAddons::sortByT<Item, HcalDcsMapAddons::LessById>(mItems, mItemsById); }
0165 void HcalDcsMap::sortByDcsId() {
0166   HcalObjectAddons::sortByT<Item, HcalDcsMapAddons::LessByDcsId>(mItems, mItemsByDcsId);
0167 }
0168 
0169 void HcalDcsMap::initialize() {
0170   sortById();
0171   sortByDcsId();
0172 }