HGCal Test Beam  03a93d6239a951948e06fb3ef8dae4cbdebfad30
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
HGCalElectronicsMap.cc
Go to the documentation of this file.
1 #include "HGCal/CondObjects/interface/HGCalElectronicsMap.h"
2 #include <algorithm>
3 
4 class DetIdMatch
5 {
6 public:
7  DetIdMatch(uint32_t matchTo) : m_id(matchTo) { }
8  bool operator()(const HGCalElectronicsMap::MapEntry& a)
9  {
10  return a.detid == m_id;
11  }
12 private:
13  uint32_t m_id;
14 };
15 
17 {
18  return eid < a.eid;
19 }
20 
21 bool HGCalElectronicsMap::existsDetId(DetId did) const
22 {
23  DetIdMatch x(did.rawId());
24  return std::find_if(m_map.begin(), m_map.end(), x) == m_map.end();
25 }
26 
27 bool HGCalElectronicsMap::existsEId(uint32_t eid) const
28 {
29  MapEntry me;
30  me.eid = eid;
31 
32  std::vector<HGCalElectronicsMap::MapEntry>::const_iterator where = std::lower_bound(m_map.begin(), m_map.end(), me);
33  return (where != m_map.end() && where->eid == eid);
34 }
35 
36 DetId HGCalElectronicsMap::eid2detId(uint32_t eid) const
37 {
38  MapEntry me;
39  me.eid = eid;
40 
41  std::vector<HGCalElectronicsMap::MapEntry>::const_iterator where = std::lower_bound(m_map.begin(), m_map.end(), me);
42  return (where == m_map.end() || where->eid != eid) ? (DetId(0)) : (DetId(where->detid));
43 }
44 
45 uint32_t HGCalElectronicsMap::detId2eid(DetId did) const
46 {
47  DetIdMatch x(did.rawId());
48  std::vector<MapEntry>::const_iterator i = std::find_if(m_map.begin(), m_map.end(), x);
49  if (i == m_map.end()) return 0;
50  else return i->eid;
51 }
52 
53 void HGCalElectronicsMap::insert(uint32_t eid, DetId did)
54 {
55  MapEntry me;
56  me.eid = eid;
57  me.detid = did.rawId();
58 
59  std::vector<HGCalElectronicsMap::MapEntry>::const_iterator where = std::lower_bound(m_map.begin(), m_map.end(), me);
60 
61  if (where != m_map.end() && where->eid == eid) return; // duplicate
62  m_map.insert(where, me);
63 }
64 
65 uint32_t HGCalElectronicsMap::eidAt(size_t i) const
66 {
67  return (i >= m_map.size()) ? (0) : (m_map[i].eid);
68 }
69 DetId HGCalElectronicsMap::didAt(size_t i) const
70 {
71  return (i >= m_map.size()) ? (DetId(0)) : (DetId(m_map[i].detid));
72 }
void insert(uint32_t, DetId did)
uint32_t eidAt(size_t i) const
DetId didAt(size_t i) const
DetId eid2detId(uint32_t eid) const
bool existsEId(uint32_t eid) const
uint32_t detId2eid(DetId did) const
bool operator<(const MapEntry &) const
bool existsDetId(DetId did) const