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 $Id: DetSet.h,v 1.17 2012/04/11 09:53:26 innocent Exp $
12 
13 ----------------------------------------------------------------------*/
14 
15 #include <vector>
16 #include <stdint.h>
17 #include <stddef.h>
20 
21 namespace edm {
22  typedef uint32_t det_id_type;
23 
24  template <class T>
25  struct DetSet
26  {
27  typedef std::vector<T> collection_type;
28  // We don't just use T as value-type, in case we switch to a
29  // fancier underlying container.
32  typedef typename collection_type::const_reference const_reference;
33  typedef typename collection_type::iterator iterator;
34  typedef typename collection_type::const_iterator const_iterator;
36 
38  DetSet() : id(0), data() { }
40  explicit DetSet(det_id_type i) : id(i), data() { }
41 
42 #if defined( __GXX_EXPERIMENTAL_CXX0X__)
43  DetSet(DetSet<T> const & rh) : id(rh.id), data(rh.data){}
44 
45  DetSet<T> & operator=(DetSet<T> const & rh) {
46  id = rh.id;
47  data = rh.data;
48  return * this;
49  }
50 
51  DetSet(DetSet<T> && rh) noexcept : id(rh.id), data(std::move(rh.data)){}
52 
53  DetSet<T> & operator=(DetSet<T> && rh) noexcept {
54  id = rh.id;
55  data.swap(rh.data);
56  return * this;
57  }
58 #endif
59 
60  iterator begin() { return data.begin(); }
61  iterator end() { return data.end(); }
62  const_iterator begin() const { return data.begin(); }
63  const_iterator end() const { return data.end(); }
64  size_type size() const { return data.size(); }
65  bool empty() const { return data.empty(); }
67  const_reference operator[](size_type i) const { return data[ i ]; }
68  void reserve(size_t s) { data.reserve(s); }
69  void push_back(const T & t) { data.push_back(t); }
70  void clear() { data.clear(); }
71  void swap(DetSet<T> & other) noexcept;
72 
73  det_id_type detId() const { return id; }
74 
75  //Used by ROOT storage
77 
80  }; // template struct DetSet
81 
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
90  bool
92  return x.detId() < y.detId();
93  }
94 
95  template <class T>
96  inline
97  bool
98  operator< (DetSet<T> const& x, det_id_type y) {
99  return x.detId() < y;
100  }
101 
102  template <class T>
103  inline
104  bool
105  operator< (det_id_type x, DetSet<T> const& y) {
106  return x < y.detId();
107  }
108 
109  template <class T>
110  inline
111  void
112  DetSet<T>::swap(DetSet<T> & other) noexcept {
113  data.swap(other.data);
114  std::swap(id, other.id);
115  }
116 
117  template <class T>
118  inline
119  void
121  a.swap(b);
122  }
123 
124 } // namespace edm;
125 
126 #endif
iterator end()
Definition: DetSet.h:61
std::vector< T > collection_type
Definition: DetSet.h:27
nocap nocap const skelname & operator=(const skelname &)
int i
Definition: DBlmapReader.cc:9
void push_back(const T &t)
Definition: DetSet.h:69
collection_type::iterator iterator
Definition: DetSet.h:33
det_id_type detId() const
Definition: DetSet.h:73
const_iterator begin() const
Definition: DetSet.h:62
reference operator[](size_type i)
Definition: DetSet.h:66
#define CMS_CLASS_VERSION(_version_)
Definition: classes.h:32
uint16_t size_type
size_type size() const
Definition: DetSet.h:64
DetSet(det_id_type i)
constructor by detector identifier
Definition: DetSet.h:40
void reserve(size_t s)
Definition: DetSet.h:68
collection_type::value_type value_type
Definition: DetSet.h:30
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
collection_type::reference reference
Definition: DetSet.h:31
Container::value_type value_type
iterator begin()
Definition: DetSet.h:60
const_iterator end() const
Definition: DetSet.h:63
#define noexcept
uint32_t det_id_type
Definition: DetSet.h:22
DetSet()
default constructor
Definition: DetSet.h:38
double b
Definition: hdecay.h:120
string const
Definition: compareJSON.py:14
collection_type data
Definition: DetSet.h:79
bool empty() const
Definition: DetSet.h:65
const_reference operator[](size_type i) const
Definition: DetSet.h:67
collection_type::size_type size_type
Definition: DetSet.h:35
double a
Definition: hdecay.h:121
det_id_type id
Definition: DetSet.h:78
collection_type::const_reference const_reference
Definition: DetSet.h:32
void clear()
Definition: DetSet.h:70
x
Definition: VDTMath.h:216
collection_type::const_iterator const_iterator
Definition: DetSet.h:34
void swap(DetSet< T > &other)
Definition: DetSet.h:112
long double T
def template
Definition: svgfig.py:520