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  //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
mps_fire.i
i
Definition: mps_fire.py:428
patZpeak.handle
handle
Definition: patZpeak.py:23
edmNew::DetSetVector::Item
Trans::Item Item
Definition: DetSetVectorNew.h:158
edmNew::DetSet::DetSet
DetSet(id_type i, DataContainer const &idata, size_type ioffset, size_type isize)
Definition: DetSetNew.h:37
cms::cuda::assert
assert(be >=bs)
edmNew::DetSet::m_id
id_type m_id
Definition: DetSetNew.h:95
edmNew::DetSet::data
data_type * data()
Definition: DetSetNew.h:90
edmNew::DetSet::Container
DetSetVector< T > Container
Definition: DetSetNew.h:24
edmNew::DetSet::operator[]
data_type & operator[](size_type i)
Definition: DetSetNew.h:50
edmNew::DetSet::begin
const_iterator begin() const
Definition: DetSetNew.h:58
edmNew
Definition: DetSet2RangeMap.h:11
edm::Ref
Definition: AssociativeIterator.h:58
edmNew::dstvdetails::DetSetVectorTrans::Item
Definition: DetSetVectorNew.h:100
edmNew::DetSet::size
size_type size() const
Definition: DetSetNew.h:68
edmNew::DetSet::end
iterator end()
Definition: DetSetNew.h:56
edmNew::DetSet::operator[]
data_type operator[](size_type i) const
Definition: DetSetNew.h:52
edmNew::DetSet::container
const DataContainer & container() const
Definition: DetSetNew.h:82
edmNew::DetSet::isValid
bool isValid() const
Definition: DetSetNew.h:48
edmNew::det_id_type
unsigned int det_id_type
Definition: DetSetNew.h:10
edmNew::DetSet
Definition: DetSetNew.h:22
edmNew::DetSet::DetSet
DetSet()
Definition: DetSetNew.h:36
edmNew::DetSet::size_type
unsigned int size_type
Definition: DetSetNew.h:25
edmNew::DetSet::m_data
const DataContainer * m_data
Definition: DetSetNew.h:96
edmNew::DetSet::id
id_type id() const
Definition: DetSetNew.h:64
edmNew::DetSet::makeRefTo
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
edmNew::DetSet::id_type
unsigned int id_type
Definition: DetSetNew.h:26
edmNew::DetSet::begin
iterator begin()
Definition: DetSetNew.h:54
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
edmNew::DetSet::m_offset
int m_offset
Definition: DetSetNew.h:97
edmNew::DetSet::key_type
id_type key_type
Definition: DetSetNew.h:34
edmNew::DetSet::offset
int offset() const
Definition: DetSetNew.h:62
edmNew::DetSet::set
void set(Container const &icont, typename Container::Item const &item, bool update=true)
Definition: DetSetVectorNew.h:637
edmNew::DetSetVector
Definition: DetSetNew.h:13
edmNew::DetSet::data
const data_type * data() const
Definition: DetSetNew.h:84
Ref.h
edmNew::DetSet::value_type
data_type value_type
Definition: DetSetNew.h:33
edmNew::DetSet::detId
id_type detId() const
Definition: DetSetNew.h:66
T
long double T
Definition: Basic3DVectorLD.h:48
edmNew::DetSet::makeKeyOf
unsigned int makeKeyOf(const_iterator ci) const
Definition: DetSetNew.h:79
edmNew::DetSet::DataContainer
std::vector< data_type > DataContainer
Definition: DetSetNew.h:29
edmNew::DetSet::end
const_iterator end() const
Definition: DetSetNew.h:60
edmNew::DetSet::m_size
size_type m_size
Definition: DetSetNew.h:98
edmNew::DetSet::DetSet
DetSet(Container const &icont, typename Container::Item const &item, bool update)
Definition: DetSetNew.h:40
edmNew::DetSet::iterator
data_type * iterator
Definition: DetSetNew.h:30
edmNew::DetSet::empty
bool empty() const
Definition: DetSetNew.h:70
edmNew::DetSet::data_type
T data_type
Definition: DetSetNew.h:27
update
#define update(a, b)
Definition: TrackClassifier.cc:10
edmNew::DetSet::const_iterator
const data_type * const_iterator
Definition: DetSetNew.h:31