| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

RootDirFcn.cpp

Go to the documentation of this file.
00001 // $Id: RootDirFcn.cpp,v 1.3 2001/11/22 09:14:49 mato Exp $
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 
00016 //-----------------------------------------------------------------------------
00017 bool RootCd(const std::string& full)
00018 //-----------------------------------------------------------------------------
00019 {
00020   int p,i=1;
00021   std::string cur,sdir;
00022   
00023   gDirectory->cd("/");
00024   while ( (p = full.find("/",i)) != -1) {
00025     sdir = full.substr(i,p-i);
00026     if (! gDirectory->GetKey(sdir.c_str()) ) { 
00027       return false;
00028     }
00029     gDirectory->cd(sdir.c_str());
00030     
00031     i = p+1;
00032   }
00033   gDirectory->cd( full.substr(i,full.length()-i).c_str() );
00034   
00035   return true;
00036   
00037 }
00038 
00039 
00040 //-----------------------------------------------------------------------------
00041 bool RootMkdir(const std::string& full)
00042 //-----------------------------------------------------------------------------
00043 {
00044 
00045   int p,i;
00046   std::string fil,cur,s;
00047   TDirectory *gDir;
00048   
00049   gDir = gDirectory;
00050   
00051   std::list<std::string> lpath;
00052   i = 1;
00053   
00054   if ( (p=full.find(":",0)) != -1 ) {
00055     fil = full.substr(0,p);
00056     i = p+1;
00057     fil += ":/";
00058     gDirectory->cd(fil.c_str());
00059   }
00060   
00061   while ( (p = full.find("/",i)) != -1) {
00062     s = full.substr(i,p-i);
00063     lpath.push_back(s);
00064     i = p+1;
00065   }
00066   lpath.push_back( full.substr(i,full.length()-i) );
00067   
00068   if ( full.substr(0,1) == "/") {
00069     gDirectory->cd("/");
00070   }
00071   
00072   std::list<std::string>::const_iterator litr;
00073   for(litr=lpath.begin(); litr!=lpath.end(); ++litr) {
00074     cur = *litr;
00075     if (! gDirectory->GetKey(litr->c_str()) ) { 
00076       gDirectory->mkdir(litr->c_str()); 
00077     }
00078     gDirectory->cd(litr->c_str());
00079   }
00080   
00081   gDirectory = gDir;
00082   
00083   return true;
00084 }
00085 
00086 //-----------------------------------------------------------------------------
00087 std::string RootPwd()
00088 //-----------------------------------------------------------------------------
00089 {
00090   std::string dir = gDirectory->GetPath();
00091 
00092   return (dir);
00093 }
00094 
00095 //-----------------------------------------------------------------------------
00096 bool RootTrimLeadingDir(std::string &full, std::string dir)
00097 //-----------------------------------------------------------------------------
00098 {
00099   
00100   if (dir.substr(0,1) != "/") {
00101     dir.insert(0,"/");
00102   }
00103 
00104   if (dir.substr(dir.length()-1,1) != "/") {
00105     dir += "/";
00106   }
00107 
00108   long ll = full.find(dir);
00109   if (ll != 0) {
00110     return false;
00111   }
00112 
00113   full.erase(0,dir.length()-1);
00114 
00115   return true;
00116 
00117 }
00118 
00119 
00120 } // RootHistCnv namespace
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 19:57:44 2011 for RootHistCnv by doxygen 1.4.7