Histograms are saved without bins

Hello,

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

As usually: it will be very heplful, if you can give a minimal code/input data to reproduce the problem.

You are right, but it is just my setup is somewhat complex. I will post instructions shortly for how to run code. Rustem

Hello,

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

Thank you for taking a look.

Cheers,
Rustem

Just to add… I am suspecting that this is a memory bug with my code and somehow I am overwriting some static memory in TH1.

Rustem

I traced the problem to this function: TDirectory::WriteObject(). I have a class which I write to TDirectory using this function:

svnweb.cern.ch/trac/penn/browse … electCut.h

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.

Cheers,
Rustem

Hi Rustem,

Humm … this sounds odd. Do you have a running example showing the problem?

Thanks,
Philippe

Hi Philippe,

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.

Thanks for taking a look.

Rustem

Hi,

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.

Cheers,
Philippe.