All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RootDirFcn.cpp
Go to the documentation of this file.
1 #define ROOTHISTCNV_ROOTDIRFCN_CPP
2 
3 #include "GaudiKernel/Kernel.h"
4 #include "RootDirFcn.h"
5 
6 #include <string>
7 #include <list>
8 #include "TFile.h"
9 #include "TDirectory.h"
10 
11 
12 
13 namespace RootHistCnv {
14 
15 //-----------------------------------------------------------------------------
16 bool RootCd(const std::string& full)
17 //-----------------------------------------------------------------------------
18 {
19  int p,i=1;
20  std::string cur,sdir;
21 
22  gDirectory->cd("/");
23  while ( (p = full.find("/",i)) != -1) {
24  sdir = full.substr(i,p-i);
25  if (! gDirectory->GetKey(sdir.c_str()) ) {
26  return false;
27  }
28  gDirectory->cd(sdir.c_str());
29 
30  i = p+1;
31  }
32  gDirectory->cd( full.substr(i,full.length()-i).c_str() );
33 
34  return true;
35 
36 }
37 
38 
39 //-----------------------------------------------------------------------------
40 bool RootMkdir(const std::string& full)
41 //-----------------------------------------------------------------------------
42 {
43 
44  int p,i;
45  std::string fil,cur,s;
46  TDirectory *gDir;
47 
48  gDir = gDirectory;
49 
50  std::list<std::string> lpath;
51  i = 1;
52 
53  if ( (p=full.find(":",0)) != -1 ) {
54  fil = full.substr(0,p);
55  i = p+1;
56  fil += ":/";
57  gDirectory->cd(fil.c_str());
58  }
59 
60  while ( (p = full.find("/",i)) != -1) {
61  s = full.substr(i,p-i);
62  lpath.push_back(s);
63  i = p+1;
64  }
65  lpath.push_back( full.substr(i,full.length()-i) );
66 
67  if ( full.substr(0,1) == "/") {
68  gDirectory->cd("/");
69  }
70 
71  std::list<std::string>::const_iterator litr;
72  for(litr=lpath.begin(); litr!=lpath.end(); ++litr) {
73  cur = *litr;
74  if (! gDirectory->GetKey(litr->c_str()) ) {
75  gDirectory->mkdir(litr->c_str());
76  }
77  gDirectory->cd(litr->c_str());
78  }
79 
80  gDirectory = gDir;
81 
82  return true;
83 }
84 
85 //-----------------------------------------------------------------------------
86 std::string RootPwd()
87 //-----------------------------------------------------------------------------
88 {
89  std::string dir = gDirectory->GetPath();
90 
91  return (dir);
92 }
93 
94 //-----------------------------------------------------------------------------
95 bool RootTrimLeadingDir(std::string &full, std::string dir)
96 //-----------------------------------------------------------------------------
97 {
98 
99  if (dir.substr(0,1) != "/") {
100  dir.insert(0,"/");
101  }
102 
103  if (dir.substr(dir.length()-1,1) != "/") {
104  dir += "/";
105  }
106 
107  long ll = full.find(dir);
108  if (ll != 0) {
109  return false;
110  }
111 
112  full.erase(0,dir.length()-1);
113 
114  return true;
115 
116 }
117 
118 
119 } // RootHistCnv namespace
bool RootTrimLeadingDir(std::string &full, std::string dir)
Definition: RootDirFcn.cpp:95
std::string RootPwd()
Definition: RootDirFcn.cpp:86
bool RootMkdir(const std::string &full)
Definition: RootDirFcn.cpp:40
bool RootCd(const std::string &full)
Definition: RootDirFcn.cpp:16
string s
Definition: gaudirun.py:210
list i
Definition: ana.py:128