I have a pre-existing tree. I used MakeClass() to generate a skeleton interface (“Whodunit” here). Inside the Loop() method, I call HistHolder::fill(), where HistHolder is a separate histogram manager class I created (simplified and attached). Its fill() method basically calls m_hist->Fill() on a private histogram.
void Whodunit::Loop()
{
if (fChain == 0) return;
Int_t nentries = Int_t(fChain->GetEntries());
nentries = 5000; // Cut short for this test; tree has 221K entries
HistHolder* ah = new HistHolder(“z”, “wxy”, 20, 1.0, 3.0);
ah->print(); // get here
Int_t nbytes = 0, nb = 0;
for (Int_t jentry=0; jentry<nentries;jentry++) {
Int_t ientry = LoadTree(jentry);
if (ientry < 0) break;
// get here fine
nb = fChain->GetEntry(jentry); nbytes += nb;
// if (Cut(ientry) < 0) continue;
ah->fill(Run, EBeam, EvtWght, EvtWght);
// but never here -- though I see print statements from the end
// of HistHolder::fill()
}
}
When I load HistHolder.cxx dierctly (".L HistHolder.cxx"), I get a SEGV before the first loop of Loop() completes. (I never get to a print statement right after ah->fill(). ) When I use ACliC (’.L HistHolder.cxx+"), everything works fine.
What am I doing wrong?
I use:
Version 3.05/07 27 July 2003 *
Compiled for alphacxx6.
CINT/ROOT C/C++ Interpreter version 5.15.94, June 30 2003
When you run, can you activate teh CINT trace option?
root > .T
Instead of
root > .L HistHolder.cxx
try
root > .L HistHolder.cxx+
Could you send you .h,.cxx file with
the Loop function?
I’ve attached the two files that result from the TTree::MakeClass(), and included a rahter long transcript from a Root session where the error occurs, with the trace turned on.
Note the error only occurs when I load with “.L HistHolder.cxx” and not when I try “.L HistHolder.cxx+” (or "++’).
Thanks to your file, I have traced the problem to be in CINT.
In HistHolder::Fill, you have the following statements
if (hist != 0) hist->Fill(value, weight);
else
{
//cout << "Run " << run << " and E = " << ebeam //OK
cout << “Run " << setw(6) << run << " and E = " << ebeam
<< " doesn’t fall into any histogram!”
<< endl;
}
If you remove the setw(6) from the cout statement, your program will work.
I have reported the problem to Masa.
Does this mean I should be cautious with my use of setw() and other manipulators (until the problem is fixed)? Or is the problem deeper, and this is just a chance symptom?
You must be careful with CINT with the following logic
for (i=0;i<nentries;i++) {
tree.GetEntry(i);
if (somecondition) {
//here some object created in the stack
//may be the if is never executed
someclass xx;
}
}
In your case setw creates an object in the stack, but the above remark
is more general.
We hope that masa will be able to fix these problems in a non too distant future