CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Friends
edm::Ptr< T > Class Template Reference

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

Public Types

typedef unsigned long key_type
 
typedef T value_type
 

Public Member Functions

T const * get () const
 Returns C++ pointer to the item. More...
 
bool hasProductCache () const
 
ProductID id () const
 Accessor for product ID. More...
 
bool isAvailable () const
 
bool isNonnull () const
 Checks for non-null. More...
 
bool isNull () const
 Checks for null. More...
 
bool isTransient () const
 Checks if this Ptr is transient (i.e. not persistable). More...
 
key_type key () const
 
bool operator! () const
 Checks for null. More...
 
T const & operator* () const
 Dereference operator. More...
 
T const * operator-> () const
 Member dereference operator. More...
 
void const * product () const
 
EDProductGetter const * productGetter () const
 Accessor for product getter. More...
 
template<typename C >
 Ptr (Handle< C > const &handle, key_type itemKey, bool=true)
 
template<typename C >
 Ptr (OrphanHandle< C > const &handle, key_type itemKey, bool=true)
 
template<typename C >
 Ptr (C const *iProduct, key_type iItemKey, bool=true)
 
 Ptr (T const *item, key_type iItemKey)
 
template<typename C >
 Ptr (TestHandle< C > const &handle, key_type itemKey, bool=true)
 
 Ptr (ProductID const &productID, key_type itemKey, EDProductGetter const *prodGetter)
 
 Ptr (ProductID const &productID, T const *item, key_type item_key)
 
 Ptr (ProductID const &productID, T const *item, key_type item_key, bool transient)
 
 Ptr (ProductID const &iId)
 
 Ptr ()
 
template<typename U >
 Ptr (Ptr< U > const &iOther, std::enable_if_t< std::is_base_of< T, U >::value > *=nullptr)
 
template<typename U >
 Ptr (Ptr< U > const &iOther, std::enable_if_t< std::is_base_of< U, T >::value > *=nullptr)
 
RefCore const & refCore () const
 
 ~Ptr ()
 Destructor. More...
 

Static Public Member Functions

static short Class_Version ()
 

Private Member Functions

void getData_ (bool throwIfNotFound=true) const
 
template<typename C >
T const * getItem_ (C const *product, key_type iKey)
 

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 31 of file AssociationVector.h.

Member Typedef Documentation

◆ key_type

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

Definition at line 44 of file Ptr.h.

◆ value_type

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

Definition at line 45 of file Ptr.h.

Constructor & Destructor Documentation

◆ Ptr() [1/12]

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

Definition at line 49 of file Ptr.h.

50  : core_(handle.id(), getItem_(handle.product(), itemKey), nullptr, false), key_(itemKey) {}
T const * getItem_(C const *product, key_type iKey)
Definition: Ptr.h:209
key_type key_
Definition: Ptr.h:204
RefCore core_
Definition: Ptr.h:203

◆ Ptr() [2/12]

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

Definition at line 54 of file Ptr.h.

55  : core_(handle.id(), getItem_(handle.product(), itemKey), nullptr, false), key_(itemKey) {}
T const * getItem_(C const *product, key_type iKey)
Definition: Ptr.h:209
key_type key_
Definition: Ptr.h:204
RefCore core_
Definition: Ptr.h:203

◆ Ptr() [3/12]

template<typename T>
template<typename C >
edm::Ptr< T >::Ptr ( C const *  iProduct,
key_type  iItemKey,
bool  = true 
)
inline

Definition at line 70 of file Ptr.h.

71  : core_(ProductID(), iProduct != nullptr ? getItem_(iProduct, iItemKey) : nullptr, nullptr, true),
72  key_(iProduct != nullptr ? iItemKey : key_traits<key_type>::value) {}
static const key_type value
Definition: traits.h:34
T const * getItem_(C const *product, key_type iKey)
Definition: Ptr.h:209
key_type key_
Definition: Ptr.h:204
RefCore core_
Definition: Ptr.h:203

◆ Ptr() [4/12]

template<typename T>
edm::Ptr< T >::Ptr ( T const *  item,
key_type  iItemKey 
)
inline

Definition at line 74 of file Ptr.h.

75  : core_(ProductID(), item, nullptr, true), key_(item != nullptr ? iItemKey : key_traits<key_type>::value) {}
static const key_type value
Definition: traits.h:34
key_type key_
Definition: Ptr.h:204
RefCore core_
Definition: Ptr.h:203

◆ Ptr() [5/12]

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

Definition at line 81 of file Ptr.h.

82  : core_(handle.id(), getItem_(handle.product(), itemKey), nullptr, true), key_(itemKey) {}
T const * getItem_(C const *product, key_type iKey)
Definition: Ptr.h:209
key_type key_
Definition: Ptr.h:204
RefCore core_
Definition: Ptr.h:203

◆ Ptr() [6/12]

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 87 of file Ptr.h.

88  : core_(productID, nullptr, mustBeNonZero(prodGetter, "Ptr", productID), false), key_(itemKey) {}
EDProductGetter const * mustBeNonZero(EDProductGetter const *prodGetter, std::string refType, ProductID const &productID)
key_type key_
Definition: Ptr.h:204
RefCore core_
Definition: Ptr.h:203

◆ Ptr() [7/12]

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 97 of file Ptr.h.

98  : core_(productID, item, nullptr, false), key_(item_key) {}
key_type key_
Definition: Ptr.h:204
RefCore core_
Definition: Ptr.h:203

◆ Ptr() [8/12]

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

Definition at line 100 of file Ptr.h.

101  : core_(productID, item, nullptr, transient), key_(item_key) {}
key_type key_
Definition: Ptr.h:204
RefCore core_
Definition: Ptr.h:203

◆ Ptr() [9/12]

template<typename T>
edm::Ptr< T >::Ptr ( ProductID const &  iId)
inlineexplicit

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

Definition at line 107 of file Ptr.h.

107 : core_(iId, nullptr, nullptr, false), key_(key_traits<key_type>::value) {}
static const key_type value
Definition: traits.h:34
key_type key_
Definition: Ptr.h:204
RefCore core_
Definition: Ptr.h:203

◆ Ptr() [10/12]

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

Definition at line 109 of file Ptr.h.

static const key_type value
Definition: traits.h:34
key_type key_
Definition: Ptr.h:204
RefCore core_
Definition: Ptr.h:203

◆ Ptr() [11/12]

template<typename T>
template<typename U >
edm::Ptr< T >::Ptr ( Ptr< U > const &  iOther,
std::enable_if_t< std::is_base_of< T, U >::value > *  = nullptr 
)
inline

Definition at line 112 of file Ptr.h.

113  : core_(iOther.id(),
114  (iOther.hasProductCache() ? static_cast<T const*>(iOther.get()) : static_cast<T const*>(nullptr)),
115  iOther.productGetter(),
116  iOther.isTransient()),
117  key_(iOther.key()) {
118  //make sure a race condition didn't happen where between the call to hasProductCache() and
119  // productGetter() the object was gotten
120  if (iOther.hasProductCache() and not hasProductCache()) {
121  core_.setProductPtr(static_cast<T const*>(iOther.get()));
122  }
123  }
void setProductPtr(void const *prodPtr) const
Definition: RefCore.h:57
key_type key_
Definition: Ptr.h:204
bool hasProductCache() const
Definition: Ptr.h:167
RefCore core_
Definition: Ptr.h:203
long double T

◆ Ptr() [12/12]

template<typename T>
template<typename U >
edm::Ptr< T >::Ptr ( Ptr< U > const &  iOther,
std::enable_if_t< std::is_base_of< U, T >::value > *  = nullptr 
)
inlineexplicit

Definition at line 126 of file Ptr.h.

127  : core_(iOther.id(), dynamic_cast<T const*>(iOther.get()), nullptr, iOther.isTransient()), key_(iOther.key()) {}
key_type key_
Definition: Ptr.h:204
RefCore core_
Definition: Ptr.h:203
long double T

◆ ~Ptr()

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

Destructor.

Definition at line 130 of file Ptr.h.

130 {}

Member Function Documentation

◆ Class_Version()

template<typename T>
static short edm::Ptr< T >::Class_Version ( )
inlinestatic

Definition at line 175 of file Ptr.h.

177 :
178  template <typename C>

◆ get()

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

Returns C++ pointer to the item.

Definition at line 139 of file Ptr.h.

Referenced by Options.Options::__getitem__(), betterConfigParser.BetterConfigParser::__updateDict(), submitPVValidationJobs.BetterConfigParser::__updateDict(), TransientTrackBuilder::build(), PFEGammaAlgo::buildRefinedSuperCluster(), util.rrapi.RRApi::columns(), rrapi.RRApi::columns(), PileupJetIdAlgo::computeIdVariables(), util.rrapi.RRApi::count(), rrapi.RRApi::count(), util.rrapi.RRApi::data(), rrapi.RRApi::data(), TauDiscriminationAgainstElectronMVA6< TauType, TauDiscriminator, ElectronType >::discriminate(), l1tVertexFinder::TP::fillUse(), l1tVertexFinder::TP::fillUseForEff(), l1tVertexFinder::TP::fillUseForVertexReco(), PFECALSuperClusterAlgo::finalizeSuperCluster(), edm::FwdPtr< T >::get(), pat::EventHypothesis::getAs(), betterConfigParser.BetterConfigParser::getCompares(), betterConfigParser.BetterConfigParser::getGeneral(), betterConfigParser.BetterConfigParser::getResultingSection(), submitPVValidationJobs.BetterConfigParser::getResultingSection(), AntiElectronIDMVA6< TauType, ElectronType >::getTauVarsTypeSpecific(), TTClusterAssociationMap< T >::isCombinatoric(), TTClusterAssociationMap< T >::isGenuine(), MuonPFIsolationWithConeVeto::isInIsolationCone(), ElectronPFIsolationWithConeVeto::isInIsolationCone(), PhotonPFIsolationWithConeVeto::isInIsolationCone(), PhotonPFIsolationWithMapBasedVeto::isInIsolationCone(), ElectronPFIsolationWithMapBasedVeto::isInIsolationCone(), TTClusterAssociationMap< T >::isUnknown(), reco::tau::lead_track_chi2(), pat::MET::MET(), AntiElectronDeadECAL::operator()(), reco::PFClusterJet::pfCluster(), reco::RecoTauPiZero::print(), EcalDigiSelector::produce(), pat::PATTauProducer::produce(), SoftPFMuonTagInfoProducer::produce(), util.rrapi.RRApi::report(), rrapi.RRApi::report(), rrapi.RRApi::reports(), util.rrapi.RRApi::reports(), BoostedDoubleSVProducer::setTracksPV(), rrapi.RRApi::tables(), util.rrapi.RRApi::tables(), rrapi.RRApi::tags(), util.rrapi.RRApi::tags(), util.rrapi.RRApi::templates(), rrapi.RRApi::templates(), toTrackRef(), reco::TrackJet::track(), GsfEleCalPFClusterIsoCut::value(), rrapi.RRApi::workspaces(), and util.rrapi.RRApi::workspaces().

139 { return isNull() ? nullptr : this->operator->(); }
T const * operator->() const
Member dereference operator.
Definition: Ptr.h:226
bool isNull() const
Checks for null.
Definition: Ptr.h:142

◆ getData_()

template<typename T>
void edm::Ptr< T >::getData_ ( bool  throwIfNotFound = true) const
inlineprivate

Definition at line 181 of file Ptr.h.

181  {
182  EDProductGetter const* getter = productGetter();
183  if (getter != nullptr) {
184  WrapperBase const* prod = getter->getIt(core_.id());
185  unsigned int iKey = key_;
186  if (prod == nullptr) {
187  auto optionalProd = getter->getThinnedProduct(core_.id(), key_);
188  if (not optionalProd.has_value()) {
189  if (throwIfNotFound) {
191  } else {
192  return;
193  }
194  }
195  std::tie(prod, iKey) = *optionalProd;
196  }
197  void const* ad = nullptr;
198  prod->setPtr(typeid(T), iKey, ad);
199  core_.setProductPtr(ad);
200  }
201  }
ProductID id() const
Definition: RefCore.h:48
void setProductPtr(void const *prodPtr) const
Definition: RefCore.h:57
key_type key_
Definition: Ptr.h:204
RefCore core_
Definition: Ptr.h:203
void productNotFoundException(std::type_info const &type) const
Definition: RefCore.cc:125
EDProductGetter const * productGetter() const
Accessor for product getter.
Definition: Ptr.h:163
long double T

◆ getItem_()

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

Definition at line 209 of file Ptr.h.

209  {
210  assert(iProduct != nullptr);
211  typename C::const_iterator it = iProduct->begin();
212  std::advance(it, iKey);
213  T const* address = detail::GetProduct<C>::address(it);
214  return address;
215  }
static const element_type * address(const iter &i)
Definition: GetProduct.h:36
assert(be >=bs)
long double T

◆ hasProductCache()

template<typename T>
bool edm::Ptr< T >::hasProductCache ( ) const
inline

Definition at line 167 of file Ptr.h.

Referenced by edm::FwdPtr< T >::hasProductCache(), edm::Ptr< reco::Muon >::Ptr(), and edm::PtrVector< reco::CaloCluster >::push_back().

167 { return nullptr != core_.productPtr(); }
void const * productPtr() const
Definition: RefCore.h:51
RefCore core_
Definition: Ptr.h:203

◆ id()

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

◆ isAvailable()

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. This function is potentially costly as it might cause a disk read (note that it does not cause the data to be cached locally)

Definition at line 232 of file Ptr.h.

Referenced by B2GDQM::analyzeAllHad(), B2GDQM::analyzeSemiE(), B2GDQM::analyzeSemiMu(), MVAJetPuId::computeIdVariables(), edm::FwdPtr< T >::get(), edm::FwdPtr< T >::isAvailable(), reco::PFCandidateFwdPtrFactory::operator()(), TopProjectorFwdPtrOverlap< Top, Bottom >::operator()(), edm::FwdPtr< T >::operator*(), edm::FwdPtr< T >::operator->(), reco::PFClusterJet::pfCluster(), JetFlavourClustering::produce(), and reco::TrackJet::track().

232  {
233  getData_(false);
234  return hasProductCache();
235  }
void getData_(bool throwIfNotFound=true) const
Definition: Ptr.h:181
bool hasProductCache() const
Definition: Ptr.h:167

◆ isNonnull()

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

Checks for non-null.

Definition at line 146 of file Ptr.h.

Referenced by reco::tau::RecoTauConstructor::addTauChargedHadron(), ZCountingElectrons::analyze(), B2GDoubleLeptonHLTValidation::analyze(), B2GHadronicHLTValidation::analyze(), B2GSingleLeptonHLTValidation::analyze(), reco::FlavorHistoryEvent::cache(), BoostedDoubleSVProducer::calcNsubjettiness(), ConversionProducer::checkTrackPair(), MVAJetPuId::computeIdVariables(), reco::tau::RecoTauConstructor::convertToPtr(), EGEnergyCorrector::CorrectedEnergyWithError(), PFRecoTauDiscriminationByNProngs::discriminate(), TauDiscriminationAgainstElectronMVA6< TauType, TauDiscriminator, ElectronType >::discriminate(), PFRecoTauDiscriminationAgainstMuon2Helper::eval(), PATTauHybridProducer::fillTauFromJet(), AntiElectronIDMVA6< TauType, ElectronType >::getTauVarsTypeSpecific(), reco::FlavorHistory::hasMatchedJet(), reco::PFTau::hasMuonReference(), reco::FlavorHistory::hasParton(), reco::FlavorHistory::hasProgenitor(), reco::FlavorHistory::hasSister(), reco::FlavorHistory::hasSisterJet(), edm::FwdPtr< T >::id(), MuonPFIsolationWithConeVeto::isInIsolationCone(), ElectronPFIsolationWithConeVeto::isInIsolationCone(), PhotonPFIsolationWithConeVeto::isInIsolationCone(), PhotonPFIsolationWithMapBasedVeto::isInIsolationCone(), edm::FwdPtr< T >::isNonnull(), edm::Ptr< reco::Muon >::isNull(), edm::FwdPtr< T >::key(), reco::tau::lead_track_chi2(), pat::Muon::numberOfSourceCandidatePtrs(), reco::PFCandidateFwdPtrFactory::operator()(), reco::tau::RecoTauElectronRejectionPlugin::operator()(), reco::tau::RecoTauBuilderConePlugin::operator()(), AntiElectronDeadECAL::operator()(), TopProjectorFwdPtrOverlap< Top, Bottom >::operator()(), reco::PFCandidate::overlap(), reco::PFClusterJet::pfCluster(), reco::PFRecoTauChargedHadron::print(), PFTauElecRejectionBenchmark::process(), L1THLTTauMatching::produce(), L1HLTTauMatching::produce(), PseudoTopProducer::produce(), PATMuonMerger::produce(), LowPtGsfElectronIDProducer::produce(), PFTauPrimaryVertexProducerBase::produce(), pat::PATTauProducer::produce(), pat::PATElectronProducer::produce(), JetFlavourClustering::produce(), edm::FwdPtr< T >::refCore(), reco::tau::setChargedHadronP4(), reco::tau::RecoTauBuilderConePlugin::setTauQuantities(), and reco::TrackJet::track().

146 { return key_traits<key_type>::value != key_; }
static const key_type value
Definition: traits.h:34
key_type key_
Definition: Ptr.h:204

◆ isNull()

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

◆ isTransient()

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

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

Definition at line 157 of file Ptr.h.

Referenced by edm::FwdPtr< T >::isTransient().

157 { return core_.isTransient(); }
bool isTransient() const
Definition: RefCore.h:105
RefCore core_
Definition: Ptr.h:203

◆ key()

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

◆ operator!()

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

Checks for null.

Definition at line 148 of file Ptr.h.

148 { return isNull(); }
bool isNull() const
Checks for null.
Definition: Ptr.h:142

◆ operator*()

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

Dereference operator.

Definition at line 219 of file Ptr.h.

219  {
220  getData_();
221  return *reinterpret_cast<T const*>(core_.productPtr());
222  }
void getData_(bool throwIfNotFound=true) const
Definition: Ptr.h:181
void const * productPtr() const
Definition: RefCore.h:51
RefCore core_
Definition: Ptr.h:203
long double T

◆ operator->()

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

Member dereference operator.

Definition at line 226 of file Ptr.h.

Referenced by edm::Ptr< reco::Muon >::get().

226  {
227  getData_();
228  return reinterpret_cast<T const*>(core_.productPtr());
229  }
void getData_(bool throwIfNotFound=true) const
Definition: Ptr.h:181
void const * productPtr() const
Definition: RefCore.h:51
RefCore core_
Definition: Ptr.h:203
long double T

◆ product()

template<typename T>
void const* edm::Ptr< T >::product ( ) const
inline

Definition at line 172 of file Ptr.h.

172 { return nullptr; }

◆ productGetter()

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

Accessor for product getter.

Definition at line 163 of file Ptr.h.

Referenced by edm::Ptr< reco::Muon >::getData_(), and edm::FwdPtr< T >::productGetter().

163 { return core_.productGetter(); }
RefCore core_
Definition: Ptr.h:203
EDProductGetter const * productGetter() const
Definition: RefCore.h:81

◆ refCore()

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

Friends And Related Function Documentation

◆ PtrVectorBase

template<typename T>
friend class PtrVectorBase
friend

Definition at line 41 of file Ptr.h.

Member Data Documentation

◆ core_

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

◆ key_

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