Accessing TObj retrieved with FindObject gives sometm. error


(using: /afs/

I experience some bug in my pyroot-code… and I could reduce it to a small working (=actually not working, because producing an error) example.

At my computer the following subroutine runs fine about two or three times, but then it failes.

def test():
    running = 0
    canv = ROOT.TCanvas()
    for i in xrange( 50 ):
        ch = ROOT.TChain()
        ch.Add('rfio:///castor/*.reco.root/TB/tree' )
        print 'cycle: ',i
        ch.Draw( 'Sum$(cl_e_topo)>>htemp()' )
        h = ROOT.gROOT.FindObject( 'htemp' )
        h.SetName( 'newname%s'%(running) )
        running += 1
        print 'getname: ',h.GetName()

I think, that the piece of code I use is correct and does only allowed things. Therefore I find it strange, that it works 2.5 times but not more.

thanks for your help,


although I’m clueless about what your snippet of code is supposed to do, and whether it does what you think it should do, I can see about half a dozen ways how the internal bookkeeping and refcounting will go haywire.

A simple fix is to name your chain:[code]for i in xrange( 50 ):
ch = ROOT.TChain(‘mychain’)

etc. …[/code]

although that still wouldn’t make me happy (I’d prefer a ‘del ch’ at the end of the loop block as well, such that the ctor of the new chain object is called after the dtor of the previous, same-named, instance), it does make the script run. :slight_smile: