What is the meaning of TH1::SetDirectory(TDirectory*)
I had created some TH1’s and called TH1::SetDirectory(NULL) on some and not on others. This caused my program to crash. The problem was resolved only when I called TH1::SetDirectory(NULL) on all of the histograms.
this is not expected: maybe this is related to another issue?
The documentation of this method can be found here:
o root.cern.ch/root/htmldoc/guide … gdirectory
The problem was caused by closing a file after opening a histogram as in the following scheme:
TFile *input_file = TFile::Open(“input_file.root”, “READ”);
TH1F * h = new TH1F(“test”, “test”, 5, 0, 5);
TH1F *h1 = new TH1F(“test1”, “test1”, 5, 0, 5);
input_file -> Close();
TFile * output_file = TFile::Open(“output_file.root”, “RECREATE”);
h1-> SetDirectory(output_file); //CRASH
h-> Write(); h1 -> Write();
output_file -> Close();
It is not the first time that I stumble upon this problem spending great effort in debugging.
That would explain it. Glad you fixed your issue!
We are keenly aware of these kind of pitfalls and we are currently prototyping new interfaces (nicknamed v7) that would (amongst other things) prevents this kind of ambiguities.