CMS 3D CMS Logo

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>
19 
20 namespace edm {
21  typedef uint32_t det_id_type;
22 
23  template <class T>
24  struct DetSet
25  {
26  typedef std::vector<T> collection_type;
27  // We don't just use T as value-type, in case we switch to a
28  // fancier underlying container.
31  typedef typename collection_type::const_reference const_reference;
32  typedef typename collection_type::iterator iterator;
33  typedef typename collection_type::const_iterator const_iterator;
35 
37  DetSet() : id(0), data() { }
39  explicit DetSet(det_id_type i) : id(i), data() { }
40 
41 #if defined( __GXX_EXPERIMENTAL_CXX0X__)
42  DetSet(DetSet<T> const & rh) : id(rh.id), data(rh.data){}
43 
44  DetSet<T> & operator=(DetSet<T> const & rh) {
45  id = rh.id;
46  data = rh.data;
47  return * this;
48  }
49 
50  DetSet(DetSet<T> && rh) noexcept : id(rh.id), data(std::move(rh.data)){}
51 
52  DetSet<T> & operator=(DetSet<T> && rh) noexcept {
53  id = rh.id;
54  data = std::move(rh.data);
55  return * this;
56  }
57 #endif
58 
59  iterator begin() { return data.begin(); }
60  iterator end() { return data.end(); }
61  const_iterator begin() const { return data.begin(); }
62  const_iterator end() const { return data.end(); }
63  size_type size() const { return data.size(); }
64  bool empty() const { return data.empty(); }
65  reference operator[](size_type i) { return data[ i ]; }
66  const_reference operator[](size_type i) const { return data[ i ]; }
67  void reserve(size_t s) { data.reserve(s); }
68  void push_back(const T & t) { data.push_back(t); }
69  template<class... Args>
70  decltype(auto) emplace_back(Args&&... args) { return data.emplace_back(std::forward<Args>(args)...); }
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 
79  det_id_type id;
80  collection_type data;
81  }; // template struct DetSet
82 
83 
84  // TODO: If it turns out that it is confusing to have operator<
85  // defined for DetSet, because this op< ignores the data member
86  // 'data', we could instead specialize the std::less class template
87  // directly.
88 
89  template <class T>
90  inline
91  bool
92  operator< (DetSet<T> const& x, DetSet<T> const& y) {
93  return x.detId() < y.detId();
94  }
95 
96  template <class T>
97  inline
98  bool
99  operator< (DetSet<T> const& x, det_id_type y) {
100  return x.detId() < y;
101  }
102 
103  template <class T>
104  inline
105  bool
106  operator< (det_id_type x, DetSet<T> const& y) {
107  return x < y.detId();
108  }
109 
110  template <class T>
111  inline
112  void
113  DetSet<T>::swap(DetSet<T> & other) noexcept {
114  data.swap(other.data);
115  std::swap(id, other.id);
116  }
117 
118  template <class T>
119  inline
120  void
122  a.swap(b);
123  }
124 
125 } // namespace edm;
126 
127 #endif
iterator end()
Definition: DetSet.h:60
std::vector< T > collection_type
Definition: DetSet.h:26
void push_back(const T &t)
Definition: DetSet.h:68
collection_type::iterator iterator
Definition: DetSet.h:32
det_id_type detId() const
Definition: DetSet.h:74
const_iterator begin() const
Definition: DetSet.h:61
reference operator[](size_type i)
Definition: DetSet.h:65
#define CMS_CLASS_VERSION(_version_)
uint16_t size_type
size_type size() const
Definition: DetSet.h:63
DetSet(det_id_type i)
constructor by detector identifier
Definition: DetSet.h:39
void reserve(size_t s)
Definition: DetSet.h:67
decltype(auto) emplace_back(Args &&...args)
Definition: DetSet.h:70
collection_type::value_type value_type
Definition: DetSet.h:29
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
collection_type::reference reference
Definition: DetSet.h:30
iterator begin()
Definition: DetSet.h:59
const_iterator end() const
Definition: DetSet.h:62
#define noexcept
uint32_t det_id_type
Definition: DetSet.h:21
DetSet()
default constructor
Definition: DetSet.h:37
double b
Definition: hdecay.h:120
collection_type data
Definition: DetSet.h:80
bool empty() const
Definition: DetSet.h:64
HLT enums.
const_reference operator[](size_type i) const
Definition: DetSet.h:66
collection_type::size_type size_type
Definition: DetSet.h:34
double a
Definition: hdecay.h:121
det_id_type id
Definition: DetSet.h:79
collection_type::const_reference const_reference
Definition: DetSet.h:31
void clear()
Definition: DetSet.h:71
collection_type::const_iterator const_iterator
Definition: DetSet.h:33
void swap(DetSet< T > &other)
Definition: DetSet.h:113
long double T
def move(src, dest)
Definition: eostools.py:511