File indexing completed on 2024-04-06 12:02:15
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include <iostream>
0011 #include <set>
0012
0013 #include "CondFormats/HcalObjects/interface/HcalElectronicsMap.h"
0014 #include "CondFormats/HcalObjects/interface/HcalObjectAddons.h"
0015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0016
0017 HcalElectronicsMap::HcalElectronicsMap(const HcalElectronicsMapAddons::Helper& helper)
0018 : mPItems(helper.mPItems), mTItems(helper.mTItems) {
0019 initialize();
0020 }
0021
0022 HcalElectronicsMap::~HcalElectronicsMap() {}
0023
0024 HcalElectronicsMap::HcalElectronicsMap(const HcalElectronicsMap& src)
0025 : mPItems(src.mPItems), mTItems(src.mTItems), mPItemsById(src.mPItemsById), mTItemsByTrigId(src.mTItemsByTrigId) {}
0026
0027 HcalElectronicsMap& HcalElectronicsMap::operator=(const HcalElectronicsMap& rhs) {
0028 HcalElectronicsMap temp(rhs);
0029 temp.swap(*this);
0030 return *this;
0031 }
0032
0033 void HcalElectronicsMap::swap(HcalElectronicsMap& other) {
0034 std::swap(mPItems, other.mPItems);
0035 std::swap(mTItems, other.mTItems);
0036 std::swap(mPItemsById, other.mPItemsById);
0037 std::swap(mTItemsByTrigId, other.mTItemsByTrigId);
0038 }
0039
0040 HcalElectronicsMap::HcalElectronicsMap(HcalElectronicsMap&& other) { other.swap(*this); }
0041
0042 const HcalElectronicsMap::PrecisionItem* HcalElectronicsMap::findById(unsigned long fId) const {
0043 PrecisionItem target(fId, 0);
0044 return HcalObjectAddons::findByT<PrecisionItem, HcalElectronicsMapAddons::LessById>(&target, mPItemsById);
0045 }
0046
0047 const HcalElectronicsMap::PrecisionItem* HcalElectronicsMap::findPByElId(unsigned long fElId) const {
0048 HcalElectronicsId eid(fElId);
0049 const PrecisionItem* i = &(mPItems[eid.linearIndex()]);
0050
0051 if (i != nullptr && i->mElId != fElId)
0052 i = nullptr;
0053 return i;
0054 }
0055
0056 const HcalElectronicsMap::TriggerItem* HcalElectronicsMap::findTByElId(unsigned long fElId) const {
0057 HcalElectronicsId eid(fElId);
0058 const TriggerItem* i = &(mTItems[eid.linearIndex()]);
0059
0060 if (i != nullptr && i->mElId != fElId)
0061 i = nullptr;
0062 return i;
0063 }
0064
0065 const HcalElectronicsMap::TriggerItem* HcalElectronicsMap::findByTrigId(unsigned long fTrigId) const {
0066 TriggerItem target(fTrigId, 0);
0067 return HcalObjectAddons::findByT<TriggerItem, HcalElectronicsMapAddons::LessByTrigId>(&target, mTItemsByTrigId);
0068 }
0069
0070 const DetId HcalElectronicsMap::lookup(HcalElectronicsId fId) const {
0071 const PrecisionItem* item = findPByElId(fId.rawId());
0072 return DetId(item ? item->mId : 0);
0073 }
0074
0075 const HcalElectronicsId HcalElectronicsMap::lookup(DetId fId) const {
0076 const PrecisionItem* item = findById(fId.rawId());
0077 return HcalElectronicsId(item ? item->mElId : 0);
0078 }
0079
0080 const DetId HcalElectronicsMap::lookupTrigger(HcalElectronicsId fId) const {
0081 const TriggerItem* item = findTByElId(fId.rawId());
0082 return DetId(item ? item->mTrigId : 0);
0083 }
0084
0085 const HcalElectronicsId HcalElectronicsMap::lookupTrigger(DetId fId) const {
0086 const TriggerItem* item = findByTrigId(fId.rawId());
0087 return HcalElectronicsId(item ? item->mElId : 0);
0088 }
0089
0090 bool HcalElectronicsMap::lookup(const HcalElectronicsId pid, HcalElectronicsId& eid, HcalGenericDetId& did) const {
0091 const PrecisionItem* i = &(mPItems[pid.linearIndex()]);
0092 if (i != nullptr && i->mId != 0) {
0093 eid = HcalElectronicsId(i->mElId);
0094 did = HcalGenericDetId(i->mId);
0095 return true;
0096 } else
0097 return false;
0098 }
0099
0100 bool HcalElectronicsMap::lookup(const HcalElectronicsId pid, HcalElectronicsId& eid, HcalTrigTowerDetId& did) const {
0101 const TriggerItem* i = &(mTItems[pid.linearIndex()]);
0102 if (i != nullptr && i->mTrigId != 0) {
0103 eid = HcalElectronicsId(i->mElId);
0104 did = HcalGenericDetId(i->mTrigId);
0105 return true;
0106 } else
0107 return false;
0108 }
0109
0110 std::vector<HcalElectronicsId> HcalElectronicsMap::allElectronicsId() const {
0111 std::vector<HcalElectronicsId> result;
0112 for (std::vector<PrecisionItem>::const_iterator item = mPItems.begin(); item != mPItems.end(); item++)
0113 if (item->mElId)
0114 result.push_back(HcalElectronicsId(item->mElId));
0115 for (std::vector<TriggerItem>::const_iterator item = mTItems.begin(); item != mTItems.end(); item++)
0116 if (item->mElId)
0117 result.push_back(HcalElectronicsId(item->mElId));
0118
0119 return result;
0120 }
0121
0122 std::vector<HcalElectronicsId> HcalElectronicsMap::allElectronicsIdPrecision() const {
0123 std::vector<HcalElectronicsId> result;
0124 for (std::vector<PrecisionItem>::const_iterator item = mPItems.begin(); item != mPItems.end(); item++)
0125 if (item->mElId)
0126 result.push_back(HcalElectronicsId(item->mElId));
0127 return result;
0128 }
0129
0130 std::vector<HcalElectronicsId> HcalElectronicsMap::allElectronicsIdTrigger() const {
0131 std::vector<HcalElectronicsId> result;
0132 for (std::vector<TriggerItem>::const_iterator item = mTItems.begin(); item != mTItems.end(); item++)
0133 if (item->mElId)
0134 result.push_back(HcalElectronicsId(item->mElId));
0135
0136 return result;
0137 }
0138
0139 std::vector<HcalGenericDetId> HcalElectronicsMap::allPrecisionId() const {
0140 std::vector<HcalGenericDetId> result;
0141 std::set<unsigned long> allIds;
0142 for (std::vector<PrecisionItem>::const_iterator item = mPItems.begin(); item != mPItems.end(); item++)
0143 if (item->mId)
0144 allIds.insert(item->mId);
0145 for (std::set<unsigned long>::const_iterator channel = allIds.begin(); channel != allIds.end(); channel++) {
0146 result.push_back(HcalGenericDetId(*channel));
0147 }
0148 return result;
0149 }
0150
0151 std::vector<HcalTrigTowerDetId> HcalElectronicsMap::allTriggerId() const {
0152 std::vector<HcalTrigTowerDetId> result;
0153 std::set<unsigned long> allIds;
0154 for (std::vector<TriggerItem>::const_iterator item = mTItems.begin(); item != mTItems.end(); item++)
0155 if (item->mTrigId)
0156 allIds.insert(item->mTrigId);
0157 for (std::set<unsigned long>::const_iterator channel = allIds.begin(); channel != allIds.end(); channel++)
0158 result.push_back(HcalTrigTowerDetId(*channel));
0159 return result;
0160 }
0161
0162
0163 HcalElectronicsMapAddons::Helper::Helper()
0164 : mPItems(HcalElectronicsId::maxLinearIndex + 1), mTItems(HcalElectronicsId::maxLinearIndex + 1) {}
0165
0166 bool HcalElectronicsMapAddons::Helper::mapEId2tId(HcalElectronicsId fElectronicsId, HcalTrigTowerDetId fTriggerId) {
0167 HcalElectronicsMap::TriggerItem& item = mTItems[fElectronicsId.linearIndex()];
0168
0169 if (item.mElId == 0)
0170 item.mElId = fElectronicsId.rawId();
0171 if (item.mTrigId == 0) {
0172 item.mTrigId = fTriggerId.rawId();
0173 } else if (item.mTrigId != fTriggerId.rawId()) {
0174 edm::LogWarning("HCAL") << "HcalElectronicsMap::Helper::mapEId2tId-> Electronics channel " << fElectronicsId
0175 << " already mapped to trigger channel " << (HcalTrigTowerDetId(item.mTrigId))
0176 << ". New value " << fTriggerId << " is ignored";
0177 return false;
0178 }
0179 return true;
0180 }
0181
0182 bool HcalElectronicsMapAddons::Helper::mapEId2chId(HcalElectronicsId fElectronicsId, DetId fId) {
0183 HcalElectronicsMap::PrecisionItem& item = mPItems[fElectronicsId.linearIndex()];
0184
0185 if (item.mElId == 0)
0186 item.mElId = fElectronicsId.rawId();
0187 if (item.mId == 0) {
0188 item.mId = fId.rawId();
0189 } else if (item.mId != fId.rawId()) {
0190 edm::LogWarning("HCAL") << "HcalElectronicsMap::Helper::mapEId2tId-> Electronics channel " << fElectronicsId
0191 << " already mapped to channel " << HcalGenericDetId(item.mId) << ". New value "
0192 << HcalGenericDetId(fId) << " is ignored";
0193 return false;
0194 }
0195 return true;
0196 }
0197
0198 void HcalElectronicsMap::sortById() {
0199 HcalObjectAddons::sortByT<PrecisionItem, HcalElectronicsMapAddons::LessById>(mPItems, mPItemsById);
0200 }
0201
0202 void HcalElectronicsMap::sortByTriggerId() {
0203 HcalObjectAddons::sortByT<TriggerItem, HcalElectronicsMapAddons::LessByTrigId>(mTItems, mTItemsByTrigId);
0204 }
0205
0206 void HcalElectronicsMap::initialize() {
0207 sortById();
0208 sortByTriggerId();
0209 }