| The Gaudi Framework v29r0 (ff2e7097)

- 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 "RootDirFcn.h"
4 #include "GaudiKernel/Kernel.h"
5
6 #include "TDirectory.h"
7 #include "TFile.h"
8 #include <list>
9 #include <string>
10
11 namespace RootHistCnv
12 {
13
14 //-----------------------------------------------------------------------------
15 bool RootCd( const std::string& full )
16 //-----------------------------------------------------------------------------
17 {
18 int p, i = 1;
19
20 gDirectory->cd( "/" );
21 while ( ( p = full.find( "/", i ) ) != -1 ) {
22 auto sdir = full.substr( i, p - i );
23 if ( !gDirectory->GetKey( sdir.c_str() ) ) {
24 return false;
25 }
26 gDirectory->cd( sdir.c_str() );
27 i = p + 1;
28 }
29 gDirectory->cd( full.substr( i ).c_str() );
30 return true;
31 }
32
33 //-----------------------------------------------------------------------------
34 bool RootMkdir( const std::string& full )
35 //-----------------------------------------------------------------------------
36 {
37
38 TDirectory* gDir = gDirectory;
39
40 int i = 1;
41 auto p = full.find( ":", 0 );
42 if ( p != std::string::npos ) {
43 auto fil = full.substr( 0, p );
44 i = p + 1;
45 fil += ":/";
46 gDirectory->cd( fil.c_str() );
47 }
48
49 std::vector<std::string> lpath;
50 while ( ( p = full.find( "/", i ) ) != std::string::npos ) {
51 lpath.push_back( full.substr( i, p - i ) );
52 i = p + 1;
53 }
54 lpath.push_back( full.substr( i ) );
55
56 if ( full.compare( 0, 1, "/" ) == 0 ) gDirectory->cd( "/" );
57
58 for ( const auto& lp : lpath ) {
59 if ( !gDirectory->GetKey( lp.c_str() ) ) {
60 gDirectory->mkdir( lp.c_str() );
61 }
62 gDirectory->cd( lp.c_str() );
63 }
64 gDirectory = gDir;
65
66 return true;
67 }
68
69 //-----------------------------------------------------------------------------
70 std::string RootPwd()
71 //-----------------------------------------------------------------------------
72 {
73 std::string dir = gDirectory->GetPath();
74
75 return ( dir );
76 }
77
78 //-----------------------------------------------------------------------------
79 bool RootTrimLeadingDir( std::string& full, std::string dir )
80 //-----------------------------------------------------------------------------
81 {
82
83 if ( dir.compare( 0, 1, "/" ) != 0 ) {
84 dir.insert( 0, "/" );
85 }
86
87 if ( dir.compare( dir.length() - 1, 1, "/" ) != 0 ) {
88 dir += "/";
89 }
90
91 long ll = full.find( dir );
92 if ( ll != 0 ) {
93 return false;
94 }
95
96 full.erase( 0, dir.length() - 1 );
97
98 return true;
99 }
100
101 } // RootHistCnv namespace
Kernel.h
RootHistCnv::RootTrimLeadingDir
bool RootTrimLeadingDir(std::string &full, std::string dir)
Definition: RootDirFcn.cpp:79
RootHistCnv::RootPwd
std::string RootPwd()
Definition: RootDirFcn.cpp:70
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:34
RootHistCnv::RootCd
bool RootCd(const std::string &full)
Definition: RootDirFcn.cpp:15
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)