CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/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/Ref.h"
00010 #include "DataFormats/Common/interface/Handle.h"
00011 #include "DataFormats/Common/interface/LazyGetter.h"
00012 
00013 namespace edm {
00014 
00015   //------------------------------------------------------------
00016 
00017   template <class T> class RefGetter {
00018     BOOST_CLASS_REQUIRE(T, boost, LessThanComparableConcept);
00019 
00020   public:
00021 
00022     typedef Ref< LazyGetter<T>, RegionIndex<T>, FindRegion<T> > region_ref;
00023     typedef std::vector<region_ref> collection_type;
00024     typedef boost::indirect_iterator<typename collection_type::const_iterator> const_iterator;
00025     typedef std::vector<T> record_type;
00026     typedef std::pair<typename record_type::const_iterator, typename record_type::const_iterator> record_pair;
00027 
00029     RefGetter(uint32_t=50000);
00030     
00032     RefGetter(const edm::Handle< LazyGetter<T> >&, const std::vector<uint32_t>&);
00033 
00035     void reserve(uint32_t);
00036 
00038     void swap(RefGetter& other);
00039 
00041     void push_back(const edm::Handle<LazyGetter<T> >&, const uint32_t&);
00042 
00044     bool empty() const;
00045 
00047     uint32_t size() const;
00048 
00050     const RegionIndex<T>& operator[](uint32_t) const;
00051 
00054     const RegionIndex<T>& back() const;
00055     
00057     const_iterator begin() const;
00058 
00060     const_iterator end() const;
00061 
00063     bool find(uint32_t) const;
00064 
00065   private:
00066 
00067     collection_type sets_;
00068     std::vector<uint32_t> regions_;
00069   };
00070   
00071   template <class T>
00072     inline
00073     RefGetter<T>::RefGetter(uint32_t maxindex) : sets_(), regions_(maxindex/32+1,0)
00074     {}
00075 
00076     template <class T>
00077     inline
00078     RefGetter<T>::RefGetter(const edm::Handle<LazyGetter<T> >& getter, const std::vector<uint32_t>& interest) : sets_(), regions_(getter->regions()/32+1,0) 
00079     {
00080       sets_.reserve(interest.size());
00081       for (uint32_t index=0;index<interest.size();index++) {
00082         sets_.push_back(region_ref(getter,interest[index],false));
00083       }
00084     }
00085   
00086   template <class T>
00087     inline
00088     void
00089     RefGetter<T>::reserve(uint32_t size) 
00090     {
00091       sets_.reserve(size);
00092     }
00093   
00094   template <class T>
00095     inline
00096     void
00097     RefGetter<T>::swap(RefGetter<T>& other) 
00098     {
00099       sets_.swap(other.sets_);
00100       regions_.swap(other.regions_);
00101     }
00102 
00103    template <class T>
00104      inline
00105      void 
00106      RefGetter<T>::push_back(const edm::Handle< LazyGetter<T> >& getter, const uint32_t& index)
00107      {
00108        sets_.push_back(region_ref(getter, index, false));
00109        regions_[index/32] = regions_[index/32]|(1<<index%32);
00110      }
00111   
00112   template <class T>
00113     inline
00114     bool
00115     RefGetter<T>::empty() const 
00116     {
00117       return sets_.empty();
00118     }
00119   
00120   template <class T>
00121     inline
00122     uint32_t
00123     RefGetter<T>::size() const
00124     {
00125       return sets_.size();
00126     }
00127 
00128   template <class T>
00129     inline
00130     const RegionIndex<T>&
00131     RefGetter<T>::operator[](uint32_t index) const 
00132     {
00133       if (size() < index+1) edm::lazydetail::_throw_range(index);
00134       const_iterator it = sets_.begin()+index;
00135       return *it;
00136     }
00137 
00138  template <class T>
00139     inline
00140     const RegionIndex<T>&
00141     RefGetter<T>::back() const 
00142     {
00143       if (empty()) edm::lazydetail::_throw_range(0);
00144       return (*this)[size()-1];
00145     } 
00146 
00147   template <class T>
00148     inline
00149     typename RefGetter<T>::const_iterator
00150     RefGetter<T>::begin() const
00151     {
00152       return sets_.begin();
00153     }
00154   
00155   template <class T>
00156     inline
00157     typename RefGetter<T>::const_iterator
00158     RefGetter<T>::end() const
00159     {
00160       return sets_.end();
00161     }
00162   
00163   template <class T>
00164     inline
00165     bool 
00166     RefGetter<T>::find(uint32_t index) const
00167     {
00168       return (regions_[index/32]>>(index%32))&1;
00169     }
00170 
00171   template <class T>
00172     inline
00173     void
00174     swap(RefGetter<T>& a, RefGetter<T>& b) 
00175     {
00176       a.swap(b);
00177     }
00178   
00179   //------------------------------------------------------------
00180 
00181 }
00182   
00183 #endif
00184