| The Gaudi Framework v32r1 (f65d50dc)

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