ROOT Version: ROOT 6.22/02
Platform: Red Hat Enterprise Linux Server 7.9 (Maipo)
Compiler: g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
I’m proficient in python, but completely new to PyROOT. I’ve looked through the tutorials, searched this forum, and scanned the documentation, and am still struggling with how to translate TTree::SetBranchAddress
from c++ to PyROOT.
If someone could fix my minimal working example below, that would be greatly appreciated. I know the fix involves the AddressOf
method, but can’t figure it out. Another confusing thing is that most of the examples use AddressOf
, but the documentation says a newer method addressof
(all lowercase) should be used.
Anyways, here is my minimal working example:
#!/usr/bin/env python3
import numpy as np
import ROOT
import time
def make_tree():
file = ROOT.TFile('output.root', 'RECREATE')
tree = ROOT.TTree('tree', '')
date_time = ROOT.TDatime()
tree.Branch('date_time', date_time)
for i in range(5):
date_time = ROOT.TDatime()
print(date_time)
tree.Fill()
time.sleep(1)
tree.Write()
def read_tree():
file = ROOT.TFile('output.root', 'READ')
tree = file.Get("tree")
date_time = ROOT.TDatime()
tree.SetBranchAddress('date_time', date_time)
#tree.SetBranchAddress('date_time', ROOT.AddressOf(date_time))
for i in range(tree.GetEntries()):
tree.GetEntry(i)
print(date_time)
def main():
make_tree()
print('=====')
read_tree()
if __name__ == '__main__':
main()
Here is the output:
-bash-4.2$ ./minimal.py
Wed Dec 9 22:09:26 2020
Wed Dec 9 22:09:27 2020
Wed Dec 9 22:09:28 2020
Wed Dec 9 22:09:29 2020
Wed Dec 9 22:09:30 2020
=====
Fri Mar 23 07:46:48 2040
Fri Mar 23 07:46:48 2040
Fri Mar 23 07:46:48 2040
Fri Mar 23 07:46:48 2040
Fri Mar 23 07:46:48 2040
As you can see, the TDatimes
from make_tree
and read_tree
are different, but I want them to be the same.