CMS 3D CMS Logo

TFileDirectory.cc

Go to the documentation of this file.
00001 #include "PhysicsTools/UtilAlgos/interface/TFileDirectory.h"
00002 #include "TROOT.h"
00003 #include "TFile.h"
00004 #include "FWCore/Utilities/interface/Exception.h"
00005 #include <ostream>
00006 using namespace std;
00007 
00008 void TFileDirectory::cd() const {
00009   string fpath = fullPath();
00010   TDirectory * dir = file_->GetDirectory( fpath.c_str() );
00011   if ( dir == 0 ) {
00012     if ( ! path_.empty() ) {
00013       dir = file_->GetDirectory( path_.c_str() );
00014       if ( dir == 0 )
00015         throw 
00016           cms::Exception( "InvalidDirectory" ) 
00017             << "Can't change directory to path: " << path_;
00018     } else {
00019       dir = file_;
00020     }
00021     dir = dir->mkdir( dir_.c_str(), descr_.c_str() );  
00022     if ( dir == 0 )
00023       throw 
00024         cms::Exception( "InvalidDirectory" ) 
00025           << "Can't create directory " << dir_ << " in path: " << path_;
00026   }
00027   bool ok = file_->cd( fpath.c_str() );
00028   if ( ! ok )
00029     throw 
00030       cms::Exception( "InvalidDirectory" ) 
00031         << "Can't change directory to path: " << fpath;
00032 }
00033 
00034 std::string TFileDirectory::fullPath() const {
00035   return string( path_.empty() ? dir_ : path_ + "/" + dir_ );
00036 }
00037 
00038 TFileDirectory TFileDirectory::mkdir( const std::string & dir, const std::string & descr ) {
00039   TH1AddDirectorySentry sentry;
00040   cd();
00041   return TFileDirectory( dir, descr, file_, fullPath() );
00042 }

Generated on Tue Jun 9 17:42:41 2009 for CMSSW by  doxygen 1.5.4