CMS 3D CMS Logo

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