Accessing TObj retrieved with FindObject gives sometm. error

Hi,

(using: /afs/cern.ch/sw/lcg/external/root/5.14.00b/slc3_ia32_gcc323/root/)

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/cern.ch/grid/atlas/ctb2004/birks/ctb_Run2343_pid211_piplus_E50GeV_Evt10000_bA1._bk0.0486_QGSP_BERT-*.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
        h.Draw()
        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,
Peter

Peter,

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:

HTH,
Wim[/i]