I see an unusual problem when saving a ROOT file with histograms. Under certain conditions, all histograms saved to output file do not have any bin information. These histograms only have one bin between 0 and 1. I have printed one histogram just before saving using TH1::Print(“base”) and I see correct histogram range and bins. The same histogram in a ROOT file has no bins.
I am using 5.26/00e. I call TH1::SetDirectory(0) after creating histograms and then later call SetDirectory based on execution flow, where all directories belong to the same output ROOT file. The output file is saved by calling TFile::Write() and TFile::Close(). I actually managed to “fix” this problem by saving a single histogram into a separate ROOT file. Still, the problem exists without this fix and I would like to understand what is wrong with the code. Clearly there is a problem somewhere but I do not know where to look.
Any help will be very much appreciated.
Thank you,
Rustem
In C++ code before saving:
PlotBase::SavePlot print PriVtx_pos_z:
Error in TClass::New: cannot create object of class TH1
TH1.Print Name = PriVtx_pos_z, Entries= 983, Total sum= 983
Title =
NbinsX= 200, xmin= -500, xmax=500
Interactive ROOT session using the output file:
root [4] PriVtx_pos_z->Print(“base”)
TH1.Print Name = PriVtx_pos_z, Entries= 0, Total sum= 0
Title =
NbinsX= 1, xmin= 0, xmax=1
I have made three shell scripts which reproduce this problem:
– this script on lxplus checks out and compiles code:
$ source /afs/cern.ch/user/r/rustem/public/debug/root/checkout.sh
– this script runs code and produce test_v2.root file where all histograms have 1 bin and (0,1) range:
$ source /afs/cern.ch/user/r/rustem/public/debug/root/test_v1.sh
– same as the previous step, but now save two (random) histograms into a separate ROOT file; all other histograms now have correct bins:
$ source /afs/cern.ch/user/r/rustem/public/debug/root/test_v2.sh
This class holds four TH1 histogram pointers which are always initialize to 0. I generate dictionary for this class using ROOT reflex code and I declare two of the histograms as transient. The problem is caused by the other two histograms which are NULL pointers: something goes wrong when ROOT tries to write these null pointers to a directory. It seems like a bug to me.
I have posted earlier the shell scripts which reproduce this problem on lxplus. There is a lot of code in this example but I can point out which part causes problems if you decide to reproduce this issue. I am at CERN if it helps.
I ran you examples on lxplus430 and found no ‘extra’ root file (only test_v1.root and test_v2.root). I also got several errors:[quote]Error in TXNetFile::CreateXClient: open attempt failed on root://castoratlas//castor/cern.ch/atla … 00005.root[/quote]which are probably because I am not allowed to read Atlas files …
The error:
[quote]Error in TClass::New: cannot create object of class TH1[/quote]should not happen unless your code is doing something wrong. You should track done (maybe by using gdb and putting break point on the function TObject::Error).
The best way to really see if this problem is a memory error is to run valgrind on your example.