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 
22 
23 #include <utility>
24 #include <vector>
25 
26 namespace edm {
27 
28  template<typename T>
29  class RefToBaseProd {
30  public:
32 
35 
36  template<typename C>
37  explicit RefToBaseProd(Handle<C> const& handle);
38  explicit RefToBaseProd(Handle<View<T> > const& handle);
39  template<typename C>
40  explicit RefToBaseProd(OrphanHandle<C> const& handle);
42  template<typename C>
43  explicit RefToBaseProd(const RefProd<C>&);
44  RefToBaseProd(ProductID const&, EDProductGetter const*);
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 product_.isNonnull(); }
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 
102  };
103 
104  template<typename T>
105  inline
107  product_(handle.id(), 0, 0, false){
109  }
110 
111  template<typename T>
112  inline
114  product_(ref.product_) {
115  if(product_.productPtr()) {
116  product_.setProductPtr(ref.viewPtr() ? (new View<T>(* ref)) : 0);
117  }
118  }
119 
120  template<typename T>
121  inline
123  RefToBaseProd<T> temp(other);
124  this->swap(temp);
125  return *this;
126  }
127 
129  template<typename T>
130  inline
132  return * operator->();
133  }
134 
135 #if !defined(__CINT__) && !defined(__MAKECINT__) && !defined(__REFLEX__)
136  template<typename T>
138  inline
140  //Another thread might change the value returned so just get it once
141  auto getter = product_.productGetter();
142  if(getter != nullptr) {
143  if(product_.isNull()) {
145  "attempting get view from a null RefToBaseProd.\n");
146  }
147  ProductID tId = product_.id();
148  std::vector<void const*> pointers;
149  FillViewHelperVector helpers;
150  WrapperBase const* prod = getter->getIt(tId);
151  if(prod == nullptr) {
153  "attempting to get view from an unavailable RefToBaseProd.");
154  }
155  prod->fillView(tId, pointers, helpers);
156  std::unique_ptr<View<T>> tmp{ new View<T>(pointers, helpers, getter) };
157  if( product_.tryToSetProductPtrForFirstTime(tmp.get())) {
158  tmp.release();
159  }
160  }
161  return viewPtr();
162  }
163 #endif
164 
165  template<typename T>
166  inline
168  edm::swap(product_, other.product_);
169  }
170 
171  template<typename T>
172  inline
173  bool
175  return lhs.refCore() == rhs.refCore();
176  }
177 
178  template<typename T>
179  inline
180  bool
182  return !(lhs == rhs);
183  }
184 
185  template<typename T>
186  inline
187  bool
188  operator< (RefToBaseProd<T> const& lhs, RefToBaseProd<T> const& rhs) {
189  return (lhs.refCore() < rhs.refCore());
190  }
191 
192  template<typename T>
193  inline void swap(edm::RefToBaseProd<T> const& lhs, edm::RefToBaseProd<T> const& rhs) {
194  lhs.swap(rhs);
195  }
196 }
197 
199 
200 namespace edm {
201 #ifndef __GCCXML__
202  template<typename T>
203  template<typename C>
204  inline
206  product_(ref.refCore()) {
207  std::vector<void const*> pointers;
208  FillViewHelperVector helpers;
209  fillView(* ref.product(), ref.id(), pointers, helpers);
210  product_.setProductPtr(new View<T>(pointers, helpers, ref.refCore().productGetter()));
211  }
212 #endif
213 
214  template<typename T>
215  template<typename C>
216  inline
218  product_(handle.id(), handle.product(), 0, false) {
219  std::vector<void const*> pointers;
220  FillViewHelperVector helpers;
221  fillView(* handle, handle.id(), pointers, helpers);
222  product_.setProductPtr(new View<T>(pointers, helpers,0));
223  }
224 
225  template<typename T>
226  template<typename C>
227  inline
229  product_(handle.id(), handle.product(), 0, false) {
230  std::vector<void const*> pointers;
231  FillViewHelperVector helpers;
232  fillView(* handle, handle.id(), pointers, helpers);
233  product_.setProductPtr(new View<T>(pointers, helpers,0));
234  }
235 
236  template<typename T>
237  inline
239  product_(id, nullptr, getter, false) { }
240 }
241 
242 #endif
View< T > const * viewPtr() const
Definition: RefToBaseProd.h:97
~RefToBaseProd()
Destructor.
Definition: RefToBaseProd.h:47
void setProductPtr(void const *prodPtr) const
Definition: RefCore.h:51
product_type const * operator->() const
Member dereference operator.
ProductID id() const
Definition: HandleBase.cc:15
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &)
#define nullptr
#define CMS_CLASS_VERSION(_version_)
Definition: classes.h:31
bool isNonnull() const
Definition: RefCore.h:67
void fillView(ProductID const &id, std::vector< void const * > &view, FillViewHelperVector &helpers) const
Definition: WrapperBase.cc:14
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="")
ProductID id() const
RefCore const & refCore() const
Definition: RefToBaseProd.h:93
RefToBaseProd()
Default constructor needed for reading from persistent store. Not for direct use. ...
Definition: RefToBaseProd.h:34
bool hasCache() const
Checks if product is in memory.
Definition: RefToBaseProd.h:83
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &)
void const * productPtr() const
Definition: RefCore.h:45
void fillView(AssociationVector< KeyRefProd, CVal, KeyRef, SizeType, KeyReferenceHelper > const &obj, ProductID const &id, std::vector< void const * > &pointers, FillViewHelperVector &helpers)
tuple handle
Definition: patZpeak.py:22
#define private
Definition: FWEveView.cc:22
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
RefCore const & refCore() const
Definition: RefProd.h:123
string const
Definition: compareJSON.py:14
EDProductGetter const * productGetter() const
Definition: RefCore.h:77
product_type const * product() const
Definition: RefToBaseProd.h:63
ProductID id() const
Definition: RefCore.h:42
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
product_type const * product() const
Definition: RefProd.h:119
ProductID id() const
Accessor for product ID.
Definition: RefProd.h:137
bool operator!() const
Checks for null.
Definition: RefToBaseProd.h:74
product_type const & operator*() const
Dereference operator.
View< T > product_type
Definition: RefToBaseProd.h:31
volatile std::atomic< bool > shutdown_flag false
ProductIndex id() const
Definition: ProductID.h:38
bool isNull() const
Checks for null.
Definition: RefToBaseProd.h:68
void swap(RefToBaseProd< T > &)
std::vector< std::pair< edm::ProductID, unsigned long > > FillViewHelperVector
bool isNonnull() const
Checks for non-null.
Definition: RefToBaseProd.h:71