CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DataFormats/Common/interface/RefGetter.h

Go to the documentation of this file.
00001 #ifndef DataFormats_Common_RefGetter_h
00002 #define DataFormats_Common_RefGetter_h
00003 
00004 #include <algorithm>
00005 #include <vector>
00006 #include <utility>
00007 #include "boost/concept_check.hpp"
00008 #include "boost/iterator/indirect_iterator.hpp"
00009 #include "DataFormats/Common/interface/CMS_CLASS_VERSION.h"
00010 #include "DataFormats/Common/interface/Ref.h"
00011 #include "DataFormats/Common/interface/Handle.h"
00012 #include "DataFormats/Common/interface/LazyGetter.h"
00013 
00014 namespace edm {
00015 
00016   //------------------------------------------------------------
00017 
00018   template <class T> class RefGetter {
00019     BOOST_CLASS_REQUIRE(T, boost, LessThanComparableConcept);
00020 
00021   public:
00022 
00023     typedef Ref< LazyGetter<T>, RegionIndex<T>, FindRegion<T> > region_ref;
00024     typedef std::vector<region_ref> collection_type;
00025     typedef boost::indirect_iterator<typename collection_type::const_iterator> const_iterator;
00026     typedef std::vector<T> record_type;
00027     typedef std::pair<typename record_type::const_iterator, typename record_type::const_iterator> record_pair;
00028 
00030     RefGetter(uint32_t=50000);
00031     
00033     RefGetter(const edm::Handle< LazyGetter<T> >&, const std::vector<uint32_t>&);
00034 
00036     void reserve(uint32_t);
00037 
00039     void swap(RefGetter& other);
00040 
00042     void push_back(const edm::Handle<LazyGetter<T> >&, const uint32_t&);
00043 
00045     bool empty() const;
00046 
00048     uint32_t size() const;
00049 
00051     const RegionIndex<T>& operator[](uint32_t) const;
00052 
00055     const RegionIndex<T>& back() const;
00056     
00058     const_iterator begin() const;
00059 
00061     const_iterator end() const;
00062 
00064     bool find(uint32_t) const;
00065 
00066     //Used by ROOT storage
00067     CMS_CLASS_VERSION(5)
00068 
00069   private:
00070 
00071     collection_type sets_;
00072     std::vector<uint32_t> regions_;
00073   };
00074   
00075   template <class T>
00076     inline
00077     RefGetter<T>::RefGetter(uint32_t maxindex) : sets_(), regions_(maxindex/32+1,0)
00078     {}
00079 
00080     template <class T>
00081     inline
00082     RefGetter<T>::RefGetter(const edm::Handle<LazyGetter<T> >& getter, const std::vector<uint32_t>& interest) : sets_(), regions_(getter->regions()/32+1,0) 
00083     {
00084       sets_.reserve(interest.size());
00085       for (uint32_t index=0;index<interest.size();index++) {
00086         sets_.push_back(region_ref(getter,interest[index],false));
00087       }
00088     }
00089   
00090   template <class T>
00091     inline
00092     void
00093     RefGetter<T>::reserve(uint32_t size) 
00094     {
00095       sets_.reserve(size);
00096     }
00097   
00098   template <class T>
00099     inline
00100     void
00101     RefGetter<T>::swap(RefGetter<T>& other) 
00102     {
00103       sets_.swap(other.sets_);
00104       regions_.swap(other.regions_);
00105     }
00106 
00107    template <class T>
00108      inline
00109      void 
00110      RefGetter<T>::push_back(const edm::Handle< LazyGetter<T> >& getter, const uint32_t& index)
00111      {
00112        sets_.push_back(region_ref(getter, index, false));
00113        regions_[index/32] = regions_[index/32]|(1<<index%32);
00114      }
00115   
00116   template <class T>
00117     inline
00118     bool
00119     RefGetter<T>::empty() const 
00120     {
00121       return sets_.empty();
00122     }
00123   
00124   template <class T>
00125     inline
00126     uint32_t
00127     RefGetter<T>::size() const
00128     {
00129       return sets_.size();
00130     }
00131 
00132   template <class T>
00133     inline
00134     const RegionIndex<T>&
00135     RefGetter<T>::operator[](uint32_t index) const 
00136     {
00137       if (size() < index+1) edm::lazydetail::_throw_range(index);
00138       const_iterator it = sets_.begin()+index;
00139       return *it;
00140     }
00141 
00142  template <class T>
00143     inline
00144     const RegionIndex<T>&
00145     RefGetter<T>::back() const 
00146     {
00147       if (empty()) edm::lazydetail::_throw_range(0);
00148       return (*this)[size()-1];
00149     } 
00150 
00151   template <class T>
00152     inline
00153     typename RefGetter<T>::const_iterator
00154     RefGetter<T>::begin() const
00155     {
00156       return sets_.begin();
00157     }
00158   
00159   template <class T>
00160     inline
00161     typename RefGetter<T>::const_iterator
00162     RefGetter<T>::end() const
00163     {
00164       return sets_.end();
00165     }
00166   
00167   template <class T>
00168     inline
00169     bool 
00170     RefGetter<T>::find(uint32_t index) const
00171     {
00172       return (regions_[index/32]>>(index%32))&1;
00173     }
00174 
00175   template <class T>
00176     inline
00177     void
00178     swap(RefGetter<T>& a, RefGetter<T>& b) 
00179     {
00180       a.swap(b);
00181     }
00182   
00183   //------------------------------------------------------------
00184 
00185 }
00186   
00187 #endif
00188