LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
art::TFileDirectory Class Reference

#include "TFileDirectory.h"

Inheritance diagram for art::TFileDirectory:
art::TFileService

Public Member Functions

virtual ~TFileDirectory ()=default
 
template<typename T , typename... ARGS>
T * make (ARGS...args) const
 
template<typename T , typename... ARGS>
T * makeAndRegister (char const *name, char const *title, ARGS...args) const
 
template<typename T , typename... ARGS>
T * makeAndRegister (std::string const &name, std::string const &title, ARGS...args) const
 
TFileDirectory mkdir (std::string const &dir, std::string const &descr="")
 

Protected Types

using Callback_t = std::function< void()>
 

Protected Member Functions

 TFileDirectory (std::string const &dir, std::string const &descr, TFile *file, std::string const &path)
 Create a new TFileDirectory object. More...
 
void invokeCallbacks ()
 
void registerCallback (Callback_t)
 
std::string fullPath () const
 

Protected Attributes

TFile * file_
 
std::string dir_
 
std::string descr_
 
bool requireCallback_ {false}
 

Private Member Functions

void cd () const
 

Private Attributes

std::string path_
 
std::map< std::string, std::vector< Callback_t > > callbacks_ {}
 

Detailed Description

Definition at line 24 of file TFileDirectory.h.

Member Typedef Documentation

using art::TFileDirectory::Callback_t = std::function<void()>
protected

Definition at line 52 of file TFileDirectory.h.

Constructor & Destructor Documentation

virtual art::TFileDirectory::~TFileDirectory ( )
virtualdefault
art::TFileDirectory::TFileDirectory ( std::string const &  dir,
std::string const &  descr,
TFile *  file,
std::string const &  path 
)
protected

Create a new TFileDirectory object.

Definition at line 11 of file TFileDirectory.cc.

References descr_, dir, dir_, and path_.

15  : file_{file}, dir_{dir}, descr_{descr}, path_{path}
16 {}
TDirectory * dir
Definition: macro.C:5
TFile * file

Member Function Documentation

void art::TFileDirectory::cd ( ) const
private

Make the current directory be the one implied by the state of this TFileDirectory.

Definition at line 36 of file TFileDirectory.cc.

References callbacks_, art::errors::Configuration, descr_, dir, dir_, file_, fullPath(), path_, and requireCallback_.

Referenced by make(), makeAndRegister(), and mkdir().

37 {
38  auto const& fpath = fullPath();
39  if (requireCallback_) {
40  auto it = callbacks_.find(dir_);
41  if (it == cend(callbacks_)) {
43  "A TFileService error occured while attempting to make a "
44  "directory or ROOT object.\n"}
45  << "File-switching has been enabled for TFileService. All modules "
46  "must register\n"
47  << "a callback function to be invoked whenever a file switch occurs. "
48  "The callback\n"
49  << "must ensure that any pointers to ROOT objects have been "
50  "updated.\n\n"
51  << " No callback has been registered for module '" << fpath << "'.\n\n"
52  << "Contact artists@fnal.gov for guidance.";
53  }
54  }
55 
56  TDirectory* dir = file_->GetDirectory(fpath.c_str());
57  if (dir == nullptr) {
58  if (!path_.empty()) {
59  dir = file_->GetDirectory(path_.c_str());
60  if (dir == nullptr) {
61  throw cet::exception("InvalidDirectory")
62  << "Can't change directory to path: " << path_;
63  }
64  } else {
65  dir = file_;
66  }
67  dir = dir->mkdir(dir_.c_str(), descr_.c_str());
68  if (dir == nullptr) {
69  throw cet::exception("InvalidDirectory")
70  << "Can't create directory " << dir_ << " in path: " << path_;
71  }
72  }
73  if (!file_->cd(fpath.c_str())) {
74  throw cet::exception("InvalidDirectory")
75  << "Can't change directory to path: " << fpath;
76  }
77 }
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
TDirectory * dir
Definition: macro.C:5
std::string fullPath() const
std::map< std::string, std::vector< Callback_t > > callbacks_
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33
std::string art::TFileDirectory::fullPath ( ) const
protected

Return the full pathname of the current directory, formed from appending 'dir' to the end of 'path'.

Definition at line 80 of file TFileDirectory.cc.

References dir_, and path_.

Referenced by cd(), and mkdir().

81 {
82  return path_.empty() ? dir_ : path_ + "/" + dir_;
83 }
void art::TFileDirectory::invokeCallbacks ( )
protected

Definition at line 19 of file TFileDirectory.cc.

References callbacks_, dir_, and f.

Referenced by art::TFileService::maybeSwitchFiles_().

20 {
21  for (auto const& pr : callbacks_) {
22  dir_ = pr.first;
23  for (auto f : pr.second) {
24  f();
25  }
26  }
27 }
TFile f
Definition: plotHisto.C:6
std::map< std::string, std::vector< Callback_t > > callbacks_
template<typename T , typename... ARGS>
T * art::TFileDirectory::make ( ARGS...  args) const

make new ROOT object of type T, using constructor parameters args. It will be made in the 'current directory', as established with a call to 'cd'.

Definition at line 82 of file TFileDirectory.h.

References cd().

Referenced by opdet::OpHitAna::analyze(), opdet::OpDigiAna::analyze(), opdet::OpFlashAna::analyze(), mvapid::MVAPID::beginJob(), lar_pandora::PFParticleTrackAna::beginJob(), lar_pandora::PFParticleCosmicAna::beginJob(), lar_pandora::PFParticleAnalysis::beginJob(), lar_pandora::PFParticleHitDumper::beginJob(), lar_pandora::PFParticleMonitoring::beginJob(), pid::PIDAAnalyzer::beginJob(), opdet::OpFlashSimpleAna::beginJob(), phot::PhotonLibraryAnalyzer::beginJob(), filt::FinalStateParticleFilter::beginJob(), opreco::OpticalRecoAna::beginJob(), filt::FinalStateSelectFilter::beginJob(), spacecharge::ShiftEdepSCE::beginJob(), opdet::FlashHypothesisAna::beginJob(), cluster::ClusterPCA::beginJob(), larg4::ISCalculationAna::beginJob(), DUNE::NeutrinoShowerEff::beginJob(), cluster::TrajCluster::beginJob(), vertex::AggregateVertexAna::beginJob(), evgen::CosmicsGen::beginJob(), ShowerQuality::beginJob(), hit::HitAnaModule::beginJob(), filt::EmptyFilter::beginJob(), cluster::DBcluster::beginJob(), rwgt::ReweightAna::beginJob(), caldata::CalWireAna::beginJob(), cluster::fuzzyCluster::beginJob(), microboone::CosmicRemovalAna::beginJob(), detsim::SimWireAna::beginJob(), evgen::NUANCEGen::beginJob(), larg4::LArG4Ana::beginJob(), trkf::TrackKalmanCheater::beginJob(), DUNE::NeutrinoTrackingEff::beginJob(), vertex::PrimaryVertexFinder::beginJob(), pfpf::PFPAna::beginJob(), cluster::ClusterAna::beginJob(), reco3d::SpacePointSolver::beginJob(), DUNE::MuonTrackingEff::beginJob(), vertex::HarrisVertexFinder::beginJob(), detsim::WienerFilterAna::beginJob(), evgen::NDKGen::beginJob(), cluster::DBclusterAna::beginJob(), hit::HitFinderAna::beginJob(), hit::GausHitFinderAna::beginJob(), hit::GausHitFinder::beginJob(), trkf::Track3DKalmanHit::beginJob(), cluster::HoughLineFinderAna::beginJob(), vertex::VertexFinder2D::beginJob(), evgen::GaisserParam::beginJob(), opdet::SimPhotonCounter::beginJob(), detsim::SimWire::beginJob(), hit::DPRawHitFinder::beginJob(), shwf::ShowerReco::beginJob(), detsim::SimWireT962::beginJob(), vertex::FeatureVertexFinderAna::beginJob(), trkf::Track3DKalman::beginJob(), evgen::GENIEGen::beginJob(), lbne::PhotonCounterT0Matching::beginJob(), trkf::Track3DKalmanSPS::beginJob(), t0::MCTruthT0Matching::beginJob(), evgen::MUSUN::beginJob(), ems::MultiEMShowers::beginJob(), lar::example::AnalysisExample::beginJob(), ems::MergeEMShower3D::beginJob(), cheat::RecoCheckAna::beginRun(), trkf::SpacePointAna::bookHistograms(), reco_tool::CandHitDerivative::configure(), reco_tool::CandHitMorphological::configure(), detsim::SimWire::ConvoluteResponseFunctions(), detsim::SimWireT962::ConvoluteResponseFunctions(), tca::HistStuff::CreateHists(), DUNE::NeutrinoShowerEff::doEfficiencies(), DUNE::NeutrinoTrackingEff::doEfficiencies(), shower::EMShowerAlg::EMShowerAlg(), opdet::LEDCalibrationAna::endJob(), larg::LArSimChannelAna::ensureHists(), hit::MagDriftAna::ensureHists(), reco_tool::CandHitMorphological::findHitCandidates(), reco_tool::CandHitDerivative::findHitCandidates(), lar_cluster3d::Cluster3D::InitializeMonitoring(), larg4::IonizationAndScintillation::IonizationAndScintillation(), opdet::LEDCalibrationAna::LEDCalibrationAna(), evgen::LightSource::LightSource(), evgen::MarleyTimeGen::make_nu_emission_histograms(), evgen::MarleyGen::MarleyGen(), evgen::MarleyTimeGen::MarleyTimeGen(), trkf::SeedAna::MCHists::MCHists(), trkf::TrackAna::MCHists::MCHists(), cluster::MergeClusterAlg::MergeClusterAlg(), opdet::OpFlashAna::OpFlashAna(), opdet::OpHitAna::OpHitAna(), trkf::PMAlgTrackMaker::PMAlgTrackMaker(), cluster::ClusterMatchAlg::PrepareTTree(), trkf::SeedAna::RecoHists::RecoHists(), trkf::TrackAna::RecoHists::RecoHists(), detsim::SimWire::SetElectResponse(), detsim::SimWireT962::SetElectResponse(), detsim::SimWire::SetFieldResponse(), detsim::SimWireT962::SetFieldResponse(), phot::PhotonLibrary::StoreLibraryToFile(), trk::TrackContainmentAnalyzer::TrackContainmentAnalyzer(), and trk::TrackContainmentTagger::TrackContainmentTagger().

83  {
84  detail::RootDirectorySentry sentry;
85  cd();
86  return new T(args...);
87  }
template<typename T , typename... ARGS>
T * art::TFileDirectory::makeAndRegister ( char const *  name,
char const *  title,
ARGS...  args 
) const

make and register a new ROOT object of type T, giving it the specified name and title, using constructor parameters 'args'. The type must be registerable, and must support naming and titling.

Definition at line 91 of file TFileDirectory.h.

References cd().

Referenced by makeAndRegister().

94  {
95  detail::RootDirectorySentry sentry;
96  cd();
97  T* p = new T(args...);
98  p->SetName(name);
99  p->SetTitle(title);
100  gDirectory->Append(p);
101  return p;
102  }
template<typename T , typename... ARGS>
T * art::TFileDirectory::makeAndRegister ( std::string const &  name,
std::string const &  title,
ARGS...  args 
) const

Definition at line 106 of file TFileDirectory.h.

References makeAndRegister().

109  {
110  return makeAndRegister(name.c_str(), title.c_str(), args...);
111  }
T * makeAndRegister(char const *name, char const *title, ARGS...args) const
art::TFileDirectory art::TFileDirectory::mkdir ( std::string const &  dir,
std::string const &  descr = "" 
)

Create a new TFileDirectory, sharing the same TFile as this one, but with an additional 'dir', and with 'path' being the fullPath() of this one.

Definition at line 86 of file TFileDirectory.cc.

References cd(), dir, file_, and fullPath().

Referenced by opdet::FIFOHistogramAna::analyze(), trkf::TrackKalmanCheater::beginJob(), trkf::Track3DKalmanHit::beginJob(), trkf::SpacePointAna::bookHistograms(), reco_tool::CandHitMorphological::configure(), reco_tool::CandHitDerivative::configure(), reco_tool::CandHitMorphological::findHitCandidates(), reco_tool::CandHitDerivative::findHitCandidates(), trkf::SeedAna::MCHists::MCHists(), trkf::TrackAna::MCHists::MCHists(), trkf::SeedAna::RecoHists::RecoHists(), and trkf::TrackAna::RecoHists::RecoHists().

87 {
88  detail::RootDirectorySentry sentry;
89  cd();
90  return TFileDirectory{dir, descr, file_, fullPath()};
91 }
TDirectory * dir
Definition: macro.C:5
std::string fullPath() const
TFileDirectory(std::string const &dir, std::string const &descr, TFile *file, std::string const &path)
Create a new TFileDirectory object.
void art::TFileDirectory::registerCallback ( Callback_t  cb)
protected

Definition at line 30 of file TFileDirectory.cc.

References callbacks_, and dir_.

Referenced by art::TFileService::registerFileSwitchCallback().

31 {
32  callbacks_[dir_].push_back(cb);
33 }
std::map< std::string, std::vector< Callback_t > > callbacks_

Member Data Documentation

std::map<std::string, std::vector<Callback_t> > art::TFileDirectory::callbacks_ {}
private

Definition at line 77 of file TFileDirectory.h.

Referenced by cd(), invokeCallbacks(), and registerCallback().

std::string art::TFileDirectory::descr_
protected

Definition at line 69 of file TFileDirectory.h.

Referenced by cd(), art::TFileService::setDirectoryName_(), and TFileDirectory().

std::string art::TFileDirectory::dir_
protected
TFile* art::TFileDirectory::file_
protected
std::string art::TFileDirectory::path_
private

Definition at line 73 of file TFileDirectory.h.

Referenced by cd(), fullPath(), and TFileDirectory().

bool art::TFileDirectory::requireCallback_ {false}
protected

Definition at line 70 of file TFileDirectory.h.

Referenced by cd(), and art::TFileService::TFileService().


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