From d6eb8f37141f8a2ac568fdaadc0a6fb155420bb4 Mon Sep 17 00:00:00 2001 From: Suter Andreas Date: Fri, 21 Nov 2014 17:58:31 +0100 Subject: [PATCH] ascii exporter for fake data. --- src/tests/analyticFakeData/exportToAscii.C | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/tests/analyticFakeData/exportToAscii.C diff --git a/src/tests/analyticFakeData/exportToAscii.C b/src/tests/analyticFakeData/exportToAscii.C new file mode 100644 index 00000000..d5d2a18c --- /dev/null +++ b/src/tests/analyticFakeData/exportToAscii.C @@ -0,0 +1,91 @@ +void exportToAscii(const char *flnRoot, const char *flnAscii) +{ + // load library + gSystem->Load("$ROOTSYS/lib/libTLemRunHeader"); + gSystem->Load("$ROOTSYS/lib/libTMusrRunHeader"); + + // open MusrRoot file + TFile fin(flnRoot, "READ"); + if (fin.IsZombie()) { + cout << endl << "**ERROR** Couldn't open " << flnRoot << " for reading." << endl << endl; + return; + } + + // get time resolution + TFolder *runHeader = 0; + fin.GetObject("RunHeader", runHeader); + if (runHeader == 0) { + cerr << endl << ">> **ERROR** Couldn't get top folder RunHeader"; + fin.Close(); + return -1; + } + + TMusrRunHeader *header = new TMusrRunHeader(flnRoot); + + if (!header->ExtractAll(runHeader)) { + cerr << endl << ">> **ERROR** couldn't extract all RunHeader information"; + fin.Close(); + return -1; + } + + TMusrRunPhysicalQuantity prop; + Bool_t ok; + header->Get("RunInfo/Time Resolution", prop, ok); + if (!ok) { + cerr << endl << "**ERROR** couldn't extract time resolution :-(, will quit" << endl; + fin.Close(); + return -1; + } + Double_t timeResolutionValue = prop.GetValue(); + TString timeResolutionUnit = prop.GetUnit(); + cout << endl << "Time Resolution: " << timeResolutionValue << " (" << timeResolutionUnit << ")" << endl; + + Int_t ival = 0; + Int_t noOfHistos = 0; + header->Get("RunInfo/No of Histos", ival, ok); + if (ok) { + noOfHistos = ival; + } + cout << endl << "Found " << noOfHistos << " number of histos." << endl; + + // get the data + TFolder *folder=0; + // check if histos folder is found + fin.GetObject("histos", folder); + if (!folder) { + cerr << endl << "**ERROR** couldn't get histo folder." << endl; + fin.Close(); + return -1; + } + + vector< vector > data; + TString str; + data.resize(noOfHistos); + for (Int_t i=0; i(folder->FindObjectAny(str.Data())); + if (!histo) { + cerr << endl << "**ERROR** Couldn't get histo " << str << endl; + fin.Close(); + return false; + } + + for (Int_t j=0; jGetNbinsX(); j++) { + data[i].push_back(histo->GetBinContent(j)); + } + } + + fin.Close(); + + // write data + ofstream fout(flnAscii, ofstream::out); + fout << "% Time Resolution: " << timeResolutionValue << " (" << timeResolutionUnit << ")" << endl; + fout << "% # histos: " << noOfHistos << endl; + for (Int_t i=1; i