CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
EcalContainer.h
Go to the documentation of this file.
1 #ifndef ECALDETID_ECALCONTAINER_H
2 #define ECALDETID_ECALCONTAINER_H
3 
5 #include <vector>
6 #include <utility>
7 #include <algorithm>
8 
9 // #include <iostream>
10 
11 /* a generic container for ecal items
12  * provides access by hashedIndex and by DetId...
13  */
14 
15 template <typename DetId, typename T>
17 public:
19  typedef T Item;
20  typedef Item value_type;
21  typedef typename std::vector<Item> Items;
22  typedef typename std::vector<Item>::const_iterator const_iterator;
23  typedef typename std::vector<Item>::iterator iterator;
24 
26 
27  void clear() {
28  m_items.clear();
30  }
31 
32  void insert(std::pair<uint32_t, Item> const& a) { (*this)[a.first] = a.second; }
33 
34  inline const Item& item(size_t hashid) const { return m_items[hashid]; }
35 
36  inline const Items& items() const { return m_items; }
37 
38  inline Item& operator[](uint32_t rawId) {
40  static Item dummy;
41  DetId id(rawId);
42  if (!isValidId(id))
43  return dummy;
44  return m_items[id.hashedIndex()];
45  }
46 
47  void checkAndResize() {
48  if (m_items.empty()) {
49  // std::cout << "resizing to " << DetId::kSizeForDenseIndexing << std::endl;
50  m_items.resize(DetId::kSizeForDenseIndexing);
51  }
52  }
53 
54  void checkAndResize(size_t priv_size) {
55  // this method allows to resize the vector to a specific size forcing a specific value
56  if (m_items.empty()) {
57  // std::cout << "resizing to " << priv_size << std::endl;
58  m_items.resize(priv_size);
59  }
60  }
61 
62  inline Item const& operator[](uint32_t rawId) const {
63  // if (m_items.size()==0) {
64  // std::cout << "resizing to " << DetId::kSizeForDenseIndexing << std::endl;
65  // m_items.resize((size_t) DetId::kSizeForDenseIndexing);
66  // }
67  DetId id(rawId);
68  if (!isValidId(id))
69  return dummy_item();
70  return m_items[id.hashedIndex()];
71  }
72 
73  inline const_iterator find(uint32_t rawId) const {
74  DetId ib(rawId);
75  if (!isValidId(ib))
76  return m_items.end();
77  return m_items.begin() + ib.hashedIndex();
78  }
79 
80  inline const_iterator begin() const { return m_items.begin(); }
81 
82  inline const_iterator end() const { return m_items.end(); }
83 
84  inline size_t size() const { return m_items.size(); }
85 
86  void setItems(const std::vector<Item>& items) { m_items = items; }
87 
88 private:
89  //Cint can't parse the new C++11 initialization syntax
90 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
91 
92  static const Item& dummy_item() {
93  static const Item s_dummy{};
94  return s_dummy;
95  }
96 #else
97  static const Item& dummy_item();
98 #endif
99  // not protected on EB <--> EE swap -- FIXME?
100  inline bool isValidId(const DetId id) const { return id.det() == ::DetId::Ecal; };
101 
102  std::vector<Item> m_items;
103 };
104 
105 #endif // ECALCONTAINER
const_iterator begin() const
Definition: EcalContainer.h:80
int ib
Definition: cuy.py:661
const Item & item(size_t hashid) const
Definition: EcalContainer.h:34
uint16_t *__restrict__ id
void setItems(const std::vector< Item > &items)
Definition: EcalContainer.h:86
std::vector< Item >::iterator iterator
Definition: EcalContainer.h:23
const Items & items() const
Definition: EcalContainer.h:36
const_iterator end() const
Definition: EcalContainer.h:82
std::vector< Item > m_items
std::vector< Item >::const_iterator const_iterator
Definition: EcalContainer.h:22
const_iterator find(uint32_t rawId) const
Definition: EcalContainer.h:73
Definition: DetId.h:17
Item & operator[](uint32_t rawId)
Definition: EcalContainer.h:38
void checkAndResize()
Definition: EcalContainer.h:47
static const Item & dummy_item()
Definition: EcalContainer.h:92
void checkAndResize(size_t priv_size)
Definition: EcalContainer.h:54
Item const & operator[](uint32_t rawId) const
Definition: EcalContainer.h:62
void insert(std::pair< uint32_t, Item > const &a)
Definition: EcalContainer.h:32
double a
Definition: hdecay.h:119
bool isValidId(const DetId id) const
std::vector< Item > Items
Definition: EcalContainer.h:21
size_t size() const
Definition: EcalContainer.h:84
long double T