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

#include "fwd.h"

Classes

class  HandleTag
 

Public Types

using element_type = T
 

Public Member Functions

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

Private Attributes

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

Detailed Description

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

Definition at line 19 of file fwd.h.

Member Typedef Documentation

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

Definition at line 100 of file Handle.h.

Constructor & Destructor Documentation

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

Definition at line 143 of file Handle.h.

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

144  : group_{gqr.result()}, prov_{group_}, whyFailed_{gqr.whyFailed()}
145 {
146  if (gqr.succeeded()) {
147  auto const wrapperPtr = dynamic_cast<Wrapper<T> const*>(
148  gqr.result()->uniqueProduct(TypeID{typeid(Wrapper<T>)}));
149  if (wrapperPtr != nullptr) {
150  prod_ = wrapperPtr->product();
151  } else {
153  e << "Product retrieval via Handle<T> succeeded for product:\n"
155  << "but an attempt to interpret it as an object of type '"
156  << cet::demangle_symbol(typeid(T).name()) << "' failed.\n";
157  whyFailed_ = std::make_shared<art::Exception const>(std::move(e));
158  }
159  }
160 }
BranchDescription const & productDescription() const noexcept
Definition: Provenance.cc:24
T const * prod_
Definition: Handle.h:133
std::shared_ptr< art::Exception const > whyFailed_
Definition: Handle.h:136
Provenance prov_
Definition: Handle.h:135
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
Float_t e
Definition: plot.C:35
cet::exempt_ptr< Group > group_
Definition: Handle.h:134
template<typename T>
art::Handle< T >::Handle ( Handle< T > const &  )
default
template<typename T>
art::Handle< T >::Handle ( Handle< T > &&  )
default

Member Function Documentation

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

Definition at line 255 of file Handle.h.

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

Referenced by art::Handle< T >::removeProduct(), and trkf::StitchAlg::StitchAlg().

256 {
257  Handle<T> tmp;
258  swap(tmp);
259 }
void swap(Handle< T > &other)
Definition: Handle.h:248
Float_t tmp
Definition: plot.C:35
template<class T >
bool art::Handle< T >::failedToGet ( ) const

Definition at line 210 of file Handle.h.

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

Referenced by cheat::RecoCheckAna::analyze(), art::Handle< T >::product(), evd::InfoTransfer::Rebuild(), and cheat::PhotonBackTracker::Rebuild().

211 {
212  return whyFailed_.get();
213 }
std::shared_ptr< art::Exception const > whyFailed_
Definition: Handle.h:136
template<class T >
art::ProductID art::Handle< T >::id ( ) const
inline

Definition at line 224 of file Handle.h.

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

Referenced by cluster::ClusterTrackAna::analyze().

225 {
226  return prov_.isValid() ? prov_.productID() : ProductID{};
227 }
bool isValid() const noexcept
Definition: Provenance.cc:18
ProductID productID() const noexcept
Definition: Provenance.cc:72
Provenance prov_
Definition: Handle.h:135
template<class T >
bool art::Handle< T >::isValid ( ) const
noexcept

Definition at line 203 of file Handle.h.

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

Referenced by shower::TCShowerAnalysis::analyze(), MCBTDemo::analyze(), cluster::ClusterAna::analyze(), lar_pandora::ConsolidatedPFParticleAnalysisTemplate::analyze(), cluster::ClusterTrackAna::analyze(), trkf::SpacePointAna::analyze(), trkf::SeedAna::analyze(), trkf::TrackAna::analyze(), trkf::TrackAna::anaStitch(), lar_pandora::LArPandoraHelper::BuildMCParticleHitMaps(), lar_cluster3d::StandardHit3DBuilder::CollectArtHits(), lar_cluster3d::SnippetHit3DBuilder::CollectArtHits(), lar_pandora::LArPandoraHelper::CollectClusters(), lar_pandora::LArPandoraHelper::CollectCosmicTags(), lar_pandora::LArPandoraHelper::CollectGeneratorMCParticles(), lar_pandora::LArPandoraHelper::CollectHits(), lar_pandora::LArPandoraHelper::CollectMCParticles(), lar_pandora::LArPandoraSliceIdHelper::CollectNeutrinoMCParticles(), 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(), t0::DirectHitParticleAssns::CreateHitParticleAssociations(), evdb_tool::OpHit3DDrawer::Draw(), evdb_tool::DrawSimPhoton3D::Draw(), evdb_tool::OpFlash3DDrawer::Draw(), evdb_tool::DrawLArVoxel3D::Draw(), evdb_tool::DrawSimEnergyDeposit3D::drawAll(), evdb_tool::DrawSimEnergyDeposit3D::drawMCPartAssociated(), evd::RecoBaseDrawer::DrawShower3D(), evd::RecoBaseDrawer::DrawShowerOrtho(), evd::RecoBaseDrawer::DrawTrack3D(), evd::RecoBaseDrawer::DrawTrackOrtho(), evdb_tool::DrawRawHist::Fill(), trkf::Track3DKalmanHit::getAllHits(), lar_pandora::LArPandoraSliceIdHelper::GetBeamNeutrinoMCTruth(), trkf::Track3DKalmanHit::getClusteredHits(), lar_pandora::LArPandoraSliceIdHelper::GetHitOrigins(), trkf::Track3DKalmanHit::getPFParticleStuff(), lar_pandora::LArPandoraSliceIdHelper::GetPFParticleToHitsMap(), trkf::SeedFinderModule::GetSortedHitsFromClusters(), lar_cluster3d::SpacePointHit3DBuilder::Hit3DBuilder(), evgb::MCTruthAndFriendsItr::MCTruthAndFriendsItr(), art::Handle< T >::operator bool(), MCReco::produce(), cosmic::TrackPFParticleMatch::produce(), hit::MCHitFinder::produce(), trkf::SpacePointFinder::produce(), trkf::SpacePointCheater::produce(), cosmic::CosmicPFParticleTagger::produce(), noisefilteralg::WireCellNoiseFilter::produce(), CRHitRemoval::produce(), cosmic::CosmicPCAxisTagger::produce(), t0::MCParticleShowerMatching::produce(), t0::MCParticleTrackMatching::produce(), ShowerReco3D::produce(), cluster::BlurredClustering::produce(), trkf::TrackKalmanCheater::produce(), CRHitRemovalByPCA::produce(), lbne::PhotonCounterT0Matching::produce(), shower::EMShower::produce(), t0::MCTruthT0Matching::produce(), opdet::OpHitFinder::produce(), art::Handle< T >::removeProduct(), and cluster::ClusterMergeHelper::SetClusters().

204 {
205  return prod_ && prov_.isValid();
206 }
bool isValid() const noexcept
Definition: Provenance.cc:18
T const * prod_
Definition: Handle.h:133
Provenance prov_
Definition: Handle.h:135
template<class T >
art::Handle< T >::operator bool ( ) const
inlineexplicitnoexcept

Definition at line 196 of file Handle.h.

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

197 {
198  return isValid();
199 }
bool isValid() const noexcept
Definition: Handle.h:203
template<class T >
T const & art::Handle< T >::operator* ( ) const
inline

Definition at line 167 of file Handle.h.

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

168 {
169  return *product();
170 }
T const * product() const
Definition: Handle.h:174
template<class T >
T const * art::Handle< T >::operator-> ( ) const
inline

Definition at line 187 of file Handle.h.

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

188 {
189  return product();
190 }
T const * product() const
Definition: Handle.h:174
template<typename T>
Handle& art::Handle< T >::operator= ( Handle< T > const &  )
default
template<typename T>
Handle& art::Handle< T >::operator= ( Handle< T > &&  )
default
template<class T >
T const * art::Handle< T >::product ( ) const

Definition at line 174 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->(), art::operator<<(), and trkf::KalmanFilterTrajectoryFitter::produce().

175 {
176  if (failedToGet()) {
177  throw *whyFailed_;
178  }
179  if (prod_ == nullptr)
181  << "Attempt to de-reference product that points to 'nullptr'.\n";
182  return prod_;
183 }
T const * prod_
Definition: Handle.h:133
std::shared_ptr< art::Exception const > whyFailed_
Definition: Handle.h:136
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
bool failedToGet() const
Definition: Handle.h:210
template<typename T >
art::EDProductGetter const * art::Handle< T >::productGetter ( ) const
inlinenoexcept

Definition at line 238 of file Handle.h.

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

239 {
240  return group_.get();
241 }
cet::exempt_ptr< Group > group_
Definition: Handle.h:134
template<class T >
bool art::Handle< T >::removeProduct ( )
inline

Definition at line 263 of file Handle.h.

References art::Handle< T >::clear(), art::Handle< T >::group_, art::Handle< T >::isValid(), art::Provenance::produced(), and art::Handle< T >::prov_.

Referenced by hit::MCHitFinder::produce().

264 {
265  if (isValid() && !prov_.produced()) {
266  assert(group_);
267  group_->removeCachedProduct();
268  clear();
269  return true;
270  }
271  return false;
272 }
bool isValid() const noexcept
Definition: Handle.h:203
Provenance prov_
Definition: Handle.h:135
void clear()
Definition: Handle.h:255
bool produced() const noexcept
Definition: Provenance.cc:30
cet::exempt_ptr< Group > group_
Definition: Handle.h:134
template<class T>
void art::Handle< T >::swap ( Handle< T > &  other)

Definition at line 248 of file Handle.h.

References art::swap().

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

249 {
250  std::swap(*this, other);
251 }
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 231 of file Handle.h.

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

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

232 {
233  return whyFailed_;
234 }
std::shared_ptr< art::Exception const > whyFailed_
Definition: Handle.h:136

Member Data Documentation

template<typename T>
cet::exempt_ptr<Group> art::Handle< T >::group_ {nullptr}
private
template<typename T>
T const* art::Handle< T >::prod_ {nullptr}
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: