Go to the documentation of this file.00001 TString CurrentDir;
00002 TString StartDir;
00003
00004 void convertfile(const char* file)
00005 {
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <fstream.h>
00024 #include <stdio.h>
00025 #include <stdarg.h>
00026
00027
00028
00029 TString filename=file;
00030 TString com1= "mkdir "+filename;
00031
00032 StartDir=gSystem->WorkingDirectory();
00033 filenameroot = filename+".root";
00034 TFile myfile(filenameroot.Data(),"READ");
00035 std::cout <<"getting objects from file "<<filenameroot.Data() << std::endl;
00036 gSystem->Exec(com1);
00037 gSystem->cd(filename.Data());
00038 CurrentDir=gSystem->WorkingDirectory();
00039
00040 gSystem->cd(StartDir.Data());
00041 convertdir(&myfile);
00042 }
00043
00044
00045 void converthisto(TH1* histo)
00046 {
00047 TString objectname=histo->GetName();
00048 TString outname=objectname+".hdat";
00049 gSystem->cd(CurrentDir.Data());
00050 std::ofstream outfile(outname.Data());
00051 if(!outfile)
00052 {
00053 std::cout <<"Error opening outputfile "<<outname.Data() << std::endl;
00054 return;
00055 }
00056
00057 std::cout <<"Converting histogram "<< histo->GetName() << std::endl;
00058 Int_t maxbinX=histo->GetNbinsX();
00059 Int_t maxbinY=histo->GetNbinsY();
00060 Int_t maxbinZ=histo->GetNbinsZ();
00061 Int_t globalbin=0;
00062 Stat_t cont=0;
00063 outfile <<"# Histogram "<<histo->ClassName() <<": "<<histo->GetName()<< std::endl;
00064 outfile <<"# Xbin \tYbin \tZbin \tContent"<< std::endl;
00065
00066 for(Int_t x=0; x<maxbinX; ++x)
00067 {
00068 for(Int_t y=0; y<maxbinY; ++y)
00069 {
00070 for(Int_t z=0; z<maxbinZ; ++z)
00071 {
00072 globalbin=histo->GetBin(x,y,z);
00073 cont=histo->GetBinContent(globalbin);
00074 outfile <<x<<" \t"<<y<<" \t"<<z<<" \t"<<cont<< std::endl;
00075
00076 }
00077 }
00078
00079 }
00080 outfile.close();
00081 gSystem->cd(StartDir.Data());
00082 }
00083
00084 void convertgraph(TGraph* graph)
00085 {
00086 TString objectname=graph->GetName();
00087 TString outname=objectname+".gdat";
00088 gSystem->cd(CurrentDir.Data());
00089 std::ofstream outfile(outname.Data());
00090 if(!outfile)
00091 {
00092 std::cout <<"Error opening outputfile "<<outname.Data() << std::endl;
00093 return;
00094 }
00095 std::cout <<"Converting graph "<< graph->GetName() << std::endl;
00096 Int_t maxpoints=graph->GetN();
00097 outfile <<"# Graph "<<graph->ClassName() <<": "<<graph->GetName()<< std::endl;
00098 outfile <<"# Point \tX \tY"<< std::endl;
00099 for(Int_t point=0; point<maxpoints; ++point)
00100 {
00101 Double_t xg=0;
00102 Double_t yg=0;
00103 graph->GetPoint(point,xg,yg);
00104 outfile <<point<<" \t\t"<<xg<<" \t"<<yg<< std::endl;
00105 }
00106 outfile.close();
00107 gSystem->cd(StartDir.Data());
00108 }
00109
00110 void convertobject(TObject* myobject)
00111 {
00112 TString objectname=myobject->GetName();
00113 TString outname=objectname+".dat";
00114 if(myobject->InheritsFrom("TDirectory"))
00115 {
00116 TDirectory* subdir=(TDirectory*) myobject;
00117 convertdir(subdir);
00118 }
00119 else if (myobject->InheritsFrom("TFolder"))
00120 {
00121 TFolder* subfold=(TFolder*) myobject;
00122 convertfolder(subfold);
00123 }
00124 else if(myobject->InheritsFrom("TH1"))
00125 {
00126
00127 TH1* histo= (TH1*) myobject;
00128 converthisto(histo);
00129 }
00130 else if (myobject->InheritsFrom("TGraph"))
00131 {
00132 TGraph* graph= (TGraph*) myobject;
00133 convertgraph(graph);
00134 }
00135 else
00136 {
00137 std::cout <<"NOT converting object"<< myobject->GetName();
00138 std::cout <<" of class "<<myobject->ClassName() <<" to ASCII."<< std::endl;
00139 }
00140 }
00141
00142
00143 void convertfolder(TFolder* fold)
00144 {
00145 std::cout <<"Converting contents of folder "<<fold->GetName())<<"..." << std::endl;
00146 TString dirname=fold->GetName();
00147 gSystem->cd(CurrentDir.Data());
00148 TString com="mkdir "+dirname;
00149 gSystem->Exec(com);
00150 gSystem->cd(dirname.Data());
00151 CurrentDir=gSystem->WorkingDirectory();
00152 TObject* myobject=0;
00153 TObject* ob=0;
00154 TIter iter(fold->GetListOfFolders());
00155 while((myobject = iter())!=0)
00156 {
00157 convertobject(myobject);
00158 }
00159 gSystem->cd(CurrentDir.Data());
00160 gSystem->cd("..");
00161 CurrentDir=gSystem->WorkingDirectory();
00162 gSystem->cd(StartDir.Data());
00163
00164 }
00165
00166
00167 void convertdir(TDirectory* source)
00168 {
00169 std::cout <<"Converting contents of directory "<<source->GetName()<<"..." << std::endl;
00170 TString dirname=source->GetName();
00171 if(!dirname.Contains(".root"))
00172 {
00173 gSystem->cd(CurrentDir.Data());
00174 TString com="mkdir "+dirname;
00175 gSystem->Exec(com);
00176 gSystem->cd(dirname.Data());
00177 CurrentDir=gSystem->WorkingDirectory();
00178
00179 }
00180 TObject* myobject=0;
00181 source->cd();
00182 gSystem->cd(StartDir.Data());
00183 TIter iter(source->GetListOfKeys());
00184 TKey* mykey=0;
00185 while((mykey=(TKey*) iter())!=0)
00186 {
00187 myobject= mykey->ReadObj();
00188 if(myobject)
00189 {
00190 convertobject(myobject);
00191 }
00192 else
00193 {
00194 std::cout <<"Could not read object "<<mykey->GetName() << std::endl;
00195 }
00196 }
00197 if(!dirname.Contains(".root"))
00198 {
00199 gSystem->cd(CurrentDir.Data());
00200 gSystem->cd("..");
00201 CurrentDir=gSystem->WorkingDirectory();
00202 gSystem->cd(StartDir.Data());
00203 }
00204
00205 }
00206