CMS 3D CMS Logo

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.9 2008/03/31 21:12:11 wmtan Exp $
00012 
00013 ----------------------------------------------------------------------*/
00014 
00015 #include <vector>
00016 
00017 namespace edm {
00018   typedef uint32_t det_id_type;
00019 
00020   template <class T>
00021   struct DetSet
00022   {
00023     typedef std::vector<T>                           collection_type;
00024     // We don't just use T as value-type, in case we switch to a
00025     // fancier underlying container.
00026     typedef typename collection_type::value_type      value_type;
00027     typedef typename collection_type::reference       reference;
00028     typedef typename collection_type::const_reference const_reference;
00029     typedef typename collection_type::iterator        iterator;
00030     typedef typename collection_type::const_iterator  const_iterator;
00031     typedef typename collection_type::size_type       size_type;
00032 
00034     DetSet() : id(0), data() { }
00036     explicit DetSet(det_id_type i) : id(i), data() { }
00037 
00038     iterator begin() { return data.begin(); }
00039     iterator end() { return data.end(); }
00040     const_iterator begin() const { return data.begin(); }
00041     const_iterator end() const { return data.end(); }
00042     size_type size() const { return data.size(); }
00043     bool empty() const { return data.empty(); }
00044     reference operator[](size_type i) { return data[ i ]; }
00045     const_reference operator[](size_type i) const { return data[ i ]; }
00046     void reserve(size_t s) { data.reserve(s); }
00047     void push_back(const T & t) { data.push_back(t); }
00048     void clear() { data.clear(); }
00049     void swap(DetSet<T> & other);
00050 
00051     det_id_type detId() const { return id; }
00052 
00053     det_id_type      id;
00054     collection_type  data;
00055   }; // template struct DetSet
00056 
00057 
00058   // TODO: If it turns out that it is confusing to have operator<
00059   // defined for DetSet, because this op< ignores the data member
00060   // 'data', we could instead specialize the std::less class template
00061   // directly.
00062 
00063   template <class T>
00064   inline
00065   bool
00066   operator< (DetSet<T> const& x, DetSet<T> const& y) {
00067     return x.detId() < y.detId();
00068   }
00069 
00070   template <class T>
00071   inline
00072   bool
00073   operator< (DetSet<T> const& x, det_id_type y) {
00074     return x.detId() < y;
00075   }
00076 
00077   template <class T>
00078   inline
00079   bool
00080   operator< (det_id_type x, DetSet<T> const& y) {
00081     return x < y.detId();
00082   }
00083 
00084   template <class T>
00085   inline
00086   void
00087   DetSet<T>::swap(DetSet<T> & other) {
00088     data.swap(other.data);
00089     std::swap(id, other.id);
00090   }
00091 
00092   template <class T>
00093   inline
00094   void
00095   swap(DetSet<T> & a, DetSet<T> & b) {
00096     a.swap(b);
00097   }
00098 
00099 } // namespace edm;
00100 
00101 #endif

Generated on Tue Jun 9 17:28:42 2009 for CMSSW by  doxygen 1.5.4