Hi,
I’d like to access TTree branches that are unknown until the user gives their names at the run time. The only thing I know is they should be Float. So I try the following code using C struct for each variable and putting them in a list:
[code]#!/usr/bin/env python
import sys
args = sys.argv[1:]
from ROOT import *
print "scanning variables ", args
gROOT.ProcessLine( "struct mydata_t { Float_t avar; } ; " )
T = TChain(“tr”)
T.Add(“mydata.root”)
vlist=[]
for var in args:
mydata = mydata_t()
T.SetBranchAddress( var, AddressOf(mydata, ‘avar’) )
vlist.append(mydata)
for i in xrange(10):
T.GetEntry(i)
for v in vlist:
print v.avar,
print
[/code]
It works but I am wondering if this is the most efficient way to do it. Suggestions are appreciated.