CMS 3D CMS Logo

ContainerXXX.h
Go to the documentation of this file.
1 #ifndef ContainerXXX_h
2 #define ContainerXXX_h
3 
4 /*
5  * file: ContainerXXX.h
6  * Author: Viktor Khristenko
7  *
8  * Description:
9  */
10 
12 #include <cmath>
13 
14 namespace hcaldqm {
15  typedef std::unordered_map<uint32_t, double> doubleCompactMap;
16  typedef std::unordered_map<uint32_t, int> intCompactMap;
17  typedef std::unordered_map<uint32_t, uint32_t> uintCompactMap;
18 
19  template <typename STDTYPE>
20  class ContainerXXX {
21  public:
24  ContainerXXX(ContainerXXX const &x);
25  ContainerXXX &operator=(const ContainerXXX &other) = default;
26  virtual ~ContainerXXX() { _cmap.clear(); }
27 
28  // initialize, booking. booking is done from Electronicsmap.
29  virtual void initialize(hashfunctions::HashType, int debug = 0);
30  virtual void book(HcalElectronicsMap const *);
31  virtual void book(HcalElectronicsMap const *, filter::HashFilter const &);
32 
33  // setters
34  virtual void set(HcalDetId const &, STDTYPE);
35  virtual void set(HcalElectronicsId const &, STDTYPE);
36  virtual void set(HcalTrigTowerDetId const &, STDTYPE);
37 
38  // getters
39  virtual STDTYPE &get(HcalDetId const &);
40  virtual STDTYPE &get(HcalElectronicsId const &);
41  virtual STDTYPE &get(HcalTrigTowerDetId const &);
42 
43  // pushers/adders - not a push_back.
44  // ignored if already is present
45  virtual void push(HcalDetId const &, STDTYPE);
46  virtual void push(HcalElectronicsId const &, STDTYPE);
47  virtual void push(HcalTrigTowerDetId const &, STDTYPE);
48 
49  // finders, note true/false - no pointer to the actual guy...
50  // I know, I know not the best coding...
51  virtual bool exists(HcalDetId const &);
52  virtual bool exists(HcalElectronicsId const &);
53  virtual bool exists(HcalTrigTowerDetId const &);
54 
55  virtual void dump(Container1D *);
56  virtual void dump(std::vector<Container1D *> const &);
57 
58  virtual void load(Container1D *);
59  virtual void reset();
60  virtual uint32_t size();
61  virtual void print();
62 
63  protected:
64  typedef std::unordered_map<uint32_t, STDTYPE> CompactMap;
68 
69  public:
70  virtual typename CompactMap::const_iterator begin() { return _cmap.begin(); }
71  virtual typename CompactMap::const_iterator end() { return _cmap.end(); }
72  };
73 
74  template <typename STDTYPE>
76  for (auto &p : _cmap) {
77  _cmap.insert(std::make_pair(p.first, p.second));
78  }
79  }
80 
81  template <typename STDTYPE>
83  _hashmap.initialize(ht);
84  _logger.set("XXX", debug);
85  }
86 
87  template <typename STDTYPE>
89  if (_hashmap.isDHash()) {
90  std::vector<HcalGenericDetId> dids = emap->allPrecisionId();
91  for (std::vector<HcalGenericDetId>::const_iterator it = dids.begin(); it != dids.end(); ++it) {
92  if (!it->isHcalDetId())
93  continue;
94 
95  HcalDetId did = HcalDetId(it->rawId());
96  uint32_t hash = _hashmap.getHash(did);
97  _logger.debug(_hashmap.getName(did));
98  typename CompactMap::iterator mit = _cmap.find(hash);
99  if (mit != _cmap.end())
100  continue;
101 
102  _cmap.insert(std::make_pair(hash, STDTYPE(0)));
103  }
104  } else if (_hashmap.isEHash()) {
105  std::vector<HcalElectronicsId> eids = emap->allElectronicsIdPrecision();
106  for (std::vector<HcalElectronicsId>::const_iterator it = eids.begin(); it != eids.end(); ++it) {
107  HcalElectronicsId eid = HcalElectronicsId(it->rawId());
108  uint32_t hash = _hashmap.getHash(eid);
109  _logger.debug(_hashmap.getName(eid));
110  typename CompactMap::iterator mit = _cmap.find(hash);
111  if (mit != _cmap.end())
112  continue;
113 
114  _cmap.insert(std::make_pair(hash, STDTYPE(0)));
115  }
116  } else if (_hashmap.isTHash()) {
117  std::vector<HcalTrigTowerDetId> tids = emap->allTriggerId();
118  for (std::vector<HcalTrigTowerDetId>::const_iterator it = tids.begin(); it != tids.end(); ++it) {
119  HcalTrigTowerDetId tid = HcalTrigTowerDetId(it->rawId());
120  uint32_t hash = _hashmap.getHash(tid);
121  _logger.debug(_hashmap.getName(tid));
122  typename CompactMap::iterator mit = _cmap.find(hash);
123  if (mit != _cmap.end())
124  continue;
125 
126  _cmap.insert(std::make_pair(hash, STDTYPE(0)));
127  }
128  }
129  }
130 
131  template <typename STDTYPE>
133  if (_hashmap.isDHash()) {
134  std::vector<HcalGenericDetId> dids = emap->allPrecisionId();
135  for (std::vector<HcalGenericDetId>::const_iterator it = dids.begin(); it != dids.end(); ++it) {
136  if (!it->isHcalDetId())
137  continue;
138 
139  HcalDetId did = HcalDetId(it->rawId());
140  uint32_t hash = _hashmap.getHash(did);
141  typename CompactMap::iterator mit = _cmap.find(hash);
142  if (mit != _cmap.end())
143  continue;
144  if (filter.filter(did))
145  continue;
146 
147  _logger.debug(_hashmap.getName(did));
148 
149  _cmap.insert(std::make_pair(hash, STDTYPE(0)));
150  }
151  } else if (_hashmap.isEHash()) {
152  std::vector<HcalElectronicsId> eids = emap->allElectronicsIdPrecision();
153  for (std::vector<HcalElectronicsId>::const_iterator it = eids.begin(); it != eids.end(); ++it) {
154  HcalElectronicsId eid = HcalElectronicsId(it->rawId());
155  uint32_t hash = _hashmap.getHash(eid);
156  typename CompactMap::iterator mit = _cmap.find(hash);
157  if (filter.filter(eid))
158  continue;
159  if (mit != _cmap.end())
160  continue;
161  _logger.debug(eid);
162 
163  _cmap.insert(std::make_pair(hash, STDTYPE(0)));
164  }
165  } else if (_hashmap.isTHash()) {
166  std::vector<HcalTrigTowerDetId> tids = emap->allTriggerId();
167  for (std::vector<HcalTrigTowerDetId>::const_iterator it = tids.begin(); it != tids.end(); ++it) {
168  HcalTrigTowerDetId tid = HcalTrigTowerDetId(it->rawId());
169  uint32_t hash = _hashmap.getHash(tid);
170  typename CompactMap::iterator mit = _cmap.find(hash);
171  if (mit != _cmap.end())
172  continue;
173  if (filter.filter(tid))
174  continue;
175  _logger.debug(_hashmap.getName(tid));
176 
177  _cmap.insert(std::make_pair(hash, STDTYPE(0)));
178  }
179  }
180  }
181 
182  template <typename STDTYPE>
183  void ContainerXXX<STDTYPE>::set(HcalDetId const &did, STDTYPE x) {
184  _cmap[_hashmap.getHash(did)] = x;
185  }
186 
187  template <typename STDTYPE>
188  void ContainerXXX<STDTYPE>::set(HcalElectronicsId const &did, STDTYPE x) {
189  _cmap[_hashmap.getHash(did)] = x;
190  }
191 
192  template <typename STDTYPE>
193  void ContainerXXX<STDTYPE>::set(HcalTrigTowerDetId const &did, STDTYPE x) {
194  _cmap[_hashmap.getHash(did)] = x;
195  }
196 
197  template <typename STDTYPE>
198  STDTYPE &ContainerXXX<STDTYPE>::get(HcalDetId const &did) {
199  return _cmap[_hashmap.getHash(did)];
200  }
201 
202  template <typename STDTYPE>
204  return _cmap[_hashmap.getHash(eid)];
205  }
206 
207  template <typename STDTYPE>
209  return _cmap[_hashmap.getHash(tid)];
210  }
211 
212  template <typename STDTYPE>
214  return _cmap.find(id.rawId()) != _cmap.end();
215  }
216 
217  template <typename STDTYPE>
219  return _cmap.find(id.rawId()) != _cmap.end();
220  }
221 
222  template <typename STDTYPE>
224  return _cmap.find(id.rawId()) != _cmap.end();
225  }
226 
227  template <typename STDTYPE>
228  void ContainerXXX<STDTYPE>::push(HcalDetId const &did, STDTYPE x) {
229  uint32_t hash = did.rawId();
230  typename CompactMap::iterator mit = _cmap.find(hash);
231  if (mit != _cmap.end())
232  return;
233  _cmap.insert(std::make_pair(hash, x));
234  }
235 
236  template <typename STDTYPE>
238  uint32_t hash = eid.rawId();
239  typename CompactMap::iterator mit = _cmap.find(hash);
240  if (mit != _cmap.end())
241  return;
242  _cmap.insert(std::make_pair(hash, x));
243  }
244 
245  template <typename STDTYPE>
246  void ContainerXXX<STDTYPE>::push(HcalTrigTowerDetId const &tid, STDTYPE x) {
247  uint32_t hash = tid.rawId();
248  typename CompactMap::iterator mit = _cmap.find(hash);
249  if (mit != _cmap.end())
250  return;
251  _cmap.insert(std::make_pair(hash, x));
252  }
253 
254  template <typename STDTYPE>
256  return (uint32_t)(_cmap.size());
257  }
258 
259  template <typename STDTYPE>
261  for (auto &p : _cmap) {
262  STDTYPE &x = p.second;
263  uint32_t hash = p.first;
264  c->fill(hash, (double)x);
265  }
266  }
267 
268  template <typename STDTYPE>
269  void ContainerXXX<STDTYPE>::dump(std::vector<Container1D *> const &vc) {
270  for (auto &p : _cmap) {
271  STDTYPE &x = p.second;
272  uint32_t hash = p.first;
273 
274  for (std::vector<Container1D *>::const_iterator it = vc.begin(); it != vc.end(); ++it)
275  (*it)->fill(hash, (double)x);
276  }
277  }
278 
279  template <typename STDTYPE>
281  std::cout << "Container by " << _hashmap.getHashTypeName() << std::endl;
282  for (auto &p : _cmap) {
283  if (_hashmap.isDHash())
284  std::cout << HcalDetId(p.first) << p.second << std::endl;
285  else if (_hashmap.isEHash())
286  std::cout << HcalElectronicsId(p.first) << p.second << std::endl;
287  else if (_hashmap.isTHash())
288  std::cout << HcalTrigTowerDetId(p.first) << p.second << std::endl;
289  }
290  }
291 
292  template <typename STDTYPE>
294  for (auto &p : _cmap) {
295  p.second = 0;
296  }
297  }
298 
299  template <typename STDTYPE>
301  for (auto &p : _cmap) {
302  STDTYPE &x = p.second;
303  uint32_t hash = p.first;
304 
305  if (_hashmap.isDHash())
306  x = cont->getBinContent(HcalDetId(hash));
307  else if (_hashmap.isEHash())
308  x = cont->getBinContent(HcalElectronicsId(hash));
309  else if (_hashmap.isTHash())
310  x = cont->getBinContent(HcalTrigTowerDetId(hash));
311  }
312  }
313 } // namespace hcaldqm
314 
315 #endif
Definition: Logger.h:6
ContainerXXX(hashfunctions::HashType ht)
Definition: ContainerXXX.h:23
std::unordered_map< uint32_t, uint32_t > uintCompactMap
Definition: ContainerXXX.h:17
virtual bool exists(HcalDetId const &)
Definition: ContainerXXX.h:213
std::unordered_map< uint32_t, int > intCompactMap
Definition: ContainerXXX.h:16
virtual uint32_t size()
Definition: ContainerXXX.h:255
std::vector< HcalTrigTowerDetId > allTriggerId() const
virtual CompactMap::const_iterator begin()
Definition: ContainerXXX.h:70
virtual void dump(Container1D *)
Definition: ContainerXXX.h:260
virtual void push(HcalDetId const &, STDTYPE)
Definition: ContainerXXX.h:228
virtual void reset()
Definition: ContainerXXX.h:293
mapper::HashMapper _hashmap
Definition: ContainerXXX.h:66
virtual CompactMap::const_iterator end()
Definition: ContainerXXX.h:71
ContainerXXX & operator=(const ContainerXXX &other)=default
#define debug
Definition: HDRShower.cc:19
virtual void book(HcalElectronicsMap const *)
Definition: ContainerXXX.h:88
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
std::unordered_map< uint32_t, STDTYPE > CompactMap
Definition: ContainerXXX.h:64
virtual void load(Container1D *)
Definition: ContainerXXX.h:300
virtual STDTYPE & get(HcalDetId const &)
Definition: ContainerXXX.h:198
std::vector< HcalGenericDetId > allPrecisionId() const
float x
std::vector< HcalElectronicsId > allElectronicsIdPrecision() const
virtual void initialize(hashfunctions::HashType, int debug=0)
Definition: ContainerXXX.h:82
Readout chain identification for Hcal.
std::unordered_map< uint32_t, double > doubleCompactMap
Definition: ContainerXXX.h:15
virtual void set(HcalDetId const &, STDTYPE)
Definition: ContainerXXX.h:183
cont
load Luminosity info ##
Definition: generateEDF.py:620
virtual void print()
Definition: ContainerXXX.h:280