LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
art::Handle< T > Class Template Reference

#include "fwd.h"

Classes

class  HandleTag
 

Public Types

using element_type = T
 

Public Member Functions

constexpr Handle ()=default
 
 Handle (GroupQueryResult const &)
 
T const & operator* () const
 
T const * operator-> () const
 
T const * product () const
 
bool isValid () const
 
bool failedToGet () const
 
Provenance const * provenance () const
 
ProductID id () const
 
std::shared_ptr< art::Exception const > whyFailed () const
 
void swap (Handle< T > &other)
 
void clear ()
 

Private Attributes

T const * prod_ {nullptr}
 
Provenance prov_ {}
 
std::shared_ptr< art::Exception const > whyFailed_ {nullptr}
 

Detailed Description

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

Definition at line 23 of file fwd.h.

Member Typedef Documentation

template<typename T>
using art::Handle< T >::element_type = T

Definition at line 101 of file Handle.h.

Constructor & Destructor Documentation

template<typename T>
constexpr art::Handle< T >::Handle ( )
explicitdefault
template<class T >
art::Handle< T >::Handle ( GroupQueryResult const &  gqr)
explicit

Definition at line 137 of file Handle.h.

References e, art::errors::LogicError, art::Handle< T >::prod_, art::Provenance::productDescription(), art::Handle< T >::prov_, and art::Handle< T >::whyFailed_.

138  : prod_{nullptr}, prov_{gqr.result()}, whyFailed_{gqr.whyFailed()}
139 {
140  if (gqr.succeeded()) {
141  auto const wrapperPtr = dynamic_cast<Wrapper<T> const*>(
142  gqr.result()->uniqueProduct(TypeID{typeid(Wrapper<T>)}));
143  if (wrapperPtr == nullptr) {
145  e << "Product retrieval via Handle<T> succeeded for product:\n"
147  << "but an attempt to interpret it as an object of type '"
148  << cet::demangle_symbol(typeid(T).name()) << "' failed.\n";
149  whyFailed_ = std::make_shared<art::Exception const>(std::move(e));
150  } else {
151  prod_ = wrapperPtr->product();
152  }
153  }
154 }
T const * prod_
Definition: Handle.h:128
std::shared_ptr< art::Exception const > whyFailed_
Definition: Handle.h:130
Provenance prov_
Definition: Handle.h:129
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
BranchDescription const & productDescription() const
Definition: Provenance.h:46
Float_t e
Definition: plot.C:34

Member Function Documentation

template<class T >
void art::Handle< T >::clear ( void  )

Definition at line 237 of file Handle.h.

References art::Handle< T >::swap(), and tmp.

Referenced by art::DataViewImpl::get(), art::DataViewImpl::getByLabel(), trkf::CCTrackMaker::produce(), art::DataViewImpl::removeCachedProduct(), and trkf::StitchAlg::StitchAlg().

238 {
239  Handle<T> tmp;
240  swap(tmp);
241 }
void swap(Handle< T > &other)
Definition: Handle.h:230
Float_t tmp
Definition: plot.C:37
template<class T >
bool art::Handle< T >::failedToGet ( ) const
template<class T >
art::ProductID art::Handle< T >::id ( ) const
inline

Definition at line 211 of file Handle.h.

References art::Provenance::isValid(), art::Provenance::productID(), and art::Handle< T >::prov_.

Referenced by art::DataViewImpl::removeCachedProduct().

212 {
213  // FIXME: returning prov_.productID() should be sufficient since
214  // ProductID{} is invalid anyway.
215  return prov_.isValid() ? prov_.productID() : ProductID{};
216 }
bool isValid() const
Definition: Provenance.h:120
ProductID const & productID() const
Definition: Provenance.h:113
Provenance prov_
Definition: Handle.h:129
template<class T >
bool art::Handle< T >::isValid ( ) const

Definition at line 190 of file Handle.h.

References art::Provenance::isValid(), art::Handle< T >::prod_, and art::Handle< T >::prov_.

Referenced by hit::MCHitAnaExample::analyze(), MCBTDemo::analyze(), ShowerQuality::analyze(), lar_pandora::ConsolidatedPFParticleAnalysisTemplate::analyze(), trkf::SpacePointAna::analyze(), cluster::ClusterAna::analyze(), trkf::SeedAna::analyze(), trkf::TrackAna::analyze(), trkf::TrackAna::anaStitch(), lar_pandora::LArPandoraHelper::BuildMCParticleHitMaps(), lar_cluster3d::StandardHit3DBuilder::CollectArtHits(), lar_pandora::LArPandoraHelper::CollectClusters(), lar_pandora::LArPandoraHelper::CollectCosmicTags(), lar_pandora::LArPandoraHelper::CollectGeneratorMCParticles(), lar_pandora::LArPandoraHelper::CollectHits(), lar_pandora::LArPandoraHelper::CollectMCParticles(), lar_pandora::LArPandoraHelper::CollectPFParticleMetadata(), lar_pandora::LArPandoraHelper::CollectPFParticles(), lar_pandora::LArPandoraHelper::CollectSeeds(), lar_pandora::LArPandoraHelper::CollectShowers(), lar_pandora::LArPandoraHelper::CollectSimChannels(), lar_pandora::LArPandoraHelper::CollectSpacePoints(), lar_pandora::LArPandoraHelper::CollectT0s(), lar_pandora::LArPandoraHelper::CollectTracks(), lar_pandora::LArPandoraHelper::CollectVertices(), lar_pandora::LArPandoraHelper::CollectWires(), t0::IndirectHitParticleAssns::CreateHitParticleAssociations(), evd::RecoBaseDrawer::DrawShower3D(), evd::RecoBaseDrawer::DrawShowerOrtho(), evd::RecoBaseDrawer::DrawTrack3D(), evd::RecoBaseDrawer::DrawTrackOrtho(), trkf::Track3DKalmanHit::getAllHits(), trkf::Track3DKalmanHit::getClusteredHits(), ShowerQuality::GetDataOrDie(), trkf::BezierTrackerModule::GetHitsFromClusters(), trkf::Track3DKalmanHit::getPFParticleStuff(), trkf::SeedFinderModule::GetSortedHitsFromClusters(), lar_cluster3d::SpacePointHit3DBuilder::Hit3DBuilder(), evgb::MCTruthAndFriendsItr::MCTruthAndFriendsItr(), MCReco::produce(), hit::MCHitFinder::produce(), cluster::SimpleClusterMerger::produce(), trkf::SpacePointFinder::produce(), trkf::SpacePointCheater::produce(), trkf::BezierTrackerModule::produce(), noisefilteralg::WireCellNoiseFilter::produce(), evwgh::EventWeight::produce(), CRHitRemoval::produce(), ShowerReco3D::produce(), cluster::FuzzyClusterMerger::produce(), cosmic::TrackPFParticleMatch::produce(), cluster::BlurredClustering::produce(), cosmic::CosmicPFParticleTagger::produce(), opdet::OpHitFinder::produce(), shower::EMShower::produce(), trkf::TrackKalmanCheater::produce(), cosmic::CosmicPCAxisTagger::produce(), t0::MCParticleShowerMatching::produce(), t0::MCParticleTrackMatching::produce(), CRHitRemovalByPCA::produce(), lbne::PhotonCounterT0Matching::produce(), t0::MCTruthT0Matching::produce(), art::DataViewImpl::removeCachedProduct(), and cluster::ClusterMergeHelper::SetClusters().

191 {
192  return prod_ && prov_.isValid();
193 }
T const * prod_
Definition: Handle.h:128
bool isValid() const
Definition: Provenance.h:120
Provenance prov_
Definition: Handle.h:129
template<class T >
T const & art::Handle< T >::operator* ( ) const
inline

Definition at line 160 of file Handle.h.

References art::Handle< T >::product().

161 {
162  return *product();
163 }
T const * product() const
Definition: Handle.h:167
template<class T >
T const * art::Handle< T >::operator-> ( ) const
inline

Definition at line 180 of file Handle.h.

References art::Handle< T >::product().

181 {
182  return product();
183 }
T const * product() const
Definition: Handle.h:167
template<class T >
T const * art::Handle< T >::product ( ) const

Definition at line 167 of file Handle.h.

References art::Handle< T >::failedToGet(), art::errors::NullPointerError, art::Handle< T >::prod_, and art::Handle< T >::whyFailed_.

Referenced by sim::DumpMCTruth::analyze(), sim::DumpGTruth::analyze(), art::Handle< T >::operator*(), art::Handle< T >::operator->(), and trkf::KalmanFilterTrajectoryFitter::produce().

168 {
169  if (failedToGet())
170  throw *whyFailed_;
171 
172  if (prod_ == nullptr)
174  << "Attempt to de-reference product that points to 'nullptr'";
175 
176  return prod_;
177 }
T const * prod_
Definition: Handle.h:128
std::shared_ptr< art::Exception const > whyFailed_
Definition: Handle.h:130
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
bool failedToGet() const
Definition: Handle.h:197
template<class T>
void art::Handle< T >::swap ( Handle< T > &  other)

Definition at line 230 of file Handle.h.

References art::swap().

Referenced by art::Handle< T >::clear(), and art::convert_handle().

231 {
232  std::swap(*this, other);
233 }
void swap(ValidHandle< T > &a, ValidHandle< T > &b)
template<class T >
std::shared_ptr< art::Exception const > art::Handle< T >::whyFailed ( ) const
inline

Definition at line 220 of file Handle.h.

References art::Handle< T >::whyFailed_.

Referenced by anab::FVectorReader< T, N >::FVectorReader(), and cheat::PhotonBackTracker::Rebuild().

221 {
222  return whyFailed_;
223 }
std::shared_ptr< art::Exception const > whyFailed_
Definition: Handle.h:130

Member Data Documentation

template<typename T>
T const* art::Handle< T >::prod_ {nullptr}
private
template<typename T>
Provenance art::Handle< T >::prov_ {}
private
template<typename T>
std::shared_ptr<art::Exception const> art::Handle< T >::whyFailed_ {nullptr}
private

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