CMS 3D CMS Logo

FwdRef.h
Go to the documentation of this file.
1 #ifndef DataFormats_Common_FwdRef_h
2 #define DataFormats_Common_FwdRef_h
3 
4 /*----------------------------------------------------------------------
5 
6 FwdRef: A template for a interproduct reference to a member of a product.
7 
8 ----------------------------------------------------------------------*/
82 /*----------------------------------------------------------------------
83 // This defines the public interface to the class FwdRef<C, T, F>.
84 // C is the collection type.
85 // T (default C::value_type) is the type of an element in the collection.
86 //
87 // ProductID productID is the product ID of the collection.
88 // key_type itemKey is the key of the element in the collection.
89 // C::value_type *itemPtr is a C++ pointer to the element
90 // FwdRef<C, T, F> const& ref is another FwdRef<C, T, F>
91 
92 // Constructors
93  FwdRef(); // Default constructor
94  FwdRef(FwdRef<C, T> const& ref); // Copy constructor (default, not explicitly specified)
95 
96  FwdRef(Ref<C,T,F> const & fwdRef, Ref<C,T,F> const & backRef);
97 
98 // Destructor
99  virtual ~FwdRef() {}
100 
101  // Operators and methods
102  FwdRef<C, T>& operator=(FwdRef<C, T> const&); // assignment (default, not explicitly specified)
103  T const& operator*() const; // dereference
104  T const* const operator->() const; // member dereference
105  bool operator==(FwdRef<C, T> const& ref) const; // equality
106  bool operator!=(FwdRef<C, T> const& ref) const; // inequality
107  bool operator<(FwdRef<C, T> const& ref) const; // ordering
108  bool isNonnull() const; // true if an object is referenced
109  bool isNull() const; // equivalent to !isNonnull()
110  bool operator!() const; // equivalent to !isNonnull()
111  ----------------------------------------------------------------------*/
112 
115 
116 #include <boost/functional.hpp>
117 
118 namespace edm {
119 
120  template <typename C,
121  typename T = typename refhelper::ValueTrait<C>::value,
122  typename F = typename refhelper::FindTrait<C, T>::value>
123  class FwdRef {
124  public:
126  typedef C product_type;
127  typedef T value_type;
128  typedef T const element_type; //used for generic programming
129  typedef F finder_type;
130  typedef typename boost::binary_traits<F>::second_argument_type argument_type;
134 
136  FwdRef() : ref_(), backRef_() {}
137 
140  assert(ref.isNull() == backRef.isNull());
141  }
142 
144  ~FwdRef() {}
145 
147  T const& operator*() const;
148 
150  T const* operator->() const;
151 
153  T const* get() const {
154  if (ref_.isAvailable()) {
155  return ref_.get();
156  } else {
157  return backRef_.get();
158  }
159  }
160 
162  bool isNull() const { return !isNonnull(); }
163 
165  //bool isNonnull() const {return id().isValid(); }
166  bool isNonnull() const { return ref_.isNonnull() || backRef_.isNonnull(); }
167 
169  bool operator!() const { return isNull(); }
170 
171  Ref<C, T, F> const& ref() const { return ref_; }
172  Ref<C, T, F> const& backRef() const { return backRef_; }
173 
176  //another thread might cause productGetter() to change its value
177  EDProductGetter const* getter = ref_.productGetter();
178  if (getter)
179  return getter;
180  else
181  return backRef_.productGetter();
182  }
183 
185  ProductID id() const { return ref_.isNonnull() ? ref_.id() : backRef_.id(); }
186 
188  key_type key() const { return ref_.isNonnull() ? ref_.key() : backRef_.key(); }
189 
190  bool hasProductCache() const { return ref_.hasProductCache() || backRef_.hasProductCache(); }
191 
194  bool isAvailable() const { return ref_.isAvailable() || backRef_.isAvailable(); }
195 
197  bool isTransient() const { return ref_.isTransient(); }
198 
199  //Used by ROOT storage
201 
202  private:
203  Ref<C, T, F> ref_;
205  };
206 } // namespace edm
207 
208 #include "DataFormats/Common/interface/RefProd.h"
209 
210 namespace edm {
211 
213  template <typename C, typename T, typename F>
214  inline T const& FwdRef<C, T, F>::operator*() const {
215  return ref_.isNonnull() && ref_.isAvailable() ? ref_.operator*() : backRef_.operator*();
216  }
217 
219  template <typename C, typename T, typename F>
220  inline T const* FwdRef<C, T, F>::operator->() const {
221  return ref_.isNonnull() && ref_.isAvailable() ? ref_.operator->() : backRef_.operator->();
222  }
223 
226  template <typename C, typename T, typename F>
227  inline bool operator==(FwdRef<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
228  return (lhs.ref() == rhs.ref()) && (lhs.backRef() == rhs.backRef());
229  }
230 
233  template <typename C, typename T, typename F>
234  inline bool operator==(Ref<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
235  return (lhs == rhs.ref()) || (lhs == rhs.backRef());
236  }
237 
240  template <typename C, typename T, typename F>
241  inline bool operator==(FwdRef<C, T, F> const& lhs, Ref<C, T, F> const& rhs) {
242  return (lhs.ref() == rhs) || (lhs.backRef() == rhs);
243  }
244 
245  template <typename C, typename T, typename F>
246  inline bool operator!=(FwdRef<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
247  return !(lhs == rhs);
248  }
249 
250  template <typename C, typename T, typename F>
251  inline bool operator!=(Ref<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
252  return !(lhs == rhs);
253  }
254 
255  template <typename C, typename T, typename F>
256  inline bool operator!=(FwdRef<C, T, F> const& lhs, Ref<C, T, F> const& rhs) {
257  return !(lhs == rhs);
258  }
259 
262  template <typename C, typename T, typename F>
263  inline bool operator<(FwdRef<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
264  return (lhs.ref() < rhs.ref());
265  }
266 
267  template <typename C, typename T, typename F>
268  inline bool operator<(Ref<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
269  return (lhs < rhs.ref());
270  }
271 
272  template <typename C, typename T, typename F>
273  inline bool operator<(FwdRef<C, T, F> const& lhs, Ref<C, T, F> const& rhs) {
274  return (lhs.ref() < rhs);
275  }
276 
277 } // namespace edm
278 
279 #endif
edm::FwdRef::FwdRef
FwdRef(Ref< C, T, F > const &ref, Ref< C, T, F > const &backRef)
General purpose constructor from 2 refs (forward and backward.
Definition: FwdRef.h:139
edm::FwdRef::key
key_type key() const
Accessor for product key.
Definition: FwdRef.h:188
edm::FwdRef::backRef_
Ref< C, T, F > backRef_
Definition: FwdRef.h:204
edm::FwdRef
Definition: FwdRef.h:123
edm::FwdRef::operator->
T const * operator->() const
Member dereference operator.
Definition: FwdRef.h:220
edm
HLT enums.
Definition: AlignableModifier.h:19
cms::cuda::assert
assert(be >=bs)
edm::FwdRef::isNonnull
bool isNonnull() const
Checks for non-null.
Definition: FwdRef.h:166
edm::FwdRef::isNull
bool isNull() const
Checks for null.
Definition: FwdRef.h:162
edm::FwdRef::operator*
T const & operator*() const
Dereference operator.
Definition: FwdRef.h:214
edm::FwdRef::get
T const * get() const
Returns C++ pointer to the item.
Definition: FwdRef.h:153
edm::Ref
Definition: AssociativeIterator.h:58
F
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:163
edm::FwdRef::hasProductCache
bool hasProductCache() const
Definition: FwdRef.h:190
edm::FwdRef::FwdRef
FwdRef()
Default constructor needed for reading from persistent store. Not for direct use.
Definition: FwdRef.h:136
edm::FwdRef::value_type
T value_type
Definition: FwdRef.h:127
edm::EDProductGetter
Definition: EDProductGetter.h:41
edm::operator!=
bool operator!=(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
Definition: debugging_allocator.h:75
edm::FwdRef::isAvailable
bool isAvailable() const
Definition: FwdRef.h:194
edm::operator==
bool operator==(debugging_allocator< X > const &, debugging_allocator< Y > const &) noexcept
Definition: debugging_allocator.h:72
edm::FwdRef::finder_type
F finder_type
Definition: FwdRef.h:129
edm::operator<
bool operator<(DetSet< T > const &x, DetSet< T > const &y)
Definition: DetSet.h:89
CMS_CLASS_VERSION
#define CMS_CLASS_VERSION(_version_)
Definition: CMS_CLASS_VERSION.h:30
edm::FwdRef::isTransient
bool isTransient() const
Checks if this ref is transient (i.e. not persistable).
Definition: FwdRef.h:197
type
type
Definition: SiPixelVCal_PayloadInspector.cc:39
gainCalibHelper::gainCalibPI::type
type
Definition: SiPixelGainCalibHelper.h:40
edm::FwdRef::key_type
std::remove_cv< typename std::remove_reference< argument_type >::type >::type key_type
Definition: FwdRef.h:131
edm::FwdRef::element_type
const T element_type
Definition: FwdRef.h:128
edm::FwdRef::~FwdRef
~FwdRef()
Destructor.
Definition: FwdRef.h:144
edm::FwdRef::backRef
Ref< C, T, F > const & backRef() const
Definition: FwdRef.h:172
edm::FwdRef::operator!
bool operator!() const
Checks for null.
Definition: FwdRef.h:169
Ref.h
CMS_CLASS_VERSION.h
edm::FwdRef::product_type
C product_type
for export
Definition: FwdRef.h:126
gen::C
C
Definition: PomwigHadronizer.cc:78
T
long double T
Definition: Basic3DVectorLD.h:48
edm::FwdRef::id
ProductID id() const
Accessor for product ID.
Definition: FwdRef.h:185
edm::FwdRef::ref
Ref< C, T, F > const & ref() const
Definition: FwdRef.h:171
edm::FwdRef::argument_type
boost::binary_traits< F >::second_argument_type argument_type
Definition: FwdRef.h:130
edm::FwdRef::ref_
Ref< C, T, F > ref_
Definition: FwdRef.h:203
edm::refhelper::FindTrait::value
FindUsingAdvance< C, T > value
Definition: RefTraits.h:42
edm::FwdRef::productGetter
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: FwdRef.h:175
edm::ProductID
Definition: ProductID.h:27
edm::refhelper::ValueTrait::value
C::value_type value
Definition: RefTraits.h:57