00001 #ifndef DataFormats_Common_DetSet_h 00002 #define DataFormats_Common_DetSet_h 00003 00004 /*---------------------------------------------------------------------- 00005 00006 DetSet: A struct which combines a collection of homogeneous objects 00007 associated with a common DetId with a DetId instance, holding the 00008 common DetId value. The collected objects may or may not contain their 00009 own copy of the common DetId. 00010 00011 $Id: DetSet.h,v 1.15 2011/03/08 18:47:15 chrjones Exp $ 00012 00013 ----------------------------------------------------------------------*/ 00014 00015 #include <vector> 00016 #include <stdint.h> 00017 #include "DataFormats/Common/interface/CMS_CLASS_VERSION.h" 00018 00019 namespace edm { 00020 typedef uint32_t det_id_type; 00021 00022 template <class T> 00023 struct DetSet 00024 { 00025 typedef std::vector<T> collection_type; 00026 // We don't just use T as value-type, in case we switch to a 00027 // fancier underlying container. 00028 typedef typename collection_type::value_type value_type; 00029 typedef typename collection_type::reference reference; 00030 typedef typename collection_type::const_reference const_reference; 00031 typedef typename collection_type::iterator iterator; 00032 typedef typename collection_type::const_iterator const_iterator; 00033 typedef typename collection_type::size_type size_type; 00034 00036 DetSet() : id(0), data() { } 00038 explicit DetSet(det_id_type i) : id(i), data() { } 00039 00040 #if defined( __GXX_EXPERIMENTAL_CXX0X__) 00041 DetSet(DetSet<T> const & rh) : id(rh.id), data(rh.data){} 00042 00043 DetSet<T> & operator=(DetSet<T> const & rh) { 00044 id = rh.id; 00045 data = rh.data; 00046 return * this; 00047 } 00048 00049 DetSet(DetSet<T> && rh) : id(rh.id), data(std::move(rh.data)){} 00050 00051 DetSet<T> & operator=(DetSet<T> && rh) { 00052 id = rh.id; 00053 data.swap(rh.data); 00054 return * this; 00055 } 00056 #endif 00057 00058 iterator begin() { return data.begin(); } 00059 iterator end() { return data.end(); } 00060 const_iterator begin() const { return data.begin(); } 00061 const_iterator end() const { return data.end(); } 00062 size_type size() const { return data.size(); } 00063 bool empty() const { return data.empty(); } 00064 reference operator[](size_type i) { return data[ i ]; } 00065 const_reference operator[](size_type i) const { return data[ i ]; } 00066 void reserve(size_t s) { data.reserve(s); } 00067 void push_back(const T & t) { data.push_back(t); } 00068 void clear() { data.clear(); } 00069 void swap(DetSet<T> & other); 00070 00071 det_id_type detId() const { return id; } 00072 00073 //Used by ROOT storage 00074 CMS_CLASS_VERSION(10) 00075 00076 det_id_type id; 00077 collection_type data; 00078 }; // template struct DetSet 00079 00080 00081 // TODO: If it turns out that it is confusing to have operator< 00082 // defined for DetSet, because this op< ignores the data member 00083 // 'data', we could instead specialize the std::less class template 00084 // directly. 00085 00086 template <class T> 00087 inline 00088 bool 00089 operator< (DetSet<T> const& x, DetSet<T> const& y) { 00090 return x.detId() < y.detId(); 00091 } 00092 00093 template <class T> 00094 inline 00095 bool 00096 operator< (DetSet<T> const& x, det_id_type y) { 00097 return x.detId() < y; 00098 } 00099 00100 template <class T> 00101 inline 00102 bool 00103 operator< (det_id_type x, DetSet<T> const& y) { 00104 return x < y.detId(); 00105 } 00106 00107 template <class T> 00108 inline 00109 void 00110 DetSet<T>::swap(DetSet<T> & other) { 00111 data.swap(other.data); 00112 std::swap(id, other.id); 00113 } 00114 00115 template <class T> 00116 inline 00117 void 00118 swap(DetSet<T> & a, DetSet<T> & b) { 00119 a.swap(b); 00120 } 00121 00122 } // namespace edm; 00123 00124 #endif