I’m using Python 2.4.3 with ROOT 4.00/08 (yes, I know this setup is super old). I’m trying to write the Python version of a C++ script that pulls some histograms out of a ROOT file and renders them to a PostScript file.
First off, I need to be able to access gDirectory. I tried
but this resulted in “TypeError: requested class gDirectory does not exist”. Instead, I had to do
from ROOT import gROOT
gDirectory = gROOT.GetGlobal("gDirectory")
However, when I try to do
file1 = TFile("data_0.05.root")
h_noncut_Lb_mass = gDirectory.Get("LbCandidates_mass")
I get a segfault after the second line. Is there a different way I should be going about this?
well, I think that in the old days the gDirectory wasn’t a pointer to a pointer object and it certainly isn’t when obtained through gROOT.GetGlobal(), so when the underlying pointer changes, gDirectory still points to the old directory. You’ll have more luck by doing the GetGlobal() anew after opening the file.
That said, why not call Get() on the file you just opened, since gDirectory supposedly points to it?
And yes, the version that you have is the first prototype that went into ROOT and upgrading is recommended.
Thanks, this works fine.
I’m working on my university’s Linux cluster, so it’s out of my control, but maybe I’ll be able to talk them into upgrading at some point…