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
 Output file. More...
 

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_() {}
std::string path_
std::string dir_
std::string descr_

◆ ~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

Member Function Documentation

◆ _cd()

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

Definition at line 17 of file TFileDirectory.cc.

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

Referenced by make().

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 }
std::string path_
TDirectory * _mkdir(TDirectory *dirPtr, const std::string &dir, const std::string &description) const
std::string fullPath() const
return the full path of the stored histograms
std::string dir_
std::string descr_

◆ _getObj()

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

Definition at line 97 of file TFileDirectory.cc.

References Exception, and mkLumiAveragedPlots::subdir.

Referenced by getObject().

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 }
TDirectory * getBareDirectory(const std::string &subdir="") const

◆ _mkdir()

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

Definition at line 69 of file TFileDirectory.cc.

References makeListRunsInFiles::description, sistrip::dir_, Exception, oniaPATMuonsWithTrigger_cff::matches, and path_.

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 }
std::string path_
TDirectory * _mkdir(TDirectory *dirPtr, const std::string &dir, const std::string &description) const
std::string dir_

◆ 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.

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

Referenced by TFileService::fullPath().

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

◆ getBareDirectory()

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

Definition at line 10 of file TFileDirectory.cc.

References mkLumiAveragedPlots::subdir.

Referenced by TFileService::getBareDirectory().

10 { return _cd(subdir, false); }
TDirectory * _cd(const std::string &subdir="", bool createNeededDirectories=true) const

◆ getObject()

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

Definition at line 40 of file TFileDirectory.h.

References _getObj(), Exception, and mkLumiAveragedPlots::subdir.

Referenced by TFileService::getObject().

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  }
TObject * _getObj(const std::string &objname, const std::string &subdir="") const
long double T

◆ 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.

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

Referenced by cms::SiPixelCondObjOfflineReader::analyze(), cms::SiPixelCondObjReader::analyze(), cms::SiPixelCondObjAllPayloadsReader::analyze(), cms::SiPixelCondObjForHLTReader::analyze(), HFPMTHitAnalyzer::beginJob(), L1GctValidation::beginJob(), l1t::L1TGlobalAnalyzer::beginJob(), NearbyPixelClustersAnalyzer::beginJob(), PrimaryVertexValidation::beginJob(), SplitVertexResolution::beginJob(), HistoParams< T >::beginRun(), HistoParams< TH2F >::beginRun(), HistoParams< TProfile2D >::beginRun(), BigEventsDebugger< T >::BigEventsDebugger(), 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(), TrackerTreeGenerator::endJob(), PrimaryVertexValidation::endJob(), SplitVertexResolution::endJob(), DMRChecker::endJob(), GctErrorAnalyzer::GctErrorAnalyzer(), HCalSD::HCalSD(), HFGflash::HFGflash(), HFShowerParam::HFShowerParam(), main(), TFileService::make(), tmtt::Histos::makeEfficiencyPlot(), MultiplicityTimeCorrelations::MultiplicityTimeCorrelations(), GctErrorAnalyzer::plotEGErrors(), GctErrorAnalyzer::plotHFErrors(), GctErrorAnalyzer::plotJetErrors(), GctErrorAnalyzer::plotMissingEErrors(), GctErrorAnalyzer::plotTotalEErrors(), TestPythiaDecays::TestPythiaDecays(), tmtt::Histos::trackerGeometryAnalysis(), and TrackerGeometryCompare::TrackerGeometryCompare().

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  }
TDirectory * _cd(const std::string &subdir="", bool createNeededDirectories=true) const
d
Definition: ztail.py:151
long double T

◆ 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

Output file.

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

Definition at line 86 of file TFileDirectory.h.