From 4e29ad6898873d5a7013c2520b4a70745c67ee17 Mon Sep 17 00:00:00 2001 From: Andreas Suter Date: Mon, 26 Jan 2026 20:32:34 +0100 Subject: [PATCH] proper TDirectory handling for the histos. --- src/classes/PRunDataHandler.cpp | 152 ++++++++++++++++++++++---------- 1 file changed, 104 insertions(+), 48 deletions(-) diff --git a/src/classes/PRunDataHandler.cpp b/src/classes/PRunDataHandler.cpp index 7313e9e1..39361531 100644 --- a/src/classes/PRunDataHandler.cpp +++ b/src/classes/PRunDataHandler.cpp @@ -1946,7 +1946,12 @@ Bool_t PRunDataHandler::ReadRootFile() runData.SetBeamline(str); // read run summary to obtain ring anode HV values - TObjArray *runSummary = dynamic_cast(folder->FindObjectAny("RunSummary")); + TObjArray *runSummary = nullptr; + if (fileType == PRH_MUSR_ROOT) // TFolder + runSummary = dynamic_cast(folder->FindObjectAny("RunSummary")); + else { // TDirectory + f.GetObject("RunHeader/RunSummary", runSummary); + } // check if run summary is valid if (!runSummary) { @@ -2056,59 +2061,110 @@ Bool_t PRunDataHandler::ReadRootFile() // read data --------------------------------------------------------- - // check if histos folder is found - f.GetObject("histos", folder); - if (!folder) { - std::cerr << std::endl << ">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't obtain histos from " << fRunPathName.Data() << std::endl; - f.Close(); - return false; - } + if (fileType == PRH_MUSR_ROOT) { // TFolder + // check if histos folder is found + f.GetObject("histos", folder); + if (!folder) { + std::cerr << std::endl << ">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't obtain histos from " << fRunPathName.Data() << std::endl; + f.Close(); + return false; + } - // get all the data - for (UInt_t i=0; i(folder->FindObjectAny(str.Data())); - if (!histo) { - std::cerr << std::endl << ">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't get histo " << str; - std::cerr << std::endl; - f.Close(); - return false; + // get all the data + for (UInt_t i=0; i(folder->FindObjectAny(str.Data())); + if (!histo) { + std::cerr << std::endl << ">> PRunDataHandler::ReadRootFile: **ERROR** Couldn't get histo " << str; + std::cerr << std::endl; + f.Close(); + return false; + } + + dataSet.Clear(); + dataSet.SetTitle(histo->GetTitle()); + dataSet.SetHistoNo(redGreenOffsets[i]+j+1); + + // get detector info + path.Form("DetectorInfo/Detector%03d/", redGreenOffsets[i]+j+1); + pathName = path + "Name"; + header->Get(pathName, str, ok); + if (ok) + dataSet.SetName(str); + pathName = path + "Time Zero Bin"; + header->Get(pathName, dval, ok); + if (ok) + dataSet.SetTimeZeroBin(dval); + pathName = path + "First Good Bin"; + header->Get(pathName, ival, ok); + if (ok) + dataSet.SetFirstGoodBin(ival); + pathName = path + "Last Good Bin"; + header->Get(pathName, ival, ok); + if (ok) + dataSet.SetLastGoodBin(ival); + dataSet.SetTimeZeroBinEstimated(histo->GetMaximumBin()); + + // fill data + for (Int_t j=1; j<=histo->GetNbinsX(); j++) { + histoData.push_back(histo->GetBinContent(j)); + } + dataSet.SetData(histoData); + runData.SetDataSet(dataSet); + + // clear histoData for the next histo + histoData.clear(); } + } + } else { // TDirectory + // get all the data + TH1F *histo; + for (UInt_t i=0; i> PRunDataHandler::ReadRootFile: **ERROR** Couldn't get histo " << str; + std::cerr << std::endl; + f.Close(); + return false; + } - dataSet.Clear(); - dataSet.SetTitle(histo->GetTitle()); - dataSet.SetHistoNo(redGreenOffsets[i]+j+1); + dataSet.Clear(); + dataSet.SetTitle(histo->GetTitle()); + dataSet.SetHistoNo(redGreenOffsets[i]+j+1); - // get detector info - path.Form("DetectorInfo/Detector%03d/", redGreenOffsets[i]+j+1); - pathName = path + "Name"; - header->Get(pathName, str, ok); - if (ok) - dataSet.SetName(str); - pathName = path + "Time Zero Bin"; - header->Get(pathName, dval, ok); - if (ok) - dataSet.SetTimeZeroBin(dval); - pathName = path + "First Good Bin"; - header->Get(pathName, ival, ok); - if (ok) - dataSet.SetFirstGoodBin(ival); - pathName = path + "Last Good Bin"; - header->Get(pathName, ival, ok); - if (ok) - dataSet.SetLastGoodBin(ival); - dataSet.SetTimeZeroBinEstimated(histo->GetMaximumBin()); + // get detector info + path.Form("DetectorInfo/Detector%03d/", redGreenOffsets[i]+j+1); + pathName = path + "Name"; + header->Get(pathName, str, ok); + if (ok) + dataSet.SetName(str); + pathName = path + "Time Zero Bin"; + header->Get(pathName, dval, ok); + if (ok) + dataSet.SetTimeZeroBin(dval); + pathName = path + "First Good Bin"; + header->Get(pathName, ival, ok); + if (ok) + dataSet.SetFirstGoodBin(ival); + pathName = path + "Last Good Bin"; + header->Get(pathName, ival, ok); + if (ok) + dataSet.SetLastGoodBin(ival); + dataSet.SetTimeZeroBinEstimated(histo->GetMaximumBin()); - // fill data - for (Int_t j=1; j<=histo->GetNbinsX(); j++) { - histoData.push_back(histo->GetBinContent(j)); + // fill data + for (Int_t j=1; j<=histo->GetNbinsX(); j++) { + histoData.push_back(histo->GetBinContent(j)); + } + dataSet.SetData(histoData); + runData.SetDataSet(dataSet); + + // clear histoData for the next histo + histoData.clear(); } - dataSet.SetData(histoData); - runData.SetDataSet(dataSet); - - // clear histoData for the next histo - histoData.clear(); } } }