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