| The Gaudi Framework v28r2p1 (f1a77ff4)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
52 std::vector<std::string> lpath;
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 //-----------------------------------------------------------------------------
73 std::string RootPwd()
74 //-----------------------------------------------------------------------------
75 {
76 std::string dir = gDirectory->GetPath();
77
78 return (dir);
79 }
80
81 //-----------------------------------------------------------------------------
82 bool RootTrimLeadingDir(std::string &full, std::string dir)
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
Kernel.h
RootHistCnv::RootTrimLeadingDir
bool RootTrimLeadingDir(std::string &full, std::string dir)
Definition: RootDirFcn.cpp:82
RootHistCnv::RootPwd
std::string RootPwd()
Definition: RootDirFcn.cpp:73
std::string
STL class.
std::vector::push_back
T push_back(T...args)
std::string::erase
T erase(T...args)
RootHistCnv
Definition: DirectoryCnv.h:17
RootHistCnv::RootMkdir
bool RootMkdir(const std::string &full)
Definition: RootDirFcn.cpp:37
RootHistCnv::RootCd
bool RootCd(const std::string &full)
Definition: RootDirFcn.cpp:16
std::string::insert
T insert(T...args)
std::string::find
T find(T...args)
std::string::length
T length(T...args)
std::vector< std::string >
RootDirFcn.h
std::string::substr
T substr(T...args)
std::string::compare
T compare(T...args)