CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RefVector.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_RefVector_h
2 #define DataFormats_Common_RefVector_h
3 
4 /*----------------------------------------------------------------------
5 
6 RefVector: A template for a vector of interproduct references.
7  Each vector element is a reference to a member of the same product.
8 
9 ----------------------------------------------------------------------*/
10 
23 
24 #include <stdexcept>
25 #include <vector>
26 
27 namespace edm {
28 
29  template<typename T>
30  T const* getProduct(RefCore const& ref);
31 
32  template<typename C,
33  typename T = typename refhelper::ValueTrait<C>::value,
34  typename F = typename refhelper::FindTrait<C, T>::value>
35  class RefVector {
36  public:
37  typedef C collection_type;
38  typedef T member_type;
39  typedef F finder_type;
43  typedef value_type const const_reference; // better this than the default 'const value_type &'
44  typedef const_reference reference; // as operator[] returns 'const R' and not 'R &'
45 
46  // key_type is the type of the key into the collection
47  typedef typename value_type::key_type key_type;
48  typedef std::vector<key_type> KeyVec;
49 
50  // size_type is the type of the index into the RefVector
51  typedef typename KeyVec::size_type size_type;
53 
58 #if defined(__GXX_EXPERIMENTAL_CXX0X__)
59  RefVector(RefVector && rh) noexcept : refVector_(std::move(rh.refVector_)){}
60 #endif
61 
62  RefVector(ProductID const& iId) : refVector_(iId) {}
64  void push_back(value_type const& ref) {
65  refVector_.pushBack(ref.refCore(), ref.key());
66  }
67 
70  key_type const& key = refVector_.keys()[idx];
71  RefCore const& prod = refVector_.refCore();
72  return value_type(prod, key);
73  }
74 
76  value_type const at(size_type idx) const {
77  key_type const& key = refVector_.keys().at(idx);
78  RefCore const& prod = refVector_.refCore();
79  return value_type(prod, key);
80  }
81 
83  contents_type const& refVector() const {return refVector_;}
84 
86  bool empty() const {return refVector_.empty();}
87 
89  size_type size() const {return refVector_.size();}
90 
92  size_type capacity() const {return refVector_.capacity();}
93 
96 
98  const_iterator begin() const;
99 
101  const_iterator end() const;
102 
104  ProductID id() const {return refVector_.refCore().id();}
105 
108 
110  bool isNull() const {return !id().isValid();}
111 
113  bool isNonnull() const {return !isNull();}
114 
116  bool operator!() const {return isNull();}
117 
119  // Accessor must get the product if necessary
120  C const* product() const;
121 
124  bool isAvailable() const {return refVector_.refCore().isAvailable();}
125 
127  bool isTransient() const {return refVector_.refCore().isTransient();}
128 
130  iterator erase(iterator const& pos);
131 
133  void clear() {refVector_.clear();}
134 
136  void swap(RefVector<C, T, F> & other) noexcept;
137 
139  RefVector& operator=(RefVector const& rhs);
140 #if defined(__GXX_EXPERIMENTAL_CXX0X__)
142  refVector_ = std::move(rhs.refVector_);
143  return *this;
144  }
145 #endif
146  bool hasProductCache() const {return refVector_.refCore().productPtr() != 0;}
148 
149  void fillView(ProductID const& id,
150  std::vector<void const*>& pointers,
151  helper_vector& helpers) const;
152 
153  //Needed for ROOT storage
155  private:
157  };
158 
159  template<typename C, typename T, typename F>
160  inline
161  void
162  RefVector<C, T, F>::swap(RefVector<C, T, F> & other) noexcept {
163  refVector_.swap(other.refVector_);
164  }
165 
166  template<typename C, typename T, typename F>
167  inline
171  this->swap(temp);
172  return *this;
173  }
174 
175  template<typename C, typename T, typename F>
176  inline
177  void
179  a.swap(b);
180  }
181 
182  template<typename C, typename T, typename F>
183  void
185  std::vector<void const*>& pointers,
186  helper_vector& helpers) const {
187  typedef Ref<C,T,F> ref_type;
188  typedef reftobase::RefHolder<ref_type> holder_type;
189 
190  pointers.reserve(this->size());
191  helpers.reserve(this->size());
192 
193  size_type key = 0;
194  for(const_iterator i=begin(), e=end(); i!=e; ++i, ++key) {
195  member_type const* address = i->isNull() ? 0 : &**i;
196  pointers.push_back(address);
197  holder_type h(ref_type(i->id(), address, i->key(), product()));
198  helpers.push_back(&h);
199  }
200  }
201 
202  template<typename C, typename T, typename F>
203  inline
204  void
206  ProductID const& id,
207  std::vector<void const*>& pointers,
208  helper_vector& helpers) {
209  obj.fillView(id, pointers, helpers);
210  }
211 
212  template<typename C, typename T, typename F>
213  struct has_fillView<RefVector<C,T,F> > {
214  static bool const value = true;
215  };
216 
217  template<typename C, typename T, typename F>
218  inline
219  bool
221  return lhs.refVector() == rhs.refVector();
222  }
223 
224  template<typename C, typename T, typename F>
225  inline
226  bool
228  return !(lhs == rhs);
229  }
230 
231  template<typename C, typename T, typename F>
232  inline
233  typename RefVector<C, T, F>::iterator
236  typename contents_type::keys_type::iterator newPos =
237  refVector_.eraseAtIndex(index);
238  RefCore const& prod = refVector_.refCore();
239  //return typename RefVector<C, T, F>::iterator(prod, newPos);
240  return iterator(prod, newPos);
241  }
242 
243  template<typename C, typename T, typename F>
245  return iterator(refVector_.refCore(), refVector_.keys().begin());
246  }
247 
248  template<typename C, typename T, typename F>
250  return iterator(refVector_.refCore(), refVector_.keys().end());
251  }
252 
253  template<typename C, typename T, typename F>
254  std::ostream&
255  operator<<(std::ostream& os, RefVector<C,T,F> const& r) {
257  i = r.begin(),
258  e = r.end();
259  i != e;
260  ++i) {
261  os << *i << '\n';
262  }
263  return os;
264  }
265 }
266 
268 
269 namespace edm {
270 
271  template<typename C, typename T, typename F>
272  C const* RefVector<C,T,F>::product() const {
273  return isNull() ? 0 : edm::template getProduct<C>(refVector_.refCore());
274  }
275 }
276 
278 namespace edm {
279  namespace detail {
280 
281  template<typename C, typename T, typename F>
282  struct GetProduct<RefVector<C, T, F> > {
283  typedef T element_type;
285  static element_type const* address(iter const& i) {
286  return &**i;
287  }
288  static C const* product(RefVector<C, T, F> const& coll) {
289  return coll.product();
290  }
291  };
292  }
293 }
294 #endif
int i
Definition: DBlmapReader.cc:9
bool isNonnull() const
Checks for non-null.
Definition: RefVector.h:113
C const * product() const
Accessor for product collection.
Definition: RefVector.h:272
value_type const const_reference
Definition: RefVector.h:43
value_type::key_type key_type
Definition: RefVector.h:47
void fillView(ProductID const &id, std::vector< void const * > &pointers, helper_vector &helpers) const
Definition: RefVector.h:184
size_type capacity() const
Capacity of the RefVector.
Definition: RefVector.h:92
static C const * product(RefVector< C, T, F > const &coll)
Definition: RefVector.h:288
bool empty() const
Is vector empty?
Definition: RefVectorBase.h:47
#define noexcept
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
const_reference reference
Definition: RefVector.h:44
contents_type refVector_
Definition: RefVector.h:156
keys_type::iterator eraseAtIndex(size_type index)
erase an element from the vector
Definition: RefVectorBase.h:64
#define CMS_CLASS_VERSION(_version_)
Definition: classes.h:31
const_iterator end() const
Termination of iteration.
Definition: RefVector.h:249
bool empty() const
Is the RefVector empty.
Definition: RefVector.h:86
uint16_t size_type
const_iterator begin() const
Initialize an iterator over the RefVector.
Definition: RefVector.h:244
void pushBack(RefCore const &product, KEY const &key)
Definition: RefVectorBase.h:52
KeyVec::size_type size_type
Definition: RefVector.h:51
bool isNull() const
Checks for null.
Definition: RefVector.h:110
void swap(RefVectorBase< KEY > &other)
swap two vectors
Definition: RefVectorBase.h:75
size_type capacity() const
Capacity of vector.
Definition: RefVectorBase.h:58
ProductID id() const
Accessor for product ID.
Definition: RefVector.h:104
RefVector(ProductID const &iId)
Definition: RefVector.h:62
std::vector< key_type > KeyVec
Definition: RefVector.h:48
RefCore const & refCore() const
Accessor for product ID and product getter.
Definition: RefVectorBase.h:41
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &)
bool isTransient() const
Checks if product collection is tansient (i.e. non persistable)
Definition: RefVector.h:127
void const * productPtr() const
Definition: RefCore.h:32
bool isAvailable() const
Definition: RefCore.cc:112
refhelper::RefVectorTrait< C, T, F >::iterator_type iterator
Definition: RefVector.h:40
void clear()
clear the vector
Definition: RefVectorBase.h:69
void swap(RefVector< C, T, F > &other)
Swap two vectors.
Definition: RefVector.h:162
keys_type const & keys() const
Accessor for vector of keys and pointers.
Definition: RefVectorBase.h:44
T const * getProduct(RefCore const &ref)
Definition: RefCoreGet.h:33
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
RefCore const & refCore() const
Definition: Ref.h:281
RefVector(RefVector const &rh)
Definition: RefVector.h:57
void reserve(size_type n)
Reserve space for RefVector.
Definition: RefVector.h:95
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: RefVector.h:107
iterator const_iterator
Definition: RefVector.h:41
RefVectorBase< key_type > contents_type
Definition: RefVector.h:52
JetCorrectorParametersCollection coll
Definition: classes.h:10
void clear()
Clear the vector.
Definition: RefVector.h:133
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
bool hasProductCache() const
Checks if product is in memory.
Definition: RefVector.h:147
key_type key() const
Accessor for product key.
Definition: Ref.h:266
RefVector< C, T, F >::const_iterator iter
Definition: RefVector.h:284
double b
Definition: hdecay.h:120
virtual void reserve(size_type n)=0
RefVector & operator=(RefVector const &rhs)
Copy assignment.
Definition: RefVector.h:169
EDProductGetter const * productGetter() const
Definition: RefCore.h:53
ProductID id() const
Definition: RefCore.h:29
value_type const operator[](size_type idx) const
Retrieve an element of the RefVector.
Definition: RefVector.h:69
#define private
Definition: FWFileEntry.h:17
reftobase::RefVectorHolderBase helper_vector
Definition: EDProductfwd.h:45
bool isTransient() const
Definition: RefCore.h:69
value_type const at(size_type idx) const
Retrieve an element of the RefVector.
Definition: RefVector.h:76
bool isAvailable() const
Definition: RefVector.h:124
list key
Definition: combine.py:13
double a
Definition: hdecay.h:121
static element_type const * address(iter const &i)
Definition: RefVector.h:285
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:64
keys_type::size_type size_type
Definition: RefVectorBase.h:25
size_type size() const
Size of the RefVector.
Definition: RefVector.h:89
virtual void push_back(RefHolderBase const *r)=0
refhelper::RefVectorTrait< C, T, F >::ref_type value_type
Definition: RefVector.h:42
boost::remove_cv< typename boost::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:170
bool isValid() const
Definition: ProductID.h:35
contents_type const & refVector() const
Accessor for all data.
Definition: RefVector.h:83
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
size_type size() const
Size of vector.
Definition: RefVectorBase.h:50
long double T
bool operator!() const
Checks for null.
Definition: RefVector.h:116
edm::RefVector< Container > RefVector
def template
Definition: svgfig.py:520
void reserve(size_type n)
Reserve space for vector.
Definition: RefVectorBase.h:61
iterator erase(iterator const &pos)
Erase an element from the vector.
Definition: RefVector.h:234