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):
selector.chain.GetEntry(ientry)
print selector.pt[/code]

the value of “selector.pt” is not read out. If I do “selector.chain.pt”, 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.

Thanks,
Sal Rappoccio

Sal,

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 ) )
Ciao,
Wim

EDITED:

Hi, Wim,

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

Thanks a lot!

Cheers,
Sal