CMS 3D CMS Logo

Classes | Namespaces | Macros | Functions
Ref.h File Reference
#include "DataFormats/Common/interface/CMS_CLASS_VERSION.h"
#include "DataFormats/Common/interface/EDProductfwd.h"
#include "DataFormats/Common/interface/EDProductGetter.h"
#include "DataFormats/Common/interface/Handle.h"
#include "DataFormats/Common/interface/OrphanHandle.h"
#include "DataFormats/Common/interface/RefCore.h"
#include "DataFormats/Common/interface/RefCoreWithIndex.h"
#include "DataFormats/Common/interface/TestHandle.h"
#include "DataFormats/Common/interface/traits.h"
#include "DataFormats/Provenance/interface/ProductID.h"
#include "boost/functional.hpp"
#include "boost/call_traits.hpp"
#include "boost/type_traits.hpp"
#include "boost/mpl/has_xxx.hpp"
#include "boost/utility/enable_if.hpp"
#include <vector>
#include <type_traits>
#include "DataFormats/Common/interface/RefTraits.h"
#include "DataFormats/Common/interface/RefProd.h"
#include "DataFormats/Common/interface/RefCoreGet.h"
#include "DataFormats/Common/interface/RefItemGet.h"
#include "DataFormats/Common/interface/HolderToVectorTrait_Ref_specialization.h"

Go to the source code of this file.

Classes

class  edm::Ref< C, T, F >
 
class  edm::Ref< std::vector< E >, typename refhelper::ValueTrait< std::vector< E > >::value, typename refhelper::FindTrait< std::vector< E >, typename refhelper::ValueTrait< std::vector< E > >::value >::value >
 
class  edm::RefToBaseVector< T >
 
class  edm::RefVector< C, T, F >
 

Namespaces

 edm
 HLT enums.
 

Macros

#define REF_FOR_VECTOR_ARGS   std::vector<E>,typename refhelper::ValueTrait<std::vector<E> >::value,typename refhelper::FindTrait<std::vector<E>, typename refhelper::ValueTrait<std::vector<E> >::value>::value
 

Functions

template<typename C , typename K >
boost::enable_if< has_key_compare< C >, bool >::type compare_key (K const &lhs, K const &rhs)
 
template<typename C , typename K >
boost::disable_if< has_key_compare< C >, bool >::type compare_key (K const &lhs, K const &rhs)
 
template<typename C , typename T , typename F >
bool edm::operator!= (Ref< C, T, F > const &lhs, Ref< C, T, F > const &rhs)
 
template<typename C , typename T , typename F >
bool edm::operator< (Ref< C, T, F > const &lhs, Ref< C, T, F > const &rhs)
 
template<typename C , typename T , typename F >
bool edm::operator== (Ref< C, T, F > const &lhs, Ref< C, T, F > const &rhs)
 

Macro Definition Documentation

#define REF_FOR_VECTOR_ARGS   std::vector<E>,typename refhelper::ValueTrait<std::vector<E> >::value,typename refhelper::FindTrait<std::vector<E>, typename refhelper::ValueTrait<std::vector<E> >::value>::value

Definition at line 301 of file Ref.h.

Function Documentation

template<typename C , typename K >
boost::enable_if<has_key_compare<C>, bool>::type compare_key ( K const &  lhs,
K const &  rhs 
)

Summary

The edm::Ref<> is a storable reference to an item in a stored container. For example, you could use one to hold a reference back to one particular track within an std::vector<> of tracks.

Usage

The edm::Ref<> works just like a pointer

1 edm::Ref<FooCollection> fooPtr = ... //set the value
2 functionTakingConstFoo(*fooPtr); //get the Foo object
3 fooPtr->bar(); //call a method of the held Foo object

The main purpose of an edm::Ref<> is it can be used as a member datum for a class that is to be stored in the edm::Event.

Customization

The edm::Ref<> takes three template parameters

1) C: The type of the container which is holding the item

2) T: The type of the item. This defaults to C::value_type

3) F: A helper class (a functor) which knows how to find a particular 'T' within the container given an appropriate key. The type of the key is deduced from F::second_argument. The default for F is refhelper::FindTrait<C, T>::value. If no specialization of FindTrait<> is available for the combination (C, T) then it defaults to getting the iterator to be beginning of the container and using std::advance() to move to the appropriate key in the container.

It is possible to customize the 'lookup' algorithm used.

1) The helper class F must provide value_type, first_argument_type and second_argument_type typedefs.

2) The helper class F must define the function call operator in such a way that the following call is well-formed: f is an instance of type F coll is an instance of type C k is an instance of type F::key_type

     result_type r = f(coll, k);     

 If one wishes to make a specialized lookup the default lookup for
 the container/type pair then one needs to partially specialize
 the templated class edm::refhelper::FindTrait<C, T> such that it
 has a typedef named 'value' which refers to the specialized
 helper class (i.e., F)

 The class template Ref<C, T, F> supports 'null' references.

 -- a default-constructed Ref is 'null'; furthermore, it also
    has an invalid (or 'null') ProductID.
 -- a Ref constructed through the single-arguement constructor
    that takes a ProductID is also null.        

Definition at line 128 of file Ref.h.

128  {
129  typedef typename C::key_compare comparison_functor;
130  return comparison_functor()(lhs, rhs);
131  }
template<typename C , typename K >
boost::disable_if<has_key_compare<C>, bool>::type compare_key ( K const &  lhs,
K const &  rhs 
)

Definition at line 135 of file Ref.h.

References patCaloMETCorrections_cff::C, and F().

135  {
136  return lhs < rhs;
137  }