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