CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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>
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  //FIXME (it may confuse users as size_type is same type as id_type...)
46  inline void set(Container const &icont, typename Container::Item const &item, bool update = true);
47 
48  bool isValid() const { return m_offset >= 0; }
49 
50  inline data_type &operator[](size_type i) { return data()[i]; }
51 
52  inline data_type operator[](size_type i) const { return data()[i]; }
53 
54  inline iterator begin() { return data(); }
55 
56  inline iterator end() { return data() + m_size; }
57 
58  inline const_iterator begin() const { return data(); }
59 
60  inline const_iterator end() const { return data() + m_size; }
61 
62  int offset() const { return m_offset; }
63 
64  inline id_type id() const { return m_id; }
65 
66  inline id_type detId() const { return m_id; }
67 
68  inline size_type size() const { return m_size; }
69 
70  inline bool empty() const { return m_size == 0; }
71 
72  template <typename HandleT>
74  HandleT const &handle, const_iterator ci) const {
76  handle.id(), ci, ci - &(container().front()));
77  }
78 
79  unsigned int makeKeyOf(const_iterator ci) const { return ci - &(container().front()); }
80 
81  private:
82  DataContainer const &container() const { return *m_data; }
83 
84  data_type const *data() const {
85  if (m_offset | m_size)
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
const_iterator begin() const
Definition: DetSetNew.h:58
int offset() const
Definition: DetSetNew.h:62
const_iterator end() const
Definition: DetSetNew.h:60
unsigned int det_id_type
Definition: DetSetNew.h:10
data_type operator[](size_type i) const
Definition: DetSetNew.h:52
void set(Container const &icont, typename Container::Item const &item, bool update=true)
unsigned int id_type
Definition: DetSetNew.h:26
data_type value_type
Definition: DetSetNew.h:33
data_type const * const_iterator
Definition: DetSetNew.h:31
data_type * iterator
Definition: DetSetNew.h:30
assert(be >=bs)
id_type key_type
Definition: DetSetNew.h:34
std::vector< data_type > DataContainer
Definition: DetSetNew.h:29
size_type m_size
Definition: DetSetNew.h:98
DetSet(Container const &icont, typename Container::Item const &item, bool update)
Definition: DetSetNew.h:40
bool isValid() const
Definition: DetSetNew.h:48
bool empty() const
Definition: DetSetNew.h:70
tuple handle
Definition: patZpeak.py:23
DetSet(id_type i, DataContainer const &idata, size_type ioffset, size_type isize)
Definition: DetSetNew.h:37
DataContainer const & container() const
Definition: DetSetNew.h:82
DataContainer const * m_data
Definition: DetSetNew.h:96
data_type & operator[](size_type i)
Definition: DetSetNew.h:50
data_type * data()
Definition: DetSetNew.h:90
id_type detId() const
Definition: DetSetNew.h:66
id_type m_id
Definition: DetSetNew.h:95
DetSetVector< T > Container
Definition: DetSetNew.h:24
iterator end()
Definition: DetSetNew.h:56
#define update(a, b)
id_type id() const
Definition: DetSetNew.h:64
unsigned int makeKeyOf(const_iterator ci) const
Definition: DetSetNew.h:79
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:73
size_type size() const
Definition: DetSetNew.h:68
long double T
data_type const * data() const
Definition: DetSetNew.h:84
unsigned int size_type
Definition: DetSetNew.h:25
iterator begin()
Definition: DetSetNew.h:54