CMS 3D CMS Logo

DetSetNew.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_DetSetNew_h
2 #define DataFormats_Common_DetSetNew_h
3 
5 #include <vector>
6 #include <cassert>
7 
8 namespace edmNew {
9  // FIXME move it elsewhere....
10  typedef unsigned int det_id_type;
11 
12  template<typename T> class DetSetVector;
13 
14  /* a proxy to a variable size array of T belonging to
15  * a "channel" identified by an 32bit id
16  *
17  * FIXME interface to be finalized once use-cases fully identified
18  *
19  */
20  template<typename T>
21  class DetSet {
22  public:
24  typedef unsigned int size_type; // for persistency
25  typedef unsigned int id_type;
26  typedef T data_type;
27 
28  typedef std::vector<data_type> DataContainer;
29  typedef data_type * iterator;
30  typedef data_type const * const_iterator;
31 
32  typedef data_type value_type;
33  typedef id_type key_type;
34 
35 
36  inline
37  DetSet() : m_id(0), m_data(0), m_offset(-1), m_size(0){}
38  inline
39  DetSet(id_type i, DataContainer const & idata, size_type ioffset, size_type isize) :
40  m_id(i), m_data(&idata), m_offset(ioffset), m_size(isize) {}
41 
42  inline
43  DetSet(Container const & icont,
44  typename Container::Item const & item, bool update) :
45  m_id(0), m_data(0), m_offset(-1), m_size(0){
46  set(icont,item, update);
47  }
48 
49  //FIXME (it may confuse users as size_type is same type as id_type...)
50  inline
51  void set(Container const & icont,
52  typename Container::Item const & item, bool update=true);
53 
54  bool isValid() const { return m_offset>=0;}
55 
56  inline
57  data_type & operator[](size_type i) {
58  return data()[i];
59  }
60 
61  inline
62  data_type operator[](size_type i) const {
63  return data()[i];
64  }
65 
66  inline
67  iterator begin() { return data();}
68 
69  inline
70  iterator end() { return data()+m_size;}
71 
72  inline
73  const_iterator begin() const { return data();}
74 
75  inline
76  const_iterator end() const { return data()+m_size;}
77 
78  int offset() const {return m_offset;}
79 
80  inline
81  id_type id() const { return m_id;}
82 
83  inline
84  id_type detId() const { return m_id;}
85 
86  inline
87  size_type size() const { return m_size; }
88 
89  inline
90  bool empty() const { return m_size==0;}
91 
92 
93  template<typename HandleT>
95  makeRefTo(HandleT const & handle, const_iterator ci) const {
97  }
98 
99  unsigned int makeKeyOf(const_iterator ci) const {
100  return ci - &(container().front());
101  }
102 
103  private:
104 
105  DataContainer const & container() const { return *m_data; }
106 
107  data_type const * data() const {
108  if(m_offset|m_size) assert(m_data);
109  return m_data ? (&((*m_data)[m_offset])) : 0;
110  }
111 
112  data_type * data() {
113  assert(m_data);
114  return const_cast<data_type *>(&((*m_data)[m_offset]));
115  }
116 
117  id_type m_id;
118  DataContainer const * m_data;
119  int m_offset;
120  size_type m_size;
121  };
122 }
123 
124 #endif // DataFormats_Common_DetSet_h
const_iterator begin() const
Definition: DetSetNew.h:73
int offset() const
Definition: DetSetNew.h:78
const_iterator end() const
Definition: DetSetNew.h:76
unsigned int det_id_type
Definition: DetSetNew.h:10
data_type operator[](size_type i) const
Definition: DetSetNew.h:62
unsigned int id_type
Definition: DetSetNew.h:25
data_type value_type
Definition: DetSetNew.h:32
data_type const * const_iterator
Definition: DetSetNew.h:30
data_type * iterator
Definition: DetSetNew.h:29
id_type key_type
Definition: DetSetNew.h:33
std::vector< data_type > DataContainer
Definition: DetSetNew.h:28
size_type m_size
Definition: DetSetNew.h:120
DetSet(Container const &icont, typename Container::Item const &item, bool update)
Definition: DetSetNew.h:43
bool isValid() const
Definition: DetSetNew.h:54
bool empty() const
Definition: DetSetNew.h:90
DetSet(id_type i, DataContainer const &idata, size_type ioffset, size_type isize)
Definition: DetSetNew.h:39
DataContainer const & container() const
Definition: DetSetNew.h:105
DataContainer const * m_data
Definition: DetSetNew.h:118
data_type & operator[](size_type i)
Definition: DetSetNew.h:57
data_type * data()
Definition: DetSetNew.h:112
id_type detId() const
Definition: DetSetNew.h:84
id_type m_id
Definition: DetSetNew.h:117
DetSetVector< T > Container
Definition: DetSetNew.h:23
iterator end()
Definition: DetSetNew.h:70
#define update(a, b)
id_type id() const
Definition: DetSetNew.h:81
unsigned int makeKeyOf(const_iterator ci) const
Definition: DetSetNew.h:99
edm::Ref< typename HandleT::element_type, typename HandleT::element_type::value_type::value_type > makeRefTo(HandleT const &handle, const_iterator ci) const
Definition: DetSetNew.h:95
size_type size() const
Definition: DetSetNew.h:87
long double T
data_type const * data() const
Definition: DetSetNew.h:107
unsigned int size_type
Definition: DetSetNew.h:24
iterator begin()
Definition: DetSetNew.h:67