Skip to content
Snippets Groups Projects
Commit a42edc26 authored by Enric Tejedor Saavedra's avatar Enric Tejedor Saavedra
Browse files

[Exp PyROOT] Test branch-as-attribute syntax with TNtuples

parent 2b943f46
No related branches found
No related tags found
No related merge requests found
......@@ -9,12 +9,13 @@ class TTreeBranchAttr(unittest.TestCase):
Test for the pythonization that allows to access top-level tree branches/leaves as attributes
(i.e. `mytree.mybranch`)
Since this pythonization is common to TTree and its subclasses, TChain is
also tested here.
Since this pythonization is common to TTree and its subclasses, TChain and TNtuple
are also tested here.
"""
filename = 'treebranchattr.root'
treename = 'mytree'
tuplename = 'mytuple'
nentries = 1
arraysize = 10
more = 10
......@@ -29,6 +30,11 @@ class TTreeBranchAttr(unittest.TestCase):
cls.arraysize,
cls.more,
'RECREATE')
ROOT.CreateTNtuple(cls.filename,
cls.tuplename,
cls.nentries,
cls.more,
'UPDATE')
# Helper
def get_file_objects(self):
......@@ -41,21 +47,30 @@ class TTreeBranchAttr(unittest.TestCase):
c.Add(self.filename)
c.Add(self.filename)
nt = f.Get(self.tuplename)
SetOwnership(nt, False)
# Read first entry
for ds in t,c:
for ds in t,c,nt:
ds.GetEntry(0)
return f,t,c
return f,t,c,nt
# Tests
def test_basic_type_branch(self):
f,t,c = self.get_file_objects()
f,t,c,nt = self.get_file_objects()
# TTree, TChain
for ds in t,c:
self.assertEqual(ds.floatb, self.more)
# TNtuple
self.assertEqual(nt.x, 0.)
self.assertEqual(nt.y, self.more)
self.assertEqual(nt.z, 2*self.more)
def test_array_branch(self):
f,t,c = self.get_file_objects()
f,t,c,_ = self.get_file_objects()
for ds in t,c:
a = ds.arrayb
......@@ -64,7 +79,7 @@ class TTreeBranchAttr(unittest.TestCase):
self.assertEqual(a[j], j)
def test_vector_branch(self):
f,t,c = self.get_file_objects()
f,t,c,_ = self.get_file_objects()
for ds in t,c:
v = ds.vectorb
......@@ -73,7 +88,7 @@ class TTreeBranchAttr(unittest.TestCase):
self.assertEqual(v[j], j)
def test_struct_branch(self):
f,t,c = self.get_file_objects()
f,t,c,_ = self.get_file_objects()
for ds in t,c:
ms = ds.structb
......@@ -82,14 +97,14 @@ class TTreeBranchAttr(unittest.TestCase):
self.assertEqual(ms.myint2, 0)
def test_struct_branch_leaflist(self):
f,t,c = self.get_file_objects()
f,t,c,_ = self.get_file_objects()
for ds in t,c:
self.assertEqual(ds.myintll1, self.more)
self.assertEqual(ds.myintll2, 0)
def test_alias_branch(self):
f,t,c = self.get_file_objects()
f,t,c,_ = self.get_file_objects()
for ds in t,c:
ds.SetAlias('myalias', 'floatb')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment