From 672a44d9d1c49a88459787c2d6a3b5b9eafc5cf3 Mon Sep 17 00:00:00 2001 From: Florian Uhlig <f.uhlig@gsi.de> Date: Thu, 11 Feb 2021 18:00:01 +0100 Subject: [PATCH] rich: Add gFile + gDirectory protection --- reco/detectors/rich/CbmRichRadiusCorrection.h | 10 ++- .../rich/alignment/CbmHistManager.cxx | 11 +++- .../rich/alignment/CbmRichAlignment.cxx | 8 +++ .../rich/alignment/CbmRichCorrection.cxx | 8 +++ .../alignment/CbmRichCorrectionVector.cxx | 8 +++ .../rich/alignment/CbmRichPMTMapping.cxx | 8 +++ .../rich/alignment/CbmRichRecoQa.cxx | 8 +++ .../rich/mcbm/CbmRichMCbmAerogelAna.cxx | 13 ++++ reco/detectors/rich/mcbm/CbmRichMCbmQa.cxx | 64 +++++++++++-------- .../detectors/rich/mcbm/CbmRichMCbmQaReal.cxx | 13 ++++ .../rich/mcbm/CbmRichMCbmQaRichOnly.cxx | 13 ++++ reco/detectors/rich/qa/CbmRichGeoTest.cxx | 8 +++ reco/detectors/rich/qa/CbmRichGeoTestOpt.cxx | 30 +++++++++ reco/detectors/rich/qa/CbmRichRecoQa.cxx | 8 +++ 14 files changed, 178 insertions(+), 32 deletions(-) diff --git a/reco/detectors/rich/CbmRichRadiusCorrection.h b/reco/detectors/rich/CbmRichRadiusCorrection.h index 71f0b7f1a5..72f8304a0a 100644 --- a/reco/detectors/rich/CbmRichRadiusCorrection.h +++ b/reco/detectors/rich/CbmRichRadiusCorrection.h @@ -65,7 +65,10 @@ private: string fileName = gSystem->Getenv("VMCWORKDIR"); fileName += "/parameters/rich/radius_correction_map_compact.root"; - TDirectory* current = gDirectory; + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + TFile* file = new TFile(fileName.c_str(), "READ"); if (NULL == file || !file->IsOpen()) { @@ -83,7 +86,10 @@ private: file->Close(); delete file; - current->cd(); + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; } static TH2D* fhMapAaxisXY; diff --git a/reco/detectors/rich/alignment/CbmHistManager.cxx b/reco/detectors/rich/alignment/CbmHistManager.cxx index 8085f37c0b..8bbf29dcde 100644 --- a/reco/detectors/rich/alignment/CbmHistManager.cxx +++ b/reco/detectors/rich/alignment/CbmHistManager.cxx @@ -105,7 +105,11 @@ void CbmHistManager::WriteToFile() { void CbmHistManager::WriteToFileNew(const string& str) { std::string histoName = ""; map<string, TNamed*>::iterator it; - TDirectory* oldir = gDirectory; + + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + TFile* fHist = new TFile(str.c_str(), "RECREATE"); fHist->cd(); @@ -134,7 +138,10 @@ void CbmHistManager::WriteToFileNew(const string& str) { fHist->cd(); // make the file root the current directory - gDirectory->cd(oldir->GetPath()); + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; + fHist->Close(); } diff --git a/reco/detectors/rich/alignment/CbmRichAlignment.cxx b/reco/detectors/rich/alignment/CbmRichAlignment.cxx index 7dfa4de080..81da33d0a4 100644 --- a/reco/detectors/rich/alignment/CbmRichAlignment.cxx +++ b/reco/detectors/rich/alignment/CbmRichAlignment.cxx @@ -535,10 +535,18 @@ void CbmRichAlignment::DrawFit(vector<Double_t>& outputFit, Int_t thresh) { } void CbmRichAlignment::DrawHistFromFile(TString fileName) { + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + fHM = new CbmHistManager(); TFile* file = new TFile(fileName, "READ"); fHM->ReadFromFile(file); DrawHistAlignment(); + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; } void CbmRichAlignment::Finish() { diff --git a/reco/detectors/rich/alignment/CbmRichCorrection.cxx b/reco/detectors/rich/alignment/CbmRichCorrection.cxx index 56246b254c..a730965f06 100644 --- a/reco/detectors/rich/alignment/CbmRichCorrection.cxx +++ b/reco/detectors/rich/alignment/CbmRichCorrection.cxx @@ -1541,10 +1541,18 @@ void CbmRichCorrection::DrawHistProjection() { } void CbmRichCorrection::DrawHistFromFile(TString fileName) { + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + fHM = new CbmHistManager(); TFile* file = new TFile(fileName, "READ"); fHM->ReadFromFile(file); DrawHistProjection(); + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; } void CbmRichCorrection::Finish() { diff --git a/reco/detectors/rich/alignment/CbmRichCorrectionVector.cxx b/reco/detectors/rich/alignment/CbmRichCorrectionVector.cxx index a410c2ced2..9c791bfe90 100644 --- a/reco/detectors/rich/alignment/CbmRichCorrectionVector.cxx +++ b/reco/detectors/rich/alignment/CbmRichCorrectionVector.cxx @@ -1566,10 +1566,18 @@ void CbmRichCorrectionVector::DrawHistProjection() { } void CbmRichCorrectionVector::DrawHistFromFile(TString fileName) { + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + fHM = new CbmHistManager(); TFile* file = new TFile(fileName, "READ"); fHM->ReadFromFile(file); DrawHistMapping(); + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; } void CbmRichCorrectionVector::Finish() { diff --git a/reco/detectors/rich/alignment/CbmRichPMTMapping.cxx b/reco/detectors/rich/alignment/CbmRichPMTMapping.cxx index bf98f89252..1f8901700d 100644 --- a/reco/detectors/rich/alignment/CbmRichPMTMapping.cxx +++ b/reco/detectors/rich/alignment/CbmRichPMTMapping.cxx @@ -1473,10 +1473,18 @@ void CbmRichPMTMapping::DrawHist() { } void CbmRichPMTMapping::DrawHistFromFile(TString fileName) { + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + fHM = new CbmHistManager(); TFile* file = new TFile(fileName, "READ"); fHM->ReadFromFile(file); DrawHist(); + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; } void CbmRichPMTMapping::Finish() { diff --git a/reco/detectors/rich/alignment/CbmRichRecoQa.cxx b/reco/detectors/rich/alignment/CbmRichRecoQa.cxx index dc9d3e4c54..37a83a4261 100644 --- a/reco/detectors/rich/alignment/CbmRichRecoQa.cxx +++ b/reco/detectors/rich/alignment/CbmRichRecoQa.cxx @@ -1223,6 +1223,10 @@ void CbmRichRecoQa::DrawFromFile(const string& fileName, const string& outputDir) { fOutputDir = outputDir; + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + if (fHM != nullptr) delete fHM; fHM = new CbmHistManager(); @@ -1232,6 +1236,10 @@ void CbmRichRecoQa::DrawFromFile(const string& fileName, DrawHist(); fHM->SaveCanvasToImage(fOutputDir); + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; } ClassImp(CbmRichRecoQa) diff --git a/reco/detectors/rich/mcbm/CbmRichMCbmAerogelAna.cxx b/reco/detectors/rich/mcbm/CbmRichMCbmAerogelAna.cxx index 3fae18de7b..4d8d7d8506 100644 --- a/reco/detectors/rich/mcbm/CbmRichMCbmAerogelAna.cxx +++ b/reco/detectors/rich/mcbm/CbmRichMCbmAerogelAna.cxx @@ -544,7 +544,10 @@ void CbmRichMCbmAerogelAna::Finish() { } if (this->fDoWriteHistToFile) { + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; TDirectory* oldir = gDirectory; + std::string s = fOutputDir + "/RecoHists.root"; TFile* outFile = new TFile(s.c_str(), "RECREATE"); if (outFile->IsOpen()) { @@ -553,6 +556,8 @@ void CbmRichMCbmAerogelAna::Finish() { outFile->Close(); std::cout << "Done!" << std::endl; } + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; gDirectory->cd(oldir->GetPath()); } } @@ -562,6 +567,10 @@ void CbmRichMCbmAerogelAna::DrawFromFile(const string& fileName, const string& outputDir) { fOutputDir = outputDir; + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + if (fHM != nullptr) delete fHM; fHM = new CbmHistManager(); @@ -570,6 +579,10 @@ void CbmRichMCbmAerogelAna::DrawFromFile(const string& fileName, DrawHist(); fHM->SaveCanvasToImage(fOutputDir); + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; } diff --git a/reco/detectors/rich/mcbm/CbmRichMCbmQa.cxx b/reco/detectors/rich/mcbm/CbmRichMCbmQa.cxx index 1dc5c49d5e..e653fd2bec 100644 --- a/reco/detectors/rich/mcbm/CbmRichMCbmQa.cxx +++ b/reco/detectors/rich/mcbm/CbmRichMCbmQa.cxx @@ -394,17 +394,17 @@ void CbmRichMCbmQa::Exec(Option_t* /*option*/) { if (point == NULL) continue; Int_t mcTrackIdPoint = point->GetTrackID(); - + if (mcTrackIdPoint == NULL) continue; CbmMCTrack* mcTrack = (CbmMCTrack*)fMCTracks->At(mcTrackIdPoint); if (mcTrack == NULL) continue; - - + + Int_t pdg = TMath::Abs(mcTrack->GetPdgCode()); // cout << "pdg: " << pdg << endl; - fHM->H2("fh_rich_points_xy")->Fill(point->GetX(), point->GetY()); - - + fHM->H2("fh_rich_points_xy")->Fill(point->GetX(), point->GetY()); + + for(int iT = 0; iT < nofTofHits; iT++){ CbmTofHit* tofHit = static_cast<CbmTofHit*>(fTofHits->At(iT)); if(NULL == tofHit) continue; @@ -418,18 +418,18 @@ void CbmRichMCbmQa::Exec(Option_t* /*option*/) { CbmMCTrack* mcTrackTof = (CbmMCTrack*)fMCTracks->At(mcTrackIdTofHit); if (NULL == mcTrackTof) continue; - + Double_t time = tofHit->GetTime(); Double_t timect = 0.2998*time; //time in ns, timect in m Double_t trackLength = tofHit->GetR()/100; Double_t beta = trackLength/timect; - - + + if(mcTrackIdPoint == mcTrackIdTofHit){ fHM->H1("fh_beta_dis_all")->Fill(beta); } } - + for(int iRing = 0; iRing < nofRichRings; iRing++){ CbmRichRing* ring = static_cast<CbmRichRing*>(fRichRings->At(iRing)); if (NULL == ring) continue; @@ -437,11 +437,11 @@ void CbmRichMCbmQa::Exec(Option_t* /*option*/) { if (NULL == ringMatch) continue; Int_t mcTrackIdRing = ringMatch->GetMatchedLink().GetIndex(); if (mcTrackIdRing < 0) continue; - - + + CbmMCTrack* mcTrackRing = (CbmMCTrack*)fMCTracks->At(mcTrackIdRing); if(mcTrackRing == NULL) continue; - + if(mcTrackIdTofHit == mcTrackIdRing){ // cout << "mcTrackIdTofHit: " << mcTrackIdTofHit << endl; // cout << "mcTrackIdRing: " << mcTrackIdRing << endl; @@ -451,11 +451,11 @@ void CbmRichMCbmQa::Exec(Option_t* /*option*/) { fHM->H2("fh_radius_beta")->Fill(beta, radius); fHM->H1("fh_beta_dis_ring")->Fill(beta); fHM->H2("fh_radius_momentum")->Fill(momTotal, radius); - + } } - } - } + } + } */ @@ -469,17 +469,17 @@ void CbmRichMCbmQa::Exec(Option_t* /*option*/) { if (NULL == ringMatch) continue; Int_t mcTrackIdRing = ringMatch->GetMatchedLink().GetIndex(); if (mcTrackIdRing < 0) continue; - - + + CbmMCTrack* mcTrackRing = (CbmMCTrack*)fMCTracks->At(mcTrackIdRing); if(mcTrackRing == NULL) continue; Double_t radius = ring->GetRadius(); - + Int_t motherId = mcTrackRing->GetMotherId(); // Int_t pdg = TMath::Abs(mcTrackRing->GetPdgCode()); // cout << "pdg" << pdg << endl; - - + + int nofHits = ring->GetNofHits(); TVector3 vec1; mcTrackRing->GetMomentum(vec1); @@ -492,7 +492,7 @@ void CbmRichMCbmQa::Exec(Option_t* /*option*/) { fHM->H1("fh_rich_ring_radius")->Fill(radius); //fHM->H2("fh_radius_momentum")->Fill(momTotal1, radius); cout << "richRingId: " << mcTrackIdRing << endl; - + for (int iH = 0; iH < nofHits; iH++) { Int_t hitInd = ring->GetHit(iH); CbmRichHit* hit = (CbmRichHit*) fRichHits->At(hitInd); @@ -503,10 +503,10 @@ void CbmRichMCbmQa::Exec(Option_t* /*option*/) { Double_t dR = radius - TMath::Sqrt( (cX - hitX)*( cX - hitX) + (cY - hitY)*(cY - hitY) ); fHM->H1("fh_dR")->Fill(dR); } - + for(int iT = 0; iT < nofTofHits; iT++){ - + CbmTofHit* tofHit = static_cast<CbmTofHit*>(fTofHits->At(iT)); if(NULL == tofHit) continue; CbmTrackMatchNew* tofHitMatch = (CbmTrackMatchNew*) fTofHitMatches->At(iT); @@ -526,10 +526,10 @@ void CbmRichMCbmQa::Exec(Option_t* /*option*/) { Double_t timect = 0.2998*time; //time in ns, timect in m Double_t trackLength = tofHit->GetR()/100; Double_t beta = trackLength/timect; - + Double_t mass2 = TMath::Power(momTotal, 2.) * (TMath::Power(1/beta, 2) - 1); //m² = p²*((1/beta)²-1) - + if(mcTrackIdTofHit == mcTrackIdRing){ //cout << "mcTrackIdTofHit: " << mcTrackIdTofHit << endl; //cout << "mcTrackIdRing: " << mcTrackIdRing << endl; @@ -539,10 +539,10 @@ void CbmRichMCbmQa::Exec(Option_t* /*option*/) { // fHM->H2("fh_radius_beta")->Fill(beta, radius); // fHM->H1("fh_beta_dis_ring")->Fill(beta); // fHM->H2("fh_radius_momentum")->Fill(momTotal, radius); - + } } - } + } } */ } @@ -746,6 +746,10 @@ void CbmRichMCbmQa::DrawFromFile(const string& fileName, const string& outputDir) { fOutputDir = outputDir; + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + if (fHM != nullptr) delete fHM; fHM = new CbmHistManager(); @@ -755,6 +759,10 @@ void CbmRichMCbmQa::DrawFromFile(const string& fileName, DrawHist(); fHM->SaveCanvasToImage(fOutputDir); + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; } diff --git a/reco/detectors/rich/mcbm/CbmRichMCbmQaReal.cxx b/reco/detectors/rich/mcbm/CbmRichMCbmQaReal.cxx index 338c8eb515..302c048974 100644 --- a/reco/detectors/rich/mcbm/CbmRichMCbmQaReal.cxx +++ b/reco/detectors/rich/mcbm/CbmRichMCbmQaReal.cxx @@ -2949,7 +2949,10 @@ void CbmRichMCbmQaReal::Finish() { } if (this->fDoWriteHistToFile) { + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; TDirectory* oldir = gDirectory; + std::string s = fOutputDir + "/RecoHists.root"; TFile* outFile = new TFile(s.c_str(), "RECREATE"); if (outFile->IsOpen()) { @@ -2958,6 +2961,8 @@ void CbmRichMCbmQaReal::Finish() { outFile->Close(); std::cout << "Done!" << std::endl; } + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; gDirectory->cd(oldir->GetPath()); } @@ -3001,6 +3006,10 @@ void CbmRichMCbmQaReal::DrawFromFile(const string& fileName, const string& outputDir) { fOutputDir = outputDir; + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + if (fHM != nullptr) delete fHM; fHM = new CbmHistManager(); @@ -3009,6 +3018,10 @@ void CbmRichMCbmQaReal::DrawFromFile(const string& fileName, DrawHist(); fHM->SaveCanvasToImage(fOutputDir); + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; } bool CbmRichMCbmQaReal::isAccmRICH(CbmTofTracklet* track) { diff --git a/reco/detectors/rich/mcbm/CbmRichMCbmQaRichOnly.cxx b/reco/detectors/rich/mcbm/CbmRichMCbmQaRichOnly.cxx index 68c6a3eda6..178faf1011 100644 --- a/reco/detectors/rich/mcbm/CbmRichMCbmQaRichOnly.cxx +++ b/reco/detectors/rich/mcbm/CbmRichMCbmQaRichOnly.cxx @@ -716,7 +716,10 @@ void CbmRichMCbmQaRichOnly::Finish() { } if (this->fDoWriteHistToFile) { + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; TDirectory* oldir = gDirectory; + std::string s = fOutputDir + "/RecoHists.root"; TFile* outFile = new TFile(s.c_str(), "RECREATE"); if (outFile->IsOpen()) { @@ -725,6 +728,8 @@ void CbmRichMCbmQaRichOnly::Finish() { outFile->Close(); std::cout << "Done!" << std::endl; } + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; gDirectory->cd(oldir->GetPath()); } } @@ -734,6 +739,10 @@ void CbmRichMCbmQaRichOnly::DrawFromFile(const string& fileName, const string& outputDir) { fOutputDir = outputDir; + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + if (fHM != nullptr) delete fHM; fHM = new CbmHistManager(); @@ -742,6 +751,10 @@ void CbmRichMCbmQaRichOnly::DrawFromFile(const string& fileName, DrawHist(); fHM->SaveCanvasToImage(fOutputDir); + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; } bool CbmRichMCbmQaRichOnly::doToT(CbmRichHit* hit) { diff --git a/reco/detectors/rich/qa/CbmRichGeoTest.cxx b/reco/detectors/rich/qa/CbmRichGeoTest.cxx index 91f216c502..74870cf0e5 100644 --- a/reco/detectors/rich/qa/CbmRichGeoTest.cxx +++ b/reco/detectors/rich/qa/CbmRichGeoTest.cxx @@ -1852,6 +1852,10 @@ void CbmRichGeoTest::DrawFromFile(const string& fileName, const string& outputDir) { fOutputDir = outputDir; + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + if (fHM != NULL) delete fHM; fHM = new CbmHistManager(); @@ -1861,6 +1865,10 @@ void CbmRichGeoTest::DrawFromFile(const string& fileName, DrawHist(); fHM->SaveCanvasToImage(fOutputDir, "png,eps"); + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; } ClassImp(CbmRichGeoTest) diff --git a/reco/detectors/rich/qa/CbmRichGeoTestOpt.cxx b/reco/detectors/rich/qa/CbmRichGeoTestOpt.cxx index 2d07505352..edb4be04de 100644 --- a/reco/detectors/rich/qa/CbmRichGeoTestOpt.cxx +++ b/reco/detectors/rich/qa/CbmRichGeoTestOpt.cxx @@ -70,12 +70,22 @@ CbmRichGeoTestOpt::H1MeanRms(CbmRichGeoTestOptFileEnum fileEnum, const string& histName) { string path = GetFilePath(fileEnum, iFile); if (path == "") return make_pair(0., 0.); + + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + TFile* file = new TFile(path.c_str(), "READ"); if (file == nullptr) return make_pair(0., 0.); TH1D* hist = (TH1D*) file->Get(histName.c_str()); if (hist == nullptr) return make_pair(0., 0.); double mean = hist->GetMean(); double rms = hist->GetRMS(); + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; + file->Close(); delete file; return make_pair(mean, rms); @@ -87,6 +97,11 @@ CbmRichGeoTestOpt::H2ProjYMeanRms(CbmRichGeoTestOptFileEnum fileEnum, const string& histName) { string path = GetFilePath(fileEnum, iFile); if (path == "") return make_pair(0., 0.); + + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + TFile* file = new TFile(path.c_str(), "READ"); if (file == nullptr) return make_pair(0., 0.); TH2D* hist = (TH2D*) file->Get(histName.c_str()); @@ -94,6 +109,11 @@ CbmRichGeoTestOpt::H2ProjYMeanRms(CbmRichGeoTestOptFileEnum fileEnum, TH1D* py = hist->ProjectionY((histName + to_string(iFile) + "_py").c_str()); double mean = py->GetMean(); double rms = py->GetRMS(); + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; + file->Close(); delete file; return make_pair(mean, rms); @@ -104,11 +124,21 @@ double CbmRichGeoTestOpt::HEntries(CbmRichGeoTestOptFileEnum fileEnum, const string& histName) { string path = GetFilePath(fileEnum, iFile); if (path == "") return 0.; + + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + TFile* file = new TFile(path.c_str(), "READ"); if (file == nullptr) return 0.; TH1* hist = (TH1*) file->Get(histName.c_str()); if (hist == nullptr) return 0.; double entries = hist->GetEntries(); //hist->Integral(); + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; + file->Close(); delete file; return entries; diff --git a/reco/detectors/rich/qa/CbmRichRecoQa.cxx b/reco/detectors/rich/qa/CbmRichRecoQa.cxx index 7bcf88e901..a7aaf87c03 100644 --- a/reco/detectors/rich/qa/CbmRichRecoQa.cxx +++ b/reco/detectors/rich/qa/CbmRichRecoQa.cxx @@ -843,6 +843,10 @@ void CbmRichRecoQa::DrawFromFile(const string& fileName, const string& outputDir) { fOutputDir = outputDir; + /// Save old global file and folder pointer to avoid messing with FairRoot + TFile* oldFile = gFile; + TDirectory* oldDir = gDirectory; + if (fHM != nullptr) delete fHM; fHM = new CbmHistManager(); @@ -852,6 +856,10 @@ void CbmRichRecoQa::DrawFromFile(const string& fileName, DrawHist(); fHM->SaveCanvasToImage(fOutputDir); + + /// Restore old global file and folder pointer to avoid messing with FairRoot + gFile = oldFile; + gDirectory = oldDir; } ClassImp(CbmRichRecoQa) -- GitLab