File indexing completed on 2024-04-06 12:03:53
0001 #ifndef DataFormats_Common_RefProd_h
0002 #define DataFormats_Common_RefProd_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 #include "DataFormats/Common/interface/CMS_CLASS_VERSION.h"
0039 #include "DataFormats/Common/interface/Handle.h"
0040 #include "DataFormats/Common/interface/OrphanHandle.h"
0041 #include "DataFormats/Common/interface/RefCore.h"
0042 #include "DataFormats/Common/interface/TestHandle.h"
0043 #include "DataFormats/Provenance/interface/ProductID.h"
0044
0045
0046 #include "DataFormats/Common/interface/Ref.h"
0047
0048 #include <utility>
0049
0050 namespace edm {
0051
0052 class EDProductGetter;
0053
0054 template <typename C>
0055 class RefProd {
0056 public:
0057 typedef C product_type;
0058 typedef C value_type;
0059
0060
0061 RefProd() : product_() {}
0062
0063
0064 explicit RefProd(Handle<C> const& handle) : product_(handle.id(), handle.product(), nullptr, false) {
0065 checkTypeAtCompileTime(handle.product());
0066 }
0067
0068
0069 explicit RefProd(OrphanHandle<C> const& handle) : product_(handle.id(), handle.product(), nullptr, false) {
0070 checkTypeAtCompileTime(handle.product());
0071 }
0072
0073
0074
0075
0076
0077
0078 RefProd(C const* iProduct) : product_(ProductID(), iProduct, nullptr, true) { checkTypeAtCompileTime(iProduct); }
0079
0080
0081
0082
0083
0084
0085 explicit RefProd(TestHandle<C> const& handle) : product_(handle.id(), handle.product(), nullptr, true) {
0086 checkTypeAtCompileTime(handle.product());
0087 }
0088
0089
0090
0091
0092 RefProd(ProductID const& productID, EDProductGetter const* prodGetter)
0093 : product_(productID, nullptr, mustBeNonZero(prodGetter, "RefProd", productID), false) {}
0094
0095
0096 ~RefProd() {}
0097
0098
0099 product_type const& operator*() const;
0100
0101
0102 product_type const* operator->() const;
0103
0104
0105
0106 product_type const* get() const { return isNull() ? nullptr : this->operator->(); }
0107
0108
0109
0110 product_type const* product() const { return isNull() ? nullptr : this->operator->(); }
0111
0112 RefCore const& refCore() const { return product_; }
0113
0114
0115 bool isNull() const { return !isNonnull(); }
0116
0117
0118 bool isNonnull() const { return product_.isNonnull(); }
0119
0120
0121 bool operator!() const { return isNull(); }
0122
0123
0124 ProductID id() const { return product_.id(); }
0125
0126
0127 EDProductGetter const* productGetter() const { return product_.productGetter(); }
0128
0129
0130 bool hasCache() const { return product_.productPtr() != nullptr; }
0131
0132
0133 bool hasProductCache() const { return hasCache(); }
0134
0135
0136
0137
0138
0139 bool isAvailable() const { return product_.isAvailable(); }
0140
0141
0142 bool isTransient() const { return product_.isTransient(); }
0143
0144 void swap(RefProd<C>&);
0145
0146
0147 CMS_CLASS_VERSION(10)
0148
0149 private:
0150
0151
0152 void checkTypeAtCompileTime(C const* ) {}
0153
0154 RefCore product_;
0155 };
0156 }
0157
0158 #include "DataFormats/Common/interface/RefCoreGet.h"
0159
0160 namespace edm {
0161
0162
0163 template <typename C>
0164 inline C const& RefProd<C>::operator*() const {
0165 return *(edm::template getProduct<C>(product_));
0166 }
0167
0168
0169 template <typename C>
0170 inline C const* RefProd<C>::operator->() const {
0171 return edm::template getProduct<C>(product_);
0172 }
0173
0174 template <typename C>
0175 inline void RefProd<C>::swap(RefProd<C>& other) {
0176 edm::swap(product_, other.product_);
0177 }
0178
0179 template <typename C>
0180 inline bool operator==(RefProd<C> const& lhs, RefProd<C> const& rhs) {
0181 return lhs.refCore() == rhs.refCore();
0182 }
0183
0184 template <typename C>
0185 inline bool operator!=(RefProd<C> const& lhs, RefProd<C> const& rhs) {
0186 return !(lhs == rhs);
0187 }
0188
0189 template <typename C>
0190 inline bool operator<(RefProd<C> const& lhs, RefProd<C> const& rhs) {
0191 return (lhs.refCore() < rhs.refCore());
0192 }
0193
0194 template <typename C>
0195 inline void swap(RefProd<C> const& lhs, RefProd<C> const& rhs) {
0196 lhs.swap(rhs);
0197 }
0198 }
0199
0200
0201 #include "DataFormats/Common/interface/HolderToVectorTrait_RefProd_specialization.h"
0202
0203 #endif