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