I often have trees that I like to process with quick like python classes similar to what TTree::MakeClass creates. For example:
class ShowProAnal: def __init__(self, tShowPro): self.tShowPro = tShowPro self.showpro = ShowProfile() self.tShowPro.SetBranchAddress("showpro", self.showpro) def Loop(self): nentries = self.tShowPro.GetEntries() for i in range(0, nentries): self.tShowPro.GetEntry(i) # Things break here def main(): tShowPro = TChain("tShowPro") for i in range(1, len(sys.argv)): tShowPro.Add(sys.argv) showAnal = ShowProAnal(tShowPro) showAnal.Loop() if __name__=="__main__": main()
The class ShowProfile is some class I’ve created in ROOT and have stored in ROOT Trees with the name “tShowPro”.
In this case, things will break when I call:
If I do this with a single file and a normal ROOT tree everything is fine. I.e.:
f = TFile(infile, "read") t = f.Get("tShowPro") showanal = ShowAnal(t)
Also, if I use a TChain, everything is fine in the scope of the function I declare it in, but anywhere else I have the same problem. So if I did all the analysis in the main function things would be fine. Or if I declare it in the init functions things are okay in the init function, but no where else.
Am I just not doing this in the right way? Or making some silly mistake? I think I understand the ownership of the objects I’m seeing, but I think something behind the scenes in the TChain is being cleared.