ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/HbbAnalysis/src/TFileDirectory.cc
Revision: 1.1
Committed: Fri Oct 2 11:05:54 2009 UTC (15 years, 7 months ago) by amagnan
Content type: text/plain
Branch: MAIN
CVS Tags: v00-05-00, HbbAnaFor35X, v00-04-02, v00-04-01, v00-04-00
Log Message:
add histos classes to fill from tree

File Contents

# User Rev Content
1 amagnan 1.1 #include <ostream>
2     #include <iostream>
3     #include <iomanip>
4     #include <stdlib.h>
5    
6     #include "TROOT.h"
7     #include "TFile.h"
8    
9     #include "UserCode/HbbAnalysis/interface/TFileDirectory.hh"
10    
11     using namespace std;
12    
13     namespace HbbAnalysis{
14    
15     TFileDirectory::TFileDirectory(TFile * file,
16     const std::string & path) :
17     file_( file ), path_( path )
18     {
19    
20     //std::cout << "[TFileDirectory] --- TFileDirectory::TFileDirectory fullPath = " << fullPath() << std::endl;
21    
22     }
23    
24     void TFileDirectory::cd() const {
25     string fpath = fullPath();
26     TDirectory * dir = file_->GetDirectory( fpath.c_str() );
27     if ( dir == 0 ) {
28     if ( ! path_.empty() ) {
29     dir = file_->GetDirectory( path_.c_str() );
30     if ( dir == 0 ){
31     std::cerr << "[TFileDirectory] --- cd() : Can't change directory to path: " << path_ << std::endl;
32     exit(1);
33     }
34     } else {
35     dir = file_;
36     }
37     dir = dir->mkdir( dir_.c_str(), descr_.c_str() );
38     if ( dir == 0 ){
39     std::cerr << "[TFileDirectory] --- cd() : Can't create directory " << dir_ << " in path: " << path_ << std::endl;
40     exit(1);
41     }
42     }
43     bool ok = file_->cd( fpath.c_str() );
44     if ( ! ok ){
45     std::cerr << "[TFileDirectory] --- cd() : Can't change directory to path: " << fpath << std::endl;
46     exit(1);
47     }
48     }
49    
50     std::string TFileDirectory::fullPath() const {
51     return string( path_.empty() ? dir_ : path_ + "/" + dir_ );
52     }
53    
54     TFileDirectory TFileDirectory::mkdir( const std::string & dir, const std::string & descr ) {
55     TH1AddDirectorySentry sentry;
56     cd();
57     //std::cout << "[TFileDirectory] --- mkdir: fullPath = " << fullPath() << std::endl;
58     return TFileDirectory( dir, descr, file_, fullPath() );
59     }
60    
61     }//namespace