LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
art::Ptr< T > Class Template Reference

#include "fwd.h"

Public Types

using key_type = std::size_t
 
using value_type = T
 
using const_pointer = T const *
 
using const_reference = T const &
 

Public Member Functions

 Ptr ()=default
 
template<typename H >
 Ptr (H const &handle, typename Ptr< T >::key_type key)
 
 Ptr (ProductID const &productID, key_type itemKey, EDProductGetter const *prodGetter)
 
template<typename U >
 Ptr (Ptr< U > const &pu, std::enable_if_t< std::is_base_of_v< T, U >> *=nullptr)
 
template<typename U >
 Ptr (Ptr< U > const &pu, std::enable_if_t< std::is_base_of_v< U, T >> *=nullptr)
 
 Ptr (ProductID const &productID, T const *item, key_type const itemKey)
 
T const & operator* () const
 
T const * get () const
 
T const * operator-> () const
 
 operator bool () const
 
ProductID id () const noexcept
 
key_type key () const noexcept
 
template<typename Collection >
Collection const & parentAs () const
 
template<template< typename... > class Collection, typename U = T>
Collection< U > const & parentAs () const
 
RefCore const & refCore () const noexcept
 
bool isNonnull () const noexcept
 
bool isNull () const noexcept
 
bool isAvailable () const
 
EDProductGetter const * productGetter () const noexcept
 

Static Public Member Functions

static constexpr short Class_Version () noexcept
 

Private Member Functions

EDProduct const * parentProduct_ () const
 

Private Attributes

RefCore core_ {}
 
key_type key_ {key_traits<key_type>::value}
 

Detailed Description

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

Definition at line 26 of file fwd.h.

Member Typedef Documentation

template<typename T>
using art::Ptr< T >::const_pointer = T const*

Definition at line 80 of file Ptr.h.

template<typename T>
using art::Ptr< T >::const_reference = T const&

Definition at line 81 of file Ptr.h.

template<typename T>
using art::Ptr< T >::key_type = std::size_t

Definition at line 78 of file Ptr.h.

template<typename T>
using art::Ptr< T >::value_type = T

Definition at line 79 of file Ptr.h.

Constructor & Destructor Documentation

template<typename T>
art::Ptr< T >::Ptr ( )
default
template<typename T>
template<typename H >
art::Ptr< T >::Ptr ( H const &  handle,
typename Ptr< T >::key_type  key 
)
inline

Definition at line 87 of file Ptr.h.

88  : core_{handle.id(),
89  detail::ItemGetter<T, typename H::element_type>{}(
90  handle.product(),
91  key),
92  handle.productGetter()}
93  , key_{key}
94  {
95  if (core_.isNull()) {
97  << "Attempt to construct a Ptr from a Handle with invalid ProductID. "
98  "Perhaps a\n"
99  "default-constructed Ptr is what you want?";
100  }
101  }
RefCore core_
Definition: Ptr.h:265
key_type key_
Definition: Ptr.h:268
constexpr bool isNull() const noexcept
Definition: RefCore.h:33
key_type key() const noexcept
Definition: Ptr.h:166
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
constexpr ProductID id() const noexcept
Definition: RefCore.h:50
template<typename T>
art::Ptr< T >::Ptr ( ProductID const &  productID,
key_type  itemKey,
EDProductGetter const *  prodGetter 
)
inline

Definition at line 104 of file Ptr.h.

107  : core_{productID, nullptr, prodGetter}, key_{itemKey}
108  {}
RefCore core_
Definition: Ptr.h:265
key_type key_
Definition: Ptr.h:268
template<typename T>
template<typename U >
art::Ptr< T >::Ptr ( Ptr< U > const &  pu,
std::enable_if_t< std::is_base_of_v< T, U >> *  = nullptr 
)
inline

Definition at line 112 of file Ptr.h.

113  : core_{pu.id(), pu.get(), pu.productGetter()}, key_{pu.key()}
114  {}
RefCore core_
Definition: Ptr.h:265
key_type key_
Definition: Ptr.h:268
constexpr ProductID id() const noexcept
Definition: RefCore.h:50
template<typename T>
template<typename U >
art::Ptr< T >::Ptr ( Ptr< U > const &  pu,
std::enable_if_t< std::is_base_of_v< U, T >> *  = nullptr 
)
inline

Definition at line 117 of file Ptr.h.

118  : core_{pu.id(), static_cast<T const*>(pu.get()), nullptr}, key_{pu.key()}
119  {}
RefCore core_
Definition: Ptr.h:265
key_type key_
Definition: Ptr.h:268
constexpr ProductID id() const noexcept
Definition: RefCore.h:50
template<typename T>
art::Ptr< T >::Ptr ( ProductID const &  productID,
T const *  item,
key_type const  itemKey 
)
inline

Definition at line 122 of file Ptr.h.

123  : core_{productID, item, nullptr}, key_{itemKey}
124  {}
RefCore core_
Definition: Ptr.h:265
key_type key_
Definition: Ptr.h:268

Member Function Documentation

template<typename T>
static constexpr short art::Ptr< T >::Class_Version ( )
inlinestaticnoexcept

Definition at line 226 of file Ptr.h.

227  {
228  return 10;
229  }
template<typename T>
bool art::Ptr< T >::isAvailable ( ) const
inline

Definition at line 219 of file Ptr.h.

220  {
221  return core_.isAvailable();
222  }
RefCore core_
Definition: Ptr.h:265
bool isAvailable() const
Definition: RefCore.cc:24
template<typename T>
bool art::Ptr< T >::isNonnull ( ) const
inlinenoexcept

Definition at line 204 of file Ptr.h.

Referenced by recob::HitCollectionCreator::CreateAssociationsToLastHit(), lar::util::details::FindAllP< Source, Dest >::Merge(), and hit::HitCheater::produce().

205  {
207  }
key_type key_
Definition: Ptr.h:268
static constexpr key_type value
Definition: traits.h:38
template<typename T>
key_type art::Ptr< T >::key ( ) const
inlinenoexcept

Definition at line 166 of file Ptr.h.

Referenced by shower::TCShowerAlg::addShowerHit(), RecoProxyUsageExample::analyze(), NuShowerEff::analyze(), lar_pandora::LArPandoraHelper::BuildMCParticleHitMaps(), ShowerRecoTools::ShowerLengthPercentile::CalculateElement(), ShowerRecoTools::ShowerStartPositionCheater::CalculateElement(), ShowerRecoTools::ShowerTrackFinderCheater::CalculateElement(), ShowerRecoTools::Shower3DCylinderTrackHitFinder::CalculateElement(), ShowerRecoTools::ShowerPCAPropergationStartPosition::CalculateElement(), ShowerRecoTools::Shower2DLinearRegressionTrackHitFinder::CalculateElement(), ShowerRecoTools::ShowerLinearEnergy::CalculateElement(), ShowerRecoTools::ShowerPFPVertexStartPosition::CalculateElement(), ShowerRecoTools::ShowerDirectionCheater::CalculateElement(), ShowerRecoTools::ShowerPandoraSlidingFitTrackFinder::CalculateElement(), ShowerRecoTools::ShowerNumElectronsEnergy::CalculateElement(), ShowerRecoTools::ShowerPCADirection::CalculateElement(), ShowerRecoTools::ShowerIncrementalTrackHitFinder::CalculateElement(), ShowerRecoTools::ShowerTrajPointdEdx::CalculateElement(), shower::EMShowerAlg::CheckShowerPlanes(), lar_pandora::LArPandoraExternalEventBuilding::CollectPFParticles(), t0::IndirectHitParticleAssns::CreateHitParticleAssociations(), shower::LArPandoraShowerAlg::DebugEVD(), evd::RecoBaseDrawer::DrawPFParticle3D(), evd::RecoBaseDrawer::DrawTrackVertexAssns2D(), ems::EndPoint::FillBins(), lar_pandora::LArPandoraHelper::GetAssociatedHits(), lar_pandora::LArPandoraSliceIdHelper::GetHitOrigins(), anab::MVAReader< T, N >::getOutput(), lar_pandora::LArPandoraSliceIdHelper::GetPFParticleToHitsMap(), shower::TCShower::getShowersWithSlices(), sce::SCECorrection::getSliceT0s(), evdb_tool::SpacePoint3DDrawerHitCharge::getSpacePointCharge(), anab::FVectorReader< T, N >::getVector(), anab::FVectorWriter< 4 >::getVector(), trkmkr::TrackMaker::makeTrack(), lar::util::details::FindAllP< Source, Dest >::Merge(), art::PtrRemapper::operator()(), art::operator==(), lar::util::details::UniqueAssociationCache< Source_t, Dest_t >::operator[](), lar_pandora::LArPandoraEventDump::PrintCluster(), lar_pandora::LArPandoraEventDump::PrintHit(), lar_pandora::LArPandoraEventDump::PrintParticle(), lar_pandora::LArPandoraEventDump::PrintShower(), lar_pandora::LArPandoraEventDump::PrintSlice(), lar_pandora::LArPandoraEventDump::PrintSpacePoint(), lar_pandora::LArPandoraEventDump::PrintTrack(), lar_pandora::LArPandoraEventDump::PrintVertex(), cosmic::TrackPFParticleMatch::produce(), cosmic::CosmicTrackTagger::produce(), apa::APAHitFinder::produce(), cosmic::CosmicPFParticleTagger::produce(), hit::HitCheater::produce(), vertex::PrimaryVertexFinder::produce(), caldata::CalWire::produce(), caldata::CalWireT962::produce(), NuSliceHitsProducer::produce(), CRHitRemoval::produce(), cosmic::CosmicPCAxisTagger::produce(), sce::SCECorrection::produce(), shwf::ShowerReco::produce(), shower::EMShower::produce(), trkf::PMAlgTrajFitter::produce(), trkf::KalmanFilterFinalTrackFitter::setMomValue(), shower::LArPandoraShowerAlg::SpacePointCharge(), and shower::LArPandoraShowerAlg::SpacePointTime().

167  {
168  return key_;
169  }
key_type key_
Definition: Ptr.h:268
template<typename T>
art::Ptr< T >::operator bool ( ) const
inlineexplicit

Definition at line 154 of file Ptr.h.

155  {
156  return isNonnull() && core_.isAvailable();
157  }
RefCore core_
Definition: Ptr.h:265
bool isAvailable() const
Definition: RefCore.cc:24
bool isNonnull() const noexcept
Definition: Ptr.h:204
template<typename T>
T const& art::Ptr< T >::operator* ( ) const
inline

Definition at line 131 of file Ptr.h.

132  {
133  // Warning: This causes a nullptr dereference if isNull!
134  return *get();
135  }
template<typename T>
T const* art::Ptr< T >::operator-> ( ) const
inline

Definition at line 144 of file Ptr.h.

145  {
146  if (core_.productPtr() == nullptr) {
147  EDProduct const* prod = parentProduct_();
148  void const* ad = prod->getElementAddress(typeid(T), key_);
149  core_.setProductPtr(ad);
150  }
151  return reinterpret_cast<T const*>(core_.productPtr());
152  }
RefCore core_
Definition: Ptr.h:265
EDProduct const * parentProduct_() const
Definition: Ptr.h:239
key_type key_
Definition: Ptr.h:268
void const * productPtr() const noexcept
Definition: RefCore.cc:34
void setProductPtr(void const *prodPtr) const noexcept
Definition: RefCore.cc:48
template<typename T>
template<typename Collection >
Collection const& art::Ptr< T >::parentAs ( ) const
inline

Definition at line 174 of file Ptr.h.

175  {
176  core_.isAvailable();
177  auto product = parentProduct_();
178  auto wrapped_product = dynamic_cast<Wrapper<Collection> const*>(product);
179  if (wrapped_product == nullptr) {
181  << "A request to retrieve the parent collection of type: "
182  << cet::demangle_symbol(typeid(Collection).name())
183  << " with ProductID " << core_.id()
184  << "\ncannot be satisfied due to a type mismatch.\n";
185  }
186  return *wrapped_product->product();
187  }
RefCore core_
Definition: Ptr.h:265
EDProduct const * parentProduct_() const
Definition: Ptr.h:239
bool isAvailable() const
Definition: RefCore.cc:24
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
constexpr ProductID id() const noexcept
Definition: RefCore.h:50
template<typename T>
template<template< typename... > class Collection, typename U = T>
Collection<U> const& art::Ptr< T >::parentAs ( ) const
inline

Definition at line 191 of file Ptr.h.

192  {
193  return parentAs<Collection<U>>();
194  }
template<typename T>
EDProduct const* art::Ptr< T >::parentProduct_ ( ) const
inlineprivate

Definition at line 239 of file Ptr.h.

240  {
241  EDProduct const* product{nullptr};
242  if (productGetter()) {
243  product = productGetter()->getIt();
244  }
245  if (product == nullptr) {
247  e << "A request to resolve an Ptr to a product containing items of "
248  "type: "
249  << cet::demangle_symbol(typeid(T).name()) << " with ProductID "
250  << core_.id()
251  << "\ncannot be satisfied because the product cannot be found.\n";
252  if (productGetter() == nullptr) {
253  e << "The productGetter was not set -- are you trying to "
254  "dereference a Ptr during mixing?\n";
255  } else {
256  e << "Probably the branch containing the product is not stored in "
257  "the input file.\n";
258  }
259  throw e;
260  }
261  return product;
262  }
EDProduct const * getIt() const
RefCore core_
Definition: Ptr.h:265
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
EDProductGetter const * productGetter() const noexcept
Definition: Ptr.h:232
constexpr ProductID id() const noexcept
Definition: RefCore.h:50
Float_t e
Definition: plot.C:35
template<typename T>
EDProductGetter const* art::Ptr< T >::productGetter ( ) const
inlinenoexcept

Definition at line 232 of file Ptr.h.

Referenced by art::Ptr< L >::Ptr().

233  {
234  return core_.productGetter();
235  }
EDProductGetter const * productGetter() const noexcept
Definition: RefCore.cc:41
RefCore core_
Definition: Ptr.h:265
template<typename T>
RefCore const& art::Ptr< T >::refCore ( ) const
inlinenoexcept

Member Data Documentation

template<typename T>
RefCore art::Ptr< T >::core_ {}
mutableprivate

Definition at line 265 of file Ptr.h.

template<typename T>
key_type art::Ptr< T >::key_ {key_traits<key_type>::value}
private

Definition at line 268 of file Ptr.h.


The documentation for this class was generated from the following files: