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::TFileDirectory ( )
inline

Definition at line 27 of file TFileDirectory.h.

27  : file_(nullptr), dir_(), descr_(), path_() {
28  }
std::string path_
std::string dir_
std::string descr_
virtual TFileDirectory::~TFileDirectory ( )
inlinevirtual

descructor

Definition at line 31 of file TFileDirectory.h.

References AlCaHLTBitMon_QueryRunRegistry::string.

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

Definition at line 88 of file TFileDirectory.h.

89  :
90  file_( file ), dir_( dir ), descr_( descr ), path_( path ) {
91  }
std::string path_
std::string dir_
dbl *** dir
Definition: mlp_gen.cc:35
std::string descr_

Member Function Documentation

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

Definition at line 26 of file TFileDirectory.cc.

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

27 {
28  string fpath = fullPath();
29  if (subdir.length())
30  {
31  // not empty, we need to append it to path
32  if (fpath.length())
33  {
34  // path is also not empty, so add a slash and let's get going.
35  fpath += "/" + subdir;
36  } else {
37  // path doesn't exist, so just use subdir
38  fpath = subdir;
39  }
40  }
41  TDirectory * dir = file_->GetDirectory( fpath.c_str() );
42  if ( dir == 0 )
43  {
44  // we didn't find the directory
45  //
46  // If we're not supposed to create the diretory, then we should
47  // complain now that it doesn't exist.
48  if (! createNeededDirectories)
49  {
50  cout << "here " << fpath << endl;
51  throw
52  cms::Exception( "InvalidDirectory" )
53  << "directory " << fpath << " doesn't exist.";
54  }
55  if ( ! path_.empty() )
56  {
57  dir = file_->GetDirectory( path_.c_str() );
58  if ( dir == 0 )
59  {
60  throw
61  cms::Exception( "InvalidDirectory" )
62  << "Can't change directory to path: " << path_;
63  }
64  } else
65  {
66  // the base path 'path_' is empty, so just use the pointer to
67  // the file.
68  dir = file_;
69  }
70  // if a subdirectory was passed in, then this directory better
71  // already exist (since you shoudln't be cd'ing into a directory
72  // before making it and the cd with a subdir is only used to get
73  // histograms that are already made).
74  if (subdir.length())
75  {
76  throw
77  cms::Exception( "InvalidDirectory" )
78  << "directory " << fpath << " doesn't exist.";
79  }
80  // if we're here, then that means that this is the first time
81  // that we are calling cd() on this directory AND cd() has not
82  // been called with a subdirectory, so go ahead and make the
83  // directory.
84  dir = _mkdir (dir, dir_, descr_);
85  }
86  bool ok = file_->cd( fpath.c_str() );
87  if ( ! ok )
88  {
89  throw
90  cms::Exception( "InvalidDirectory" )
91  << "Can't change directory to path: " << fpath;
92  }
93  return dir;
94 }
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_
dbl *** dir
Definition: mlp_gen.cc:35
std::string descr_
TObject * TFileDirectory::_getObj ( const std::string &  objname,
const std::string &  subdir = "" 
) const
private

Definition at line 134 of file TFileDirectory.cc.

References Exception, and AlCaHLTBitMon_QueryRunRegistry::string.

135 {
136  TObject *objPtr = getBareDirectory (subdir)->Get (objname.c_str());
137  if ( ! objPtr)
138  {
139  // no histogram found by that name. Sorry dude.
140  if (subdir.length())
141  {
142  throw
143  cms::Exception ("ObjectNotFound")
144  << "Can not find object named " << objname
145  << " in subdir " << subdir;
146  } else {
147  throw
148  cms::Exception ("ObjectNotFound")
149  << "Can not find object named " << objname;
150  }
151  } // if nothing found
152  return objPtr;
153 }
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 97 of file TFileDirectory.cc.

References sistrip::dir_, Exception, patRefSel_triggerMatching_cfi::matches, and path_.

100 {
101  // do we have this one already
102  TDirectory *subdirPtr = dirPtr->GetDirectory (subdirName.c_str());
103  if (subdirPtr)
104  {
105  subdirPtr->cd();
106  return subdirPtr;
107  }
108  // if we're here, then this directory doesn't exist. Is this
109  // directory a subdirectory?
110  const boost::regex subdirRE ("(.+?)/([^/]+)");
111  boost::smatch matches;
112  TDirectory *parentDir = 0;
113  string useName = subdirName;
114  if( boost::regex_match (subdirName, matches, subdirRE) )
115  {
116  parentDir = _mkdir (dirPtr, matches[1], description);
117  useName = matches[2];
118  } else {
119  // This is not a subdirectory, so we're golden
120  parentDir = dirPtr;
121  }
122  subdirPtr = parentDir->mkdir (useName.c_str());
123  if ( ! subdirPtr )
124  {
125  throw
126  cms::Exception( "InvalidDirectory" )
127  << "Can't create directory " << dir_ << " in path: " << path_;
128  }
129  subdirPtr->cd();
130  return subdirPtr;
131 }
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 19 of file TFileDirectory.cc.

Referenced by 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().

20 {
21  _cd ("", false);
22  return true;
23 }
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 156 of file TFileDirectory.cc.

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

157 {
158  return string( path_.empty() ? dir_ : path_ + "/" + dir_ );
159 }
std::string path_
std::string dir_
TDirectory * TFileDirectory::getBareDirectory ( const std::string &  subdir = "") const

Definition at line 13 of file TFileDirectory.cc.

14 {
15  return _cd (subdir, false);
16 }
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 41 of file TFileDirectory.h.

References Exception.

43  {
44  TObject *objPtr = _getObj (objname, subdir);
45  // Ok, we've got it. Let's see if it's a histogram
46  T * retval = dynamic_cast< T* > ( objPtr );
47  if ( ! retval )
48  {
49  // object isn't a of class T
50  throw
51  cms::Exception ("ObjectNotCorrectlyTyped")
52  << "Object named " << objname << " is not of correct type";
53  }
54  return retval;
55  }
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 59 of file TFileDirectory.h.

References fftjetcommon_cfi::Class, edmIntegrityCheck::d, heppy_report::description, dir, RecoEcal_EventContent_cff::func, eostools::mkdir(), AlCaHLTBitMon_QueryRunRegistry::string, and lumiQTWidget::t.

Referenced by AnalysisTasksAnalyzerBTag::AnalysisTasksAnalyzerBTag(), AnalysisTasksAnalyzerJEC::AnalysisTasksAnalyzerJEC(), l1t::L1TStage2CaloAnalyzer::analyze(), CentralityTableProducer::analyze(), SiStripBaselineAnalyzer::analyze(), BasicMuonAnalyzer::BasicMuonAnalyzer(), L1GctValidation::beginJob(), l1t::L1TGlobalAnalyzer::beginJob(), PrimaryVertexValidation::beginJob(), HistoParams< T >::beginRun(), HistoParams< TH2F >::beginRun(), HistoParams< TProfile2D >::beginRun(), BigEventsDebugger< T >::BigEventsDebugger(), BjetAnalysis::BjetAnalysis(), AlignmentMonitorSurvey::book(), VertexHistogramMaker::book(), DigiBXCorrHistogramMaker< T >::book(), BSvsPVHistogramMaker::book(), AlignmentMonitorMuonResiduals::book(), ConfigurableHisto::book(), SplittingConfigurableHisto::book(), AlignmentMonitorBase::book1D(), AlignmentMonitorBase::book2D(), TrackerSectorStruct::bookCorrHists(), L1GtDataEmulAnalyzer::bookHistograms(), IsolatedGenParticles::BookHistograms(), IsolatedTracksNxN::BookHistograms(), AlignmentMonitorBase::bookProfile(), ApeEstimator::bookSectorHistsForAnalyzerMode(), ApeEstimator::bookSectorHistsForApeCalculation(), ApeEstimator::bookTrackHists(), PrimaryVertexValidation::bookVertexHistograms(), PatBTagAnalyzer::endJob(), TrackerTreeGenerator::endJob(), EWKSystUnc::EWKSystUnc(), GctErrorAnalyzer::GctErrorAnalyzer(), GlbMuQualityCutsAnalysis::GlbMuQualityCutsAnalysis(), HCalSD::HCalSD(), HFGflash::HFGflash(), HFShowerParam::HFShowerParam(), WMuNuValidator::init_histograms(), ExpressionHisto< T >::initialize(), main(), SiStripSpyDisplayModule::MakeDigiHist_(), SiStripSpyDisplayModule::MakeProcessedRawDigiHist_(), SiStripSpyDisplayModule::MakeRawDigiHist_(), MultiplicityTimeCorrelations::MultiplicityTimeCorrelations(), PatMuonAnalyzer::PatMuonAnalyzer(), MuonResiduals1DOFFitter::plot(), MuonResidualsAngleFitter::plot(), MuonResidualsBfieldAngleFitter::plot(), MuonResidualsPositionFitter::plot(), MuonResiduals5DOFFitter::plot(), MuonResiduals6DOFrphiFitter::plot(), MuonResiduals6DOFFitter::plot(), GctErrorAnalyzer::plotEGErrors(), GctErrorAnalyzer::plotHFErrors(), GctErrorAnalyzer::plotJetErrors(), GctErrorAnalyzer::plotMissingEErrors(), MuonResidualsFitter::plotsimple(), GctErrorAnalyzer::plotTotalEErrors(), MuonResidualsFitter::plotweighted(), TrackerDpgAnalysis::TrackerDpgAnalysis(), 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().

59  {
60  TDirectory *d = _cd();
61  T* t = new T(args ...);
62  ROOT::DirAutoAdd_t func = T::Class()->GetDirectoryAutoAdd();
63  if (func) { TH1AddDirectorySentry sentry; func(t,d); }
64  else { d->Append(t); }
65  return t;
66  }
TDirectory * _cd(const std::string &subdir="", bool createNeededDirectories=true) const
long double T
TFileDirectory TFileDirectory::mkdir ( const std::string &  dir,
const std::string &  descr = "" 
)

Friends And Related Function Documentation

friend class fwlite::TFileService
friend

Definition at line 93 of file TFileDirectory.h.

friend class TFileService
friend

Definition at line 92 of file TFileDirectory.h.

Member Data Documentation

std::string TFileDirectory::descr_
private

Definition at line 95 of file TFileDirectory.h.

Referenced by TFileService::setDirectoryName().

std::string TFileDirectory::dir_
private

Definition at line 95 of file TFileDirectory.h.

Referenced by TFileService::setDirectoryName().

TFile* TFileDirectory::file_
private

Definition at line 94 of file TFileDirectory.h.

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

std::string TFileDirectory::path_
private