TString CurrentDir; TString StartDir; void convertfile(const char* file) { ////////////////////////////////////////////////// // NOTE: for Go4 Version > 2.8 and ROOT >= 4.00/06, // Go4 uses the root library mapping, so it is not // necessary to use gSystem->Load of required libraries in any // macro. If you work with older versions of root, // please uncomment the following lines: //gSystem->Load("libThread.so"); //gSystem->Load("libMinuit.so"); //gSystem->Load("$GO4SYS/lib/libGo4Base.so"); //gSystem->Load("$GO4SYS/lib/libGo4Fit.so"); //gSystem->Load("$GO4SYS/lib/libGo4ThreadManager.so"); //gSystem->Load("$GO4SYS/lib/libGo4TaskHandler.so"); //gSystem->Load("$GO4SYS/lib/libGo4Version.so"); //gSystem->Load("$GO4SYS/lib/libGo4AnalBase.so"); //gSystem->Load("$GO4SYS/lib/libGo4Analysis.so"); //gSystem->Load("libGo4UserAnalysis.so"); #include #include #include //TString filename="test_ASF.root"; TString filename=file; TString com1= "mkdir "+filename; StartDir=gSystem->WorkingDirectory(); filenameroot = filename+".root"; TFile myfile(filenameroot.Data(),"READ"); std::cout <<"getting objects from file "<Exec(com1); gSystem->cd(filename.Data()); CurrentDir=gSystem->WorkingDirectory(); // gSystem->Exec("pwd"); gSystem->cd(StartDir.Data()); convertdir(&myfile); } void converthisto(TH1* histo) { TString objectname=histo->GetName(); TString outname=objectname+".hdat"; gSystem->cd(CurrentDir.Data()); std::ofstream outfile(outname.Data()); if(!outfile) { std::cout <<"Error opening outputfile "<GetName() << std::endl; Int_t maxbinX=histo->GetNbinsX(); Int_t maxbinY=histo->GetNbinsY(); Int_t maxbinZ=histo->GetNbinsZ(); Int_t globalbin=0; Stat_t cont=0; outfile <<"# Histogram "<ClassName() <<": "<GetName()<< std::endl; outfile <<"# Xbin \tYbin \tZbin \tContent"<< std::endl; //outfile <<"# Xbin \tContent"<< std::endl; for(Int_t x=0; xGetBin(x,y,z); cont=histo->GetBinContent(globalbin); outfile <cd(StartDir.Data()); } void convertgraph(TGraph* graph) { TString objectname=graph->GetName(); TString outname=objectname+".gdat"; gSystem->cd(CurrentDir.Data()); std::ofstream outfile(outname.Data()); if(!outfile) { std::cout <<"Error opening outputfile "<GetName() << std::endl; Int_t maxpoints=graph->GetN(); outfile <<"# Graph "<ClassName() <<": "<GetName()<< std::endl; outfile <<"# Point \tX \tY"<< std::endl; for(Int_t point=0; pointGetPoint(point,xg,yg); outfile <cd(StartDir.Data()); } void convertobject(TObject* myobject) { TString objectname=myobject->GetName(); TString outname=objectname+".dat"; if(myobject->InheritsFrom("TDirectory")) { TDirectory* subdir=(TDirectory*) myobject; convertdir(subdir); } else if (myobject->InheritsFrom("TFolder")) { TFolder* subfold=(TFolder*) myobject; convertfolder(subfold); } else if(myobject->InheritsFrom("TH1")) { TH1* histo= (TH1*) myobject; converthisto(histo); } else if (myobject->InheritsFrom("TGraph")) { TGraph* graph= (TGraph*) myobject; convertgraph(graph); } else { std::cout <<"NOT converting object"<< myobject->GetName(); std::cout <<" of class "<ClassName() <<" to ASCII."<< std::endl; } } void convertfolder(TFolder* fold) { std::cout <<"Converting contents of folder "<GetName())<<"..." << std::endl; TString dirname=fold->GetName(); gSystem->cd(CurrentDir.Data()); // create subdirectory in file system TString com="mkdir "+dirname; gSystem->Exec(com); gSystem->cd(dirname.Data()); CurrentDir=gSystem->WorkingDirectory(); TObject* myobject=0; TObject* ob=0; TIter iter(fold->GetListOfFolders()); while((myobject = iter())!=0) { convertobject(myobject); } gSystem->cd(CurrentDir.Data()); gSystem->cd(".."); CurrentDir=gSystem->WorkingDirectory(); // go up one directory level again gSystem->cd(StartDir.Data()); } void convertdir(TDirectory* source) { std::cout <<"Converting contents of directory "<GetName()<<"..." << std::endl; TString dirname=source->GetName(); if(!dirname.Contains(".root")) { gSystem->cd(CurrentDir.Data()); // create subdirectory in file system TString com="mkdir "+dirname; gSystem->Exec(com); gSystem->cd(dirname.Data()); CurrentDir=gSystem->WorkingDirectory(); } TObject* myobject=0; source->cd(); gSystem->cd(StartDir.Data()); TIter iter(source->GetListOfKeys()); TKey* mykey=0; while((mykey=(TKey*) iter())!=0) { myobject= mykey->ReadObj(); if(myobject) { convertobject(myobject); } else { std::cout <<"Could not read object "<GetName() << std::endl; } } // while if(!dirname.Contains(".root")) { gSystem->cd(CurrentDir.Data()); gSystem->cd(".."); CurrentDir=gSystem->WorkingDirectory(); // go up one directory level again gSystem->cd(StartDir.Data()); } }