CMS 3D CMS Logo

edm::Ptr< T > Class Template Reference

Description: Persistent 'pointer' to an item in a collection where the collection is in the edm::Event. More...

#include <DataFormats/Common/interface/Ptr.h>

List of all members.

Public Types

typedef unsigned long key_type
typedef T value_type

Public Member Functions

T const * get () const
 Returns C++ pointer to the item.
bool hasCache () const
ProductID id () const
 Accessor for product ID.
bool isAvailable () const
 Checks if collection is in memory or available in the event.
bool isNonnull () const
 Checks for non-null.
bool isNull () const
 Checks for null.
bool isTransient () const
 Checks if this Ptr is transient (i.e. not persistable).
key_type key () const
T const & operator * () const
 Dereference operator.
bool operator! () const
 Checks for null.
T const * operator-> () const
 Member dereference operator.
EDProductGetter const * productGetter () const
 Accessor for product getter.
template<typename U>
 Ptr (Ptr< U > const &iOther, typename boost::enable_if_c< boost::is_base_of< U, T >::value >::type *=0)
template<typename U>
 Ptr (Ptr< U > const &iOther, typename boost::enable_if_c< boost::is_base_of< T, U >::value >::type *=0)
 Ptr (Ptr< T > const &iOther)
 Ptr ()
 Ptr (ProductID const &id)
 Constructor that creates an invalid ("null") Ptr that is associated with a given product (denoted by that product's ProductID).
 Ptr (ProductID const &productID, T const *item, key_type item_key)
 Constructor for use in the various X::fillView(.
 Ptr (ProductID const &productID, key_type itemKey, EDProductGetter const *prodGetter)
 Constructor for those users who do not have a product handle, but have a pointer to a product getter (such as the EventPrincipal).
template<typename C>
 Ptr (TestHandle< C > const &handle, key_type itemKey, bool setNow=true)
template<typename C>
 Ptr (C const *product, key_type itemKey, bool setNow=true)
template<typename C>
 Ptr (OrphanHandle< C > const &handle, key_type itemKey, bool setNow=true)
template<typename C>
 Ptr (Handle< C > const &handle, key_type itemKey, bool setNow=true)
RefCore const & refCore () const
 ~Ptr ()
 Destructor.

Private Member Functions

void getData_ () const
template<typename C>
T const * getItem_ (C const *product, key_type iKey)
 Ptr (T const *item, key_type item_key)
 Constructor for extracting a transient Ptr from a PtrVector.

Private Attributes

RefCore core_
key_type key_

Friends

class PtrVectorBase


Detailed Description

template<typename T>
class edm::Ptr< T >

Description: Persistent 'pointer' to an item in a collection where the collection is in the edm::Event.

Usage: <usage>

Definition at line 40 of file Ptr.h.


Member Typedef Documentation

template<typename T>
typedef unsigned long edm::Ptr< T >::key_type

Definition at line 44 of file Ptr.h.

template<typename T>
typedef T edm::Ptr< T >::value_type

Definition at line 45 of file Ptr.h.


Constructor & Destructor Documentation

template<typename T>
template<typename C>
edm::Ptr< T >::Ptr ( Handle< C > const &  handle,
key_type  itemKey,
bool  setNow = true 
) [inline]

Definition at line 49 of file Ptr.h.

00049                                                                     :
00050     core_(handle.id(), getItem_(handle.product(), itemKey), 0, false), key_(itemKey) {}
    

template<typename T>
template<typename C>
edm::Ptr< T >::Ptr ( OrphanHandle< C > const &  handle,
key_type  itemKey,
bool  setNow = true 
) [inline]

Definition at line 54 of file Ptr.h.

00054                                                                           :
00055     core_(handle.id(), getItem_(handle.product(), itemKey), 0, false), key_(itemKey) {}

template<typename T>
template<typename C>
edm::Ptr< T >::Ptr ( C const *  product,
key_type  itemKey,
bool  setNow = true 
) [inline]

Definition at line 63 of file Ptr.h.

00063                                                              :
00064     core_(ProductID(), product != 0 ? getItem_(product,itemKey) : 0, 0, true),
00065          key_(product != 0 ? itemKey : key_traits<key_type>::value) {}

template<typename T>
template<typename C>
edm::Ptr< T >::Ptr ( TestHandle< C > const &  handle,
key_type  itemKey,
bool  setNow = true 
) [inline]

Definition at line 71 of file Ptr.h.

00071                                                                         :
00072     core_(handle.id(), getItem_(handle.product(), itemKey), 0, true), key_(itemKey) {}

template<typename T>
edm::Ptr< T >::Ptr ( ProductID const &  productID,
key_type  itemKey,
EDProductGetter const *  prodGetter 
) [inline]

Constructor for those users who do not have a product handle, but have a pointer to a product getter (such as the EventPrincipal).

prodGetter will ususally be a pointer to the event principal.

Definition at line 77 of file Ptr.h.

00077                                                                                          :
00078     core_(productID, 0, mustBeNonZero(prodGetter, "Ptr", productID), false), key_(itemKey) {
00079     }
    

template<typename T>
edm::Ptr< T >::Ptr ( ProductID const &  productID,
T const *  item,
key_type  item_key 
) [inline]

Constructor for use in the various X::fillView(.

..) functions or for extracting a persistent Ptr from a PtrVector. It is an error (not diagnosable at compile- or run-time) to call this constructor with a pointer to a T unless the pointed-to T object is already in a collection of type C stored in the Event. The given ProductID must be the id of the collection in the Event.

Definition at line 88 of file Ptr.h.

00088                                                                       :
00089     core_(productID, item, 0, false),
00090     key_(item_key) { 
00091     }

template<typename T>
edm::Ptr< T >::Ptr ( ProductID const &  id  )  [inline, explicit]

Constructor that creates an invalid ("null") Ptr that is associated with a given product (denoted by that product's ProductID).

Definition at line 97 of file Ptr.h.

00097                                       :
00098     core_(id, 0, 0, false),
00099     key_(key_traits<key_type>::value)
00100     { }
    

template<typename T>
edm::Ptr< T >::Ptr (  )  [inline]

Definition at line 102 of file Ptr.h.

00102          :
00103     core_(),
00104     key_(key_traits<key_type>::value)
00105     {}
    

template<typename T>
edm::Ptr< T >::Ptr ( Ptr< T > const &  iOther  )  [inline]

Definition at line 107 of file Ptr.h.

00107                              :
00108     core_(iOther.core_),
00109     key_(iOther.key_)
00110     {}

template<typename T>
template<typename U>
edm::Ptr< T >::Ptr ( Ptr< U > const &  iOther,
typename boost::enable_if_c< boost::is_base_of< T, U >::value >::type = 0 
) [inline]

Definition at line 113 of file Ptr.h.

00113                                                                                               :
00114     core_(iOther.id(), 
00115           (iOther.hasCache()? static_cast<T const*>(iOther.get()): static_cast<T const*>(0)),
00116           iOther.productGetter(),
00117           iOther.isTransient()),
00118     key_(iOther.key())
00119     {
00120     }
    

template<typename T>
template<typename U>
edm::Ptr< T >::Ptr ( Ptr< U > const &  iOther,
typename boost::enable_if_c< boost::is_base_of< U, T >::value >::type = 0 
) [inline, explicit]

Definition at line 124 of file Ptr.h.

00124                                                                                               :
00125     core_(iOther.id(), 
00126           dynamic_cast<T const*>(iOther.get()),
00127           0,
00128           iOther.isTransient()),
00129     key_(iOther.key())
00130     {
00131     }
    

template<typename T>
edm::Ptr< T >::~Ptr (  )  [inline]

Destructor.

Definition at line 134 of file Ptr.h.

00134 {}

template<typename T>
edm::Ptr< T >::Ptr ( T const *  item,
key_type  item_key 
) [inline, private]

Constructor for extracting a transient Ptr from a PtrVector.

Definition at line 182 of file Ptr.h.

00182                                           :
00183     core_(ProductID(), item, 0, true),
00184     key_(item_key) { 
00185     }
    


Member Function Documentation

template<typename T>
T const* edm::Ptr< T >::get ( void   )  const [inline]

Returns C++ pointer to the item.

Definition at line 145 of file Ptr.h.

Referenced by pat::EventHypothesis::getAs(), reco::CaloJet::getCaloConstituent(), pat::MET::MET(), pat::PATObject< ObjectType >::originalObject(), and pat::Tau::Tau().

00145                          {
00146       return isNull() ? 0 : this->operator->();
00147     }

template<typename T>
void edm::Ptr< T >::getData_ (  )  const [inline, private]

Definition at line 191 of file Ptr.h.

Referenced by edm::Ptr< T >::operator *(), and edm::Ptr< T >::operator->().

00191                           { 
00192       if(!hasCache() && 0 != productGetter()) {
00193         void const* ad = 0;
00194          const EDProduct* prod = productGetter()->getIt(core_.id());
00195          if(prod==0) {
00196             throw edm::Exception(errors::ProductNotFound)
00197             << "A request to resolve an edm::Ptr to a product containing items of type: "
00198             << typeid(T).name()
00199             << " with ProductID "<<core_.id()
00200             << "\ncan not be satisfied because the product cannot be found."
00201             << "\nProbably the branch containing the product is not stored in the input file.\n";
00202          }
00203          prod->setPtr(typeid(T),
00204                       key_,
00205                       ad);
00206         core_.setProductPtr(ad);
00207       }
00208     }

template<typename T>
template<typename C>
T const * Ptr< T >::getItem_ ( C const *  product,
key_type  iKey 
) [inline, private]

Definition at line 216 of file Ptr.h.

References it.

00217   {
00218     assert (product != 0);
00219     typename C::const_iterator it = product->begin();
00220     advance(it,iKey);
00221     T const* address = detail::GetProduct<C>::address(it);
00222     return address;
00223   }

template<typename T>
bool edm::Ptr< T >::hasCache (  )  const [inline]

Definition at line 173 of file Ptr.h.

Referenced by edm::Ptr< pat::MET >::getData_(), and edm::PtrVector< reco::CaloCluster >::push_back().

00173 { return 0!=core_.productPtr(); }

template<typename T>
ProductID edm::Ptr< T >::id ( void   )  const [inline]

Accessor for product ID.

Definition at line 166 of file Ptr.h.

Referenced by pat::PATUserDataMerger< ObjectType, Operation >::add(), GlobalFitCorrector::correction(), reco::CaloJet::getCaloConstituent(), reco::operator<<(), reco::Jet::print(), PFTopProjector::ptrToAncestor(), and pat::helper::RefHelper< T >::recursiveLookup().

00166 {return core_.id();}

template<typename T>
bool edm::Ptr< T >::isAvailable (  )  const [inline]

Checks if collection is in memory or available in the event.

No type checking is done.

Definition at line 160 of file Ptr.h.

Referenced by reco::CaloJet::getCaloConstituent(), and pat::PATObject< ObjectType >::originalObject().

00160 {return core_.isAvailable();}

template<typename T>
bool edm::Ptr< T >::isNonnull (  )  const [inline]

Checks for non-null.

Definition at line 154 of file Ptr.h.

Referenced by pat::helper::AddUserPtr::addData(), reco::CaloJet::getCaloConstituent(), edm::Ptr< pat::MET >::isNull(), reco::Jet::print(), and pat::helper::RefHelper< T >::recursiveLookup().

00154 {return key_traits<key_type>::value != key_;}

template<typename T>
bool edm::Ptr< T >::isNull (  )  const [inline]

Checks for null.

Definition at line 150 of file Ptr.h.

Referenced by edm::Ptr< pat::MET >::get(), edm::Ptr< pat::MET >::operator!(), and pat::PATObject< ObjectType >::originalObject().

00150 {return !isNonnull(); }

template<typename T>
bool edm::Ptr< T >::isTransient (  )  const [inline]

Checks if this Ptr is transient (i.e. not persistable).

Definition at line 163 of file Ptr.h.

00163 {return core_.isTransient();}

template<typename T>
key_type edm::Ptr< T >::key (  )  const [inline]

Definition at line 171 of file Ptr.h.

Referenced by reco::CaloJet::getCaloConstituent(), reco::FlavorHistory::hasParton(), reco::FlavorHistory::hasProgenitor(), reco::FlavorHistory::hasSister(), reco::FlavorHistory::operator<(), reco::operator<<(), operator<<(), reco::FlavorHistory::operator==(), edm::operator==(), reco::FlavorHistory::operator>(), reco::Jet::print(), and edm::PtrVector< reco::CaloCluster >::push_back().

00171 {return key_;}

template<typename T>
T const & Ptr< T >::operator * (  )  const [inline]

Dereference operator.

Definition at line 229 of file Ptr.h.

References edm::Ptr< T >::core_, edm::Ptr< T >::getData_(), and edm::RefCore::productPtr().

00229                           {
00230     getData_();
00231     return *reinterpret_cast<T const*>(core_.productPtr());
00232   }

template<typename T>
bool edm::Ptr< T >::operator! (  )  const [inline]

Checks for null.

Definition at line 156 of file Ptr.h.

00156 {return isNull();}

template<typename T>
T const * Ptr< T >::operator-> (  )  const [inline]

Member dereference operator.

Definition at line 238 of file Ptr.h.

References edm::Ptr< T >::core_, edm::Ptr< T >::getData_(), and edm::RefCore::productPtr().

Referenced by edm::Ptr< pat::MET >::get().

00238                            {
00239     getData_();
00240     return reinterpret_cast<T const*>(core_.productPtr());
00241   }

template<typename T>
EDProductGetter const* edm::Ptr< T >::productGetter (  )  const [inline]

Accessor for product getter.

Definition at line 169 of file Ptr.h.

Referenced by edm::Ptr< pat::MET >::getData_().

00169 {return core_.productGetter();}

template<typename T>
RefCore const& edm::Ptr< T >::refCore (  )  const [inline]

Definition at line 175 of file Ptr.h.

Referenced by edm::operator==(), and edm::PtrVector< reco::CaloCluster >::push_back().

00175 {return core_;}


Friends And Related Function Documentation

template<typename T>
friend class PtrVectorBase [friend]

Definition at line 41 of file Ptr.h.


Member Data Documentation

template<typename T>
RefCore edm::Ptr< T >::core_ [private]

Definition at line 210 of file Ptr.h.

Referenced by edm::Ptr< pat::MET >::getData_(), edm::Ptr< pat::MET >::hasCache(), edm::Ptr< pat::MET >::id(), edm::Ptr< pat::MET >::isAvailable(), edm::Ptr< pat::MET >::isTransient(), edm::Ptr< T >::operator *(), edm::Ptr< T >::operator->(), edm::Ptr< pat::MET >::productGetter(), and edm::Ptr< pat::MET >::refCore().

template<typename T>
key_type edm::Ptr< T >::key_ [private]

Definition at line 211 of file Ptr.h.

Referenced by edm::Ptr< pat::MET >::getData_(), edm::Ptr< pat::MET >::isNonnull(), and edm::Ptr< pat::MET >::key().


The documentation for this class was generated from the following file:
Generated on Tue Jun 9 18:43:12 2009 for CMSSW by  doxygen 1.5.4