test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RefToBaseProd.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_RefToBaseProd_h
2 #define DataFormats_Common_RefToBaseProd_h
3 
4 /* \class edm::RefToBaseProd<T>
5  *
6  * \author Luca Lista, INFN
7  *
8  */
10 
16 
17 namespace edm {
18  template<typename T> class View;
19  template<typename C> class Handle;
20 
21  template<typename T>
22  class RefToBaseProd {
23  public:
25 
28 
30  // The templating is artificial.
31  // HandleC must have the following methods:
32  // id(), returning a ProductID,
33  // product(), returning a C*.
34  template<class HandleC>
35  explicit RefToBaseProd(HandleC const& handle);
36  explicit RefToBaseProd(Handle<View<T> > const& handle);
38  template<typename C, typename F>
39  explicit RefToBaseProd(Ref<C, T, F> const& ref);
40  explicit RefToBaseProd(RefToBase<T> const& ref);
41  explicit RefToBaseProd(const View<T>&);
43  template<typename C>
44  RefToBaseProd(const RefProd<C>&);
45 
47  ~RefToBaseProd() { delete viewPtr();}
48 
50  product_type const& operator*() const;
51 
53  product_type const* operator->() const;
54 
57  product_type const* get() const {
58  return isNull() ? 0 : this->operator->();
59  }
60 
63  product_type const* product() const {
64  return isNull() ? 0 : this->operator->();
65  }
66 
68  bool isNull() const {return !isNonnull(); }
69 
71  bool isNonnull() const {return id().isValid(); }
72 
74  bool operator!() const {return isNull(); }
75 
77  ProductID id() const {return product_.id();}
78 
81 
83  bool hasCache() const {return product_.productPtr() != 0;}
84 
86 
87  void swap(RefToBaseProd<T>&);
88 
89  //Needed for ROOT storage
91  private:
92  //NOTE: Access to RefCore should be private since we modify the use of productPtr
93  RefCore const& refCore() const {
94  return product_;
95  }
96 
97  View<T> const* viewPtr() const {
98  return reinterpret_cast<const View<T>*>(product_.productPtr());
99  }
100  //needs to be mutable so we can modify the 'productPtr' it holds
101  // so that 'productPtr' can hold our View
102  mutable RefCore product_;
103  };
104 }
105 
113 
114 namespace edm {
115 
116  namespace refhelper {
117  template<typename C,
118  typename T = typename refhelper::ValueTrait<C>::value,
119  typename F = typename refhelper::FindTrait<C, T>::value>
122  };
123 
124  template<typename C, typename T, typename F, typename T1, typename F1>
125  struct RefToBaseProdTrait<RefVector<C, T, F>, T1, F1> {
127  };
128  }
129 
130  template<typename T>
131  inline
133  product_(handle->id(), 0, handle->productGetter(), false){
135  assert(handle->productGetter() == 0);
136  }
137 
138  template<typename T>
139  inline
141  product_(view.id(), 0, view.productGetter(), false) {
142  product_.setProductPtr(new View<T>(view));
143  }
144 
145  template<typename T>
146  inline
148  product_(ref.product_) {
149  if(product_.productPtr()) {
150  product_.setProductPtr(ref.viewPtr() ? (new View<T>(* ref)) : 0);
151  }
152  }
153 
154  template<typename T>
155  inline
157  RefToBaseProd<T> temp(other);
158  this->swap(temp);
159  return *this;
160  }
161 
163  template<typename T>
164  inline
166  return * operator->();
167  }
168 
170  template<typename T>
171  inline
173  if(product_.productPtr() == 0) {
174  if(product_.isNull()) {
176  "attempting get view from a null RefToBaseProd.\n");
177  }
178  ProductID tId = product_.id();
179  std::vector<void const*> pointers;
180  helper_vector_ptr helpers;
181  WrapperHolder it = product_.productGetter()->getIt(tId);
182  if(!it.isValid()) {
184  "attempting to get view from an unavailable RefToBaseProd.");
185  }
186  it.fillView(tId, pointers, helpers);
187  product_.setProductPtr((new View<T>(pointers, helpers)));
188  }
189  return viewPtr();
190  }
191 
192  template<typename T>
193  inline
195  std::swap(product_, other.product_);
196  }
197 
198  template<typename T>
199  inline
200  bool
202  return lhs.refCore() == rhs.refCore();
203  }
204 
205  template<typename T>
206  inline
207  bool
209  return !(lhs == rhs);
210  }
211 
212  template<typename T>
213  inline
214  bool
215  operator< (RefToBaseProd<T> const& lhs, RefToBaseProd<T> const& rhs) {
216  return (lhs.refCore() < rhs.refCore());
217  }
218 
219  template<typename T>
220  inline void swap(edm::RefToBaseProd<T> const& lhs, edm::RefToBaseProd<T> const& rhs) {
221  lhs.swap(rhs);
222  }
223 }
224 
226 
227 namespace edm {
228  template<typename T>
229  template<typename C>
230  inline
232  product_(ref.refCore()) {
233  std::vector<void const*> pointers;
234  typedef typename refhelper::RefToBaseProdTrait<C>::ref_vector_type ref_vector;
235  typedef reftobase::RefVectorHolder<ref_vector> holder_type;
236  helper_vector_ptr helpers(new holder_type);
237  detail::reallyFillView(* ref.product(), ref.id(), pointers, * helpers);
238  product_.setProductPtr(new View<T>(pointers, helpers));
239  }
240 
241  template<typename T>
242  template<class HandleC>
243  inline
245  product_(handle.id(), handle.product(), 0, false) {
246  std::vector<void const*> pointers;
248  typedef reftobase::RefVectorHolder<ref_vector> holder_type;
249  helper_vector_ptr helpers(new holder_type);
250  detail::reallyFillView(* handle, handle.id(), pointers, * helpers);
251  product_.setProductPtr(new View<T>(pointers, helpers));
252  }
253 
255  template<typename T>
256  template<typename C, typename F>
257  inline
259  product_(ref.id(),
260  ref.hasProductCache() ? ref.product() : 0,
261  ref.productGetter(),
262  false) {
263  std::vector<void const*> pointers;
264  typedef typename refhelper::RefToBaseProdTrait<C>::ref_vector_type ref_vector;
265  typedef reftobase::RefVectorHolder<ref_vector> holder_type;
266  helper_vector_ptr helpers(new holder_type);
267  detail::reallyFillView(* ref.product(), ref.id(), pointers, * helpers);
268  product_.setProductPtr(new View<T>(pointers, helpers));
269  }
270 
272  template<typename T>
273  inline
275  product_(ref.id(),
276  ref.hasProductCache() ? ref.product() : 0,
277  ref.productGetter(),
278  false) {
279  std::vector<void const*> pointers;
280  helper_vector_ptr helpers(ref.holder_->makeVectorBaseHolder().release());
281  helpers->reallyFillView(ref.product(), ref.id(), pointers);
282  product_.setProductPtr(new View<T>(pointers, helpers));
283  }
284 
285 }
286 
287 #endif
View< T > const * viewPtr() const
Definition: RefToBaseProd.h:97
~RefToBaseProd()
Destructor.
Definition: RefToBaseProd.h:47
boost::shared_ptr< reftobase::RefVectorHolderBase > helper_vector_ptr
Definition: EDProductfwd.h:46
void setProductPtr(void const *prodPtr) const
Definition: RefCore.h:34
product_type const * operator->() const
Member dereference operator.
void reallyFillView(COLLECTION const &coll, ProductID const &id, std::vector< void const * > &ptrs, helper_vector &helpers)
Definition: FillView.h:49
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
RefVector< C, T, F > ref_vector_type
#define CMS_CLASS_VERSION(_version_)
Definition: classes.h:31
ProductID id() const
Definition: RefToBase.h:220
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:116
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
RefCore const & refCore() const
Definition: RefToBaseProd.h:93
RefToBaseProd()
Default constructor needed for reading from persistent store. Not for direct use. ...
Definition: RefToBaseProd.h:27
bool hasCache() const
Checks if product is in memory.
Definition: RefToBaseProd.h:83
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &)
void const * productPtr() const
Definition: RefCore.h:32
tuple handle
Definition: patZpeak.py:22
void const * product() const
Definition: RefToBase.h:333
RefToBaseProd< T > & operator=(const RefToBaseProd< T > &other)
ProductID id() const
Accessor for product ID.
Definition: RefToBaseProd.h:77
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: RefToBaseProd.h:80
void fillView(ProductID const &id, std::vector< void const * > &view, helper_vector_ptr &helpers) const
Definition: WrapperHolder.h:31
string const
Definition: compareJSON.py:14
EDProductGetter const * productGetter() const
Definition: RefCore.h:53
product_type const * product() const
Definition: RefToBaseProd.h:63
ProductID id() const
Definition: RefCore.h:29
#define private
Definition: FWFileEntry.h:17
product_type const * product() const
Definition: RefProd.h:122
ProductID id() const
Accessor for product ID.
Definition: RefProd.h:140
bool operator!() const
Checks for null.
Definition: RefToBaseProd.h:74
bool isValid() const
Definition: WrapperHolder.h:27
product_type const & operator*() const
Dereference operator.
reftobase::BaseHolder< value_type > * holder_
Definition: RefToBase.h:118
View< T > product_type
Definition: RefToBaseProd.h:24
ProductID id() const
Accessor for product ID.
Definition: Ref.h:256
volatile std::atomic< bool > shutdown_flag false
ProductIndex id() const
Definition: ProductID.h:38
bool isValid() const
Definition: ProductID.h:35
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
bool isNull() const
Checks for null.
Definition: RefToBaseProd.h:68
void swap(RefToBaseProd< T > &)
long double T
C const * product() const
Accessor for product collection.
Definition: Ref.h:601
bool isNonnull() const
Checks for non-null.
Definition: RefToBaseProd.h:71