//*-- AUTHOR : J. Markert //////////////////////////////////////////////////////////////////////////// // HTool // Tool Class //////////////////////////////////////////////////////////////////////////// #include #include #include "htool.h" #include "TDirectory.h" #include "TFile.h" #include "TString.h" #include "TObjString.h" #include "TList.h" #include "TString.h" #include "TROOT.h" #include "TObject.h" ClassImp(HTool) HTool::HTool(const char* name="",const char* title="") : TNamed(name,title) { // constructor for HTool initVariables(); } HTool::~HTool() { // destructor of HTool } void HTool::initVariables() { // inits all variables } Bool_t HTool::open(TFile** file,TString fName,TString option) { // Opens root file "fName" to the pointer "file" with option // New,Read,Recreate and Update. Checks if file exists or is // already opened. If everything works fine kTRUE is returned. if(*file) { // checking if file is opened if((*file)->IsOpen()){ cout<<"Error(HTool::open() , SPECIFIED INPUT FILE IS ALREADY OPEN!"<GetListOfFiles()->FindObject(fName.Data()); if (!*file){ *file= new TFile(fName.Data(),"READ"); cout<<"HTool::open() : Reading from "<GetListOfFiles()->FindObject(fName.Data()); if (!*file){ *file= new TFile(fName.Data(),"UPDATE"); cout<<"HTool::open() : Updating "<IsOpen()){ opt=(*file)->GetOption(); if(opt.CompareTo("READ")!=0)(*file)->Save(); (*file)->Close(); *file=0; return kTRUE; }else{ cout<<"Warning(HTool::close() , SPECIFIED FILE IS NOT OPEN!"<GetListOfFiles()->FindObject(fName.Data()); if (!*file){ *file= fopen(fName.Data(),"r"); cout<<"HTool::openAscii() : Reading from "<FindKey(sDir)) { dirNew = dirOld->mkdir(sDir); } else { dirNew=(TDirectory*)dirOld->Get(sDir); } dirOld->cd(sDir); return dirNew; } TDirectory* HTool::changeToDir(TString p) { // Changes into the given path. If the Directory is not existing // it will be created. The pointer to the new directory will be returned. TDirectory *dirNew=0; TString s1=p; Ssiz_t len=s1.Length(); if(len!=0) { char* mystring=(char*)s1.Data(); Char_t* buffer; TList myarguments; TObjString *stemp; TString argument; Int_t count=0; while(1) // find all token in option string and put them to a list { if(count==0) { buffer=strtok(mystring,"/"); stemp=new TObjString(buffer); myarguments.Add(stemp); } if(!(buffer=strtok(NULL,"/")))break; stemp=new TObjString(buffer); myarguments.Add(stemp); count++; } TIterator* myiter=myarguments.MakeIterator(); // iterate over the list of arguments while ((stemp=(TObjString*)myiter->Next())!= 0) { argument=stemp->GetString(); dirNew=HTool::Mkdir(gDirectory,argument.Data(),-99); } } return dirNew; } Bool_t HTool::checkDir(TString p,TFile* input) { // Checks if a given path "p" in file "input" exists. // The actual directory will not be changed. Returns // kTRUE if OK. TDirectory* dirSave=gDirectory; TDirectory *dirNew=input; TString s1=p; Ssiz_t len=s1.Length(); if(len!=0) { char* mystring=(char*)s1.Data(); Char_t* buffer; TList myarguments; TObjString *stemp; TString argument; Int_t count=0; while(1) // find all token in option string and put them to a list { if(count==0) { buffer=strtok(mystring,"/"); stemp=new TObjString(buffer); myarguments.Add(stemp); } if(!(buffer=strtok(NULL,"/")))break; stemp=new TObjString(buffer); myarguments.Add(stemp); count++; } TIterator* myiter=myarguments.MakeIterator(); // iterate over the list of arguments while ((stemp=(TObjString*)myiter->Next())!= 0) { argument=stemp->GetString(); if(dirNew->FindKey(argument.Data())) { dirNew->cd(argument.Data()); dirNew=gDirectory; } else { dirSave->cd(); return kFALSE; } } } dirSave->cd(); return kTRUE; } void HTool::scanOracle(TString inputname,TString outputname) { // scans oracle runs table source code to extract // file names, run ids and number of events FILE* input =0; FILE* output=0; if(!HTool::openAscii(&input,inputname ,"r")) { exit(1); } if(!HTool::openAscii(&output,outputname,"w")) { exit(1); } Char_t line[4000]; TString buffer=""; TString filename; TString fileRunId; TString fileNEvents; TString newLine; Int_t count=0; Int_t sumEvts=0; Int_t Evts=0; while(1) { if(feof(input)) break; fgets(line, sizeof(line), input); buffer=line; if (buffer.Contains("100")) { buffer.ReplaceAll("",""); buffer.ReplaceAll("",""); buffer.ReplaceAll("\n",""); fileRunId=buffer; fgets(line, sizeof(line), input); fgets(line, sizeof(line), input); fgets(line, sizeof(line), input); fgets(line, sizeof(line), input); buffer=line; buffer.ReplaceAll("",""); buffer.ReplaceAll("",""); buffer.ReplaceAll("\n",""); fileNEvents=buffer; newLine= filename + " " + fileRunId + " " + fileNEvents; sscanf(newLine.Data(),"%*s%*s%i",&Evts); sumEvts=sumEvts+Evts; count++; fprintf(output,"%s%s",newLine.Data(),"\n"); } } cout<