test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 
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
58  return data()[i];
59  }
60 
61  inline
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 
79  inline
80  id_type id() const { return m_id;}
81 
82  inline
83  id_type detId() const { return m_id;}
84 
85  inline
86  size_type size() const { return m_size; }
87 
88  inline
89  bool empty() const { return m_size==0;}
90 
91  private:
92  data_type const * data() const {
93  if(m_offset|m_size) assert(m_data);
94  return m_data ? (&((*m_data)[m_offset])) : 0;
95  }
96 
98  assert(m_data);
99  return const_cast<data_type *>(&((*m_data)[m_offset]));
100  }
101 
104  int m_offset;
106  };
107 }
108 
109 #endif // DataFormats_Common_DetSet_h
const_iterator begin() const
Definition: DetSetNew.h:73
int i
Definition: DBlmapReader.cc:9
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
void set(Container const &icont, typename Container::Item const &item, bool update=true)
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:105
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:89
DetSet(id_type i, DataContainer const &idata, size_type ioffset, size_type isize)
Definition: DetSetNew.h:39
DataContainer const * m_data
Definition: DetSetNew.h:103
data_type & operator[](size_type i)
Definition: DetSetNew.h:57
data_type * data()
Definition: DetSetNew.h:97
id_type detId() const
Definition: DetSetNew.h:83
id_type m_id
Definition: DetSetNew.h:102
DetSetVector< T > Container
Definition: DetSetNew.h:23
iterator end()
Definition: DetSetNew.h:70
#define update(a, b)
id_type id() const
Definition: DetSetNew.h:80
size_type size() const
Definition: DetSetNew.h:86
long double T
data_type const * data() const
Definition: DetSetNew.h:92
unsigned int size_type
Definition: DetSetNew.h:24
iterator begin()
Definition: DetSetNew.h:67