GammaWare  Head Version for release 0.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MacroToRoot.C
Go to the documentation of this file.
1 
12 #include "TFile.h"
13 #include "TSystem.h"
14 #include "TMacro.h"
15 
16 Bool_t istopdir = false;
17 
18 void importdir(const char *dirname)
19 {
20  //Example of script showing how to create a ROOT file with subdirectories.
21  //The script scans a given directory tree and recreates the
22  //same structure in the ROOT file.
23  //All source files of type .h,cxx,c,dat,py are imported as TMacro objects
24  //see also other tutorial readCode.C
25 
26  char *slash = (char*)strrchr(dirname,'/');
27  char *locdir;
28  if (slash) locdir = slash+1;
29  else locdir = (char*)dirname;
30  printf("processing dir %s\n",dirname);
31 
32  TDirectory *savdir = gDirectory; // to avoid having top directory inside the root file
33  if ( istopdir )
34  { adir = gFile; istopdir = false; }
35  else
36  adir = savdir->mkdir(locdir);
37 
38  adir->cd();
39  void *dirp = gSystem->OpenDirectory(dirname);
40  if (!dirp) return;
41  char *direntry;
42  Long_t id, size,flags,modtime;
43  //loop on all entries of this directory
44  while ((direntry=(char*)gSystem->GetDirEntry(dirp))) {
45  TString afile = Form("%s/%s",dirname,direntry);
46  gSystem->GetPathInfo(afile,&id,&size,&flags,&modtime);
47  if (strstr(direntry,"G__")) continue;
48  if (strstr(direntry,"~")) continue;
49  if (strstr(direntry,"%")) continue;
50  if (strstr(direntry,".c") ||
51  strstr(direntry,".h") ||
52  strstr(direntry,".m") ||
53  strstr(direntry,".dat") ||
54  strstr(direntry,".py") ||
55  strstr(direntry,".C")) {
56  TMacro *m = new TMacro(afile);
57  m->Write(direntry);
58  delete m;
59  } else {
60  if (flags != 3) continue; //must be a directory
61  if (direntry[0] == '.') continue; //forget the "." and ".." special cases
62  if (!strcmp(direntry,"CVS")) continue; //forget some special directories
63  if (!strcmp(direntry,"htmldoc")) continue;
64  if (strstr(dirname,"root/include")) continue;
65  //we have found a valid sub-directory. Process it
66  importdir(afile);
67  }
68  }
69  gSystem->FreeDirectory(dirp);
70  savdir->cd();
71 }
72 
73 void MacroToRoot(const char *topdir, const char *rootname)
74 {
75  TFile *f = new TFile(rootname,"recreate"); istopdir = kTRUE; importdir(topdir); f->Close(); delete f;
76 }
printf("******************************************************************** \n")
void importdir(const char *dirname)
Definition: MacroToRoot.C:18
Bool_t istopdir
Definition: MacroToRoot.C:16
void MacroToRoot(const char *topdir, const char *rootname)
Definition: MacroToRoot.C:73
const Int_t size
Definition: BenchIO.C:24