From cc311aad5c6e9465a6ff2482ad04a897306beee0 Mon Sep 17 00:00:00 2001 From: Florian Uhlig <f.uhlig@gsi.de> Date: Thu, 11 Feb 2021 17:51:49 +0100 Subject: [PATCH] pwgcha: Add gFile + gDirectory protection --- analysis/PWGCHA/jpsi/CbmAnaJpsiSuperEvent.cxx | 18 ++++++++++++++++++ .../PWGCHA/jpsi/CbmAnaJpsiSuperEventReport.cxx | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/analysis/PWGCHA/jpsi/CbmAnaJpsiSuperEvent.cxx b/analysis/PWGCHA/jpsi/CbmAnaJpsiSuperEvent.cxx index fa8cbcae3d..0c87b143a2 100644 --- a/analysis/PWGCHA/jpsi/CbmAnaJpsiSuperEvent.cxx +++ b/analysis/PWGCHA/jpsi/CbmAnaJpsiSuperEvent.cxx @@ -58,8 +58,17 @@ void CbmAnaJpsiSuperEvent::Run() { Draw(); + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + TFile* file = new TFile(fOutputFile.c_str(), "RECREATE"); fHM->WriteToFile(); + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; + file->Close(); cout << "-I- Output file:" << fOutputFile << endl; @@ -234,6 +243,11 @@ void CbmAnaJpsiSuperEvent::ReadCandidates() { fPlusCandidates.clear(); cout << "-I- ReadCandidates" << endl; cout << "-I- fFileNames.size:" << fFileNames.size() << endl; + + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + for (UInt_t iFile = 0; iFile < fFileNames.size(); iFile++) { cout << "-I- Reading file No " << iFile << " path:" << fFileNames[iFile] << endl; @@ -278,6 +292,10 @@ void CbmAnaJpsiSuperEvent::ReadCandidates() { f->Close(); delete f; } + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; + cout << "-I- fMinusCandidates.size:" << fMinusCandidates.size() << endl; cout << "-I- fPlusCandidates.size:" << fPlusCandidates.size() << endl; cout << "-I- number of events:" << fHM->H1("fh_se_event_number")->GetEntries() diff --git a/analysis/PWGCHA/jpsi/CbmAnaJpsiSuperEventReport.cxx b/analysis/PWGCHA/jpsi/CbmAnaJpsiSuperEventReport.cxx index b0f9c9f95c..6ec304c9b2 100644 --- a/analysis/PWGCHA/jpsi/CbmAnaJpsiSuperEventReport.cxx +++ b/analysis/PWGCHA/jpsi/CbmAnaJpsiSuperEventReport.cxx @@ -38,6 +38,10 @@ CbmAnaJpsiSuperEventReport::~CbmAnaJpsiSuperEventReport() {} void CbmAnaJpsiSuperEventReport::Create(const string& fileEventByEvent, const string& fileSuperEvent, const string& outputDir) { + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + fHMSuperEvent = new CbmHistManager(); TFile* fileSE = new TFile(fileSuperEvent.c_str()); fHMSuperEvent->ReadFromFile(fileSE); @@ -48,6 +52,10 @@ void CbmAnaJpsiSuperEventReport::Create(const string& fileEventByEvent, SetOutputDir(outputDir); CreateReports(); + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; } void CbmAnaJpsiSuperEventReport::Create() { //Out().precision(3); -- GitLab