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
hcaldqm::electronicsmap::ElectronicsMap::lookup
uint32_t lookup(DetId const &)
Definition: ElectronicsMap.cc:122
HcalGenericDetId
Definition: HcalGenericDetId.h:15
cond::hash
Definition: Time.h:19
hcaldqm
Definition: Constants.h:8
gather_cfg.cout
cout
Definition: gather_cfg.py:144
hcaldqm::electronicsmap::ElectronicsMap::initialize
void initialize(HcalElectronicsMap const *, ElectronicsMapType etype=fHcalElectronicsMap)
Definition: ElectronicsMap.cc:6
hcaldqm::electronicsmap::fHcalElectronicsMap
Definition: ElectronicsMap.h:24
findQualityFiles.v
v
Definition: findQualityFiles.py:179
ElectronicsMap.h
hcaldqm::electronicsmap::fT2EHashMap
Definition: ElectronicsMap.h:26
hcaldqm::electronicsmap::fE2DHashMap
Definition: ElectronicsMap.h:27
HcalElectronicsMap::lookupTrigger
const DetId lookupTrigger(HcalElectronicsId fId) const
brief lookup the trigger logical detid associated with the given electronics id
Definition: HcalElectronicsMap.cc:80
DetId
Definition: DetId.h:17
HcalElectronicsMap::allTriggerId
std::vector< HcalTrigTowerDetId > allTriggerId() const
Definition: HcalElectronicsMap.cc:151
HcalElectronicsId
Readout chain identification for Hcal.
Definition: HcalElectronicsId.h:32
HcalElectronicsMap::allElectronicsIdTrigger
std::vector< HcalElectronicsId > allElectronicsIdTrigger() const
Definition: HcalElectronicsMap.cc:130
ALCARECOTkAlBeamHalo_cff.filter
filter
Definition: ALCARECOTkAlBeamHalo_cff.py:27
hcaldqm::filter::HashFilter
Definition: HashFilter.h:21
HcalDetId
Definition: HcalDetId.h:12
runTauDisplay.eid
eid
Definition: runTauDisplay.py:298
hcaldqm::electronicsmap::ElectronicsMap::_emap
const HcalElectronicsMap * _emap
Definition: ElectronicsMap.h:58
hcaldqm::electronicsmap::ElectronicsMap::print
void print()
Definition: ElectronicsMap.cc:157
HcalElectronicsMap::allElectronicsIdPrecision
std::vector< HcalElectronicsId > allElectronicsIdPrecision() const
Definition: HcalElectronicsMap.cc:122
HcalElectronicsMap
Definition: HcalElectronicsMap.h:31
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
HcalElectronicsMap::lookup
const DetId lookup(HcalElectronicsId fId) const
lookup the logical detid associated with the given electronics id
Definition: HcalElectronicsMap.cc:70
hcaldqm::electronicsmap::fD2EHashMap
Definition: ElectronicsMap.h:25
hcaldqm::electronicsmap::ElectronicsMap::_etype
ElectronicsMapType _etype
Definition: ElectronicsMap.h:51
hcaldqm::electronicsmap::ElectronicsMapType
ElectronicsMapType
Definition: ElectronicsMap.h:23
hcaldqm::hashfunctions::hash_EChannel
uint32_t hash_EChannel(HcalElectronicsId const &)
Definition: HashFunctions.cc:327
hcaldqm::electronicsmap::fE2THashMap
Definition: ElectronicsMap.h:28
TauDecayModes.dec
dec
Definition: TauDecayModes.py:142
HcalTrigTowerDetId
Definition: HcalTrigTowerDetId.h:14
hcaldqm::electronicsmap::ElectronicsMap::_ids
EMapType _ids
Definition: ElectronicsMap.h:55