#include "TDirectory.h"#include "TFile.h"#include <string>#include <vector>#include <sys/stat.h>#include <sys/types.h>Go to the source code of this file.
Namespaces | |
| namespace | DirectoryHelpers |
Functions | |
| void | Tokenize (const string &str, vector< string > &tokens, const string &delimiters) |
| TDirectory * | GetDirectory (TDirectory *f, string dir, int create=0) |
| TDirectory * | GetDirectory (TFile *f, string dir, int create=0) |
| int | MakeTrueDirectory (vector< string > paths, int pos=1) |
| int | MakeTrueDirectory (string dir) |
|
||||||||||||||||
|
Definition at line 85 of file DirectoryHelpers.cxx. References DirectoryHelpers::GetDirectory(). Referenced by Anp::CountHist::ComputeRatio(). 00086 {
00087 TDirectory *ret = GetDirectory(f->GetDirectory("/"),dir,create);
00088
00089 if(!ret)printf("failed to get directory %s\n",dir.c_str());
00090
00091 return ret;
00092 }
|
|
||||||||||||||||
|
Definition at line 35 of file DirectoryHelpers.cxx. References DirectoryHelpers::Tokenize(). Referenced by DirectoryHelpers::GetDirectory(), MiniPlotMaker::MakeDirectory(), and MiniPlotMaker::SaveHistos(). 00036 {
00037 if(!create)
00038 {
00039 TDirectory * r = f->GetDirectory(dir.c_str());
00040 if(r)return r;
00041
00042 //maybe the string has repeating tokens?
00043 vector<string> paths;
00044 Tokenize(dir,paths,"/");
00045
00046 r = f->GetDirectory("/");
00047 for(int i=0;i<(int)paths.size();i++)
00048 {
00049 r=r->GetDirectory(paths[i].c_str());
00050 if(!r)break;
00051 }
00052 return r;
00053
00054 }
00055
00056 //parse the dir
00057
00058 vector<string> paths;
00059 Tokenize(dir,paths,"/");
00060
00061
00062 TDirectory *tmp=f;
00063 TDirectory *tmpNew=0;
00064 for(int i=0;i<(int)paths.size();i++)
00065 {
00066 tmpNew=tmp->GetDirectory(paths[i].c_str());
00067 if(!tmpNew)
00068 tmp->mkdir(paths[i].c_str());
00069 tmpNew=tmp->GetDirectory(paths[i].c_str());
00070 tmp=tmpNew;
00071 }
00072
00073
00074 //clear directory?
00075 if(create==2)
00076 {
00077 tmp->Close();
00078 tmp->Write();
00079 }
00080
00081 return tmp;
00082 }
|
|
|
Definition at line 117 of file DirectoryHelpers.cxx. References DirectoryHelpers::MakeTrueDirectory(), and DirectoryHelpers::Tokenize(). 00118 {
00119 printf("Making directory %s\n",dir.c_str());
00120
00121 vector<string> paths;
00122 Tokenize(dir,paths,"/");
00123
00124 return MakeTrueDirectory(paths,1);
00125 }
|
|
||||||||||||
|
Definition at line 97 of file DirectoryHelpers.cxx. Referenced by DirectoryHelpers::MakeTrueDirectory(). 00098 {
00099
00100 if(paths.size()>0)
00101 {
00102 string str ="/";
00103 if(pos > (int)paths.size())return 1;
00104
00105 for(int i=0;i<pos;i++)str+=paths[i]+"/";
00106
00107 int res = mkdir(str.c_str(),0755);
00108
00109 return MakeTrueDirectory(paths,pos+1) || res; //0 if OK
00110
00111 }
00112
00113 return 10;
00114 }
|
|
||||||||||||||||
|
Definition at line 7 of file DirectoryHelpers.cxx. Referenced by DirectoryHelpers::GetDirectory(), DirectoryHelpers::MakeTrueDirectory(), and MiniPlotMaker::SaveHistos(). 00010 {
00011 // Skip delimiters at beginning.
00012 string::size_type lastPos = str.find_first_not_of(delimiters, 0);
00013 // Find first "non-delimiter".
00014 string::size_type pos = str.find_first_of(delimiters, lastPos);
00015
00016 //printf("tokens: ");
00017
00018 while (string::npos != pos || string::npos != lastPos)
00019 {
00020 // Found a token, add it to the vector.
00021 string t = str.substr(lastPos, pos - lastPos);
00022 if(t!="")tokens.push_back(t);
00023
00024 // printf("-%s- ",t.c_str());
00025 // Skip delimiters. Note the "not_of"
00026 lastPos = str.find_first_not_of(delimiters, pos);
00027 // Find next "non-delimiter"
00028 pos = str.find_first_of(delimiters, lastPos);
00029 }
00030 // printf("\n");
00031 }
|
1.3.9.1