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 /* 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
EcalContainer::end
const_iterator end() const
Definition: EcalContainer.h:82
EcalContainer::items
const Items & items() const
Definition: EcalContainer.h:36
EcalContainer::item
const Item & item(size_t hashid) const
Definition: EcalContainer.h:34
EcalContainer
Definition: EcalContainer.h:16
EcalContainer::value_type
Item value_type
Definition: EcalContainer.h:20
EcalContainer::operator[]
Item const & operator[](uint32_t rawId) const
Definition: EcalContainer.h:62
EcalContainer::Item
T Item
Definition: EcalContainer.h:19
EcalContainer::checkAndResize
void checkAndResize()
Definition: EcalContainer.h:47
EcalContainer::EcalContainer
EcalContainer()
Definition: EcalContainer.h:25
EcalContainer::checkAndResize
void checkAndResize(size_t priv_size)
Definition: EcalContainer.h:54
DetId
Definition: DetId.h:17
EcalContainer::iterator
std::vector< Item >::iterator iterator
Definition: EcalContainer.h:23
EcalContainer::m_items
std::vector< Item > m_items
Definition: EcalContainer.h:100
EcalContainer::isValidId
bool isValidId(const DetId id) const
Definition: EcalContainer.h:100
a
double a
Definition: hdecay.h:119
EcalContainer::Items
std::vector< Item > Items
Definition: EcalContainer.h:21
EcalContainer::clear
void clear()
Definition: EcalContainer.h:27
EcalContainer::dummy_item
static const Item & dummy_item()
Definition: EcalContainer.h:92
EcalContainer::find
const_iterator find(uint32_t rawId) const
Definition: EcalContainer.h:73
cuy.ib
ib
Definition: cuy.py:662
DetId::Ecal
Definition: DetId.h:27
EcalContainer::operator[]
Item & operator[](uint32_t rawId)
Definition: EcalContainer.h:38
DetId.h
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
T
long double T
Definition: Basic3DVectorLD.h:48
EcalContainer::setItems
void setItems(const std::vector< Item > &items)
Definition: EcalContainer.h:86
EcalContainer::insert
void insert(std::pair< uint32_t, Item > const &a)
Definition: EcalContainer.h:32
dummy
Definition: DummySelector.h:38
EcalContainer::begin
const_iterator begin() const
Definition: EcalContainer.h:80
EcalContainer::size
size_t size() const
Definition: EcalContainer.h:84
EcalContainer::const_iterator
std::vector< Item >::const_iterator const_iterator
Definition: EcalContainer.h:22