Hi all,
I’d like to be able dump all the entries from a TTree in a root file to an ASCII file. I’ve been using PyRoot for a while now, so I’d like to keep it in that format if possible.
However, I find that for a TTree with ~150 branches it takes about 1/3 second to read out. This seems long to me since on the same machine all of my other PyRoot activities run fast.
I fear I’m doing something silly in how I access the Leaf/Branches (I can never keep this straight) and maybe this is more a general ROOT question than a PyRoot question, but I figured I’d try here first.
Here’s the code.
[code]#!/usr/bin/env python
import some modules
import sys
from ROOT import *
outfile = open(“default.txt”, “w”)
##########################################
Create a chain based on the ntuple names
##########################################
Assuming the tree is named “ntp”
t = TChain(“ntp”)
print len(sys.argv)
for j in range(1, len(sys.argv)):
filename = sys.argv[j]
print("Adding file: " + filename)
t.Add(filename)
t.SetBranchStatus("*",1)
##########################################
Read and dump the tree entries
##########################################
nentries = t.GetEntries()
for nev in xrange (100):
t.GetEntry( nev )
output = ""
leaves = t.GetListOfLeaves()
for leaf in leaves:
output += "%f " % ( leaf.GetValue() )
output += "\n"
outfile.write(output)
outfile.close()
[/code]
Usage is “script.py infile.root”
Maybe this is just a slow process between the reading/writing of the 150 values/event. Any suggestions/help would be greatly appreciated. Much thanks in advance.
Matt