00001
00002 #define ROOTHISTCNV_ROOTDIRFCN_CPP
00003
00004 #include "GaudiKernel/Kernel.h"
00005 #include "RootDirFcn.h"
00006
00007 #include <string>
00008 #include <list>
00009 #include "TFile.h"
00010 #include "TDirectory.h"
00011
00012
00013
00014 namespace RootHistCnv {
00015 bool RootCd(const std::string& full) {
00016
00017 int p,i=1;
00018 std::string cur,sdir;
00019
00020 gDirectory->cd("/");
00021 while ( (p = full.find("/",i)) != -1) {
00022 sdir = full.substr(i,p-i);
00023 if (! gDirectory->GetKey(sdir.c_str()) ) {
00024 return false;
00025 }
00026 gDirectory->cd(sdir.c_str());
00027
00028 i = p+1;
00029 }
00030 gDirectory->cd( full.substr(i,full.length()-i).c_str() );
00031
00032 return true;
00033
00034 }
00035
00036
00037 bool RootMkdir(const std::string& full) {
00038
00039 int p,i;
00040 std::string fil,cur,s;
00041 TDirectory *gDir;
00042
00043 gDir = gDirectory;
00044
00045 std::list<std::string> lpath;
00046 i = 1;
00047
00048 if ( (p=full.find(":",0)) != -1 ) {
00049 fil = full.substr(0,p);
00050 i = p+1;
00051 fil += ":/";
00052 gDirectory->cd(fil.c_str());
00053 }
00054
00055 while ( (p = full.find("/",i)) != -1) {
00056 s = full.substr(i,p-i);
00057 lpath.push_back(s);
00058 i = p+1;
00059 }
00060 lpath.push_back( full.substr(i,full.length()-i) );
00061
00062 if ( full.substr(0,1) == "/") {
00063 gDirectory->cd("/");
00064 }
00065
00066 std::list<std::string>::const_iterator litr;
00067 for(litr=lpath.begin(); litr!=lpath.end(); ++litr) {
00068 cur = *litr;
00069 if (! gDirectory->GetKey(litr->c_str()) ) {
00070 gDirectory->mkdir(litr->c_str());
00071 }
00072 gDirectory->cd(litr->c_str());
00073 }
00074
00075 gDirectory = gDir;
00076
00077 return true;
00078 }
00079
00080 std::string RootPwd() {
00081 std::string dir = gDirectory->GetPath();
00082
00083 return (dir);
00084 }
00085
00086 bool RootTrimLeadingDir(std::string &full, std::string dir) {
00087
00088 if (dir.substr(0,1) != "/") {
00089 dir.insert(0,"/");
00090 }
00091
00092 if (dir.substr(dir.length()-1,1) != "/") {
00093 dir += "/";
00094 }
00095
00096 long ll = full.find(dir);
00097 if (ll != 0) {
00098 return false;
00099 }
00100
00101 full.erase(0,dir.length()-1);
00102
00103 return true;
00104
00105 }
00106
00107 }