CMS 3D CMS Logo

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 { return isNull() ? nullptr : this->operator->(); }
58 
61  product_type const* product() const { return isNull() ? 0 : this->operator->(); }
62 
64  bool isNull() const { return !isNonnull(); }
65 
67  bool isNonnull() const { return product_.isNonnull(); }
68 
70  bool operator!() const { return isNull(); }
71 
73  ProductID id() const { return product_.id(); }
74 
76  EDProductGetter const* productGetter() const { return product_.productGetter(); }
77 
79  bool hasCache() const { return product_.productPtr() != nullptr; }
80 
82 
83  void swap(RefToBaseProd<T>&);
84 
85  //Needed for ROOT storage
87  private:
88  //NOTE: Access to RefCore should be private since we modify the use of productPtr
89  RefCore const& refCore() const { return product_; }
90 
91  View<T> const* viewPtr() const { return reinterpret_cast<const View<T>*>(product_.productPtr()); }
92 
94  };
95 
96  template <typename T>
98  : product_(handle.id(), nullptr, nullptr, false) {
100  }
101 
102  template <typename T>
103  inline RefToBaseProd<T>::RefToBaseProd(const RefToBaseProd<T>& ref) : product_(ref.product_) {
104  if (product_.productPtr()) {
105  product_.setProductPtr(ref.viewPtr() ? (new View<T>(*ref)) : nullptr);
106  }
107  }
108 
109  template <typename T>
112  this->swap(temp);
113  return *this;
114  }
115 
117  template <typename T>
118  inline View<T> const& RefToBaseProd<T>::operator*() const {
119  return *operator->();
120  }
121 
123  template <typename T>
124  inline View<T> const* RefToBaseProd<T>::operator->() const {
125  //Another thread might change the value returned so just get it once
126  auto getter = product_.productGetter();
127  if (getter != nullptr) {
128  if (product_.isNull()) {
129  Exception::throwThis(errors::InvalidReference, "attempting get view from a null RefToBaseProd.\n");
130  }
131  ProductID tId = product_.id();
132  std::vector<void const*> pointers;
134  WrapperBase const* prod = getter->getIt(tId);
135  if (prod == nullptr) {
136  Exception::throwThis(errors::InvalidReference, "attempting to get view from an unavailable RefToBaseProd.");
137  }
138  prod->fillView(tId, pointers, helpers);
139  std::unique_ptr<View<T>> tmp{new View<T>(pointers, helpers, getter)};
140  if (product_.tryToSetProductPtrForFirstTime(tmp.get())) {
141  tmp.release();
142  }
143  }
144  return viewPtr();
145  }
146 
147  template <typename T>
149  edm::swap(product_, other.product_);
150  }
151 
152  template <typename T>
153  inline bool operator==(RefToBaseProd<T> const& lhs, RefToBaseProd<T> const& rhs) {
154  return lhs.refCore() == rhs.refCore();
155  }
156 
157  template <typename T>
158  inline bool operator!=(RefToBaseProd<T> const& lhs, RefToBaseProd<T> const& rhs) {
159  return !(lhs == rhs);
160  }
161 
162  template <typename T>
163  inline bool operator<(RefToBaseProd<T> const& lhs, RefToBaseProd<T> const& rhs) {
164  return (lhs.refCore() < rhs.refCore());
165  }
166 
167  template <typename T>
168  inline void swap(edm::RefToBaseProd<T> const& lhs, edm::RefToBaseProd<T> const& rhs) {
169  lhs.swap(rhs);
170  }
171 } // namespace edm
172 
174 
175 namespace edm {
176  template <typename T>
177  template <typename C>
178  inline RefToBaseProd<T>::RefToBaseProd(const RefProd<C>& ref) : product_(ref.refCore()) {
179  std::vector<void const*> pointers;
181  fillView(*ref.product(), ref.id(), pointers, helpers);
182  product_.setProductPtr(new View<T>(pointers, helpers, ref.refCore().productGetter()));
183  }
184 
185  template <typename T>
186  template <typename C>
188  : product_(handle.id(), handle.product(), nullptr, false) {
189  std::vector<void const*> pointers;
191  fillView(*handle, handle.id(), pointers, helpers);
192  product_.setProductPtr(new View<T>(pointers, helpers, nullptr));
193  }
194 
195  template <typename T>
196  template <typename C>
198  : product_(handle.id(), handle.product(), nullptr, false) {
199  std::vector<void const*> pointers;
201  fillView(*handle, handle.id(), pointers, helpers);
202  product_.setProductPtr(new View<T>(pointers, helpers, nullptr));
203  }
204 
205  template <typename T>
207  : product_(id, nullptr, getter, false) {}
208 } // namespace edm
209 
210 #endif
edm::RefProd
Definition: EDProductfwd.h:25
edm::FillViewHelperVector
std::vector< std::pair< edm::ProductID, unsigned long > > FillViewHelperVector
Definition: FillViewHelperVector.h:30
RefProd.h
edm::RefToBaseProd::productGetter
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: RefToBaseProd.h:76
edm::RefToBaseProd::product
product_type const * product() const
Definition: RefToBaseProd.h:61
edm::RefCore
Definition: RefCore.h:21
Handle.h
edm::RefCore::setProductPtr
void setProductPtr(void const *prodPtr) const
Definition: RefCore.h:57
funct::false
false
Definition: Factorize.h:34
edm::RefProd::id
ProductID id() const
Accessor for product ID.
Definition: RefProd.h:124
edm::errors::InvalidReference
Definition: EDMException.h:39
edm::RefToBaseProd::hasCache
bool hasCache() const
Checks if product is in memory.
Definition: RefToBaseProd.h:79
View< T >
patZpeak.handle
handle
Definition: patZpeak.py:23
edm::RefProd::refCore
RefCore const & refCore() const
Definition: RefProd.h:112
edm
HLT enums.
Definition: AlignableModifier.h:19
edm::RefToBaseProd::RefToBaseProd
RefToBaseProd()
Default constructor needed for reading from persistent store. Not for direct use.
Definition: RefToBaseProd.h:34
edm::swap
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:117
edm::RefToBaseProd::get
product_type const * get() const
Definition: RefToBaseProd.h:57
edm::RefToBaseProd::id
ProductID id() const
Accessor for product ID.
Definition: RefToBaseProd.h:73
createJobs.tmp
tmp
align.sh
Definition: createJobs.py:716
edm::RefToBaseProd::operator*
product_type const & operator*() const
Dereference operator.
Definition: RefToBaseProd.h:118
watchdog.const
const
Definition: watchdog.py:83
edm::Handle
Definition: AssociativeIterator.h:50
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
edm::RefCore::productGetter
EDProductGetter const * productGetter() const
Definition: RefCore.h:81
EDMException.h
edm::RefToBaseProd::refCore
RefCore const & refCore() const
Definition: RefToBaseProd.h:89
edm::EDProductGetter
Definition: EDProductGetter.h:32
FillViewHelperVector.h
edm::operator!=
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
Definition: debugging_allocator.h:75
edm::operator==
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
Definition: debugging_allocator.h:72
OrphanHandle.h
dumpMFGeometry_cfg.prod
prod
Definition: dumpMFGeometry_cfg.py:24
edm::operator<
bool operator<(DetSet< T > const &x, DetSet< T > const &y)
Definition: DetSet.h:89
ProductID.h
edm::RefToBaseProd::product_type
View< T > product_type
Definition: RefToBaseProd.h:31
trackingPlots.other
other
Definition: trackingPlots.py:1465
CMS_CLASS_VERSION
#define CMS_CLASS_VERSION(_version_)
Definition: CMS_CLASS_VERSION.h:30
edm::RefProd::product
product_type const * product() const
Definition: RefProd.h:110
edm::RefToBaseProd::isNull
bool isNull() const
Checks for null.
Definition: RefToBaseProd.h:64
WrapperBase.h
helpers
Definition: makeCompositeCandidate.h:8
edm::RefToBaseProd::~RefToBaseProd
~RefToBaseProd()
Destructor.
Definition: RefToBaseProd.h:47
edm::RefToBaseProd::operator!
bool operator!() const
Checks for null.
Definition: RefToBaseProd.h:70
edm::WrapperBase
Definition: WrapperBase.h:23
edm::RefToBaseProd::swap
void swap(RefToBaseProd< T > &)
Definition: RefToBaseProd.h:148
edm::RefToBaseProd::viewPtr
View< T > const * viewPtr() const
Definition: RefToBaseProd.h:91
edm::RefCore::id
ProductID id() const
Definition: RefCore.h:48
FillView.h
edm::RefCore::productPtr
void const * productPtr() const
Definition: RefCore.h:51
CMS_CLASS_VERSION.h
edm::OrphanHandle
Definition: EDProductfwd.h:39
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
edm::Exception::throwThis
static void throwThis(Code category, char const *message0="", char const *message1="", char const *message2="", char const *message3="", char const *message4="")
Definition: EDMException.cc:83
edm::RefToBaseProd::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: RefToBaseProd.h:67
edm::RefToBaseProd::operator->
product_type const * operator->() const
Member dereference operator.
Definition: RefToBaseProd.h:124
View.h
RefCore.h
edm::RefToBaseProd::operator=
RefToBaseProd< T > & operator=(const RefToBaseProd< T > &other)
Definition: RefToBaseProd.h:110
edm::fillView
void fillView(AssociationVector< KeyRefProd, CVal, KeyRef, SizeType, KeyReferenceHelper > const &obj, ProductID const &id, std::vector< void const * > &pointers, FillViewHelperVector &helpers)
Definition: AssociationVector.h:290
edm::RefToBaseProd::product_
RefCore product_
Definition: RefToBaseProd.h:93
EDProductfwd.h
edm::ProductID
Definition: ProductID.h:27
edm::RefToBaseProd
Definition: RefToBase.h:65
edm::ProductID::id
ProductIndex id() const
Definition: ProductID.h:35
edm::RefCore::isNonnull
bool isNonnull() const
Definition: RefCore.h:71