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"
13 
14 namespace edm {
15 
16  //------------------------------------------------------------
17 
18  template <class T> class RefGetter {
19  BOOST_CLASS_REQUIRE(T, boost, LessThanComparableConcept);
20 
21  public:
22 
24  typedef std::vector<region_ref> collection_type;
25  typedef boost::indirect_iterator<typename collection_type::const_iterator> const_iterator;
26  typedef std::vector<T> record_type;
27  typedef std::pair<typename record_type::const_iterator, typename record_type::const_iterator> record_pair;
28 
30  RefGetter(uint32_t=50000);
31 
33  RefGetter(const edm::Handle< LazyGetter<T> >&, const std::vector<uint32_t>&);
34 
36  void reserve(uint32_t);
37 
39  void swap(RefGetter& other);
40 
42  void push_back(const edm::Handle<LazyGetter<T> >&, const uint32_t&);
43 
45  bool empty() const;
46 
48  uint32_t size() const;
49 
51  const RegionIndex<T>& operator[](uint32_t) const;
52 
55  const RegionIndex<T>& back() const;
56 
58  const_iterator begin() const;
59 
61  const_iterator end() const;
62 
64  bool find(uint32_t) const;
65 
66  //Used by ROOT storage
68 
69  private:
70 
72  std::vector<uint32_t> regions_;
73  };
74 
75  template <class T>
76  inline
77  RefGetter<T>::RefGetter(uint32_t maxindex) : sets_(), regions_(maxindex/32+1,0)
78  {}
79 
80  template <class T>
81  inline
82  RefGetter<T>::RefGetter(const edm::Handle<LazyGetter<T> >& getter, const std::vector<uint32_t>& interest) : sets_(), regions_(getter->regions()/32+1,0)
83  {
84  sets_.reserve(interest.size());
85  for (uint32_t index=0;index<interest.size();index++) {
86  sets_.push_back(region_ref(getter,interest[index],false));
87  }
88  }
89 
90  template <class T>
91  inline
92  void
94  {
95  sets_.reserve(size);
96  }
97 
98  template <class T>
99  inline
100  void
102  {
103  sets_.swap(other.sets_);
104  regions_.swap(other.regions_);
105  }
106 
107  template <class T>
108  inline
109  void
110  RefGetter<T>::push_back(const edm::Handle< LazyGetter<T> >& getter, const uint32_t& index)
111  {
112  sets_.push_back(region_ref(getter, index, false));
113  regions_[index/32] = regions_[index/32]|(1<<index%32);
114  }
115 
116  template <class T>
117  inline
118  bool
120  {
121  return sets_.empty();
122  }
123 
124  template <class T>
125  inline
126  uint32_t
128  {
129  return sets_.size();
130  }
131 
132  template <class T>
133  inline
134  const RegionIndex<T>&
136  {
137  if (size() < index+1) edm::lazydetail::_throw_range(index);
138  const_iterator it = sets_.begin()+index;
139  return *it;
140  }
141 
142  template <class T>
143  inline
144  const RegionIndex<T>&
146  {
148  return (*this)[size()-1];
149  }
150 
151  template <class T>
152  inline
155  {
156  return sets_.begin();
157  }
158 
159  template <class T>
160  inline
163  {
164  return sets_.end();
165  }
166 
167  template <class T>
168  inline
169  bool
170  RefGetter<T>::find(uint32_t index) const
171  {
172  return (regions_[index/32]>>(index%32))&1;
173  }
174 
175  template <class T>
176  inline
177  void
179  {
180  a.swap(b);
181  }
182 
183  //------------------------------------------------------------
184 
185 }
186 
187 #endif
188 
std::vector< uint32_t > regions_
Definition: RefGetter.h:72
collection_type sets_
Definition: RefGetter.h:71
void push_back(const edm::Handle< LazyGetter< T > > &, const uint32_t &)
Add a new region to the end of the collection.
Definition: RefGetter.h:110
RefGetter(uint32_t=50000)
Default constructor. Default maximum region number 50,000.
Definition: RefGetter.h:77
std::vector< T > record_type
Definition: RefGetter.h:26
uint32_t size() const
Return the number of contained &#39;region_ref&#39;s (one per Region).
Definition: RefGetter.h:127
std::pair< typename record_type::const_iterator, typename record_type::const_iterator > record_pair
Definition: RefGetter.h:27
const_iterator end() const
Return the off-the-end iterator.
Definition: RefGetter.h:162
const_iterator begin() const
Return an iterator to the first RegionIndex&lt;T&gt;.
Definition: RefGetter.h:154
const RegionIndex< T > & back() const
Definition: RefGetter.h:145
#define CMS_CLASS_VERSION(_version_)
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:117
void reserve(uint32_t)
Reserve memory for sets_ collection.
Definition: RefGetter.h:93
std::vector< region_ref > collection_type
Definition: RefGetter.h:24
void _throw_range(uint32_t region)
Definition: LazyGetter.h:30
BOOST_CLASS_REQUIRE(T, boost, LessThanComparableConcept)
Ref< LazyGetter< T >, RegionIndex< T >, FindRegion< T > > region_ref
Definition: RefGetter.h:23
const RegionIndex< T > & operator[](uint32_t) const
Return a reference to the RegionIndex&lt;T&gt; for a given region.
Definition: RefGetter.h:135
boost::indirect_iterator< typename collection_type::const_iterator > const_iterator
Definition: RefGetter.h:25
double b
Definition: hdecay.h:120
bool find(uint32_t) const
Returns true if region already defined.
Definition: RefGetter.h:170
void swap(RefGetter &other)
Swap contents of class.
Definition: RefGetter.h:101
#define private
Definition: FWFileEntry.h:18
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:119
long double T
tuple size
Write out results.
def template
Definition: svgfig.py:520