CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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::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_
virtual TFileDirectory::~TFileDirectory ( )
inlinevirtual

descructor

Definition at line 29 of file TFileDirectory.h.

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

Member Function Documentation

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, and path_.

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_
tuple cout
Definition: gather_cfg.py:144
std::string descr_
TObject * TFileDirectory::_getObj ( const std::string &  objname,
const std::string &  subdir = "" 
) const
private

Definition at line 97 of file TFileDirectory.cc.

References Exception.

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

Definition at line 69 of file TFileDirectory.cc.

References sistrip::dir_, Exception, 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_
bool TFileDirectory::cd ( ) const

Definition at line 12 of file TFileDirectory.cc.

Referenced by TFileService::cd(), dqm_interfaces.DQMcommunicator::get_root_objects_list_recursive(), dqm_interfaces.DQMcommunicator::get_root_objects_names_list_recursive(), dqm_interfaces.DQMcommunicator::get_root_objects_recursive(), and dqm_interfaces.DirWalkerFile::walk().

12  {
13  _cd("", false);
14  return true;
15 }
TDirectory * _cd(const std::string &subdir="", bool createNeededDirectories=true) const
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_
TDirectory * TFileDirectory::getBareDirectory ( const std::string &  subdir = "") const

Definition at line 10 of file TFileDirectory.cc.

Referenced by TFileService::getBareDirectory().

10 { return _cd(subdir, false); }
TDirectory * _cd(const std::string &subdir="", bool createNeededDirectories=true) const
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(), and Exception.

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
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(), ztail::d, cms::cuda::func, and submitPVValidationJobs::t.

Referenced by AnalysisTasksAnalyzerBTag::AnalysisTasksAnalyzerBTag(), AnalysisTasksAnalyzerJEC::AnalysisTasksAnalyzerJEC(), l1t::L1TStage2CaloAnalyzer::analyze(), CentralityTableProducer::analyze(), cms::SiPixelCondObjOfflineReader::analyze(), cms::SiPixelCondObjReader::analyze(), cms::SiPixelCondObjForHLTReader::analyze(), cms::SiPixelCondObjAllPayloadsReader::analyze(), BasicMuonAnalyzer::BasicMuonAnalyzer(), 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(), VertexHistogramMaker::book(), DigiBXCorrHistogramMaker< T >::book(), BSvsPVHistogramMaker::book(), AlignmentMonitorMuonResiduals::book(), ConfigurableHisto::book(), SplittingConfigurableHisto::book(), AlignmentMonitorBase::book1D(), AlignmentMonitorBase::book2D(), TrackerSectorStruct::bookCorrHists(), tmtt::Histos::bookEtaPhiSectors(), DiLeptonHelp::PlotsVsKinematics::bookFromPSet(), StudyCaloGen::bookHistograms(), L1GtDataEmulAnalyzer::bookHistograms(), IsolatedGenParticles::bookHistograms(), IsolatedTracksNxN::bookHistograms(), tmtt::Histos::bookInputData(), DiLeptonHelp::PlotsVsKinematics::bookPlots(), AlignmentMonitorBase::bookProfile(), SplitVertexResolution::bookResidualsHistogram(), PrimaryVertexValidation::bookResidualsHistogram(), DMRChecker::bookResidualsHistogram(), ApeEstimator::bookSectorHistsForAnalyzerMode(), ApeEstimator::bookSectorHistsForApeCalculation(), DMRChecker::bookSplitDMRHistograms(), tmtt::Histos::bookTrackCands(), tmtt::Histos::bookTrackFitting(), ApeEstimator::bookTrackHists(), PrimaryVertexValidation::bookVertexHistograms(), ECalSD::ECalSD(), PatBTagAnalyzer::endJob(), TrackerTreeGenerator::endJob(), PrimaryVertexValidation::endJob(), SplitVertexResolution::endJob(), DMRChecker::endJob(), GctErrorAnalyzer::GctErrorAnalyzer(), HCalSD::HCalSD(), HFGflash::HFGflash(), HFShowerParam::HFShowerParam(), ExpressionHisto< T >::initialize(), main(), TFileService::make(), SiStripSpyDisplayModule::MakeDigiHist_(), tmtt::Histos::makeEfficiencyPlot(), SiStripSpyDisplayModule::MakeProcessedRawDigiHist_(), SiStripSpyDisplayModule::MakeRawDigiHist_(), MultiplicityTimeCorrelations::MultiplicityTimeCorrelations(), PatMuonAnalyzer::PatMuonAnalyzer(), MuonResiduals1DOFFitter::plot(), MuonResidualsPositionFitter::plot(), MuonResidualsAngleFitter::plot(), MuonResidualsBfieldAngleFitter::plot(), MuonResiduals6DOFrphiFitter::plot(), MuonResiduals5DOFFitter::plot(), MuonResiduals6DOFFitter::plot(), GctErrorAnalyzer::plotEGErrors(), GctErrorAnalyzer::plotHFErrors(), GctErrorAnalyzer::plotJetErrors(), GctErrorAnalyzer::plotMissingEErrors(), MuonResidualsFitter::plotsimple(), GctErrorAnalyzer::plotTotalEErrors(), MuonResidualsFitter::plotweighted(), StubsSimHitsMatcher::StubsSimHitsMatcher(), TrackerDpgAnalysis::TrackerDpgAnalysis(), tmtt::Histos::trackerGeometryAnalysis(), TrackerGeometryCompare::TrackerGeometryCompare(), and TSOSHistogramMaker::TSOSHistogramMaker().

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  }
uint32_t T const *__restrict__ uint32_t const *__restrict__ int32_t int Histo::index_type cudaStream_t Func __host__ __device__ V int Func func
TDirectory * _cd(const std::string &subdir="", bool createNeededDirectories=true) const
tuple d
Definition: ztail.py:151
long double T
TFileDirectory TFileDirectory::mkdir ( const std::string &  dir,
const std::string &  descr = "" 
)

create a new subdirectory

Definition at line 112 of file TFileDirectory.cc.

References contentValuesFiles::fullPath.

Referenced by l1t::L1TStage2CaloAnalyzer::analyze(), APVCyclePhaseMonitor::analyze(), BigEventsDebugger< T >::analyze(), SiStripSpyDisplayModule::analyze(), fwlite::AnalyzerWrapper< T >::AnalyzerWrapper(), DMRChecker::beginJob(), RunHistogramManager::beginRun(), DigiInvestigatorHistogramMaker::book(), DigiVtxPosCorrHistogramMaker::book(), DigiPileupCorrHistogramMaker::book(), DigiVertexCorrHistogramMaker::book(), DigiLumiCorrHistogramMaker::book(), ApeEstimator::bookSectorHistsForApeCalculation(), AlignmentMonitorBase::directory(), DMRChecker::endJob(), VariablePlotter::fill(), GctErrorAnalyzer::GctErrorAnalyzer(), main(), TFileService::mkdir(), batchmanager.BatchManager::PrepareJob(), and StubsSimHitsMatcher::StubsSimHitsMatcher().

112  {
113  TH1AddDirectorySentry sentry;
114  _cd();
115  return TFileDirectory(dir, descr, file_, fullPath());
116 }
TDirectory * _cd(const std::string &subdir="", bool createNeededDirectories=true) const
std::string fullPath() const
return the full path of the stored histograms

Friends And Related Function Documentation

friend class fwlite::TFileService
friend

Definition at line 84 of file TFileDirectory.h.

friend class TFileService
friend

Definition at line 83 of file TFileDirectory.h.

Member Data Documentation

std::string TFileDirectory::descr_
private

Definition at line 86 of file TFileDirectory.h.

Referenced by TFileService::setDirectoryName().

std::string TFileDirectory::dir_
private

Definition at line 86 of file TFileDirectory.h.

Referenced by TFileService::setDirectoryName().

TFile* TFileDirectory::file_
private

Definition at line 85 of file TFileDirectory.h.

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

std::string TFileDirectory::path_
private

Definition at line 86 of file TFileDirectory.h.