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>
13  class DetSetVector;
14 
15  /* a proxy to a variable size array of T belonging to
16  * a "channel" identified by an 32bit id
17  *
18  * FIXME interface to be finalized once use-cases fully identified
19  *
20  */
21  template <typename T>
22  class DetSet {
23  public:
25  typedef unsigned int size_type; // for persistency
26  typedef unsigned int id_type;
27  typedef T data_type;
28 
29  typedef std::vector<data_type> DataContainer;
30  typedef data_type *iterator;
31  typedef data_type const *const_iterator;
32 
34  typedef id_type key_type;
35 
36  inline DetSet() : m_id(0), m_data(nullptr), m_offset(-1), m_size(0) {}
37  inline DetSet(id_type i, DataContainer const &idata, size_type ioffset, size_type isize)
38  : m_id(i), m_data(&idata), m_offset(ioffset), m_size(isize) {}
39 
40  inline DetSet(Container const &icont, typename Container::Item const &item, bool update)
41  : m_id(0), m_data(nullptr), m_offset(-1), m_size(0) {
42  set(icont, item, update);
43  }
44 
45  bool isValid() const { return m_offset >= 0; }
46 
47  inline data_type &operator[](size_type i) { return data()[i]; }
48 
49  inline data_type operator[](size_type i) const { return data()[i]; }
50 
51  inline iterator begin() { return data(); }
52 
53  inline iterator end() { return data() + m_size; }
54 
55  inline const_iterator begin() const { return data(); }
56 
57  inline const_iterator end() const { return data() + m_size; }
58 
59  int offset() const { return m_offset; }
60 
61  inline id_type id() const { return m_id; }
62 
63  inline id_type detId() const { return m_id; }
64 
65  inline size_type size() const { return m_size; }
66 
67  inline bool empty() const { return m_size == 0; }
68 
69  template <typename HandleT>
71  HandleT const &handle, const_iterator ci) const {
73  handle.id(), ci, ci - &(container().front()));
74  }
75 
76  unsigned int makeKeyOf(const_iterator ci) const { return ci - &(container().front()); }
77 
78  private:
79  //FIXME (it may confuse users as size_type is same type as id_type...)
80  inline void set(Container const &icont, typename Container::Item const &item, bool update = true);
81 
82  DataContainer const &container() const { return *m_data; }
83 
84  data_type const *data() const {
85  if (isValid() || !empty())
86  assert(m_data);
87  return m_data ? (&((*m_data)[m_offset])) : nullptr;
88  }
89 
91  assert(m_data);
92  return const_cast<data_type *>(&((*m_data)[m_offset]));
93  }
94 
97  int m_offset;
99  };
100 } // namespace edmNew
101 
102 #endif // DataFormats_Common_DetSet_h
data_type operator[](size_type i) const
Definition: DetSetNew.h:49
bool isValid() const
Definition: DetSetNew.h:45
id_type id() const
Definition: DetSetNew.h:61
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:70
unsigned int det_id_type
Definition: DetSetNew.h:10
DataContainer const & container() const
Definition: DetSetNew.h:82
unsigned int id_type
Definition: DetSetNew.h:26
data_type value_type
Definition: DetSetNew.h:33
unsigned int makeKeyOf(const_iterator ci) const
Definition: DetSetNew.h:76
data_type const * const_iterator
Definition: DetSetNew.h:31
data_type * iterator
Definition: DetSetNew.h:30
assert(be >=bs)
bool empty() const
Definition: DetSetNew.h:67
id_type detId() const
Definition: DetSetNew.h:63
id_type key_type
Definition: DetSetNew.h:34
std::vector< data_type > DataContainer
Definition: DetSetNew.h:29
int offset() const
Definition: DetSetNew.h:59
size_type m_size
Definition: DetSetNew.h:98
DetSet(Container const &icont, typename Container::Item const &item, bool update)
Definition: DetSetNew.h:40
const_iterator end() const
Definition: DetSetNew.h:57
data_type const * data() const
Definition: DetSetNew.h:84
DetSet(id_type i, DataContainer const &idata, size_type ioffset, size_type isize)
Definition: DetSetNew.h:37
DataContainer const * m_data
Definition: DetSetNew.h:96
data_type & operator[](size_type i)
Definition: DetSetNew.h:47
const_iterator begin() const
Definition: DetSetNew.h:55
data_type * data()
Definition: DetSetNew.h:90
size_type size() const
Definition: DetSetNew.h:65
id_type m_id
Definition: DetSetNew.h:95
DetSetVector< T > Container
Definition: DetSetNew.h:24
iterator end()
Definition: DetSetNew.h:53
#define update(a, b)
long double T
unsigned int size_type
Definition: DetSetNew.h:25
iterator begin()
Definition: DetSetNew.h:51