CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 
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.size()==0) {
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.size()==0) {
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  static Item dummy;
75  DetId id(rawId);
76  if ( !isValidId(id) ) return dummy;
77  return m_items[id.hashedIndex()];
78  }
79 
80  inline const_iterator find(uint32_t rawId) const {
81  DetId ib(rawId);
82  if ( !isValidId(ib) ) return m_items.end();
83  return m_items.begin() + ib.hashedIndex();
84  }
85 
86  inline const_iterator begin() const {
87  return m_items.begin();
88  }
89 
90  inline const_iterator end() const {
91  return m_items.end();
92  }
93 
94  inline size_t size() const {
95  return m_items.size();
96  }
97 
98  private:
99 
100  // not protected on EB <--> EE swap -- FIXME?
101  inline bool isValidId(const DetId id) const {
102  return id.det() == ::DetId::Ecal;
103  };
104 
105  std::vector<Item> m_items;
106 
107 };
108 
109 
110 
111 #endif // ECALCONTAINER
const_iterator begin() const
Definition: EcalContainer.h:86
const Item & item(size_t hashid) const
Definition: EcalContainer.h:36
std::vector< Item >::iterator iterator
Definition: EcalContainer.h:27
const Items & items() const
Definition: EcalContainer.h:40
const_iterator end() const
Definition: EcalContainer.h:90
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:80
Definition: DetId.h:20
Item & operator[](uint32_t rawId)
Definition: EcalContainer.h:44
void checkAndResize()
Definition: EcalContainer.h:53
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:94
long double T