void merge(TString outfile, TString firstfile, TString pat=defaultPattern) { TList decayModes; bool save=false; TString dir="."; TString first=""; long flags=0,id=0,size=0,modtime=0; if(firstfile.Contains("~")) { cout<<"ERROR: input path cannot contain '~' character."<<endl; return; } // Check pattern TRegexp pattern(pat,true); if(pattern.Status()!=0) { cout<<"ERROR: Wrong regular expression."<<endl; return; } // Load libraries loadLibs(); gSystem->GetPathInfo(firstfile, &id, &size, &flags, &modtime); bool isDirectory = flags&2; if(isDirectory) { dir=firstfile; first=""; } else { //Separate directory from filename int separator=firstfile.Last('/'); if(separator!=-1) dir=firstfile(0,separator+1); first=firstfile(separator+1,firstfile.Length()); } cout<<"Output file: "<<outfile<<endl; cout<<"Input dir: "<<dir<<endl; if(!isDirectory) cout<<"First file: "<<first<<endl; cout<<endl; // Get file list and add first file if present TList *files = getFileList(first,dir,pattern); if(!isDirectory) { TFile *ff = new TFile(firstfile,"READ"); files->AddBefore(files->First(),ff); } // Merge files TIter next(files); TFile *file; while(file = (TFile*)next()) { if(!file->IsOpen()) continue; ReadFile(file,decayModes); cout<<"=============================="<<endl; save=true; } // Save output if(save) { cout<<"Saving..."<<endl; SaveOutput(outfile,decayModes); cout<<"Output saved to "<<outfile<<endl<<endl; } else cout<<"Nothing to save."<<endl<<endl; // Closing files cout<<"Closing files..."<<endl; TIter cl(files); while(file = (TFile*)cl()) { file->Close(); delete file; } delete files; gSystem->Exit(0); }