CMS 3D CMS Logo

RefProd.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_RefProd_h
2 #define DataFormats_Common_RefProd_h
3 
4 /*----------------------------------------------------------------------
5 
6 Ref: A template for an interproduct reference to a product.
7 
8 ----------------------------------------------------------------------*/
9 
10 /*----------------------------------------------------------------------
11 // This defines the public interface to the class RefProd<T>.
12 //
13 // ProductID productID is the product ID of the collection. (0 is invalid)
14 // RefProd<T> const& ref is another RefProd<T>
15 
16 // Constructors
17  RefProd(); // Default constructor
18  RefProd(RefProd<T> const& ref); // Copy constructor (default, not explicitly specified)
19 
20  RefProd(Handle<T> const& handle);
21  RefProd(ProductID pid, EDProductGetter const* prodGetter);
22 
23 // Destructor
24  virtual ~RefProd() {}
25 
26 // Operators and methods
27  RefProd<T>& operator=(RefProd<T> const&); // assignment (default, not explicitly specified)
28  T const& operator*() const; // dereference
29  T const* operator->() const; // member dereference
30  bool operator==(RefProd<T> const& ref) const; // equality
31  bool operator!=(RefProd<T> const& ref) const; // inequality
32  bool operator<(RefProd<T> const& ref) const; // ordering
33  bool isNonnull() const; // true if an object is referenced
34  bool isNull() const; // equivalent to !isNonnull()
35  bool operator!() const; // equivalent to !isNonnull()
36 ----------------------------------------------------------------------*/
37 
44 
45 // Not really needed but things depend on it being here ...
47 
48 #include <utility>
49 
50 namespace edm {
51 
52  class EDProductGetter;
53 
54  template <typename C>
55  class RefProd {
56  public:
57  typedef C product_type;
58  typedef C value_type;
59 
61  RefProd() : product_() {}
62 
64  explicit RefProd(Handle<C> const& handle) : product_(handle.id(), handle.product(), nullptr, false) {
65  checkTypeAtCompileTime(handle.product());
66  }
67 
69  explicit RefProd(OrphanHandle<C> const& handle) : product_(handle.id(), handle.product(), nullptr, false) {
70  checkTypeAtCompileTime(handle.product());
71  }
72 
74  // An exception will be thrown if an attempt is made to persistify
75  // any object containing this RefProd. Also, in the future work will
76  // be done to throw an exception if an attempt is made to put any object
77  // containing this RefProd into an event(or run or lumi).
78  RefProd(C const* iProduct) : product_(ProductID(), iProduct, nullptr, true) { checkTypeAtCompileTime(iProduct); }
79 
81  // An exception will be thrown if an attempt is made to persistify
82  // any object containing this RefProd. Also, in the future work will
83  // be done to throw an exception if an attempt is made to put any object
84  // containing this RefProd into an event(or run or lumi).
85  explicit RefProd(TestHandle<C> const& handle) : product_(handle.id(), handle.product(), nullptr, true) {
86  checkTypeAtCompileTime(handle.product());
87  }
88 
89  // Constructor for those users who do not have a product handle,
90  // but have a pointer to a product getter (such as the EventPrincipal).
91  // prodGetter will ususally be a pointer to the event principal.
92  RefProd(ProductID const& productID, EDProductGetter const* prodGetter)
93  : product_(productID, nullptr, mustBeNonZero(prodGetter, "RefProd", productID), false) {}
94 
96  ~RefProd() {}
97 
99  product_type const& operator*() const;
100 
102  product_type const* operator->() const;
103 
106  product_type const* get() const { return isNull() ? nullptr : this->operator->(); }
107 
110  product_type const* product() const { return isNull() ? nullptr : this->operator->(); }
111 
112  RefCore const& refCore() const { return product_; }
113 
115  bool isNull() const { return !isNonnull(); }
116 
118  bool isNonnull() const { return product_.isNonnull(); }
119 
121  bool operator!() const { return isNull(); }
122 
124  ProductID id() const { return product_.id(); }
125 
128 
130  bool hasCache() const { return product_.productPtr() != 0; }
131 
133  bool hasProductCache() const { return hasCache(); }
134 
137  bool isAvailable() const { return product_.isAvailable(); }
138 
140  bool isTransient() const { return product_.isTransient(); }
141 
142  void swap(RefProd<C>&);
143 
144  //Needed for ROOT storage
146 
147  private:
148  // Compile time check that the argument is a C* or C const*
149  // or derived from it.
150  void checkTypeAtCompileTime(C const* /*ptr*/) {}
151 
153  };
154 } // namespace edm
155 
157 
158 namespace edm {
159 
161  template <typename C>
162  inline C const& RefProd<C>::operator*() const {
163  return *(edm::template getProduct<C>(product_));
164  }
165 
167  template <typename C>
168  inline C const* RefProd<C>::operator->() const {
169  return edm::template getProduct<C>(product_);
170  }
171 
172  template <typename C>
174  edm::swap(product_, other.product_);
175  }
176 
177  template <typename C>
178  inline bool operator==(RefProd<C> const& lhs, RefProd<C> const& rhs) {
179  return lhs.refCore() == rhs.refCore();
180  }
181 
182  template <typename C>
183  inline bool operator!=(RefProd<C> const& lhs, RefProd<C> const& rhs) {
184  return !(lhs == rhs);
185  }
186 
187  template <typename C>
188  inline bool operator<(RefProd<C> const& lhs, RefProd<C> const& rhs) {
189  return (lhs.refCore() < rhs.refCore());
190  }
191 
192  template <typename C>
193  inline void swap(RefProd<C> const& lhs, RefProd<C> const& rhs) {
194  lhs.swap(rhs);
195  }
196 } // namespace edm
197 
198 //Handle specialization here
200 
201 #endif
edm::RefProd
Definition: EDProductfwd.h:25
edm::RefCore
Definition: RefCore.h:21
Handle.h
funct::false
false
Definition: Factorize.h:34
edm::RefProd::id
ProductID id() const
Accessor for product ID.
Definition: RefProd.h:124
edm::RefProd::RefProd
RefProd(Handle< C > const &handle)
General purpose constructor from handle.
Definition: RefProd.h:64
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::RefProd::RefProd
RefProd()
Default constructor needed for reading from persistent store. Not for direct use.
Definition: RefProd.h:61
edm::swap
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:117
edm::RefProd::productGetter
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: RefProd.h:127
watchdog.const
const
Definition: watchdog.py:83
edm::Handle
Definition: AssociativeIterator.h:50
edm::RefProd::get
product_type const * get() const
Definition: RefProd.h:106
edm::RefProd::~RefProd
~RefProd()
Destructor.
Definition: RefProd.h:96
edm::mustBeNonZero
EDProductGetter const * mustBeNonZero(EDProductGetter const *prodGetter, std::string refType, ProductID const &productID)
Definition: EDProductGetter.cc:65
edm::RefCore::productGetter
EDProductGetter const * productGetter() const
Definition: RefCore.h:81
edm::EDProductGetter
Definition: EDProductGetter.h:32
edm::operator!=
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
Definition: debugging_allocator.h:75
edm::RefProd::isAvailable
bool isAvailable() const
Definition: RefProd.h:137
edm::RefProd::RefProd
RefProd(C const *iProduct)
Constructor for ref to object that is not in an event.
Definition: RefProd.h:78
edm::operator==
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
Definition: debugging_allocator.h:72
OrphanHandle.h
edm::RefProd::isNull
bool isNull() const
Checks for null.
Definition: RefProd.h:115
edm::operator<
bool operator<(DetSet< T > const &x, DetSet< T > const &y)
Definition: DetSet.h:89
ProductID.h
edm::RefProd::operator!
bool operator!() const
Checks for null.
Definition: RefProd.h:121
trackingPlots.other
other
Definition: trackingPlots.py:1465
CMS_CLASS_VERSION
#define CMS_CLASS_VERSION(_version_)
Definition: CMS_CLASS_VERSION.h:30
edm::RefProd::RefProd
RefProd(TestHandle< C > const &handle)
General purpose constructor from test handle.
Definition: RefProd.h:85
edm::RefProd::RefProd
RefProd(ProductID const &productID, EDProductGetter const *prodGetter)
Definition: RefProd.h:92
edm::RefProd::product
product_type const * product() const
Definition: RefProd.h:110
edm::RefProd::isTransient
bool isTransient() const
Checks if this RefProd is transient (i.e. not persistable).
Definition: RefProd.h:140
edm::RefProd::product_type
C product_type
Definition: RefProd.h:57
edm::TestHandle
Definition: TestHandle.h:29
funct::true
true
Definition: Factorize.h:173
edm::RefProd::swap
void swap(RefProd< C > &)
Definition: RefProd.h:173
edm::RefCore::isTransient
bool isTransient() const
Definition: RefCore.h:103
EDProductGetter
edm::RefProd::RefProd
RefProd(OrphanHandle< C > const &handle)
General purpose constructor from orphan handle.
Definition: RefProd.h:69
edm::RefProd::product_
RefCore product_
Definition: RefProd.h:152
edm::RefCore::id
ProductID id() const
Definition: RefCore.h:48
svgfig.template
def template(fileName, svg, replaceme="REPLACEME")
Definition: svgfig.py:521
HolderToVectorTrait_RefProd_specialization.h
edm::RefProd::checkTypeAtCompileTime
void checkTypeAtCompileTime(C const *)
Definition: RefProd.h:150
edm::RefCore::productPtr
void const * productPtr() const
Definition: RefCore.h:51
edm::RefProd::hasCache
bool hasCache() const
Checks if product is in memory.
Definition: RefProd.h:130
Ref.h
CMS_CLASS_VERSION.h
edm::OrphanHandle
Definition: EDProductfwd.h:39
gen::C
C
Definition: PomwigHadronizer.cc:76
edm::RefProd::operator->
product_type const * operator->() const
Member dereference operator.
Definition: RefProd.h:168
edm::RefProd::value_type
C value_type
Definition: RefProd.h:58
RefCore.h
edm::RefProd::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: RefProd.h:118
edm::RefCore::isAvailable
bool isAvailable() const
Definition: RefCore.cc:145
RefCoreGet.h
edm::RefProd::hasProductCache
bool hasProductCache() const
Checks if product is in memory.
Definition: RefProd.h:133
TestHandle.h
edm::RefProd::operator*
product_type const & operator*() const
Dereference operator.
Definition: RefProd.h:162
reco::JetExtendedAssociation::RefProd
edm::RefProd< Container > RefProd
Definition: JetExtendedAssociation.h:33
edm::ProductID
Definition: ProductID.h:27
edm::RefCore::isNonnull
bool isNonnull() const
Definition: RefCore.h:71