CMS 3D CMS Logo

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 
12 
13 /* a generic container for ecal items
14  * provides access by hashedIndex and by DetId...
15  */
16 
17 template<typename DetId, typename T>
19 
20  public:
21 
23  typedef T Item;
24  typedef Item value_type;
25  typedef typename std::vector<Item> Items;
26  typedef typename std::vector<Item>::const_iterator const_iterator;
27  typedef typename std::vector<Item>::iterator iterator;
28 
29 
31 
32  void insert(std::pair<uint32_t, Item> const &a) {
33  (*this)[a.first] = a.second;
34  }
35 
36  inline const Item & item(size_t hashid) const {
37  return m_items[hashid];
38  }
39 
40  inline const Items & items() const {
41  return m_items;
42  }
43 
44  inline Item & operator[](uint32_t rawId) {
46  static Item dummy;
47  DetId id(rawId);
48  if ( !isValidId(id) ) return dummy;
49  return m_items[id.hashedIndex()];
50  }
51 
52 
53  void checkAndResize() {
54  if (m_items.empty()) {
55  // std::cout << "resizing to " << DetId::kSizeForDenseIndexing << std::endl;
56  m_items.resize(DetId::kSizeForDenseIndexing);
57  }
58  }
59 
60 
61  void checkAndResize( size_t priv_size ) {
62  // this method allows to resize the vector to a specific size forcing a specific value
63  if (m_items.empty()) {
64  // std::cout << "resizing to " << priv_size << std::endl;
65  m_items.resize(priv_size);
66  }
67  }
68 
69  inline Item const & operator[](uint32_t rawId) const {
70  // if (m_items.size()==0) {
71  // std::cout << "resizing to " << DetId::kSizeForDenseIndexing << std::endl;
72  // m_items.resize((size_t) DetId::kSizeForDenseIndexing);
73  // }
74  DetId id(rawId);
75  if ( !isValidId(id) ) return dummy_item();
76  return m_items[id.hashedIndex()];
77  }
78 
79  inline const_iterator find(uint32_t rawId) const {
80  DetId ib(rawId);
81  if ( !isValidId(ib) ) return m_items.end();
82  return m_items.begin() + ib.hashedIndex();
83  }
84 
85  inline const_iterator begin() const {
86  return m_items.begin();
87  }
88 
89  inline const_iterator end() const {
90  return m_items.end();
91  }
92 
93  inline size_t size() const {
94  return m_items.size();
95  }
96 
97  void setItems(const std::vector<Item> & items) {
98  m_items = items;
99  }
100  private:
101 
102  //Cint can't parse the new C++11 initialization syntax
103 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
104 
105  static const Item& dummy_item() {
106  static const Item s_dummy{};
107  return s_dummy;
108  }
109 #else
110  static const Item& dummy_item();
111 #endif
112  // not protected on EB <--> EE swap -- FIXME?
113  inline bool isValidId(const DetId id) const {
114  return id.det() == ::DetId::Ecal;
115  };
116 
117  std::vector<Item> m_items;
118 
119 };
120 
121 
122 
123 #endif // ECALCONTAINER
const_iterator begin() const
Definition: EcalContainer.h:85
const Item & item(size_t hashid) const
Definition: EcalContainer.h:36
void setItems(const std::vector< Item > &items)
Definition: EcalContainer.h:97
std::vector< Item >::iterator iterator
Definition: EcalContainer.h:27
const Items & items() const
Definition: EcalContainer.h:40
const_iterator end() const
Definition: EcalContainer.h:89
std::vector< Item > m_items
std::vector< Item >::const_iterator const_iterator
Definition: EcalContainer.h:26
const_iterator find(uint32_t rawId) const
Definition: EcalContainer.h:79
Definition: DetId.h:18
Item & operator[](uint32_t rawId)
Definition: EcalContainer.h:44
void checkAndResize()
Definition: EcalContainer.h:53
static const Item & dummy_item()
void checkAndResize(size_t priv_size)
Definition: EcalContainer.h:61
Item const & operator[](uint32_t rawId) const
Definition: EcalContainer.h:69
void insert(std::pair< uint32_t, Item > const &a)
Definition: EcalContainer.h:32
double a
Definition: hdecay.h:121
bool isValidId(const DetId id) const
std::vector< Item > Items
Definition: EcalContainer.h:25
size_t size() const
Definition: EcalContainer.h:93
long double T
ib
Definition: cuy.py:661