From 953dcab5c0c0e42a94fcc6c9cb72a50369645559 Mon Sep 17 00:00:00 2001
From: Florian Uhlig <f.uhlig@gsi.de>
Date: Thu, 11 Feb 2021 17:50:58 +0100
Subject: [PATCH] c2f: Add gFile + gDirectory protection

---
 .../nicafemto/format/anatree/CbmAnaTreeSource.cxx         | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/analysis/PWGC2F/femtoscopy/nicafemto/format/anatree/CbmAnaTreeSource.cxx b/analysis/PWGC2F/femtoscopy/nicafemto/format/anatree/CbmAnaTreeSource.cxx
index 85b2389088..b4803bbadf 100644
--- a/analysis/PWGC2F/femtoscopy/nicafemto/format/anatree/CbmAnaTreeSource.cxx
+++ b/analysis/PWGC2F/femtoscopy/nicafemto/format/anatree/CbmAnaTreeSource.cxx
@@ -104,6 +104,10 @@ Int_t CbmAnaTreeSource::ReadEvent(UInt_t unsignedInt) {
 void CbmAnaTreeSource::Close() {}
 
 void CbmAnaTreeSource::LoadConf(TString name) {
+  /// Save old global file and folder pointer to avoid messing with FairRoot
+  TFile* oldFile     = gFile;
+  TDirectory* oldDir = gDirectory;
+
   TFile* f = new TFile(name);
   // TTree *tree = (TTree*)f->Get("aTree");
   AnalysisTree::Configuration* conf =
@@ -155,6 +159,10 @@ void CbmAnaTreeSource::LoadConf(TString name) {
       conf->GetBranchConfig("SimEventHeader").GetFieldId("psi_RP");
   }
 
+  /// Restore old global file and folder pointer to avoid messing with FairRoot
+  gFile      = oldFile;
+  gDirectory = oldDir;
+
   f->Close();
   delete f;
 }
-- 
GitLab