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 namespace edm {
117 
118  template <typename C,
119  typename T = typename refhelper::ValueTrait<C>::value,
120  typename F = typename refhelper::FindTrait<C, T>::value>
121  class FwdRef {
122  public:
124  typedef C product_type;
125  typedef T value_type;
126  typedef T const element_type; //used for generic programming
127  typedef F finder_type;
128  typedef typename boost::binary_traits<F>::second_argument_type argument_type;
132 
134  FwdRef() : ref_(), backRef_() {}
135 
138  assert(ref.isNull() == backRef.isNull());
139  }
140 
142  ~FwdRef() {}
143 
145  T const& operator*() const;
146 
148  T const* operator->() const;
149 
151  T const* get() const {
152  if (ref_.isAvailable()) {
153  return ref_.get();
154  } else {
155  return backRef_.get();
156  }
157  }
158 
160  bool isNull() const { return !isNonnull(); }
161 
163  //bool isNonnull() const {return id().isValid(); }
164  bool isNonnull() const { return ref_.isNonnull() || backRef_.isNonnull(); }
165 
167  bool operator!() const { return isNull(); }
168 
169  Ref<C, T, F> const& ref() const { return ref_; }
170  Ref<C, T, F> const& backRef() const { return backRef_; }
171 
174  //another thread might cause productGetter() to change its value
175  EDProductGetter const* getter = ref_.productGetter();
176  if (getter)
177  return getter;
178  else
179  return backRef_.productGetter();
180  }
181 
183  ProductID id() const { return ref_.isNonnull() ? ref_.id() : backRef_.id(); }
184 
186  key_type key() const { return ref_.isNonnull() ? ref_.key() : backRef_.key(); }
187 
188  bool hasProductCache() const { return ref_.hasProductCache() || backRef_.hasProductCache(); }
189 
192  bool isAvailable() const { return ref_.isAvailable() || backRef_.isAvailable(); }
193 
195  bool isTransient() const { return ref_.isTransient(); }
196 
197  //Used by ROOT storage
199 
200  private:
201  Ref<C, T, F> ref_;
203  };
204 } // namespace edm
205 
206 #include "DataFormats/Common/interface/RefProd.h"
207 
208 namespace edm {
209 
211  template <typename C, typename T, typename F>
212  inline T const& FwdRef<C, T, F>::operator*() const {
213  return ref_.isNonnull() && ref_.isAvailable() ? ref_.operator*() : backRef_.operator*();
214  }
215 
217  template <typename C, typename T, typename F>
218  inline T const* FwdRef<C, T, F>::operator->() const {
219  return ref_.isNonnull() && ref_.isAvailable() ? ref_.operator->() : backRef_.operator->();
220  }
221 
224  template <typename C, typename T, typename F>
225  inline bool operator==(FwdRef<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
226  return (lhs.ref() == rhs.ref()) && (lhs.backRef() == rhs.backRef());
227  }
228 
231  template <typename C, typename T, typename F>
232  inline bool operator==(Ref<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
233  return (lhs == rhs.ref()) || (lhs == rhs.backRef());
234  }
235 
238  template <typename C, typename T, typename F>
239  inline bool operator==(FwdRef<C, T, F> const& lhs, Ref<C, T, F> const& rhs) {
240  return (lhs.ref() == rhs) || (lhs.backRef() == rhs);
241  }
242 
243  template <typename C, typename T, typename F>
244  inline bool operator!=(FwdRef<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
245  return !(lhs == rhs);
246  }
247 
248  template <typename C, typename T, typename F>
249  inline bool operator!=(Ref<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
250  return !(lhs == rhs);
251  }
252 
253  template <typename C, typename T, typename F>
254  inline bool operator!=(FwdRef<C, T, F> const& lhs, Ref<C, T, F> const& rhs) {
255  return !(lhs == rhs);
256  }
257 
260  template <typename C, typename T, typename F>
261  inline bool operator<(FwdRef<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
262  return (lhs.ref() < rhs.ref());
263  }
264 
265  template <typename C, typename T, typename F>
266  inline bool operator<(Ref<C, T, F> const& lhs, FwdRef<C, T, F> const& rhs) {
267  return (lhs < rhs.ref());
268  }
269 
270  template <typename C, typename T, typename F>
271  inline bool operator<(FwdRef<C, T, F> const& lhs, Ref<C, T, F> const& rhs) {
272  return (lhs.ref() < rhs);
273  }
274 
275 } // namespace edm
276 
277 #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:137
edm::FwdRef::key
key_type key() const
Accessor for product key.
Definition: FwdRef.h:186
edm::FwdRef::backRef_
Ref< C, T, F > backRef_
Definition: FwdRef.h:202
edm::FwdRef
Definition: FwdRef.h:121
edm::FwdRef::operator->
T const * operator->() const
Member dereference operator.
Definition: FwdRef.h:218
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:164
edm::FwdRef::isNull
bool isNull() const
Checks for null.
Definition: FwdRef.h:160
edm::FwdRef::operator*
T const & operator*() const
Dereference operator.
Definition: FwdRef.h:212
edm::FwdRef::get
T const * get() const
Returns C++ pointer to the item.
Definition: FwdRef.h:151
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:188
edm::FwdRef::FwdRef
FwdRef()
Default constructor needed for reading from persistent store. Not for direct use.
Definition: FwdRef.h:134
edm::FwdRef::value_type
T value_type
Definition: FwdRef.h:125
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::FwdRef::isAvailable
bool isAvailable() const
Definition: FwdRef.h:192
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:127
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:195
edm::FwdRef::key_type
boost::remove_cv< typename boost::remove_reference< argument_type >::type >::type key_type
Definition: FwdRef.h:129
edm::FwdRef::element_type
const T element_type
Definition: FwdRef.h:126
edm::FwdRef::~FwdRef
~FwdRef()
Destructor.
Definition: FwdRef.h:142
edm::FwdRef::backRef
Ref< C, T, F > const & backRef() const
Definition: FwdRef.h:170
edm::FwdRef::operator!
bool operator!() const
Checks for null.
Definition: FwdRef.h:167
type
type
Definition: HCALResponse.h:21
Ref.h
CMS_CLASS_VERSION.h
edm::FwdRef::product_type
C product_type
for export
Definition: FwdRef.h:124
gen::C
C
Definition: PomwigHadronizer.cc:76
T
long double T
Definition: Basic3DVectorLD.h:48
edm::FwdRef::id
ProductID id() const
Accessor for product ID.
Definition: FwdRef.h:183
edm::FwdRef::ref
Ref< C, T, F > const & ref() const
Definition: FwdRef.h:169
edm::FwdRef::argument_type
boost::binary_traits< F >::second_argument_type argument_type
Definition: FwdRef.h:128
edm::FwdRef::ref_
Ref< C, T, F > ref_
Definition: FwdRef.h:201
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:173
edm::ProductID
Definition: ProductID.h:27
edm::refhelper::ValueTrait::value
C::value_type value
Definition: RefTraits.h:57