The Gaudi Framework  v30r3 (a5ef0a68)
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 
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  //-----------------------------------------------------------------------------
71  //-----------------------------------------------------------------------------
72  {
73  std::string dir = gDirectory->GetPath();
74 
75  return ( dir );
76  }
77 
78  //-----------------------------------------------------------------------------
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
bool RootTrimLeadingDir(std::string &full, std::string dir)
Definition: RootDirFcn.cpp:79
std::string RootPwd()
Definition: RootDirFcn.cpp:70
STL class.
T push_back(T...args)
T erase(T...args)
bool RootMkdir(const std::string &full)
Definition: RootDirFcn.cpp:34
bool RootCd(const std::string &full)
Definition: RootDirFcn.cpp:15
T insert(T...args)
T find(T...args)
T length(T...args)
T substr(T...args)
T compare(T...args)