From 129cf157e62f90dcd63c1a2e1c64cd1761b4df43 Mon Sep 17 00:00:00 2001 From: Stephan Hageboeck Date: Mon, 16 Mar 2026 17:17:10 +0100 Subject: [PATCH 1/2] [core] Disable the TDirectory::Append warning when using the same object. It makes sense when a different object with the same name is registered (the old object will leak), but if the object is identical, the replacement is like a no-op. --- core/base/src/TDirectory.cxx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/base/src/TDirectory.cxx b/core/base/src/TDirectory.cxx index a8bcee69e8db1..e33d82a3694d8 100644 --- a/core/base/src/TDirectory.cxx +++ b/core/base/src/TDirectory.cxx @@ -207,8 +207,10 @@ void TDirectory::Append(TObject *obj, Bool_t replace /* = kFALSE */) if (replace && obj->GetName() && obj->GetName()[0]) { TObject *old; while (nullptr != (old = GetList()->FindObject(obj->GetName()))) { - Warning("Append","Replacing existing %s: %s (Potential memory leak).", - obj->IsA()->GetName(),obj->GetName()); + if (obj != old) { + Warning("Append", "Replacing existing %s: %s (Potential memory leak).", obj->IsA()->GetName(), + obj->GetName()); + } ROOT::DirAutoAdd_t func = old->IsA()->GetDirectoryAutoAdd(); if (func) { func(old,nullptr); From ce4eefd7a157b8e8b35b56b576d98f573b814904 Mon Sep 17 00:00:00 2001 From: Stephan Hageboeck Date: Fri, 20 Mar 2026 11:47:14 +0100 Subject: [PATCH 2/2] [treeplayer] Make TTree::Draw independent of histogram registration. In order for TTree::Draw to work as documented, histograms must be registered to gDirectory. Therefore, make it independent of TH1::AddDirectory and DisableImplicitObjectOwnership. Histograms will unconditionally be registered. --- tree/treeplayer/src/TSelectorDraw.cxx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tree/treeplayer/src/TSelectorDraw.cxx b/tree/treeplayer/src/TSelectorDraw.cxx index 2dda2a80a2596..8aa71aec11512 100644 --- a/tree/treeplayer/src/TSelectorDraw.cxx +++ b/tree/treeplayer/src/TSelectorDraw.cxx @@ -578,6 +578,7 @@ void TSelectorDraw::Begin(TTree *tree) } else { hist = new TH1D(hname, htitle.Data(), fNbins[0], fVmin[0], fVmax[0]); } + hist->SetDirectory(gDirectory); hist->SetLineColor(fTree->GetLineColor()); hist->SetLineWidth(fTree->GetLineWidth()); hist->SetLineStyle(fTree->GetLineStyle()); @@ -661,6 +662,7 @@ void TSelectorDraw::Begin(TTree *tree) } else { hp = new TProfile(hname, htitle.Data(), fNbins[1], fVmin[1], fVmax[1], ""); } + hp->SetDirectory(gDirectory); if (!hkeep) { hp->SetBit(kCanDelete); if (!opt.Contains("goff")) hp->SetDirectory(nullptr); @@ -689,6 +691,7 @@ void TSelectorDraw::Begin(TTree *tree) } else { h2 = new TH2D(hname, htitle.Data(), fNbins[1], fVmin[1], fVmax[1], fNbins[0], fVmin[0], fVmax[0]); } + h2->SetDirectory(gDirectory); h2->SetLineColor(fTree->GetLineColor()); h2->SetLineWidth(fTree->GetLineWidth()); h2->SetLineStyle(fTree->GetLineStyle()); @@ -803,6 +806,7 @@ void TSelectorDraw::Begin(TTree *tree) } else { hp = new TProfile2D(hname, htitle.Data(), fNbins[2], fVmin[2], fVmax[2], fNbins[1], fVmin[1], fVmax[1], ""); } + hp->SetDirectory(gDirectory); if (!hkeep) { hp->SetBit(kCanDelete); if (!opt.Contains("goff")) hp->SetDirectory(nullptr); @@ -826,6 +830,7 @@ void TSelectorDraw::Begin(TTree *tree) h2 = (TH2F*)fOldHistogram; } else { h2 = new TH2F(hname, htitle.Data(), fNbins[1], fVmin[1], fVmax[1], fNbins[0], fVmin[0], fVmax[0]); + h2->SetDirectory(gDirectory); h2->SetLineColor(fTree->GetLineColor()); h2->SetLineWidth(fTree->GetLineWidth()); h2->SetLineStyle(fTree->GetLineStyle()); @@ -859,6 +864,7 @@ void TSelectorDraw::Begin(TTree *tree) } else { h3 = new TH3D(hname, htitle.Data(), fNbins[2], fVmin[2], fVmax[2], fNbins[1], fVmin[1], fVmax[1], fNbins[0], fVmin[0], fVmax[0]); } + h3->SetDirectory(gDirectory); h3->SetLineColor(fTree->GetLineColor()); h3->SetLineWidth(fTree->GetLineWidth()); h3->SetLineStyle(fTree->GetLineStyle());