From e6553509f620cb19962f7a4963fbb3c221c58b32 Mon Sep 17 00:00:00 2001 From: Florian Uhlig <f.uhlig@gsi.de> Date: Thu, 11 Feb 2021 17:55:50 +0100 Subject: [PATCH] lx-track: Add gFile + gDirectory protection --- .../GenNoiseElectrons/GenNoiseElectrons.cxx | 10 ++++++++++ reco/tracking/lx/Simple/Lx.cxx | 18 +++++++++++++++++ reco/tracking/lx/TBBinned/LxTBTrdTask.cxx | 10 ++++++++++ reco/tracking/lxTriplet/Lx.cxx | 20 +++++++++++++++++++ .../tracking/lxTriplet/LxTrackAnaSegments.cxx | 10 ++++++++++ 5 files changed, 68 insertions(+) diff --git a/reco/tracking/lx/GenNoiseElectrons/GenNoiseElectrons.cxx b/reco/tracking/lx/GenNoiseElectrons/GenNoiseElectrons.cxx index 46c43d4a9b..0ab3812a31 100644 --- a/reco/tracking/lx/GenNoiseElectrons/GenNoiseElectrons.cxx +++ b/reco/tracking/lx/GenNoiseElectrons/GenNoiseElectrons.cxx @@ -36,6 +36,11 @@ static Double_t GetRMS(const char* name) { char fileName[128]; sprintf(fileName, "%s.root", name); TFile* curFile = TFile::CurrentFile(); + + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + TFile* f = new TFile(fileName); if (!f->IsZombie()) { @@ -46,6 +51,11 @@ static Double_t GetRMS(const char* name) { delete f; TFile::CurrentFile() = curFile; + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; + return result; } diff --git a/reco/tracking/lx/Simple/Lx.cxx b/reco/tracking/lx/Simple/Lx.cxx index 21ba88b4e6..7f52c919fc 100644 --- a/reco/tracking/lx/Simple/Lx.cxx +++ b/reco/tracking/lx/Simple/Lx.cxx @@ -296,6 +296,11 @@ GetHistoRMS(const char* histoNameBase, Int_t histoNumber, scaltype& retVal) { sprintf(name, "%s/%s_%d.root", dir_name, histoNameBase, histoNumber); TFile* curFile = TFile::CurrentFile(); + + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + TFile* f = new TFile(name); if (!f->IsZombie()) { @@ -311,6 +316,10 @@ GetHistoRMS(const char* histoNameBase, Int_t histoNumber, scaltype& retVal) { delete f; TFile::CurrentFile() = curFile; + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; } return result; } @@ -328,6 +337,11 @@ static bool GetHistoCOV(const char* histoNameBase, sprintf(dir_name, "configuration.%s", lxFinderParticleType.Data()); sprintf(name, "%s/%s_%d.root", dir_name, histoNameBase, histoNumber); TFile* curFile = TFile::CurrentFile(); + + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + TFile* f = new TFile(name); if (!f->IsZombie()) { @@ -339,6 +353,10 @@ static bool GetHistoCOV(const char* histoNameBase, delete f; TFile::CurrentFile() = curFile; + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; } return result; } diff --git a/reco/tracking/lx/TBBinned/LxTBTrdTask.cxx b/reco/tracking/lx/TBBinned/LxTBTrdTask.cxx index 23b4d9266e..6d326854f6 100644 --- a/reco/tracking/lx/TBBinned/LxTBTrdTask.cxx +++ b/reco/tracking/lx/TBBinned/LxTBTrdTask.cxx @@ -148,6 +148,11 @@ static bool GetHistoRMS(const char* name, Double_t& retVal) { sprintf(fileName, "%s.root", name); bool result = false; TFile* curFile = TFile::CurrentFile(); + + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + TFile* f = new TFile(fileName); if (!f->IsZombie()) { @@ -158,6 +163,11 @@ static bool GetHistoRMS(const char* name, Double_t& retVal) { delete f; TFile::CurrentFile() = curFile; + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; + return result; } diff --git a/reco/tracking/lxTriplet/Lx.cxx b/reco/tracking/lxTriplet/Lx.cxx index 61877229c0..92333c590a 100644 --- a/reco/tracking/lxTriplet/Lx.cxx +++ b/reco/tracking/lxTriplet/Lx.cxx @@ -139,6 +139,11 @@ GetHistoRMS(const char* histoNameBase, Int_t histoNumber, Double_t& retVal) { bool result = false; sprintf(name, "%s/%s_%d.root", dir_name, histoNameBase, histoNumber); TFile* curFile = TFile::CurrentFile(); + + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + TFile* f = new TFile(name); if (!f->IsZombie()) { @@ -150,6 +155,11 @@ GetHistoRMS(const char* histoNameBase, Int_t histoNumber, Double_t& retVal) { delete f; TFile::CurrentFile() = curFile; + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; + return result; } @@ -162,6 +172,11 @@ static bool GetHistoCOV(const char* histoNameBase, bool result = false; sprintf(name, "configuration/%s_%d.root", histoNameBase, histoNumber); TFile* curFile = TFile::CurrentFile(); + + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + TFile* f = new TFile(name); if (!f->IsZombie()) { @@ -173,6 +188,11 @@ static bool GetHistoCOV(const char* histoNameBase, delete f; TFile::CurrentFile() = curFile; + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; + return result; } diff --git a/reco/tracking/lxTriplet/LxTrackAnaSegments.cxx b/reco/tracking/lxTriplet/LxTrackAnaSegments.cxx index f996fd52ec..e6a4d71c38 100644 --- a/reco/tracking/lxTriplet/LxTrackAnaSegments.cxx +++ b/reco/tracking/lxTriplet/LxTrackAnaSegments.cxx @@ -62,6 +62,11 @@ GetHistoRMS(const char* histoNameBase, Int_t histoNumber, Double_t& retVal) { bool result = false; sprintf(name, "%s/%s_%d.root", dir_name, histoNameBase, histoNumber); TFile* curFile = TFile::CurrentFile(); + + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + TFile* f = new TFile(name); if (!f->IsZombie()) { @@ -73,6 +78,11 @@ GetHistoRMS(const char* histoNameBase, Int_t histoNumber, Double_t& retVal) { delete f; TFile::CurrentFile() = curFile; + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; + return result; } -- GitLab