CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DetSet.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_DetSet_h
2 #define DataFormats_Common_DetSet_h
3 
4 /*----------------------------------------------------------------------
5 
6 DetSet: A struct which combines a collection of homogeneous objects
7 associated with a common DetId with a DetId instance, holding the
8 common DetId value. The collected objects may or may not contain their
9 own copy of the common DetId.
10 
11 
12 ----------------------------------------------------------------------*/
13 
14 #include <vector>
15 #include <cstdint>
16 #include <cstddef>
18 
19 namespace edm {
20  typedef uint32_t det_id_type;
21 
22  template <class T>
23  struct DetSet {
24  typedef std::vector<T> collection_type;
25  // We don't just use T as value-type, in case we switch to a
26  // fancier underlying container.
29  typedef typename collection_type::const_reference const_reference;
30  typedef typename collection_type::iterator iterator;
31  typedef typename collection_type::const_iterator const_iterator;
33 
35  DetSet() : id(0), data() {}
37  explicit DetSet(det_id_type i) : id(i), data() {}
38 
39 #if defined(__GXX_EXPERIMENTAL_CXX0X__)
40  DetSet(DetSet<T> const& rh) : id(rh.id), data(rh.data) {}
41 
42  DetSet<T>& operator=(DetSet<T> const& rh) {
43  id = rh.id;
44  data = rh.data;
45  return *this;
46  }
47 
48  DetSet(DetSet<T>&& rh) noexcept : id(rh.id), data(std::move(rh.data)) {}
49 
50  DetSet<T>& operator=(DetSet<T>&& rh) noexcept {
51  id = rh.id;
52  data = std::move(rh.data);
53  return *this;
54  }
55 #endif
56 
57  iterator begin() { return data.begin(); }
58  iterator end() { return data.end(); }
59  const_iterator begin() const { return data.begin(); }
60  const_iterator end() const { return data.end(); }
61  size_type size() const { return data.size(); }
62  bool empty() const { return data.empty(); }
65  void reserve(size_t s) { data.reserve(s); }
66  void push_back(const T& t) { data.push_back(t); }
67  template <class... Args>
68  decltype(auto) emplace_back(Args&&... args) {
69  return data.emplace_back(std::forward<Args>(args)...);
70  }
71  void clear() { data.clear(); }
72  void swap(DetSet<T>& other) noexcept;
73 
74  det_id_type detId() const { return id; }
75 
76  //Used by ROOT storage
78 
81  }; // template struct DetSet
82 
83  // TODO: If it turns out that it is confusing to have operator<
84  // defined for DetSet, because this op< ignores the data member
85  // 'data', we could instead specialize the std::less class template
86  // directly.
87 
88  template <class T>
89  inline bool operator<(DetSet<T> const& x, DetSet<T> const& y) {
90  return x.detId() < y.detId();
91  }
92 
93  template <class T>
94  inline bool operator<(DetSet<T> const& x, det_id_type y) {
95  return x.detId() < y;
96  }
97 
98  template <class T>
99  inline bool operator<(det_id_type x, DetSet<T> const& y) {
100  return x < y.detId();
101  }
102 
103  template <class T>
104  inline void DetSet<T>::swap(DetSet<T>& other) noexcept {
105  data.swap(other.data);
106  std::swap(id, other.id);
107  }
108 
109  template <class T>
110  inline void swap(DetSet<T>& a, DetSet<T>& b) {
111  a.swap(b);
112  }
113 
114 } // namespace edm
115 
116 #endif
iterator end()
Definition: DetSet.h:58
std::vector< T > collection_type
Definition: DetSet.h:24
void push_back(const T &t)
Definition: DetSet.h:66
collection_type::iterator iterator
Definition: DetSet.h:30
det_id_type detId() const
Definition: DetSet.h:74
const_iterator begin() const
Definition: DetSet.h:59
reference operator[](size_type i)
Definition: DetSet.h:63
#define CMS_CLASS_VERSION(_version_)
uint16_t size_type
size_type size() const
Definition: DetSet.h:61
DetSet(det_id_type i)
constructor by detector identifier
Definition: DetSet.h:37
void reserve(size_t s)
Definition: DetSet.h:65
decltype(auto) emplace_back(Args &&...args)
Definition: DetSet.h:68
collection_type::value_type value_type
Definition: DetSet.h:27
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
def move
Definition: eostools.py:511
collection_type::reference reference
Definition: DetSet.h:28
iterator begin()
Definition: DetSet.h:57
const_iterator end() const
Definition: DetSet.h:60
uint32_t det_id_type
Definition: DetSet.h:20
DetSet()
default constructor
Definition: DetSet.h:35
void swap(DetSet< T > &other) noexcept
Definition: DetSet.h:104
double b
Definition: hdecay.h:118
collection_type data
Definition: DetSet.h:80
bool empty() const
Definition: DetSet.h:62
const_reference operator[](size_type i) const
Definition: DetSet.h:64
collection_type::size_type size_type
Definition: DetSet.h:32
double a
Definition: hdecay.h:119
det_id_type id
Definition: DetSet.h:79
collection_type::const_reference const_reference
Definition: DetSet.h:29
float x
void clear()
Definition: DetSet.h:71
collection_type::const_iterator const_iterator
Definition: DetSet.h:31
long double T
def template
Definition: svgfig.py:521