CMS 3D CMS Logo

MasterCollectionHelper.h
Go to the documentation of this file.
1 #ifndef CommonTools_UtilAlgos_MasterCollectionHelper_h
2 #define CommonTools_UtilAlgos_MasterCollectionHelper_h
3 /* \class helper::MasterCollection<C>
4  *
5  * differentiate index addressing in case of edm::View
6  * since a View retrieving a collection of reference
7  * would have referece indices (key()) pointing to the master
8  * collection different from reference position into the view
9  *
10  * \author Luca Lista, INFN
11  *
12  * \version $Id: MasterCollectionHelper.h,v 1.1 2009/03/03 13:07:26 llista Exp $
13  *
14  */
19 
20 namespace helper {
21  template <typename C1>
25  size_t size() const { return handle_->size(); }
26  size_t index(size_t i) const { return i; }
27  const edm::Handle<C1>& get() const { return handle_; }
28  ref_type getRef(size_t idx) const { return ref_type(get(), idx); }
29  template <typename R>
30  R getConcreteRef(size_t idx) const {
31  return getRef(idx);
32  }
33 
34  private:
36  };
37 
38  template <typename T>
39  struct MasterCollection<edm::View<T> > {
42  if (!handle_->empty()) {
43  ref_ = edm::makeRefToBaseProdFrom(handle_->refAt(0), event);
44  }
45  }
46  size_t size() const {
47  if (ref_.isNull())
48  return 0;
49  return ref_->size();
50  }
51  size_t index(size_t i) const { return handle_->refAt(i).key(); }
52  const edm::RefToBaseProd<T>& get() const { return ref_; }
53  ref_type getRef(size_t idx) const { return ref_type(get(), idx); }
54  template <typename R>
55  R getConcreteRef(size_t idx) const {
56  return getRef(idx).template castTo<R>();
57  }
58 
59  private:
62  };
63 
64 } // namespace helper
65 
66 #endif
Definition: helper.py:1
R getConcreteRef(size_t idx) const
MasterCollection(const edm::Handle< edm::View< T > > &handle, edm::Event const &event)
ref_type getRef(size_t idx) const
RefToBaseProd< T > makeRefToBaseProdFrom(RefToBase< T > const &iRef, Event const &iEvent)
HLT enums.
size_t index(size_t i) const
MasterCollection(const edm::Handle< C1 > &handle, edm::Event const &event)
Definition: event.py:1