All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules 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 
21  gDirectory->cd("/");
22  while ( (p = full.find("/",i)) != -1) {
23  auto sdir = full.substr(i,p-i);
24  if (! gDirectory->GetKey(sdir.c_str()) ) {
25  return false;
26  }
27  gDirectory->cd(sdir.c_str());
28  i = p+1;
29  }
30  gDirectory->cd( full.substr(i).c_str() );
31  return true;
32 
33 }
34 
35 
36 //-----------------------------------------------------------------------------
37 bool RootMkdir(const std::string& full)
38 //-----------------------------------------------------------------------------
39 {
40 
41  TDirectory *gDir = gDirectory;
42 
43  int i = 1;
44  auto p=full.find(":",0);
45  if ( p != std::string::npos ) {
46  auto fil = full.substr(0,p);
47  i = p+1;
48  fil += ":/";
49  gDirectory->cd(fil.c_str());
50  }
51 
53  while ( (p = full.find("/",i)) != std::string::npos ) {
54  lpath.push_back(full.substr(i,p-i));
55  i = p+1;
56  }
57  lpath.push_back( full.substr(i) );
58 
59  if ( full.compare(0,1,"/") == 0 ) gDirectory->cd("/");
60 
61  for(const auto& lp : lpath) {
62  if (! gDirectory->GetKey(lp.c_str()) ) {
63  gDirectory->mkdir(lp.c_str());
64  }
65  gDirectory->cd(lp.c_str());
66  }
67  gDirectory = gDir;
68 
69  return true;
70 }
71 
72 //-----------------------------------------------------------------------------
74 //-----------------------------------------------------------------------------
75 {
76  std::string dir = gDirectory->GetPath();
77 
78  return (dir);
79 }
80 
81 //-----------------------------------------------------------------------------
83 //-----------------------------------------------------------------------------
84 {
85 
86  if (dir.compare(0,1,"/") != 0) {
87  dir.insert(0,"/");
88  }
89 
90  if (dir.compare(dir.length()-1,1,"/") != 0) {
91  dir += "/";
92  }
93 
94  long ll = full.find(dir);
95  if (ll != 0) {
96  return false;
97  }
98 
99  full.erase(0,dir.length()-1);
100 
101  return true;
102 
103 }
104 
105 
106 } // RootHistCnv namespace
bool RootTrimLeadingDir(std::string &full, std::string dir)
Definition: RootDirFcn.cpp:82
std::string RootPwd()
Definition: RootDirFcn.cpp:73
STL class.
T push_back(T...args)
T erase(T...args)
bool RootMkdir(const std::string &full)
Definition: RootDirFcn.cpp:37
bool RootCd(const std::string &full)
Definition: RootDirFcn.cpp:16
T insert(T...args)
T find(T...args)
T length(T...args)
T substr(T...args)
T compare(T...args)