Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
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 "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 
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  //-----------------------------------------------------------------------------
66  //-----------------------------------------------------------------------------
67  {
68  std::string dir = gDirectory->GetPath();
69 
70  return ( dir );
71  }
72 
73  //-----------------------------------------------------------------------------
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
bool RootTrimLeadingDir(std::string &full, std::string dir)
Definition: RootDirFcn.cpp:74
std::string RootPwd()
Definition: RootDirFcn.cpp:65
STL class.
T push_back(T...args)
T erase(T...args)
bool RootMkdir(const std::string &full)
Definition: RootDirFcn.cpp:31
bool RootCd(const std::string &full)
Definition: RootDirFcn.cpp:14
T insert(T...args)
T find(T...args)
T length(T...args)
T substr(T...args)
T compare(T...args)