Strange behaviour

This is funny:

def load_data(file_name, dir_name):
    ROOTfile = ROOT.TFile(file_name)
    dir = ROOTfile.Get("PAUReco")
    tree = dir.Get("PAUReco")
    print tree
    return tree

def main():
    t = load_data("../MC.root","PAUReco")
    print t

and I got:

<ROOT.TTree object ("PAUReco") at 0x1624200>
None

Hi,

Most likely the problem is that the TFile object got deleted/garbage collected at the end of the routine (the deletion of the TFile deletes the TTree object).

Cheers,
Philippe.

[quote=“pcanal”]Hi,

Most likely the problem is that the TFile object got deleted/garbage collected at the end of the routine (the deletion of the TFile deletes the TTree object).

Cheers,
Philippe.[/quote]

Why the deletion of TFile deletes TTree? At the end of the function there is a name associated to the TTree so the garbage collector doesn’t delete it. It’s not a python garbage collector problem, it is a problem of the ROOT implementation.

I’ve opened a bug:
savannah.cern.ch/bugs/?62245