CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes | Friends
TFileDirectory Class Reference

#include <TFileDirectory.h>

Inheritance diagram for TFileDirectory:
fwlite::TFileService

Public Member Functions

bool cd () const
 
std::string fullPath () const
 return the full path of the stored histograms More...
 
TDirectory * getBareDirectory (const std::string &subdir="") const
 
template<typename T >
TgetObject (const std::string &objname, const std::string &subdir="")
 
template<typename T , typename... Args>
Tmake (const Args &... args) const
 make new ROOT object More...
 
TFileDirectory mkdir (const std::string &dir, const std::string &descr="")
 create a new subdirectory More...
 
 TFileDirectory ()
 
virtual ~TFileDirectory ()
 descructor More...
 

Private Member Functions

TDirectory * _cd (const std::string &subdir="", bool createNeededDirectories=true) const
 
TObject * _getObj (const std::string &objname, const std::string &subdir="") const
 
TDirectory * _mkdir (TDirectory *dirPtr, const std::string &dir, const std::string &description) const
 
 TFileDirectory (const std::string &dir, const std::string &descr, TFile *file, const std::string &path)
 

Private Attributes

std::string descr_
 
std::string dir_
 
TFile * file_
 
std::string path_
 

Friends

class fwlite::TFileService
 
class TFileService
 

Detailed Description

Definition at line 24 of file TFileDirectory.h.

Constructor & Destructor Documentation

◆ TFileDirectory() [1/2]

TFileDirectory::TFileDirectory ( )
inline

Definition at line 26 of file TFileDirectory.h.

26 : file_(nullptr), dir_(), descr_(), path_() {}

◆ ~TFileDirectory()

virtual TFileDirectory::~TFileDirectory ( )
inlinevirtual

descructor

Definition at line 29 of file TFileDirectory.h.

29 {}

◆ TFileDirectory() [2/2]

TFileDirectory::TFileDirectory ( const std::string &  dir,
const std::string &  descr,
TFile *  file,
const std::string &  path 
)
inlineprivate

Definition at line 81 of file TFileDirectory.h.

82  : file_(file), dir_(dir), descr_(descr), path_(path) {}

Member Function Documentation

◆ _cd()

TDirectory * TFileDirectory::_cd ( const std::string &  subdir = "",
bool  createNeededDirectories = true 
) const
private

Definition at line 17 of file TFileDirectory.cc.

17  {
18  string fpath = fullPath();
19  if (subdir.length()) {
20  // not empty, we need to append it to path
21  if (fpath.length()) {
22  // path is also not empty, so add a slash and let's get going.
23  fpath += "/" + subdir;
24  } else {
25  // path doesn't exist, so just use subdir
26  fpath = subdir;
27  }
28  }
29  TDirectory *dir = file_->GetDirectory(fpath.c_str());
30  if (dir == nullptr) {
31  // we didn't find the directory
32  //
33  // If we're not supposed to create the diretory, then we should
34  // complain now that it doesn't exist.
35  if (!createNeededDirectories) {
36  cout << "here " << fpath << endl;
37  throw cms::Exception("InvalidDirectory") << "directory " << fpath << " doesn't exist.";
38  }
39  if (!path_.empty()) {
40  dir = file_->GetDirectory(path_.c_str());
41  if (dir == nullptr) {
42  throw cms::Exception("InvalidDirectory") << "Can't change directory to path: " << path_;
43  }
44  } else {
45  // the base path 'path_' is empty, so just use the pointer to
46  // the file.
47  dir = file_;
48  }
49  // if a subdirectory was passed in, then this directory better
50  // already exist (since you shoudln't be cd'ing into a directory
51  // before making it and the cd with a subdir is only used to get
52  // histograms that are already made).
53  if (subdir.length()) {
54  throw cms::Exception("InvalidDirectory") << "directory " << fpath << " doesn't exist.";
55  }
56  // if we're here, then that means that this is the first time
57  // that we are calling cd() on this directory AND cd() has not
58  // been called with a subdirectory, so go ahead and make the
59  // directory.
60  dir = _mkdir(dir, dir_, descr_);
61  }
62  bool ok = file_->cd(fpath.c_str());
63  if (!ok) {
64  throw cms::Exception("InvalidDirectory") << "Can't change directory to path: " << fpath;
65  }
66  return dir;
67 }

References gather_cfg::cout, DeadROC_duringRun::dir, sistrip::dir_, Exception, contentValuesFiles::fullPath, convertSQLiteXML::ok, and path_.

Referenced by make().

◆ _getObj()

TObject * TFileDirectory::_getObj ( const std::string &  objname,
const std::string &  subdir = "" 
) const
private

Definition at line 97 of file TFileDirectory.cc.

97  {
98  TObject *objPtr = getBareDirectory(subdir)->Get(objname.c_str());
99  if (!objPtr) {
100  // no histogram found by that name. Sorry dude.
101  if (subdir.length()) {
102  throw cms::Exception("ObjectNotFound") << "Can not find object named " << objname << " in subdir " << subdir;
103  } else {
104  throw cms::Exception("ObjectNotFound") << "Can not find object named " << objname;
105  }
106  } // if nothing found
107  return objPtr;
108 }

References Exception.

Referenced by getObject().

◆ _mkdir()

TDirectory * TFileDirectory::_mkdir ( TDirectory *  dirPtr,
const std::string &  dir,
const std::string &  description 
) const
private

Definition at line 69 of file TFileDirectory.cc.

69  {
70  // do we have this one already
71  TDirectory *subdirPtr = dirPtr->GetDirectory(subdirName.c_str());
72  if (subdirPtr) {
73  subdirPtr->cd();
74  return subdirPtr;
75  }
76  // if we're here, then this directory doesn't exist. Is this
77  // directory a subdirectory?
78  const boost::regex subdirRE("(.+?)/([^/]+)");
79  boost::smatch matches;
80  TDirectory *parentDir = nullptr;
81  string useName = subdirName;
82  if (boost::regex_match(subdirName, matches, subdirRE)) {
83  parentDir = _mkdir(dirPtr, matches[1], description);
84  useName = matches[2];
85  } else {
86  // This is not a subdirectory, so we're golden
87  parentDir = dirPtr;
88  }
89  subdirPtr = parentDir->mkdir(useName.c_str());
90  if (!subdirPtr) {
91  throw cms::Exception("InvalidDirectory") << "Can't create directory " << dir_ << " in path: " << path_;
92  }
93  subdirPtr->cd();
94  return subdirPtr;
95 }

References edmLumisInFiles::description, sistrip::dir_, Exception, patCandidatesForDimuonsSequences_cff::matches, and path_.

◆ cd()

bool TFileDirectory::cd ( ) const

◆ fullPath()

std::string TFileDirectory::fullPath ( ) const

return the full path of the stored histograms

Definition at line 110 of file TFileDirectory.cc.

110 { return string(path_.empty() ? dir_ : path_ + "/" + dir_); }

References sistrip::dir_, path_, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by TFileService::fullPath().

◆ getBareDirectory()

TDirectory * TFileDirectory::getBareDirectory ( const std::string &  subdir = "") const

Definition at line 10 of file TFileDirectory.cc.

10 { return _cd(subdir, false); }

Referenced by TFileService::getBareDirectory().

◆ getObject()

template<typename T >
T* TFileDirectory::getObject ( const std::string &  objname,
const std::string &  subdir = "" 
)
inline

Definition at line 40 of file TFileDirectory.h.

40  {
41  TObject *objPtr = _getObj(objname, subdir);
42  // Ok, we've got it. Let's see if it's a histogram
43  T *retval = dynamic_cast<T *>(objPtr);
44  if (!retval) {
45  // object isn't a of class T
46  throw cms::Exception("ObjectNotCorrectlyTyped") << "Object named " << objname << " is not of correct type";
47  }
48  return retval;
49  }

References _getObj(), and Exception.

Referenced by TFileService::getObject().

◆ make()

template<typename T , typename... Args>
T* TFileDirectory::make ( const Args &...  args) const
inline

make new ROOT object

Definition at line 53 of file TFileDirectory.h.

53  {
54  TDirectory *d = _cd();
55  T *t = new T(args...);
56  ROOT::DirAutoAdd_t func = T::Class()->GetDirectoryAutoAdd();
57  if (func) {
58  TH1AddDirectorySentry sentry;
59  func(t, d);
60  } else {
61  d->Append(t);
62  }
63  return t;
64  }

References _cd(), writedatasetfile::args, HLT_FULL_cff::Class, ztail::d, TrackCollections2monitor_cff::func, and submitPVValidationJobs::t.

Referenced by AnalysisTasksAnalyzerBTag::AnalysisTasksAnalyzerBTag(), AnalysisTasksAnalyzerJEC::AnalysisTasksAnalyzerJEC(), BasicMuonAnalyzer::BasicMuonAnalyzer(), HFPMTHitAnalyzer::beginJob(), L1GctValidation::beginJob(), l1t::L1TGlobalAnalyzer::beginJob(), PrimaryVertexValidation::beginJob(), SplitVertexResolution::beginJob(), HistoParams< T >::beginRun(), HistoParams< TH2F >::beginRun(), HistoParams< TProfile2D >::beginRun(), BigEventsDebugger< T >::BigEventsDebugger(), BjetAnalysis::BjetAnalysis(), AlignmentMonitorSurvey::book(), DigiBXCorrHistogramMaker< EventWithHistory >::book(), VertexHistogramMaker::book(), BSvsPVHistogramMaker::book(), AlignmentMonitorMuonResiduals::book(), AlignmentMonitorBase::book1D(), AlignmentMonitorBase::book2D(), tmtt::Histos::bookEtaPhiSectors(), L1GtDataEmulAnalyzer::bookHistograms(), tmtt::Histos::bookInputData(), AlignmentMonitorBase::bookProfile(), ApeEstimator::bookSectorHistsForAnalyzerMode(), ApeEstimator::bookSectorHistsForApeCalculation(), tmtt::Histos::bookTrackCands(), tmtt::Histos::bookTrackFitting(), ApeEstimator::bookTrackHists(), ECalSD::ECalSD(), PatBTagAnalyzer::endJob(), TrackerTreeGenerator::endJob(), PrimaryVertexValidation::endJob(), SplitVertexResolution::endJob(), DMRChecker::endJob(), EWKSystUnc::EWKSystUnc(), GctErrorAnalyzer::GctErrorAnalyzer(), GlbMuQualityCutsAnalysis::GlbMuQualityCutsAnalysis(), HCalSD::HCalSD(), HFGflash::HFGflash(), HFShowerParam::HFShowerParam(), ExpressionHisto< T >::initialize(), main(), TFileService::make(), tmtt::Histos::makeEfficiencyPlot(), MultiplicityTimeCorrelations::MultiplicityTimeCorrelations(), PatMuonAnalyzer::PatMuonAnalyzer(), GctErrorAnalyzer::plotEGErrors(), GctErrorAnalyzer::plotHFErrors(), GctErrorAnalyzer::plotJetErrors(), GctErrorAnalyzer::plotMissingEErrors(), GctErrorAnalyzer::plotTotalEErrors(), tmtt::Histos::trackerGeometryAnalysis(), TrackerGeometryCompare::TrackerGeometryCompare(), TSOSHistogramMaker::TSOSHistogramMaker(), ZHistogrammer::ZHistogrammer(), ZLONLOHistogrammer::ZLONLOHistogrammer(), ZMCHistogrammer::ZMCHistogrammer(), ZMuMu_efficiencyAnalyzer::ZMuMu_efficiencyAnalyzer(), ZMuMuAnalyzer_cynematics::ZMuMuAnalyzer_cynematics(), ZMuMuEfficiency::ZMuMuEfficiency(), ZMuPtScaleAnalyzer::ZMuPtScaleAnalyzer(), and zPdfUnc::zPdfUnc().

◆ mkdir()

TFileDirectory TFileDirectory::mkdir ( const std::string &  dir,
const std::string &  descr = "" 
)

Friends And Related Function Documentation

◆ fwlite::TFileService

friend class fwlite::TFileService
friend

Definition at line 84 of file TFileDirectory.h.

◆ TFileService

friend class TFileService
friend

Definition at line 83 of file TFileDirectory.h.

Member Data Documentation

◆ descr_

std::string TFileDirectory::descr_
private

Definition at line 86 of file TFileDirectory.h.

Referenced by TFileService::setDirectoryName().

◆ dir_

std::string TFileDirectory::dir_
private

Definition at line 86 of file TFileDirectory.h.

Referenced by TFileService::setDirectoryName().

◆ file_

TFile* TFileDirectory::file_
private

Definition at line 85 of file TFileDirectory.h.

Referenced by TFileService::setDirectoryName(), and TFileService::TFileService().

◆ path_

std::string TFileDirectory::path_
private
writedatasetfile.args
args
Definition: writedatasetfile.py:18
TFileDirectory::fullPath
std::string fullPath() const
return the full path of the stored histograms
Definition: TFileDirectory.cc:110
HLT_FULL_cff.Class
Class
Definition: HLT_FULL_cff.py:8427
TFileDirectory::dir_
std::string dir_
Definition: TFileDirectory.h:86
edmLumisInFiles.description
description
Definition: edmLumisInFiles.py:11
gather_cfg.cout
cout
Definition: gather_cfg.py:144
TFileDirectory::path_
std::string path_
Definition: TFileDirectory.h:86
TFileDirectory::file_
TFile * file_
Definition: TFileDirectory.h:85
convertSQLiteXML.ok
bool ok
Definition: convertSQLiteXML.py:98
TFileDirectory::TFileDirectory
TFileDirectory()
Definition: TFileDirectory.h:26
TFileDirectory::descr_
std::string descr_
Definition: TFileDirectory.h:86
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
TFileDirectory::_getObj
TObject * _getObj(const std::string &objname, const std::string &subdir="") const
Definition: TFileDirectory.cc:97
FrontierConditions_GlobalTag_cff.file
file
Definition: FrontierConditions_GlobalTag_cff.py:13
TFileDirectory::getBareDirectory
TDirectory * getBareDirectory(const std::string &subdir="") const
Definition: TFileDirectory.cc:10
TrackCollections2monitor_cff.func
func
Definition: TrackCollections2monitor_cff.py:359
TFileDirectory::_cd
TDirectory * _cd(const std::string &subdir="", bool createNeededDirectories=true) const
Definition: TFileDirectory.cc:17
T
long double T
Definition: Basic3DVectorLD.h:48
Exception
Definition: hltDiff.cc:246
TFileDirectory::_mkdir
TDirectory * _mkdir(TDirectory *dirPtr, const std::string &dir, const std::string &description) const
Definition: TFileDirectory.cc:69
patCandidatesForDimuonsSequences_cff.matches
matches
Definition: patCandidatesForDimuonsSequences_cff.py:131
ztail.d
d
Definition: ztail.py:151
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
TH1AddDirectorySentry
Definition: TH1AddDirectorySentry.h:24
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23