CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 <stdint.h>
16 #include <stddef.h>
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  void clear() { data.clear(); }
70  void swap(DetSet<T> & other) noexcept;
71 
72  det_id_type detId() const { return id; }
73 
74  //Used by ROOT storage
76 
77  det_id_type id;
78  collection_type data;
79  }; // template struct DetSet
80 
81 
82  // TODO: If it turns out that it is confusing to have operator<
83  // defined for DetSet, because this op< ignores the data member
84  // 'data', we could instead specialize the std::less class template
85  // directly.
86 
87  template <class T>
88  inline
89  bool
90  operator< (DetSet<T> const& x, DetSet<T> const& y) {
91  return x.detId() < y.detId();
92  }
93 
94  template <class T>
95  inline
96  bool
97  operator< (DetSet<T> const& x, det_id_type y) {
98  return x.detId() < y;
99  }
100 
101  template <class T>
102  inline
103  bool
104  operator< (det_id_type x, DetSet<T> const& y) {
105  return x < y.detId();
106  }
107 
108  template <class T>
109  inline
110  void
111  DetSet<T>::swap(DetSet<T> & other) noexcept {
112  data.swap(other.data);
113  std::swap(id, other.id);
114  }
115 
116  template <class T>
117  inline
118  void
120  a.swap(b);
121  }
122 
123 } // namespace edm;
124 
125 #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:72
const_iterator begin() const
Definition: DetSet.h:61
#define noexcept
reference operator[](size_type i)
Definition: DetSet.h:65
#define CMS_CLASS_VERSION(_version_)
Definition: classes.h:31
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
T x() const
Cartesian x coordinate.
void reserve(size_t s)
Definition: DetSet.h:67
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:520
collection_type::reference reference
Definition: DetSet.h:30
iterator begin()
Definition: DetSet.h:59
const_iterator end() const
Definition: DetSet.h:62
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:78
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:77
collection_type::const_reference const_reference
Definition: DetSet.h:31
void clear()
Definition: DetSet.h:69
collection_type::const_iterator const_iterator
Definition: DetSet.h:33
void swap(DetSet< T > &other)
Definition: DetSet.h:111
long double T
def move(src, dest)
Definition: eostools.py:510