00001 void writeTextFile(const char* inRootFile=
00002 "links/P00hk.nofield.refitOS.undoPTCME.slice/dip5.typec.slice.root",
00003 const char* outDir=
00004 "links/P00hk.nofield.refitOS.undoPTCME.slice")
00005 {
00006 cout << "in root=" << inRootFile << endl
00007 << "out dir=" << outDir << endl;
00008
00009 TFile inRoot(inRootFile);
00010 if(!inRoot.IsOpen()){
00011 cout << "Cannot open " << inRootFile << endl;
00012 return;
00013 }
00014 TIterator* iterator = inRoot.GetListOfKeys()->MakeIterator();
00015 TKey* key;
00016
00017 TString outText = inRootFile;
00018 outText.Replace(0,outText.Last('/')+1,"");
00019 outText.ReplaceAll(".root",".txt");
00020 outText.Prepend("/"); outText.Prepend(outDir);
00021
00022 ofstream os(outText.Data());
00023 if(!os){cout << "huh?" << endl; return; }
00024
00025 char buf[500];
00026
00027 int count(0),nLimit(5);
00028 while( (key=dynamic_cast<TKey*>(iterator->Next())) != 0){
00029
00030 TH1* h = (TH1*)inRoot.Get(key->GetName());
00031 if(h->GetDimension()!=1) continue;
00032
00033
00034
00035 int nBin = h->GetNbinsX();
00036 os << "name: " << h->GetName() << endl
00037 << "title: " << h->GetTitle() << endl
00038 << "bins: " << h->GetNbinsX() << endl;
00039 TArrayD* ary=0;
00040 if(ary=h->GetXaxis()->GetXbins()){
00041 os << "isarray" << endl;
00042 for(int i=0; i<ary->GetSize();i++){
00043 os << ary->At(i) << " ";
00044 }
00045 os << endl;
00046 } else{
00047 os << "notarray" << endl;
00048 << "min: " << h->GetXaxis()->GetBinLowEdge(1) << endl
00049 << "max: " << h->GetXaxis()->GetBinUpEdge(h->GetNbinsX()) << endl;
00050 }
00051
00052 for(int i=1; i<=nBin; i++){
00053 os << "bin=" << i << " value: " << h->GetBinContent(i)
00054 << " error: " << h->GetBinError(i) << endl;
00055
00056 }
00057 }
00058
00059 }