#include "hsrckeeper.h" #include "hdiskspace.h" #include "TSystem.h" #include "TRegexp.h" #include "TPRegexp.h" #include #include #include #include using namespace std; //_HADES_CLASS_DESCRIPTION //////////////////////////////////////////////////////////////////////////////// // // // HSrcKeeper // // Tool to store source code along root output files. // REMARK: To work with hadd for histogram merging // a special hadd version has to be compiled which is linked // against hydra libs (Dictionary is needed) // //------------------------------------------------------------------------------ // USAGE: // // TFile* out = new TFile(outfile.Data(),"RECREATE"); // // HSrcKeeper keeper("hydra","hydra"); // // //keeper.addSourceFile("test.C"); // //keeper.addSourceFiles(dir,"\\..*[cCh]+$"); // single files or files matching the regexp inside dir // keeper.addSourceFilesRecursive(dir,"\\..*[cCh]+$"); // recursive add through all subdir of dir // // //keeper.print(".*",kFALSE); // print all files names (kTRUE: print also source code) // //keeper.extract(destinationdir,replacedir,".*"); // extract source code matching the regexp to destinationdir, replace replacedir in path names // // TMacro* m=keeper.getFile(name); // return NULL if nothing was found // // keeper.Write(); // // // out->Save(); // out->Close(); // //////////////////////////////////////////////////////////////////////////////// ClassImp(HSrcKeeper) HSrcKeeper::HSrcKeeper(const char* name,const char* title) : TNamed(name,title) { } HSrcKeeper::~HSrcKeeper(void) { } TMacro* HSrcKeeper::newFile(TString fname) { // opens the input source fname // and creates TMacro by addiding line // by line the source code. If the soure // cannot be read Null will be returned TString n = fname; TMacro* m = NULL; ifstream input; input.open(fname); if(input.fail()) return m; m = new TMacro(); m ->SetName(n.Data()); Char_t line[4000]; while(!input.eof()){ input.getline(line,4000); m->AddLine(line); } input.close(); return m; } Bool_t HSrcKeeper::addSourceFile(TString name) { // add a single source file. return kFALSE // if a problems occurs. TMacro* m = newFile(name); if(m) { cout< files; HFileSys::lsFiles(dir,files,kTRUE); sort(files.begin(),files.end()); TPRegexp expr(regexp); Int_t n=0; for(UInt_t i=0;i files; HFileSys::lsFilesRecursive(dir,files); sort(files.begin(),files.end()); TPRegexp expr(regexp); Int_t n=0; for(UInt_t i=0;iGetName() ; if(name(expr)!= ""){ if(show) { cout<<"-------------------------------------------------------------"<GetName()<Print(); } else cout<GetName()<AccessPathName(destinationdir.Data())!=0){ if( gSystem->mkdir(destinationdir.Data()) ==-1) { Error("extract()","Could not create destination dir %s. skipped.",destinationdir.Data()); return; } } TString name; for(Int_t i=0;iGetName() ; if(name(expr)!= ""){ cout<GetName()<DirName(name.Data()); if(gSystem->AccessPathName(Form("%s/%s",destinationdir.Data(),dir.Data()))!=0) { if( gSystem->mkdir(Form("%s/%s",destinationdir.Data(),dir.Data()),kTRUE) ==-1) { Error("extract()","Could not create destination dir %s. skipped.",destinationdir.Data()); continue; } } m->SaveSource(Form("%s/%s",destinationdir.Data(),name.Data())); } } } TMacro* HSrcKeeper::getFile(TString fname,Bool_t usePath) { // get TMacro of file fname. returns 0 if // the file does not exist in the container if(fname == "") return 0; TString name; for(Int_t i=0;iGetName() ; if(!usePath) name = gSystem->BaseName(name.Data()); if(name.CompareTo(fname.Data())==0) return m; } return 0; } Long64_t HSrcKeeper::Merge(TCollection *li){ // dummy function for hadd like merge of hist files if (!li) return 0; return (Long64_t) 1; }