CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalElectronicsMap.cc
Go to the documentation of this file.
1 
10 #include <iostream>
11 #include <set>
12 
15 
17  mPItems(HcalElectronicsId::maxLinearIndex+1),
18  mTItems(HcalElectronicsId::maxLinearIndex+1),
19  sortedByPId(false),
20  sortedByTId(false)
21 {}
22 
23 namespace hcal_impl {
24  class LessById {public: bool operator () (const HcalElectronicsMap::PrecisionItem* a, const HcalElectronicsMap::PrecisionItem* b) {return a->mId < b->mId;}};
26 }
27 
29 
31  PrecisionItem target (fId, 0);
32  std::vector<const HcalElectronicsMap::PrecisionItem*>::const_iterator item;
33 
34  if (!sortedByPId) sortById();
35 
36  item = std::lower_bound (mPItemsById.begin(), mPItemsById.end(), &target, hcal_impl::LessById());
37  if (item == mPItemsById.end() || (*item)->mId != fId)
38  // throw cms::Exception ("Conditions not found") << "Unavailable Electronics map for cell " << fId;
39  return 0;
40  return *item;
41 }
42 
44  HcalElectronicsId eid(fElId);
45  const PrecisionItem* i=&(mPItems[eid.linearIndex()]);
46 
47  if (i!=0 && i->mElId!=fElId) i=0;
48  return i;
49 }
50 
52  HcalElectronicsId eid(fElId);
53  const TriggerItem* i=&(mTItems[eid.linearIndex()]);
54 
55  if (i!=0 && i->mElId!=fElId) i=0;
56  return i;
57 }
58 
59 
61  TriggerItem target (fTrigId,0);
62  std::vector<const HcalElectronicsMap::TriggerItem*>::const_iterator item;
63 
65 
66  item = std::lower_bound (mTItemsByTrigId.begin(), mTItemsByTrigId.end(), &target, hcal_impl::LessByTrigId());
67  if (item == mTItemsByTrigId.end() || (*item)->mTrigId != fTrigId)
68  // throw cms::Exception ("Conditions not found") << "Unavailable Electronics map for cell " << fId;
69  return 0;
70  return *item;
71 }
72 
74  const PrecisionItem* item = findPByElId (fId.rawId ());
75  return DetId (item ? item->mId : 0);
76 }
77 
79  const PrecisionItem* item = findById (fId.rawId ());
80  return HcalElectronicsId (item ? item->mElId : 0);
81 }
82 
84  const TriggerItem* item = findTByElId (fId.rawId ());
85  return DetId (item ? item->mTrigId : 0);
86 }
87 
89  const TriggerItem* item = findByTrigId (fId.rawId ());
90  return HcalElectronicsId (item ? item->mElId : 0);
91 }
92 
94  const PrecisionItem* i=&(mPItems[pid.linearIndex()]);
95  if (i!=0 && i->mId!=0) {
96  eid=HcalElectronicsId(i->mElId);
97  did=HcalGenericDetId(i->mId);
98  return true;
99  } else return false;
100 }
101 
103  const TriggerItem* i=&(mTItems[pid.linearIndex()]);
104  if (i!=0 && i->mTrigId!=0) {
105  eid=HcalElectronicsId(i->mElId);
106  did=HcalGenericDetId(i->mTrigId);
107  return true;
108  } else return false;
109 }
110 
111 
112 std::vector <HcalElectronicsId> HcalElectronicsMap::allElectronicsId () const {
113  std::vector <HcalElectronicsId> result;
114  for (std::vector<PrecisionItem>::const_iterator item = mPItems.begin (); item != mPItems.end (); item++)
115  if (item->mElId) result.push_back(HcalElectronicsId(item->mElId));
116  for (std::vector<TriggerItem>::const_iterator item = mTItems.begin (); item != mTItems.end (); item++)
117  if (item->mElId) 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) result.push_back(HcalElectronicsId(item->mElId));
126  return result;
127 }
128 
129 std::vector <HcalElectronicsId> HcalElectronicsMap::allElectronicsIdTrigger() const {
130  std::vector <HcalElectronicsId> result;
131  for (std::vector<TriggerItem>::const_iterator item = mTItems.begin (); item != mTItems.end (); item++)
132  if (item->mElId) result.push_back(HcalElectronicsId(item->mElId));
133 
134  return result;
135 }
136 
137 std::vector <HcalGenericDetId> HcalElectronicsMap::allPrecisionId () const {
138  std::vector <HcalGenericDetId> result;
139  std::set <unsigned long> allIds;
140  for (std::vector<PrecisionItem>::const_iterator item = mPItems.begin (); item != mPItems.end (); item++)
141  if (item->mId) allIds.insert (item->mId);
142  for (std::set <unsigned long>::const_iterator channel = allIds.begin (); channel != allIds.end (); channel++) {
143  result.push_back (HcalGenericDetId (*channel));
144  }
145  return result;
146 }
147 
148 std::vector <HcalTrigTowerDetId> HcalElectronicsMap::allTriggerId () const {
149  std::vector <HcalTrigTowerDetId> result;
150  std::set <unsigned long> allIds;
151  for (std::vector<TriggerItem>::const_iterator item = mTItems.begin (); item != mTItems.end (); item++)
152  if (item->mTrigId) allIds.insert (item->mTrigId);
153  for (std::set <unsigned long>::const_iterator channel = allIds.begin (); channel != allIds.end (); channel++)
154  result.push_back (HcalTrigTowerDetId (*channel));
155  return result;
156 }
157 
159  TriggerItem& item = mTItems[fElectronicsId.linearIndex()];
160  sortedByTId=false;
161  if (item.mElId==0) item.mElId=fElectronicsId.rawId();
162  if (item.mTrigId == 0) {
163  item.mTrigId = fTriggerId.rawId (); // just cast avoiding long machinery
164  }
165  else if (item.mTrigId != fTriggerId.rawId ()) {
166  edm::LogWarning("HCAL") << "HcalElectronicsMap::mapEId2tId-> Electronics channel " << fElectronicsId << " already mapped to trigger channel "
167  << (HcalTrigTowerDetId(item.mTrigId)) << ". New value " << fTriggerId << " is ignored" ;
168  return false;
169  }
170  return true;
171 }
172 
174  PrecisionItem& item = mPItems[fElectronicsId.linearIndex()];
175 
176  sortedByPId=false;
177  if (item.mElId==0) item.mElId=fElectronicsId.rawId();
178  if (item.mId == 0) {
179  item.mId = fId.rawId ();
180  }
181  else if (item.mId != fId.rawId ()) {
182  edm::LogWarning("HCAL") << "HcalElectronicsMap::mapEId2tId-> Electronics channel " << fElectronicsId << " already mapped to channel "
183  << HcalGenericDetId(item.mId) << ". New value " << HcalGenericDetId(fId) << " is ignored" ;
184  return false;
185  }
186  return true;
187 }
188 
190  if (!sortedByPId) {
191  mPItemsById.clear();
192  for (std::vector<PrecisionItem>::const_iterator i=mPItems.begin(); i!=mPItems.end(); ++i) {
193  if (i->mElId) mPItemsById.push_back(&(*i));
194  }
195 
197  sortedByPId=true;
198  }
199 }
200 
202  if (!sortedByTId) {
203  mTItemsByTrigId.clear();
204  for (std::vector<TriggerItem>::const_iterator i=mTItems.begin(); i!=mTItems.end(); ++i) {
205  if (i->mElId) mTItemsByTrigId.push_back(&(*i));
206  }
207 
209  sortedByTId=true;
210  }
211 }
int i
Definition: DBlmapReader.cc:9
const TriggerItem * findByTrigId(unsigned long fTrigId) const
const PrecisionItem * findPByElId(unsigned long fElId) const
std::vector< HcalElectronicsId > allElectronicsIdPrecision() const
uint32_t rawId() const
std::vector< PrecisionItem > mPItems
bool operator()(const HcalElectronicsMap::TriggerItem *a, const HcalElectronicsMap::TriggerItem *b)
bool mapEId2tId(HcalElectronicsId fElectronicsId, HcalTrigTowerDetId fTriggerId)
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
std::vector< HcalElectronicsId > allElectronicsIdTrigger() const
std::vector< const PrecisionItem * > mPItemsById
const PrecisionItem * findById(unsigned long fId) const
tuple result
Definition: query.py:137
std::vector< TriggerItem > mTItems
std::vector< HcalGenericDetId > allPrecisionId() const
bool mapEId2chId(HcalElectronicsId fElectronicsId, DetId fId)
Definition: DetId.h:20
std::vector< HcalElectronicsId > allElectronicsId() const
std::vector< const TriggerItem * > mTItemsByTrigId
double b
Definition: hdecay.h:120
bool operator()(const HcalDcsMap::Item *a, const HcalDcsMap::Item *b)
Definition: HcalDcsMap.cc:30
const TriggerItem * findTByElId(unsigned long fElId) const
int linearIndex() const
get a fast, compact, unique index for linear lookups (maximum value = 16384)
double a
Definition: hdecay.h:121
void sortByTriggerId() const
const DetId lookupTrigger(HcalElectronicsId fId) const
brief lookup the trigger logical detid associated with the given electronics id
Readout chain identification for Hcal [31:26] Unused (so far) [25] Trigger-chain id flag [24:20] Read...
std::vector< HcalTrigTowerDetId > allTriggerId() const
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id