Using python class data members in SetBranchAddress

Hi, Folks,

I’m trying to use SetBranchAddress to set the address of a TBranch to a specific data member of a python class. For example:

import ROOT class Selector( ) : def __init__( self, options ): self.vars = ['pt'] self.chain = ROOT.TChain("ana", "ana") self.chain.AddFile( options.input ) self.chain.SetBranchStatus ('*', 0) for var in vars: setattr( self, var, array.array('d', [-1] ) ) self.chain.SetBranchAddress( var, getattr( self, var ) ) self.chain.SetBranchStatus( var, 1 )

However, when I do

[code]selector = Selector( options)

for ientry in xrange(entries):

the value of “” is not read out. If I do “”, this is correctly done, but this has terrible performance because it reads out branches I am uninterested in.

Any ideas? I’ve tried some instances of ‘AddressOf’ but it doesn’t seem to work.

Sal Rappoccio


I think this is just an ordering problem. TTree::SetBranchAddress() call finds the branch, then calls TBranch::SetAddress(), which has this preamble: if (TestBit(kDoNotProcess)) { return; }The ‘TestBit(kDoNotProcess)’ predicate evaluates ‘true’ b/c you earlier switched off all branches. Thus, this should work instead: self.chain.SetBranchStatus( var, 1 ) self.chain.SetBranchAddress( var, getattr( self, var ) )


Hi, Wim,

This did indeed solve the problem, I then had a separate issue that I found.

Thanks a lot!