CMS 3D CMS Logo

ElectronicsMap.cc
Go to the documentation of this file.
2 #include <iomanip>
3 
4 namespace hcaldqm {
5  namespace electronicsmap {
6  void ElectronicsMap::initialize(HcalElectronicsMap const *emap, ElectronicsMapType etype /*=fHcalElectronicsMap*/) {
7  _etype = etype;
8  _emap = emap;
9  // if we actually use a HashMap then
10  if (_etype != fHcalElectronicsMap) {
11  if (_etype == fD2EHashMap) {
12  std::vector<HcalElectronicsId> eids = emap->allElectronicsIdPrecision();
13  for (std::vector<HcalElectronicsId>::const_iterator it = eids.begin(); it != eids.end(); ++it) {
15  EMapType::iterator dit = _ids.find(did.rawId());
16  if (dit != _ids.end())
17  continue;
18  // if (!did.isHcalDetId())
19  // continue;
20 
21  _ids.insert(std::make_pair(did.rawId(), it->rawId()));
22  }
23  } else if (_etype == fT2EHashMap) {
24  // HcalTrigTowerDetId -> HcalElectronicsId
25  std::vector<HcalTrigTowerDetId> tids = emap->allTriggerId();
26  for (std::vector<HcalTrigTowerDetId>::const_iterator it = tids.begin(); it != tids.end(); ++it) {
28  uint32_t hash = it->rawId();
29  EMapType::iterator eit = _ids.find(hash);
30  if (eit != _ids.end())
31  continue;
32 
33  _ids.insert(std::make_pair(hash, eid.rawId()));
34  }
35  } else if (_etype == fE2DHashMap) {
36  // HcalElectronicId -> HcalDetId hash map
37  std::vector<HcalElectronicsId> eids = emap->allElectronicsIdPrecision();
38  for (std::vector<HcalElectronicsId>::const_iterator it = eids.begin(); it != eids.end(); ++it) {
40  uint32_t hash = it->rawId();
41  EMapType::iterator eit = _ids.find(hash);
42  if (eit != _ids.end())
43  continue;
44 
45  // note, we have EChannel hashing here
46  _ids.insert(std::make_pair(hash, did.rawId()));
47  }
48  } else if (_etype == fE2THashMap) {
49  // HcalElectronicId -> HcalDetId hash map
50  std::vector<HcalElectronicsId> eids = emap->allElectronicsIdTrigger();
51  for (std::vector<HcalElectronicsId>::const_iterator it = eids.begin(); it != eids.end(); ++it) {
53  EMapType::iterator eit = _ids.find(it->rawId());
54  if (eit != _ids.end())
55  continue;
56 
57  // eid.rawId() -> tid.rawId()
58  _ids.insert(std::make_pair(it->rawId(), tid.rawId()));
59  }
60  }
61  }
62  }
63 
65  ElectronicsMapType etype,
66  filter::HashFilter const &filter) {
67  _etype = etype;
68  _emap = emap;
69 
70  // note this initialization has iteration over electronics not
71  // detector.
72  // Filtering is done on Electronics id - possible to have
73  // several electronics ids to 1 detid - not vice versa
74  if (_etype != fHcalElectronicsMap) {
75  if (_etype == fD2EHashMap) {
76  std::vector<HcalElectronicsId> eids = emap->allElectronicsIdPrecision();
77  for (std::vector<HcalElectronicsId>::const_iterator it = eids.begin(); it != eids.end(); ++it) {
79  if (filter.filter(*it))
80  continue;
81  // skip those that are not detid or calib ids
82  // if (!did.isHcalDetId())
83  // continue;
84 
85  _ids.insert(std::make_pair(did.rawId(), it->rawId()));
86  }
87  } else if (_etype == fT2EHashMap) {
88  std::vector<HcalElectronicsId> eids = emap->allElectronicsIdTrigger();
89  for (std::vector<HcalElectronicsId>::const_iterator it = eids.begin(); it != eids.end(); ++it) {
90  if (filter.filter(*it))
91  continue;
92  HcalTrigTowerDetId tid = emap->lookupTrigger(*it);
93  _ids.insert(std::make_pair(tid.rawId(), it->rawId()));
94  }
95  } else if (_etype == fE2DHashMap) {
96  std::vector<HcalElectronicsId> eids = emap->allElectronicsIdPrecision();
97  for (std::vector<HcalElectronicsId>::const_iterator it = eids.begin(); it != eids.end(); ++it) {
99  uint32_t hash = hashfunctions::hash_EChannel(*it);
100  if (filter.filter(*it))
101  continue;
102  // skip those that are not detid or calib ids
103  // if (!did.isHcalDetId())
104  // continue;
105 
106  // note: use EChannel hashing here!
107  _ids.insert(std::make_pair(hash, did.rawId()));
108  }
109  } else if (_etype == fE2THashMap) {
110  std::vector<HcalElectronicsId> eids = emap->allElectronicsIdTrigger();
111  for (std::vector<HcalElectronicsId>::const_iterator it = eids.begin(); it != eids.end(); ++it) {
112  if (filter.filter(*it))
113  continue;
114  HcalTrigTowerDetId tid = emap->lookupTrigger(*it);
115  _ids.insert(std::make_pair(it->rawId(), tid.rawId()));
116  }
117  }
118  }
119  }
120 
121  // 3 funcs below are only for 1->1 mappings
122  uint32_t ElectronicsMap::lookup(DetId const &id) {
123  uint32_t hash = id.rawId();
125  return _emap->lookup(id).rawId();
126  else {
127  EMapType::iterator it = _ids.find(hash);
128  return it == _ids.end() ? 0 : it->second;
129  }
130  return 0;
131  }
132 
133  uint32_t ElectronicsMap::lookup(HcalDetId const &id) {
134  // Turn the HcalDetId into a HcalGenericDetId to avoid newForm
135  uint32_t hash = (id.oldFormat() ? id.otherForm() : id.rawId());
136  HcalGenericDetId gdid(hash);
138  return _emap->lookup(gdid).rawId();
139  else {
140  EMapType::iterator it = _ids.find(hash);
141  return it == _ids.end() ? 0 : it->second;
142  }
143  return 0;
144  }
145 
147  uint32_t hash = id.rawId();
149  return _emap->lookup(id).rawId();
150  else {
151  EMapType::iterator it = _ids.find(hash);
152  return it == _ids.end() ? 0 : it->second;
153  }
154  return 0;
155  }
156 
158  std::cout << "Electronics HashMap Type=" << _etype << std::endl;
159  for (auto const &v : _ids) {
160  std::cout << std::hex << v.first << " " << v.second << std::dec << std::endl;
161  }
162  }
163  } // namespace electronicsmap
164 } // namespace hcaldqm
std::vector< HcalElectronicsId > allElectronicsIdTrigger() const
void initialize(HcalElectronicsMap const *, ElectronicsMapType etype=fHcalElectronicsMap)
std::vector< HcalTrigTowerDetId > allTriggerId() const
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
HcalElectronicsMap const * _emap
Definition: DetId.h:17
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
std::vector< HcalElectronicsId > allElectronicsIdPrecision() const
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.