Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions bindings/pyroot/pythonizations/test/memory.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ROOT
import gc
import os
import unittest

Check failure on line 4 in bindings/pyroot/pythonizations/test/memory.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

bindings/pyroot/pythonizations/test/memory.py:1:1: I001 Import block is un-sorted or un-formatted


def _leak(obj):
Expand All @@ -16,7 +16,7 @@
def test_tstyle_memory_management(self):
"""Regression test for https://github.com/root-project/root/issues/16918"""

h1 = ROOT.TH1F("h1", "", 100, 0, 10)

Check failure on line 19 in bindings/pyroot/pythonizations/test/memory.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F841)

bindings/pyroot/pythonizations/test/memory.py:19:9: F841 Local variable `h1` is assigned to but never used

style = ROOT.TStyle("NewSTYLE", "")
groot = ROOT.ROOT.GetROOT()
Expand All @@ -27,19 +27,19 @@
"""Regression test for https://github.com/root-project/root/issues/16942"""
# The test is just that the memory regulation works correctly and the
# application does not segfault
f2 = ROOT.TF2("f2", "sin(x)*sin(y)/x/y")

Check failure on line 30 in bindings/pyroot/pythonizations/test/memory.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F841)

bindings/pyroot/pythonizations/test/memory.py:30:9: F841 Local variable `f2` is assigned to but never used

def test_tf3_memory_regulation(self):
"""Make sure TF3 is properly managed by the memory regulation logic"""
# The test is just that the memory regulation works correctly and the
# application does not segfault
f3 = ROOT.TF3("f3","[0] * sin(x) + [1] * cos(y) + [2] * z",0,10,0,10,0,10)

Check failure on line 36 in bindings/pyroot/pythonizations/test/memory.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F841)

bindings/pyroot/pythonizations/test/memory.py:36:9: F841 Local variable `f3` is assigned to but never used

def test_tcolor_memory_regulation(self):
"""Make sure TColor is properly managed by the memory regulation logic"""
# The test is just that the memory regulation works correctly and the
# application does not segfault
c = ROOT.TColor(42, 42, 42)

Check failure on line 42 in bindings/pyroot/pythonizations/test/memory.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F841)

bindings/pyroot/pythonizations/test/memory.py:42:9: F841 Local variable `c` is assigned to but never used

def test_ttree_clone_in_file_context(self):
"""Test that CloneTree() doesn't give the ownership to Python when
Expand All @@ -49,8 +49,8 @@

ttree = ROOT.TTree("tree", "tree")

with ROOT.TFile(filename, "RECREATE") as infile:
with ROOT.TFile(filename, "RECREATE") as _:
ttree_clone = ttree.CloneTree()

Check failure on line 53 in bindings/pyroot/pythonizations/test/memory.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F841)

bindings/pyroot/pythonizations/test/memory.py:53:13: F841 Local variable `ttree_clone` is assigned to but never used

os.remove(filename)

Expand Down Expand Up @@ -88,7 +88,6 @@
"TH1I": ("h", "h", 10, 0, 10),
"TH1L": ("h", "h", 10, 0, 10),
"TH1F": ("h", "h", 10, 0, 10),
"TH1D": ("h", "h", 10, 0, 10),
"TProfile": ("h", "h", 10, 0, 10),
"TH2C": ("h", "h", 10, 0, 10, 10, 0, 10),
"TH2S": ("h", "h", 10, 0, 10, 10, 0, 10),
Expand All @@ -111,8 +110,6 @@
"TGraph2D": (100,),
"TEntryList": ("name", "title"),
"TEventList": ("name", "title"),
"TTree": ("name", "title"),
"TNtuple": ("name", "title", "x:y:z"),
}
for klass, args in objs.items():
with self.subTest(klass=klass):
Expand Down
2 changes: 1 addition & 1 deletion io/io/src/TFileMerger.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ Bool_t TFileMerger::MergeOne(TDirectory *target, TList *sourcelist, Int_t type,
&& !cl->InheritsFrom( TDirectory::Class() )) {
R__ASSERT(cl->IsTObject());
TDirectory::TContext ctxt(current_sourcedir);
obj = obj->Clone();
obj = gDirectory->CloneObject(obj);
ownobj = kTRUE;
}
} else if (key) {
Expand Down
2 changes: 1 addition & 1 deletion roofit/roofitcore/src/RooTreeDataStore.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ void RooTreeDataStore::loadValues(const TTree *t, const RooFormulaVar* select, c
// We need a custom deleter, because if we don't deregister the Tree from the directory
// of the original, it tears it down at destruction time!
auto deleter = [](TTree* tree){tree->SetDirectory(nullptr); delete tree;};
std::unique_ptr<TTree, decltype(deleter)> tClone(static_cast<TTree*>(t->Clone()), deleter);
std::unique_ptr<TTree, decltype(deleter)> tClone{static_cast<TTree*>(gDirectory->CloneObject(t)), deleter};
tClone->SetDirectory(t->GetDirectory());

// Clone list of variables
Expand Down
3 changes: 3 additions & 0 deletions tree/tree/inc/TTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,9 @@ class TTree : public TNamed, public TAttLine, public TAttFill, public TAttMarker
TTree(const TTree& tt) = delete;
TTree& operator=(const TTree& tt) = delete;

TObject *Clone(const char *newname="") const override;
void Copy(TObject &object) const override;

virtual Int_t AddBranchToCache(const char *bname, bool subbranches = false);
virtual Int_t AddBranchToCache(TBranch *branch, bool subbranches = false);
virtual Int_t DropBranchFromCache(const char *bname, bool subbranches = false);
Expand Down
13 changes: 12 additions & 1 deletion tree/tree/src/TTree.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,17 @@ TTree::~TTree()
}
}

TObject *TTree::Clone(const char *) const
{
Error("Clone", "Not implemented, use TTree::CloneTree instead.");
return nullptr;
}

void TTree::Copy(TObject &) const
{
Error("Copy", "Not implemented, use TTree::CopyTree or TTree::CopyEntries instead.");
}

////////////////////////////////////////////////////////////////////////////////
/// Returns the transient buffer currently used by this TTree for reading/writing baskets.

Expand Down Expand Up @@ -3204,7 +3215,7 @@ TTree* TTree::CloneTree(Long64_t nentries /* = -1 */, Option_t* option /* = "" *

// Note: For a chain, the returned clone will be
// a clone of the chain's first tree.
TTree* newtree = (TTree*) thistree->Clone();
TTree* newtree = (TTree*) thistree->TNamed::Clone();
if (!newtree) {
return nullptr;
}
Expand Down
Loading