00001 #include "writeTextFile.h"
00002
00003 const char* inrootfile="HIST/finish_central_cut1.hist.root";
00004 const char* outdir="REAL";
00005
00006 int main(int argc,char** argv)
00007 {
00008 char* argvZ[] = {"-b"};
00009 Int_t argcZ = 1;
00010 TApplication r00t("r00t", &argcZ, argvZ);
00011
00012 extern char* optarg;
00013 const char* options = "i:o:m:";
00014 Int_t chr, i=0,o=0;
00015 char inRootFile[300],outDir[300];
00016 TString match;
00017 while ((chr = getopt(argc, argv, options)) >= 0){
00018 switch(chr){
00019 case 'i': strcpy(inRootFile,optarg); i=1; break;
00020 case 'o': strcpy(outDir,optarg); o=1; break;
00021 case 'm': match=optarg; break;
00022 }
00023 }
00024 if(!(i*o)){
00025 cout << "-i infile -o outdir [-m <match>]" << endl;
00026 exit(-1);
00027 }
00028
00029
00030 cout << "in root=" << inRootFile << endl
00031 << "out dir=" << outDir << endl;
00032 if(match!="") cout << "match=" << match << endl;
00033
00034
00035 TFile inRoot(inRootFile);
00036 if(!inRoot.IsOpen()){
00037 cout << "Cannot open " << inRootFile << endl;
00038 return -1;
00039 }
00040 TIterator* iterator = inRoot.GetListOfKeys()->MakeIterator();
00041 TKey* key;
00042
00043 TString outText = inRootFile;
00044 outText.Replace(0,outText.Last('/')+1,"");
00045 outText.ReplaceAll(".root",".txt");
00046 outText.Prepend("/"); outText.Prepend(outDir);
00047
00048 cout << "out txt file=" << outText.Data() << endl;
00049
00050 ofstream os(outText.Data());
00051 if(!os){cout << "huh?" << endl; return -1; }
00052
00053
00054 int count(0),nLimit(99999999);
00055 while( (key=dynamic_cast<TKey*>(iterator->Next())) != 0){
00056
00057 TObject* t = inRoot.Get(key->GetName());
00058 if(!t) continue;
00059 if(!(t->IsA()->InheritsFrom("TH1"))) continue;
00060
00061 TH1* h=(TH1*)t;
00062
00063 TString name=h->GetName();
00064 if(match!="" && !strstr(name,match.Data())) continue;
00065
00066 if(++count>nLimit) break;
00067
00068 if(h->GetXaxis()->GetXbins()->GetSize()) continue;
00069
00070 os << "name: " << h->GetName() << endl
00071 << "title: " << h->GetTitle() << endl
00072 << "dim: " << h->GetDimension() << endl
00073 << "ary: " << (h->GetXaxis()->GetXbins()->GetSize()!=0) << endl;
00074 for(int iDim=1; iDim<=h->GetDimension(); iDim++){
00075 TAxis* axis = 0;
00076 switch(iDim){
00077 case 1: axis = h->GetXaxis(); break;
00078 case 2: axis = h->GetYaxis(); break;
00079 case 3: axis = h->GetZaxis(); break;
00080 default: cout << "wrong dimension" << endl;exit(0);
00081 }
00082
00083 int nBin = axis->GetNbins();
00084
00085 os << "bins: " << nBin << endl;
00086
00087 TArrayD* ary=0;
00088 if(axis->GetXbins()->GetSize()){
00089 ary=axis->GetXbins();
00090 for(int i=0; i<ary->GetSize();i++){
00091 os << ary->At(i) << " ";
00092 }
00093 os << endl;
00094
00095 } else{
00096 os << "min: " << axis->GetBinLowEdge(1) << endl
00097 << "max: " << axis->GetBinUpEdge(nBin) << endl;
00098 }
00099 }
00100
00101 for(int ix=0; ix<h->GetNbinsX()+2; ix++){
00102 for(int iy=0; iy<h->GetNbinsY()+2; iy++){
00103 for(int iz=0; iz<h->GetNbinsZ()+2; iz++){
00104
00105 int bin = h->GetBin(ix,iy,iz);
00106 os << "bin=" << bin << " " << h->GetBinContent(bin) << " "
00107 << h->GetBinError(bin) << endl;
00108 }
00109 }
00110 }
00111
00112 }
00113
00114 cout << "done" << endl;
00115
00116 return 0;
00117 }