CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RefGetter.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_RefGetter_h
2 #define DataFormats_Common_RefGetter_h
3 
4 #include <algorithm>
5 #include <vector>
6 #include <utility>
7 #include "boost/concept_check.hpp"
8 #include "boost/iterator/indirect_iterator.hpp"
12 
13 namespace edm {
14 
15  //------------------------------------------------------------
16 
17  template <class T> class RefGetter {
18  BOOST_CLASS_REQUIRE(T, boost, LessThanComparableConcept);
19 
20  public:
21 
23  typedef std::vector<region_ref> collection_type;
24  typedef boost::indirect_iterator<typename collection_type::const_iterator> const_iterator;
25  typedef std::vector<T> record_type;
26  typedef std::pair<typename record_type::const_iterator, typename record_type::const_iterator> record_pair;
27 
29  RefGetter(uint32_t=50000);
30 
32  RefGetter(const edm::Handle< LazyGetter<T> >&, const std::vector<uint32_t>&);
33 
35  void reserve(uint32_t);
36 
38  void swap(RefGetter& other);
39 
41  void push_back(const edm::Handle<LazyGetter<T> >&, const uint32_t&);
42 
44  bool empty() const;
45 
47  uint32_t size() const;
48 
50  const RegionIndex<T>& operator[](uint32_t) const;
51 
54  const RegionIndex<T>& back() const;
55 
57  const_iterator begin() const;
58 
60  const_iterator end() const;
61 
63  bool find(uint32_t) const;
64 
65  private:
66 
68  std::vector<uint32_t> regions_;
69  };
70 
71  template <class T>
72  inline
73  RefGetter<T>::RefGetter(uint32_t maxindex) : sets_(), regions_(maxindex/32+1,0)
74  {}
75 
76  template <class T>
77  inline
78  RefGetter<T>::RefGetter(const edm::Handle<LazyGetter<T> >& getter, const std::vector<uint32_t>& interest) : sets_(), regions_(getter->regions()/32+1,0)
79  {
80  sets_.reserve(interest.size());
81  for (uint32_t index=0;index<interest.size();index++) {
82  sets_.push_back(region_ref(getter,interest[index],false));
83  }
84  }
85 
86  template <class T>
87  inline
88  void
90  {
91  sets_.reserve(size);
92  }
93 
94  template <class T>
95  inline
96  void
98  {
99  sets_.swap(other.sets_);
100  regions_.swap(other.regions_);
101  }
102 
103  template <class T>
104  inline
105  void
106  RefGetter<T>::push_back(const edm::Handle< LazyGetter<T> >& getter, const uint32_t& index)
107  {
108  sets_.push_back(region_ref(getter, index, false));
109  regions_[index/32] = regions_[index/32]|(1<<index%32);
110  }
111 
112  template <class T>
113  inline
114  bool
116  {
117  return sets_.empty();
118  }
119 
120  template <class T>
121  inline
122  uint32_t
124  {
125  return sets_.size();
126  }
127 
128  template <class T>
129  inline
130  const RegionIndex<T>&
132  {
133  if (size() < index+1) edm::lazydetail::_throw_range(index);
134  const_iterator it = sets_.begin()+index;
135  return *it;
136  }
137 
138  template <class T>
139  inline
140  const RegionIndex<T>&
142  {
144  return (*this)[size()-1];
145  }
146 
147  template <class T>
148  inline
151  {
152  return sets_.begin();
153  }
154 
155  template <class T>
156  inline
159  {
160  return sets_.end();
161  }
162 
163  template <class T>
164  inline
165  bool
166  RefGetter<T>::find(uint32_t index) const
167  {
168  return (regions_[index/32]>>(index%32))&1;
169  }
170 
171  template <class T>
172  inline
173  void
175  {
176  a.swap(b);
177  }
178 
179  //------------------------------------------------------------
180 
181 }
182 
183 #endif
184 
std::vector< uint32_t > regions_
Definition: RefGetter.h:68
collection_type sets_
Definition: RefGetter.h:67
void push_back(const edm::Handle< LazyGetter< T > > &, const uint32_t &)
Add a new region to the end of the collection.
Definition: RefGetter.h:106
RefGetter(uint32_t=50000)
Default constructor. Default maximum region number 50,000.
Definition: RefGetter.h:73
std::vector< T > record_type
Definition: RefGetter.h:25
uint32_t size() const
Return the number of contained &#39;region_ref&#39;s (one per Region).
Definition: RefGetter.h:123
std::pair< typename record_type::const_iterator, typename record_type::const_iterator > record_pair
Definition: RefGetter.h:26
const_iterator end() const
Return the off-the-end iterator.
Definition: RefGetter.h:158
const_iterator begin() const
Return an iterator to the first RegionIndex&lt;T&gt;.
Definition: RefGetter.h:150
const RegionIndex< T > & back() const
Definition: RefGetter.h:141
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:112
void reserve(uint32_t)
Reserve memory for sets_ collection.
Definition: RefGetter.h:89
std::vector< region_ref > collection_type
Definition: RefGetter.h:23
void _throw_range(uint32_t region)
Definition: LazyGetter.h:27
BOOST_CLASS_REQUIRE(T, boost, LessThanComparableConcept)
Ref< LazyGetter< T >, RegionIndex< T >, FindRegion< T > > region_ref
Definition: RefGetter.h:22
const RegionIndex< T > & operator[](uint32_t) const
Return a reference to the RegionIndex&lt;T&gt; for a given region.
Definition: RefGetter.h:131
boost::indirect_iterator< typename collection_type::const_iterator > const_iterator
Definition: RefGetter.h:24
double b
Definition: hdecay.h:120
bool find(uint32_t) const
Returns true if region already defined.
Definition: RefGetter.h:166
void swap(RefGetter &other)
Swap contents of class.
Definition: RefGetter.h:97
double a
Definition: hdecay.h:121
bool empty() const
Return true if we contain no &#39;region_ref&#39;s (one per Region).
Definition: RefGetter.h:115
tuple size
Write out results.