importCode.C

Go to the documentation of this file.
00001 #include "TFile.h"
00002 #include "TSystem.h"
00003 #include "TMacro.h"
00004       
00005 void importdir(const char *dirname) {
00006   //Example of script showing how to create a ROOT file with subdirectories.
00007   //The script scans a given directory tree and recreates the
00008   //same structure in the ROOT file.
00009   //All source files of type .h,cxx,c,dat,py are imported as TMacro objects
00010   //see also other tutorial readCode.C
00011   //Author: Rene Brun
00012          
00013    char *slash = (char*)strrchr(dirname,'/');
00014    char *locdir;
00015    if (slash) locdir = slash+1;
00016    else       locdir = (char*)dirname;
00017    printf("processing dir %s\n",dirname);
00018    TDirectory *savdir = gDirectory;
00019    TDirectory *adir = savdir->mkdir(locdir);
00020    adir->cd();
00021    void *dirp = gSystem->OpenDirectory(dirname);
00022    if (!dirp) return;
00023    char *direntry;
00024    Long_t id, size,flags,modtime;
00025    //loop on all entries of this directory
00026    while ((direntry=(char*)gSystem->GetDirEntry(dirp))) {
00027       TString afile = Form("%s/%s",dirname,direntry);
00028       gSystem->GetPathInfo(afile,&id,&size,&flags,&modtime);
00029       if (direntry[0] == '.')             continue; //forget the "." and ".." special cases
00030       if (!strcmp(direntry,"CVS"))        continue; //forget some special directories
00031       if (!strcmp(direntry,"htmldoc"))    continue;
00032       if (strstr(dirname,"root/include")) continue;
00033       if (strstr(direntry,"G__"))         continue;
00034       if (strstr(direntry,".c")    ||
00035           strstr(direntry,".h")    ||
00036           strstr(direntry,".dat")  ||
00037           strstr(direntry,".py")   ||
00038           strstr(direntry,".C")) {
00039          TMacro *m = new TMacro(afile);
00040          m->Write(direntry);
00041          delete m;
00042       } else {
00043          if (flags != 3)                     continue; //must be a directory
00044          //we have found a valid sub-directory. Process it
00045          importdir(afile);
00046      }
00047   }
00048   gSystem->FreeDirectory(dirp);
00049   savdir->cd();
00050 }
00051 void importCode() {
00052    TFile *f = new TFile("code.root","recreate");
00053    importdir("../../../root"); //change the directory as you like
00054    delete f;
00055 }

Generated on Tue Jul 5 15:44:49 2011 for ROOT_528-00b_version by  doxygen 1.5.1