DirectoryHelpers Namespace Reference

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)

Function Documentation

TDirectory * DirectoryHelpers::GetDirectory ( TFile *  f,
string  dir,
int  create = 0 
)

Definition at line 85 of file DirectoryHelpers.cxx.

References GetDirectory().

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 }

TDirectory * DirectoryHelpers::GetDirectory ( TDirectory *  f,
string  dir,
int  create = 0 
)

Definition at line 35 of file DirectoryHelpers.cxx.

References Tokenize().

Referenced by GetDirectory(), and MadDpID::~MadDpID().

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 }

int DirectoryHelpers::MakeTrueDirectory ( string  dir  ) 

Definition at line 117 of file DirectoryHelpers.cxx.

References MakeTrueDirectory(), and 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 }

int DirectoryHelpers::MakeTrueDirectory ( vector< string >  paths,
int  pos = 1 
)

Definition at line 97 of file DirectoryHelpers.cxx.

Referenced by 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 }

void DirectoryHelpers::Tokenize ( const string &  str,
vector< string > &  tokens,
const string &  delimiters 
)

Definition at line 7 of file DirectoryHelpers.cxx.

Referenced by GetDirectory(), 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 }


Generated on 14 Dec 2017 for loon by  doxygen 1.6.1