test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  virtual void dump(Container1D*);
55  virtual void dump(std::vector<Container1D*> const&);
56 
57  virtual void load(Container1D*);
58  virtual void reset();
59  virtual uint32_t size();
60  virtual void print();
61 
62  protected:
63  typedef boost::unordered_map<uint32_t, STDTYPE> CompactMap;
67 
68  public:
69  virtual typename CompactMap::const_iterator begin()
70  {return _cmap.begin();}
71  virtual typename CompactMap::const_iterator end()
72  {return _cmap.end();}
73  };
74 
75  template<typename STDTYPE>
77  {
78  BOOST_FOREACH(typename CompactMap::value_type &p, _cmap)
79  {
80  _cmap.insert(std::make_pair(p.first, p.second));
81  }
82  }
83 
84  template<typename STDTYPE>
86  int debug)
87  {
88  _hashmap.initialize(ht);
89  _logger.set("XXX", debug);
90  }
91 
92  template<typename STDTYPE>
94  {
95  if (_hashmap.isDHash())
96  {
97  std::vector<HcalGenericDetId> dids =
98  emap->allPrecisionId();
99  for (std::vector<HcalGenericDetId>::const_iterator it=
100  dids.begin(); it!=dids.end(); ++it)
101  {
102  if (!it->isHcalDetId())
103  continue;
104 
105  HcalDetId did = HcalDetId(it->rawId());
106  uint32_t hash = _hashmap.getHash(did);
107  _logger.debug(_hashmap.getName(did));
108  typename CompactMap::iterator mit = _cmap.find(hash);
109  if (mit!=_cmap.end())
110  continue;
111 
112  _cmap.insert(
113  std::make_pair(hash, STDTYPE(0)));
114  }
115  }
116  else if (_hashmap.isEHash())
117  {
118  std::vector<HcalElectronicsId> eids =
120  for (std::vector<HcalElectronicsId>::const_iterator it=
121  eids.begin(); it!=eids.end(); ++it)
122  {
123  HcalElectronicsId eid = HcalElectronicsId(it->rawId());
124  uint32_t hash = _hashmap.getHash(eid);
125  _logger.debug(_hashmap.getName(eid));
126  typename CompactMap::iterator mit = _cmap.find(hash);
127  if (mit!=_cmap.end())
128  continue;
129 
130  _cmap.insert(
131  std::make_pair(hash, STDTYPE(0)));
132  }
133  }
134  else if (_hashmap.isTHash())
135  {
136  std::vector<HcalTrigTowerDetId> tids = emap->allTriggerId();
137  for (std::vector<HcalTrigTowerDetId>::const_iterator it=
138  tids.begin(); it!=tids.end(); ++it)
139  {
140  HcalTrigTowerDetId tid = HcalTrigTowerDetId(it->rawId());
141  uint32_t hash = _hashmap.getHash(tid);
142  _logger.debug(_hashmap.getName(tid));
143  typename CompactMap::iterator mit = _cmap.find(hash);
144  if (mit!=_cmap.end())
145  continue;
146 
147  _cmap.insert(
148  std::make_pair(hash, STDTYPE(0)));
149  }
150  }
151  }
152 
153  template<typename STDTYPE>
155  filter::HashFilter const& filter)
156  {
157  if (_hashmap.isDHash())
158  {
159  std::vector<HcalGenericDetId> dids =
160  emap->allPrecisionId();
161  for (std::vector<HcalGenericDetId>::const_iterator it=
162  dids.begin(); it!=dids.end(); ++it)
163  {
164  if (!it->isHcalDetId())
165  continue;
166 
167  HcalDetId did = HcalDetId(it->rawId());
168  uint32_t hash = _hashmap.getHash(did);
169  typename CompactMap::iterator mit = _cmap.find(hash);
170  if (mit!=_cmap.end())
171  continue;
172  if (filter.filter(did))
173  continue;
174 
175  _logger.debug(_hashmap.getName(did));
176 
177  _cmap.insert(
178  std::make_pair(hash, STDTYPE(0)));
179  }
180  }
181  else if (_hashmap.isEHash())
182  {
183  std::vector<HcalElectronicsId> eids =
185  for (std::vector<HcalElectronicsId>::const_iterator it=
186  eids.begin(); it!=eids.end(); ++it)
187  {
188  HcalElectronicsId eid = HcalElectronicsId(it->rawId());
189  uint32_t hash = _hashmap.getHash(eid);
190  typename CompactMap::iterator mit = _cmap.find(hash);
191  if (filter.filter(eid))
192  continue;
193  if (mit!=_cmap.end())
194  continue;
195  _logger.debug(eid);
196 
197  _cmap.insert(
198  std::make_pair(hash, STDTYPE(0)));
199  }
200  }
201  else if (_hashmap.isTHash())
202  {
203  std::vector<HcalTrigTowerDetId> tids = emap->allTriggerId();
204  for (std::vector<HcalTrigTowerDetId>::const_iterator it=
205  tids.begin(); it!=tids.end(); ++it)
206  {
207  HcalTrigTowerDetId tid = HcalTrigTowerDetId(it->rawId());
208  uint32_t hash = _hashmap.getHash(tid);
209  typename CompactMap::iterator mit = _cmap.find(hash);
210  if (mit!=_cmap.end())
211  continue;
212  if (filter.filter(tid))
213  continue;
214  _logger.debug(_hashmap.getName(tid));
215 
216  _cmap.insert(
217  std::make_pair(hash, STDTYPE(0)));
218  }
219  }
220  }
221 
222  template<typename STDTYPE>
223  void ContainerXXX<STDTYPE>::set(HcalDetId const& did, STDTYPE x)
224  {
225  _cmap[_hashmap.getHash(did)] = x;
226  }
227 
228  template<typename STDTYPE>
230  STDTYPE x)
231  {
232  _cmap[_hashmap.getHash(did)] = x;
233  }
234 
235  template<typename STDTYPE>
237  STDTYPE x)
238  {
239  _cmap[_hashmap.getHash(did)] = x;
240  }
241 
242  template<typename STDTYPE>
244  {
245  return _cmap[_hashmap.getHash(did)];
246  }
247 
248  template<typename STDTYPE>
250  {
251  return _cmap[_hashmap.getHash(eid)];
252  }
253 
254  template<typename STDTYPE>
256  {
257  return _cmap[_hashmap.getHash(tid)];
258  }
259 
260  template<typename STDTYPE>
261  void ContainerXXX<STDTYPE>::push(HcalDetId const& did, STDTYPE x)
262  {
263  uint32_t hash = did.rawId();
264  typename CompactMap::iterator mit=_cmap.find(hash);
265  if (mit!=_cmap.end())
266  return;
267  _cmap.insert(
268  std::make_pair(hash, x));
269  }
270 
271  template<typename STDTYPE>
272  void ContainerXXX<STDTYPE>::push(HcalElectronicsId const& eid, STDTYPE x)
273  {
274  uint32_t hash = eid.rawId();
275  typename CompactMap::iterator mit=_cmap.find(hash);
276  if (mit!=_cmap.end())
277  return;
278  _cmap.insert(
279  std::make_pair(hash, x));
280  }
281 
282  template<typename STDTYPE>
284  {
285  uint32_t hash = tid.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  return (uint32_t)(_cmap.size());
297  }
298 
299  template<typename STDTYPE>
301  {
302  BOOST_FOREACH(typename CompactMap::value_type &p, _cmap)
303  {
304  STDTYPE &x = p.second;
305  uint32_t hash = p.first;
306  c->fill(hash, (double)x);
307  }
308  }
309 
310  template<typename STDTYPE>
311  void ContainerXXX<STDTYPE>::dump(std::vector<Container1D*> const &vc)
312  {
313  BOOST_FOREACH(typename CompactMap::value_type &p, _cmap)
314  {
315  STDTYPE &x = p.second;
316  uint32_t hash = p.first;
317 
318  for (std::vector<Container1D*>::const_iterator it=vc.begin();
319  it!=vc.end(); ++it)
320  (*it)->fill(hash, (double)x);
321  }
322  }
323 
324  template<typename STDTYPE>
326  {
327  std::cout << "Container by " << _hashmap.getHashTypeName() << std::endl;
328  BOOST_FOREACH(typename CompactMap::value_type &p, _cmap)
329  {
330  if (_hashmap.isDHash())
331  std::cout << HcalDetId(p.first) << p.second << std::endl;
332  else if (_hashmap.isEHash())
333  std::cout << HcalElectronicsId(p.first) << p.second
334  << std::endl;
335  else if (_hashmap.isTHash())
336  std::cout << HcalTrigTowerDetId(p.first) << p.second
337  << std::endl;
338  }
339  }
340 
341  template<typename STDTYPE>
343  {
344  BOOST_FOREACH(typename CompactMap::value_type &p, _cmap)
345  {
346  p.second = 0;
347  }
348  }
349 
350  template<typename STDTYPE>
352  {
353  BOOST_FOREACH(typename CompactMap::value_type &p, _cmap)
354  {
355  STDTYPE &x = p.second;
356  uint32_t hash = p.first;
357 
358  if (_hashmap.isDHash())
359  x = cont->getBinContent(HcalDetId(hash));
360  else if (_hashmap.isEHash())
361  x = cont->getBinContent(HcalElectronicsId(hash));
362  else if (_hashmap.isTHash())
363  x = cont->getBinContent(HcalTrigTowerDetId(hash));
364  }
365  }
366 }
367 
368 #endif
Definition: Logger.h:6
static AlgebraicMatrix initialize()
ContainerXXX(hashfunctions::HashType ht)
Definition: ContainerXXX.h:27
boost::unordered_map< uint32_t, double > doubleCompactMap
Definition: ContainerXXX.h:18
std::vector< HcalElectronicsId > allElectronicsIdPrecision() const
tuple cont
load Luminosity info ##
Definition: generateEDF.py:622
uint32_t rawId() const
virtual uint32_t size()
Definition: ContainerXXX.h:294
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
Definition: print.cc:10
virtual CompactMap::const_iterator begin()
Definition: ContainerXXX.h:69
virtual void dump(Container1D *)
Definition: ContainerXXX.h:300
virtual void push(HcalDetId const &, STDTYPE)
Definition: ContainerXXX.h:261
virtual void reset()
Definition: ContainerXXX.h:342
mapper::HashMapper _hashmap
Definition: ContainerXXX.h:65
boost::unordered_map< uint32_t, uint32_t > uintCompactMap
Definition: ContainerXXX.h:20
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
virtual CompactMap::const_iterator end()
Definition: ContainerXXX.h:71
T x() const
Cartesian x coordinate.
virtual void fill(uint32_t)
Definition: Container1D.cc:82
def load
Definition: svgfig.py:546
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:63
#define debug
Definition: HDRShower.cc:19
virtual void book(HcalElectronicsMap const *)
Definition: ContainerXXX.h:93
virtual void load(Container1D *)
Definition: ContainerXXX.h:351
virtual STDTYPE & get(HcalDetId const &)
Definition: ContainerXXX.h:243
virtual double getBinContent(HcalDetId const &)
Definition: Container1D.cc:214
virtual bool filter(HcalDetId const &) const
Definition: HashFilter.cc:36
tuple cout
Definition: gather_cfg.py:145
virtual void initialize(hashfunctions::HashType, int debug=0)
Definition: ContainerXXX.h:85
void reset(double vett[256])
Definition: TPedValues.cc:11
Readout chain identification for Hcal.
tuple size
Write out results.
std::vector< HcalTrigTowerDetId > allTriggerId() const
virtual void set(HcalDetId const &, STDTYPE)
Definition: ContainerXXX.h:223
virtual void print()
Definition: ContainerXXX.h:325