CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/DataFormats/Common/interface/DetSet.h

Go to the documentation of this file.
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.16 2011/09/09 08:43:17 eulisse Exp $
00012 
00013 ----------------------------------------------------------------------*/
00014 
00015 #include <vector>
00016 #include <stdint.h>
00017 #include <stddef.h>
00018 #include "DataFormats/Common/interface/CMS_CLASS_VERSION.h"
00019 
00020 namespace edm {
00021   typedef uint32_t det_id_type;
00022 
00023   template <class T>
00024   struct DetSet
00025   {
00026     typedef std::vector<T>                           collection_type;
00027     // We don't just use T as value-type, in case we switch to a
00028     // fancier underlying container.
00029     typedef typename collection_type::value_type      value_type;
00030     typedef typename collection_type::reference       reference;
00031     typedef typename collection_type::const_reference const_reference;
00032     typedef typename collection_type::iterator        iterator;
00033     typedef typename collection_type::const_iterator  const_iterator;
00034     typedef typename collection_type::size_type       size_type;
00035 
00037     DetSet() : id(0), data() { }
00039     explicit DetSet(det_id_type i) : id(i), data() { }
00040 
00041 #if defined( __GXX_EXPERIMENTAL_CXX0X__)
00042     DetSet(DetSet<T> const & rh) : id(rh.id), data(rh.data){}
00043 
00044     DetSet<T> & operator=(DetSet<T> const & rh)  {
00045       id = rh.id;
00046       data = rh.data;
00047       return * this;
00048     }
00049 
00050     DetSet(DetSet<T> && rh) : id(rh.id), data(std::move(rh.data)){}
00051     
00052     DetSet<T> & operator=(DetSet<T> && rh)  {
00053       id = rh.id;
00054       data.swap(rh.data);
00055       return * this;
00056     }
00057 #endif
00058 
00059     iterator begin() { return data.begin(); }
00060     iterator end() { return data.end(); }
00061     const_iterator begin() const { return data.begin(); }
00062     const_iterator end() const { return data.end(); }
00063     size_type size() const { return data.size(); }
00064     bool empty() const { return data.empty(); }
00065     reference operator[](size_type i) { return data[ i ]; }
00066     const_reference operator[](size_type i) const { return data[ i ]; }
00067     void reserve(size_t s) { data.reserve(s); }
00068     void push_back(const T & t) { data.push_back(t); }
00069     void clear() { data.clear(); }
00070     void swap(DetSet<T> & other);
00071 
00072     det_id_type detId() const { return id; }
00073 
00074     //Used by ROOT storage
00075     CMS_CLASS_VERSION(10)
00076 
00077     det_id_type      id;
00078     collection_type  data;
00079   }; // template struct DetSet
00080 
00081 
00082   // TODO: If it turns out that it is confusing to have operator<
00083   // defined for DetSet, because this op< ignores the data member
00084   // 'data', we could instead specialize the std::less class template
00085   // directly.
00086 
00087   template <class T>
00088   inline
00089   bool
00090   operator< (DetSet<T> const& x, DetSet<T> const& y) {
00091     return x.detId() < y.detId();
00092   }
00093 
00094   template <class T>
00095   inline
00096   bool
00097   operator< (DetSet<T> const& x, det_id_type y) {
00098     return x.detId() < y;
00099   }
00100 
00101   template <class T>
00102   inline
00103   bool
00104   operator< (det_id_type x, DetSet<T> const& y) {
00105     return x < y.detId();
00106   }
00107 
00108   template <class T>
00109   inline
00110   void
00111   DetSet<T>::swap(DetSet<T> & other) {
00112     data.swap(other.data);
00113     std::swap(id, other.id);
00114   }
00115 
00116   template <class T>
00117   inline
00118   void
00119   swap(DetSet<T> & a, DetSet<T> & b) {
00120     a.swap(b);
00121   }
00122 
00123 } // namespace edm;
00124 
00125 #endif