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 {
16  typedef boost::unordered_map<uint32_t, double> doubleCompactMap;
17  typedef boost::unordered_map<uint32_t, int> intCompactMap;
18  typedef boost::unordered_map<uint32_t, uint32_t> uintCompactMap;
19 
20  template<typename STDTYPE>
22  {
23  public:
26  {}
27  ContainerXXX(ContainerXXX const& x);
28  virtual ~ContainerXXX() {_cmap.clear();}
29 
30  // initialize, booking. booking is done from Electronicsmap.
31  virtual void initialize(hashfunctions::HashType,int debug=0);
32  virtual void book(HcalElectronicsMap const*);
33  virtual void book(HcalElectronicsMap const*,
34  filter::HashFilter const&);
35 
36  // setters
37  virtual void set(HcalDetId const&, STDTYPE);
38  virtual void set(HcalElectronicsId const&, STDTYPE);
39  virtual void set(HcalTrigTowerDetId const&, STDTYPE);
40 
41  // getters
42  virtual STDTYPE& get(HcalDetId const&);
43  virtual STDTYPE& get(HcalElectronicsId const&);
44  virtual STDTYPE& get(HcalTrigTowerDetId const&);
45 
46  // pushers/adders - not a push_back.
47  // ignored if already is present
48  virtual void push(HcalDetId const&, STDTYPE);
49  virtual void push(HcalElectronicsId const&, STDTYPE);
50  virtual void push(HcalTrigTowerDetId const&, STDTYPE);
51 
52  // finders, note true/false - no pointer to the actual guy...
53  // I know, I know not the best coding...
54  virtual bool exists(HcalDetId const&);
55  virtual bool exists(HcalElectronicsId const&);
56  virtual bool exists(HcalTrigTowerDetId const&);
57 
58  virtual void dump(Container1D*);
59  virtual void dump(std::vector<Container1D*> const&);
60 
61  virtual void load(Container1D*);
62  virtual void reset();
63  virtual uint32_t size();
64  virtual void print();
65 
66  protected:
67  typedef boost::unordered_map<uint32_t, STDTYPE> CompactMap;
68  CompactMap _cmap;
71 
72  public:
73  virtual typename CompactMap::const_iterator begin()
74  {return _cmap.begin();}
75  virtual typename CompactMap::const_iterator end()
76  {return _cmap.end();}
77  };
78 
79  template<typename STDTYPE>
81  {
82  BOOST_FOREACH(typename CompactMap::value_type &p, _cmap)
83  {
84  _cmap.insert(std::make_pair(p.first, p.second));
85  }
86  }
87 
88  template<typename STDTYPE>
90  int debug)
91  {
92  _hashmap.initialize(ht);
93  _logger.set("XXX", debug);
94  }
95 
96  template<typename STDTYPE>
98  {
99  if (_hashmap.isDHash())
100  {
101  std::vector<HcalGenericDetId> dids =
102  emap->allPrecisionId();
103  for (std::vector<HcalGenericDetId>::const_iterator it=
104  dids.begin(); it!=dids.end(); ++it)
105  {
106  if (!it->isHcalDetId())
107  continue;
108 
109  HcalDetId did = HcalDetId(it->rawId());
110  uint32_t hash = _hashmap.getHash(did);
112  typename CompactMap::iterator mit = _cmap.find(hash);
113  if (mit!=_cmap.end())
114  continue;
115 
116  _cmap.insert(
117  std::make_pair(hash, STDTYPE(0)));
118  }
119  }
120  else if (_hashmap.isEHash())
121  {
122  std::vector<HcalElectronicsId> eids =
124  for (std::vector<HcalElectronicsId>::const_iterator it=
125  eids.begin(); it!=eids.end(); ++it)
126  {
127  HcalElectronicsId eid = HcalElectronicsId(it->rawId());
128  uint32_t hash = _hashmap.getHash(eid);
130  typename CompactMap::iterator mit = _cmap.find(hash);
131  if (mit!=_cmap.end())
132  continue;
133 
134  _cmap.insert(
135  std::make_pair(hash, STDTYPE(0)));
136  }
137  }
138  else if (_hashmap.isTHash())
139  {
140  std::vector<HcalTrigTowerDetId> tids = emap->allTriggerId();
141  for (std::vector<HcalTrigTowerDetId>::const_iterator it=
142  tids.begin(); it!=tids.end(); ++it)
143  {
144  HcalTrigTowerDetId tid = HcalTrigTowerDetId(it->rawId());
145  uint32_t hash = _hashmap.getHash(tid);
147  typename CompactMap::iterator mit = _cmap.find(hash);
148  if (mit!=_cmap.end())
149  continue;
150 
151  _cmap.insert(
152  std::make_pair(hash, STDTYPE(0)));
153  }
154  }
155  }
156 
157  template<typename STDTYPE>
159  filter::HashFilter const& filter)
160  {
161  if (_hashmap.isDHash())
162  {
163  std::vector<HcalGenericDetId> dids =
164  emap->allPrecisionId();
165  for (std::vector<HcalGenericDetId>::const_iterator it=
166  dids.begin(); it!=dids.end(); ++it)
167  {
168  if (!it->isHcalDetId())
169  continue;
170 
171  HcalDetId did = HcalDetId(it->rawId());
172  uint32_t hash = _hashmap.getHash(did);
173  typename CompactMap::iterator mit = _cmap.find(hash);
174  if (mit!=_cmap.end())
175  continue;
176  if (filter.filter(did))
177  continue;
178 
180 
181  _cmap.insert(
182  std::make_pair(hash, STDTYPE(0)));
183  }
184  }
185  else if (_hashmap.isEHash())
186  {
187  std::vector<HcalElectronicsId> eids =
189  for (std::vector<HcalElectronicsId>::const_iterator it=
190  eids.begin(); it!=eids.end(); ++it)
191  {
192  HcalElectronicsId eid = HcalElectronicsId(it->rawId());
193  uint32_t hash = _hashmap.getHash(eid);
194  typename CompactMap::iterator mit = _cmap.find(hash);
195  if (filter.filter(eid))
196  continue;
197  if (mit!=_cmap.end())
198  continue;
199  _logger.debug(eid);
200 
201  _cmap.insert(
202  std::make_pair(hash, STDTYPE(0)));
203  }
204  }
205  else if (_hashmap.isTHash())
206  {
207  std::vector<HcalTrigTowerDetId> tids = emap->allTriggerId();
208  for (std::vector<HcalTrigTowerDetId>::const_iterator it=
209  tids.begin(); it!=tids.end(); ++it)
210  {
211  HcalTrigTowerDetId tid = HcalTrigTowerDetId(it->rawId());
212  uint32_t hash = _hashmap.getHash(tid);
213  typename CompactMap::iterator mit = _cmap.find(hash);
214  if (mit!=_cmap.end())
215  continue;
216  if (filter.filter(tid))
217  continue;
219 
220  _cmap.insert(
221  std::make_pair(hash, STDTYPE(0)));
222  }
223  }
224  }
225 
226  template<typename STDTYPE>
227  void ContainerXXX<STDTYPE>::set(HcalDetId const& did, STDTYPE x)
228  {
229  _cmap[_hashmap.getHash(did)] = x;
230  }
231 
232  template<typename STDTYPE>
234  STDTYPE x)
235  {
236  _cmap[_hashmap.getHash(did)] = x;
237  }
238 
239  template<typename STDTYPE>
241  STDTYPE x)
242  {
243  _cmap[_hashmap.getHash(did)] = x;
244  }
245 
246  template<typename STDTYPE>
248  {
249  return _cmap[_hashmap.getHash(did)];
250  }
251 
252  template<typename STDTYPE>
254  {
255  return _cmap[_hashmap.getHash(eid)];
256  }
257 
258  template<typename STDTYPE>
260  {
261  return _cmap[_hashmap.getHash(tid)];
262  }
263 
264  template<typename STDTYPE>
266  {
267  return _cmap.find(id.rawId())!=_cmap.end();
268  }
269 
270  template<typename STDTYPE>
272  {
273  return _cmap.find(id.rawId())!=_cmap.end();
274  }
275 
276  template<typename STDTYPE>
278  {
279  return _cmap.find(id.rawId())!=_cmap.end();
280  }
281 
282  template<typename STDTYPE>
283  void ContainerXXX<STDTYPE>::push(HcalDetId const& did, STDTYPE x)
284  {
285  uint32_t hash = did.rawId();
286  typename CompactMap::iterator mit=_cmap.find(hash);
287  if (mit!=_cmap.end())
288  return;
289  _cmap.insert(
290  std::make_pair(hash, x));
291  }
292 
293  template<typename STDTYPE>
295  {
296  uint32_t hash = eid.rawId();
297  typename CompactMap::iterator mit=_cmap.find(hash);
298  if (mit!=_cmap.end())
299  return;
300  _cmap.insert(
301  std::make_pair(hash, x));
302  }
303 
304  template<typename STDTYPE>
306  {
307  uint32_t hash = tid.rawId();
308  typename CompactMap::iterator mit=_cmap.find(hash);
309  if (mit!=_cmap.end())
310  return;
311  _cmap.insert(
312  std::make_pair(hash, x));
313  }
314 
315  template<typename STDTYPE>
317  {
318  return (uint32_t)(_cmap.size());
319  }
320 
321  template<typename STDTYPE>
323  {
324  BOOST_FOREACH(typename CompactMap::value_type &p, _cmap)
325  {
326  STDTYPE &x = p.second;
327  uint32_t hash = p.first;
328  c->fill(hash, (double)x);
329  }
330  }
331 
332  template<typename STDTYPE>
333  void ContainerXXX<STDTYPE>::dump(std::vector<Container1D*> const &vc)
334  {
335  BOOST_FOREACH(typename CompactMap::value_type &p, _cmap)
336  {
337  STDTYPE &x = p.second;
338  uint32_t hash = p.first;
339 
340  for (std::vector<Container1D*>::const_iterator it=vc.begin();
341  it!=vc.end(); ++it)
342  (*it)->fill(hash, (double)x);
343  }
344  }
345 
346  template<typename STDTYPE>
348  {
349  std::cout << "Container by " << _hashmap.getHashTypeName() << std::endl;
350  BOOST_FOREACH(typename CompactMap::value_type &p, _cmap)
351  {
352  if (_hashmap.isDHash())
353  std::cout << HcalDetId(p.first) << p.second << std::endl;
354  else if (_hashmap.isEHash())
355  std::cout << HcalElectronicsId(p.first) << p.second
356  << std::endl;
357  else if (_hashmap.isTHash())
358  std::cout << HcalTrigTowerDetId(p.first) << p.second
359  << std::endl;
360  }
361  }
362 
363  template<typename STDTYPE>
365  {
366  BOOST_FOREACH(typename CompactMap::value_type &p, _cmap)
367  {
368  p.second = 0;
369  }
370  }
371 
372  template<typename STDTYPE>
374  {
375  BOOST_FOREACH(typename CompactMap::value_type &p, _cmap)
376  {
377  STDTYPE &x = p.second;
378  uint32_t hash = p.first;
379 
380  if (_hashmap.isDHash())
381  x = cont->getBinContent(HcalDetId(hash));
382  else if (_hashmap.isEHash())
383  x = cont->getBinContent(HcalElectronicsId(hash));
384  else if (_hashmap.isTHash())
385  x = cont->getBinContent(HcalTrigTowerDetId(hash));
386  }
387  }
388 }
389 
390 #endif
Definition: Logger.h:6
constexpr uint32_t rawId() const
ContainerXXX(hashfunctions::HashType ht)
Definition: ContainerXXX.h:25
boost::unordered_map< uint32_t, double > doubleCompactMap
Definition: ContainerXXX.h:16
virtual bool exists(HcalDetId const &)
Definition: ContainerXXX.h:265
std::vector< HcalElectronicsId > allElectronicsIdPrecision() const
virtual bool isTHash() const
Definition: HashMapper.h:63
virtual void initialize(hashfunctions::HashType htype)
Definition: HashMapper.h:29
virtual uint32_t size()
Definition: ContainerXXX.h:316
void debug(STDTYPE const &msg) const
Definition: Logger.h:31
virtual CompactMap::const_iterator begin()
Definition: ContainerXXX.h:73
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:47
virtual void dump(Container1D *)
Definition: ContainerXXX.h:322
virtual void push(HcalDetId const &, STDTYPE)
Definition: ContainerXXX.h:283
virtual void reset()
Definition: ContainerXXX.h:364
mapper::HashMapper _hashmap
Definition: ContainerXXX.h:69
boost::unordered_map< uint32_t, uint32_t > uintCompactMap
Definition: ContainerXXX.h:18
virtual std::string getHashTypeName() const
Definition: HashMapper.h:50
virtual CompactMap::const_iterator end()
Definition: ContainerXXX.h:75
virtual void fill(uint32_t)
Definition: Container1D.cc:83
void set(std::string const &name, int debug=0)
Definition: Logger.h:41
boost::unordered_map< uint32_t, int > intCompactMap
Definition: ContainerXXX.h:17
std::vector< HcalGenericDetId > allPrecisionId() const
boost::unordered_map< uint32_t, STDTYPE > CompactMap
Definition: ContainerXXX.h:67
uint32_t getHash(HcalDetId const &did) const override
Definition: HashMapper.h:33
#define debug
Definition: HDRShower.cc:19
virtual void book(HcalElectronicsMap const *)
Definition: ContainerXXX.h:97
virtual bool isDHash() const
Definition: HashMapper.h:56
virtual void load(Container1D *)
Definition: ContainerXXX.h:373
virtual STDTYPE & get(HcalDetId const &)
Definition: ContainerXXX.h:247
virtual double getBinContent(HcalDetId const &)
Definition: Container1D.cc:215
virtual bool filter(HcalDetId const &) const
Definition: HashFilter.cc:38
virtual bool isEHash() const
Definition: HashMapper.h:58
virtual void initialize(hashfunctions::HashType, int debug=0)
Definition: ContainerXXX.h:89
Readout chain identification for Hcal.
std::vector< HcalTrigTowerDetId > allTriggerId() const
std::string getName(HcalDetId const &did) const override
Definition: HashMapper.h:42
virtual void set(HcalDetId const &, STDTYPE)
Definition: ContainerXXX.h:227
virtual void print()
Definition: ContainerXXX.h:347