Hello!
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.
Hello Danilo,
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);
h-> SetDirectory(0);
TH1F *h1 = new TH1F(“test1”, “test1”, 5, 0, 5);
input_file -> Close();
TFile * output_file = TFile::Open(“output_file.root”, “RECREATE”);
h-> SetDirectory(output_file);
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.
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.