CMS 3D CMS Logo

HcalElectronicsMap.cc
Go to the documentation of this file.
1 
10 #include <iostream>
11 #include <set>
12 
16 
18  : mPItems(helper.mPItems), mTItems(helper.mTItems) {
19  initialize();
20 }
21 
23 // copy-ctor
25  : mPItems(src.mPItems), mTItems(src.mTItems), mPItemsById(src.mPItemsById), mTItemsByTrigId(src.mTItemsByTrigId) {}
26 // copy assignment operator
29  temp.swap(*this);
30  return *this;
31 }
32 // public swap function
34  std::swap(mPItems, other.mPItems);
35  std::swap(mTItems, other.mTItems);
36  std::swap(mPItemsById, other.mPItemsById);
37  std::swap(mTItemsByTrigId, other.mTItemsByTrigId);
38 }
39 // move constructor
41 
43  PrecisionItem target(fId, 0);
44  return HcalObjectAddons::findByT<PrecisionItem, HcalElectronicsMapAddons::LessById>(&target, mPItemsById);
45 }
46 
48  HcalElectronicsId eid(fElId);
49  const PrecisionItem* i = &(mPItems[eid.linearIndex()]);
50 
51  if (i != nullptr && i->mElId != fElId)
52  i = nullptr;
53  return i;
54 }
55 
57  HcalElectronicsId eid(fElId);
58  const TriggerItem* i = &(mTItems[eid.linearIndex()]);
59 
60  if (i != nullptr && i->mElId != fElId)
61  i = nullptr;
62  return i;
63 }
64 
66  TriggerItem target(fTrigId, 0);
67  return HcalObjectAddons::findByT<TriggerItem, HcalElectronicsMapAddons::LessByTrigId>(&target, mTItemsByTrigId);
68 }
69 
71  const PrecisionItem* item = findPByElId(fId.rawId());
72  return DetId(item ? item->mId : 0);
73 }
74 
76  const PrecisionItem* item = findById(fId.rawId());
77  return HcalElectronicsId(item ? item->mElId : 0);
78 }
79 
81  const TriggerItem* item = findTByElId(fId.rawId());
82  return DetId(item ? item->mTrigId : 0);
83 }
84 
86  const TriggerItem* item = findByTrigId(fId.rawId());
87  return HcalElectronicsId(item ? item->mElId : 0);
88 }
89 
91  const PrecisionItem* i = &(mPItems[pid.linearIndex()]);
92  if (i != nullptr && i->mId != 0) {
93  eid = HcalElectronicsId(i->mElId);
94  did = HcalGenericDetId(i->mId);
95  return true;
96  } else
97  return false;
98 }
99 
101  const TriggerItem* i = &(mTItems[pid.linearIndex()]);
102  if (i != nullptr && i->mTrigId != 0) {
103  eid = HcalElectronicsId(i->mElId);
104  did = HcalGenericDetId(i->mTrigId);
105  return true;
106  } else
107  return false;
108 }
109 
110 std::vector<HcalElectronicsId> HcalElectronicsMap::allElectronicsId() const {
111  std::vector<HcalElectronicsId> result;
112  for (std::vector<PrecisionItem>::const_iterator item = mPItems.begin(); item != mPItems.end(); item++)
113  if (item->mElId)
114  result.push_back(HcalElectronicsId(item->mElId));
115  for (std::vector<TriggerItem>::const_iterator item = mTItems.begin(); item != mTItems.end(); item++)
116  if (item->mElId)
117  result.push_back(HcalElectronicsId(item->mElId));
118 
119  return result;
120 }
121 
122 std::vector<HcalElectronicsId> HcalElectronicsMap::allElectronicsIdPrecision() const {
123  std::vector<HcalElectronicsId> result;
124  for (std::vector<PrecisionItem>::const_iterator item = mPItems.begin(); item != mPItems.end(); item++)
125  if (item->mElId)
126  result.push_back(HcalElectronicsId(item->mElId));
127  return result;
128 }
129 
130 std::vector<HcalElectronicsId> HcalElectronicsMap::allElectronicsIdTrigger() const {
131  std::vector<HcalElectronicsId> result;
132  for (std::vector<TriggerItem>::const_iterator item = mTItems.begin(); item != mTItems.end(); item++)
133  if (item->mElId)
134  result.push_back(HcalElectronicsId(item->mElId));
135 
136  return result;
137 }
138 
139 std::vector<HcalGenericDetId> HcalElectronicsMap::allPrecisionId() const {
140  std::vector<HcalGenericDetId> result;
141  std::set<unsigned long> allIds;
142  for (std::vector<PrecisionItem>::const_iterator item = mPItems.begin(); item != mPItems.end(); item++)
143  if (item->mId)
144  allIds.insert(item->mId);
145  for (std::set<unsigned long>::const_iterator channel = allIds.begin(); channel != allIds.end(); channel++) {
146  result.push_back(HcalGenericDetId(*channel));
147  }
148  return result;
149 }
150 
151 std::vector<HcalTrigTowerDetId> HcalElectronicsMap::allTriggerId() const {
152  std::vector<HcalTrigTowerDetId> result;
153  std::set<unsigned long> allIds;
154  for (std::vector<TriggerItem>::const_iterator item = mTItems.begin(); item != mTItems.end(); item++)
155  if (item->mTrigId)
156  allIds.insert(item->mTrigId);
157  for (std::set<unsigned long>::const_iterator channel = allIds.begin(); channel != allIds.end(); channel++)
158  result.push_back(HcalTrigTowerDetId(*channel));
159  return result;
160 }
161 
162 //use helper to do mapping
164  : mPItems(HcalElectronicsId::maxLinearIndex + 1), mTItems(HcalElectronicsId::maxLinearIndex + 1) {}
165 
167  HcalElectronicsMap::TriggerItem& item = mTItems[fElectronicsId.linearIndex()];
168 
169  if (item.mElId == 0)
170  item.mElId = fElectronicsId.rawId();
171  if (item.mTrigId == 0) {
172  item.mTrigId = fTriggerId.rawId(); // just cast avoiding long machinery
173  } else if (item.mTrigId != fTriggerId.rawId()) {
174  edm::LogWarning("HCAL") << "HcalElectronicsMap::Helper::mapEId2tId-> Electronics channel " << fElectronicsId
175  << " already mapped to trigger channel " << (HcalTrigTowerDetId(item.mTrigId))
176  << ". New value " << fTriggerId << " is ignored";
177  return false;
178  }
179  return true;
180 }
181 
183  HcalElectronicsMap::PrecisionItem& item = mPItems[fElectronicsId.linearIndex()];
184 
185  if (item.mElId == 0)
186  item.mElId = fElectronicsId.rawId();
187  if (item.mId == 0) {
188  item.mId = fId.rawId();
189  } else if (item.mId != fId.rawId()) {
190  edm::LogWarning("HCAL") << "HcalElectronicsMap::Helper::mapEId2tId-> Electronics channel " << fElectronicsId
191  << " already mapped to channel " << HcalGenericDetId(item.mId) << ". New value "
192  << HcalGenericDetId(fId) << " is ignored";
193  return false;
194  }
195  return true;
196 }
197 
199  HcalObjectAddons::sortByT<PrecisionItem, HcalElectronicsMapAddons::LessById>(mPItems, mPItemsById);
200 }
201 
203  HcalObjectAddons::sortByT<TriggerItem, HcalElectronicsMapAddons::LessByTrigId>(mTItems, mTItemsByTrigId);
204 }
205 
207  sortById();
208  sortByTriggerId();
209 }
const TriggerItem * findByTrigId(unsigned long fTrigId) const
std::vector< HcalElectronicsId > allElectronicsIdTrigger() const
bool mapEId2chId(HcalElectronicsId fElectronicsId, DetId fId)
Definition: helper.py:1
std::vector< PrecisionItem > mPItems
std::vector< HcalTrigTowerDetId > allTriggerId() const
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:112
void swap(HcalElectronicsMap &other)
std::vector< const PrecisionItem * > mPItemsById
std::vector< TriggerItem > mTItems
const PrecisionItem * findPByElId(unsigned long fElId) const
bool mapEId2tId(HcalElectronicsId fElectronicsId, HcalTrigTowerDetId fTriggerId)
std::vector< HcalElectronicsId > allElectronicsId() const
const PrecisionItem * findById(unsigned long fId) const
Definition: DetId.h:17
std::vector< const TriggerItem * > mTItemsByTrigId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
HcalElectronicsMap & operator=(const HcalElectronicsMap &rhs)
constexpr uint32_t rawId() const
const TriggerItem * findTByElId(unsigned long fElId) const
std::vector< HcalGenericDetId > allPrecisionId() const
std::vector< HcalElectronicsId > allElectronicsIdPrecision() const
const DetId lookupTrigger(HcalElectronicsId fId) const
brief lookup the trigger logical detid associated with the given electronics id
Log< level::Warning, false > LogWarning
constexpr int linearIndex() const
get a fast, compact, unique index for linear lookups
Readout chain identification for Hcal.