The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
RootDirFcn.cpp
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#define ROOTHISTCNV_ROOTDIRFCN_CPP
12
13#include "RootDirFcn.h"
14#include <GaudiKernel/Kernel.h>
15
16#include <TDirectory.h>
17#include <TFile.h>
18#include <list>
19#include <string>
20
21namespace RootHistCnv {
22
23 //-----------------------------------------------------------------------------
24 bool RootCd( const std::string& full )
25 //-----------------------------------------------------------------------------
26 {
27 int p, i = 1;
28
29 gDirectory->cd( "/" );
30 while ( ( p = full.find( "/", i ) ) != -1 ) {
31 auto sdir = full.substr( i, p - i );
32 if ( !gDirectory->GetKey( sdir.c_str() ) ) { return false; }
33 gDirectory->cd( sdir.c_str() );
34 i = p + 1;
35 }
36 gDirectory->cd( full.substr( i ).c_str() );
37 return true;
38 }
39
40 //-----------------------------------------------------------------------------
41 bool RootMkdir( const std::string& full )
42 //-----------------------------------------------------------------------------
43 {
44
45 TDirectory* gDir = gDirectory;
46
47 int i = 1;
48 auto p = full.find( ":", 0 );
49 if ( p != std::string::npos ) {
50 auto fil = full.substr( 0, p );
51 i = p + 1;
52 fil += ":/";
53 gDirectory->cd( fil.c_str() );
54 }
55
56 std::vector<std::string> lpath;
57 while ( ( p = full.find( "/", i ) ) != std::string::npos ) {
58 lpath.push_back( full.substr( i, p - i ) );
59 i = p + 1;
60 }
61 lpath.push_back( full.substr( i ) );
62
63 if ( full.compare( 0, 1, "/" ) == 0 ) gDirectory->cd( "/" );
64
65 for ( const auto& lp : lpath ) {
66 if ( !gDirectory->GetKey( lp.c_str() ) ) { gDirectory->mkdir( lp.c_str() ); }
67 gDirectory->cd( lp.c_str() );
68 }
69 gDirectory = gDir;
70
71 return true;
72 }
73
74 //-----------------------------------------------------------------------------
75 std::string RootPwd()
76 //-----------------------------------------------------------------------------
77 {
78 std::string dir = gDirectory->GetPath();
79
80 return ( dir );
81 }
82
83 //-----------------------------------------------------------------------------
84 bool RootTrimLeadingDir( std::string& full, std::string dir )
85 //-----------------------------------------------------------------------------
86 {
87
88 if ( dir.compare( 0, 1, "/" ) != 0 ) { dir.insert( 0, "/" ); }
89
90 if ( dir.compare( dir.length() - 1, 1, "/" ) != 0 ) { dir += "/"; }
91
92 long ll = full.find( dir );
93 if ( ll != 0 ) { return false; }
94
95 full.erase( 0, dir.length() - 1 );
96
97 return true;
98 }
99
100} // namespace RootHistCnv
bool RootMkdir(const std::string &full)
bool RootTrimLeadingDir(std::string &full, std::string dir)
std::string RootPwd()
bool RootCd(const std::string &full)