CMS 3D CMS Logo

ElectronicsMap.cc
Go to the documentation of this file.
2 #include <iomanip>
3 
4 namespace hcaldqm
5 {
6  namespace electronicsmap
7  {
9  ElectronicsMapType etype/*=fHcalElectronicsMap*/)
10  {
11  _etype=etype;
12  _emap = emap;
13  // if we actually use a HashMap then
15  {
16  if (_etype==fD2EHashMap)
17  {
18  std::vector<HcalElectronicsId> eids =
20  for (std::vector<HcalElectronicsId>::const_iterator it=
21  eids.begin(); it!=eids.end(); ++it)
22  {
24  _emap->lookup(*it));
25  EMapType::iterator dit = _ids.find(did.rawId());
26  if (dit!=_ids.end())
27  continue;
28 // if (!did.isHcalDetId())
29 // continue;
30 
31  _ids.insert(std::make_pair(did.rawId(), it->rawId()));
32  }
33  }
34  else if (_etype==fT2EHashMap)
35  {
36  // HcalTrigTowerDetId -> HcalElectronicsId
37  std::vector<HcalTrigTowerDetId> tids =
38  emap->allTriggerId();
39  for (std::vector<HcalTrigTowerDetId>::const_iterator it=
40  tids.begin(); it!=tids.end(); ++it)
41  {
43  uint32_t hash = it->rawId();
44  EMapType::iterator eit = _ids.find(hash);
45  if (eit!=_ids.end())
46  continue;
47 
48  _ids.insert(std::make_pair(hash, eid.rawId()));
49  }
50  }
51  else if (_etype==fE2DHashMap)
52  {
53  // HcalElectronicId -> HcalDetId hash map
54  std::vector<HcalElectronicsId> eids =
56  for (std::vector<HcalElectronicsId>::const_iterator
57  it=eids.begin(); it!=eids.end(); ++it)
58  {
60  uint32_t hash = it->rawId();
61  EMapType::iterator eit = _ids.find(hash);
62  if (eit!=_ids.end())
63  continue;
64 
65  // note, we have EChannel hashing here
66  _ids.insert(std::make_pair(hash, did.rawId()));
67  }
68  }
69  else if (_etype==fE2THashMap)
70  {
71  // HcalElectronicId -> HcalDetId hash map
72  std::vector<HcalElectronicsId> eids =
74  for (std::vector<HcalElectronicsId>::const_iterator
75  it=eids.begin(); it!=eids.end(); ++it)
76  {
77  HcalTrigTowerDetId tid =
79  EMapType::iterator eit = _ids.find(it->rawId());
80  if (eit!=_ids.end())
81  continue;
82 
83  // eid.rawId() -> tid.rawId()
84  _ids.insert(std::make_pair(it->rawId(),
85  tid.rawId()));
86  }
87  }
88  }
89  }
90 
93  {
94  _etype=etype;
95  _emap = emap;
96 
97  // note this initialization has iteration over electronics not
98  // detector.
99  // Filtering is done on Electronics id - possible to have
100  // several electronics ids to 1 detid - not vice versa
102  {
103  if (_etype==fD2EHashMap)
104  {
105  std::vector<HcalElectronicsId> eids =
107  for (std::vector<HcalElectronicsId>::const_iterator it=
108  eids.begin(); it!=eids.end(); ++it)
109  {
111  _emap->lookup(*it));
112  if (filter.filter(*it))
113  continue;
114  // skip those that are not detid or calib ids
115 // if (!did.isHcalDetId())
116 // continue;
117 
118  _ids.insert(std::make_pair(did.rawId(), it->rawId()));
119  }
120  }
121  else if (_etype==fT2EHashMap)
122  {
123  std::vector<HcalElectronicsId> eids=
124  emap->allElectronicsIdTrigger();
125  for (std::vector<HcalElectronicsId>::const_iterator it=
126  eids.begin(); it!=eids.end(); ++it)
127  {
128  if (filter.filter(*it))
129  continue;
130  HcalTrigTowerDetId tid = emap->lookupTrigger(*it);
131  _ids.insert(std::make_pair(tid.rawId(), it->rawId()));
132  }
133  }
134  else if (_etype==fE2DHashMap)
135  {
136  std::vector<HcalElectronicsId> eids =
138  for (std::vector<HcalElectronicsId>::const_iterator it=
139  eids.begin(); it!=eids.end(); ++it)
140  {
142  _emap->lookup(*it));
144  *it);
145  if (filter.filter(*it))
146  continue;
147  // skip those that are not detid or calib ids
148 // if (!did.isHcalDetId())
149 // continue;
150 
151  // note: use EChannel hashing here!
152  _ids.insert(std::make_pair(hash,did.rawId()));
153  }
154  }
155  else if (_etype==fE2THashMap)
156  {
157  std::vector<HcalElectronicsId> eids=
158  emap->allElectronicsIdTrigger();
159  for (std::vector<HcalElectronicsId>::const_iterator it=
160  eids.begin(); it!=eids.end(); ++it)
161  {
162  if (filter.filter(*it))
163  continue;
164  HcalTrigTowerDetId tid = emap->lookupTrigger(*it);
165  _ids.insert(std::make_pair(it->rawId(), tid.rawId()));
166  }
167  }
168  }
169  }
170 
171  // 3 funcs below are only for 1->1 mappings
172  uint32_t ElectronicsMap::lookup(DetId const &id)
173  {
174  uint32_t hash = id.rawId();
176  return _emap->lookup(id).rawId();
177  else
178  {
179  EMapType::iterator it = _ids.find(hash);
180  return it==_ids.end() ? 0 : it->second;
181  }
182  return 0;
183  }
184 
185  uint32_t ElectronicsMap::lookup(HcalDetId const &id)
186  {
187  // Turn the HcalDetId into a HcalGenericDetId to avoid newForm
188  uint32_t hash = (id.oldFormat() ? id.otherForm() : id.rawId());
189  HcalGenericDetId gdid(hash);
191  return _emap->lookup(gdid).rawId();
192  else
193  {
194  EMapType::iterator it = _ids.find(hash);
195  return it==_ids.end() ? 0 : it->second;
196  }
197  return 0;
198  }
199 
201  {
202  uint32_t hash = id.rawId();
204  return _emap->lookup(id).rawId();
205  else
206  {
207  EMapType::iterator it=_ids.find(hash);
208  return it==_ids.end() ? 0 : it->second;
209  }
210  return 0;
211  }
212 
214  {
215  std::cout << "Electronics HashMap Type=" << _etype << std::endl;
216  for(auto const& v : _ids)
217  {
218  std::cout << std::hex << v.first
219  << " "<< v.second << std::dec << std::endl;
220  }
221  }
222  }
223 }
constexpr uint32_t rawId() const
std::vector< HcalElectronicsId > allElectronicsIdPrecision() const
void initialize(HcalElectronicsMap const *, ElectronicsMapType etype=fHcalElectronicsMap)
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
std::vector< HcalElectronicsId > allElectronicsIdTrigger() const
HcalElectronicsMap const * _emap
Definition: DetId.h:18
virtual bool filter(HcalDetId const &) const
Definition: HashFilter.cc:38
const DetId lookupTrigger(HcalElectronicsId fId) const
brief lookup the trigger logical detid associated with the given electronics id
uint32_t hash_EChannel(HcalElectronicsId const &)
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