Home | News | Documentation | Download

TEfficiency crash on destructor if it has attached functions


#1

Hi,

I’ve been using the TEfficiency class, and I ran into some troubles.
I noticed that if I create a TFile, then a TEfficiency, attach some function to it and then either {delete the TEff. object; close the file; quit root without closing the file}, ie, somehow call the TEfficiency destructor, it crashes.
However if I create the file after attaching the function, it runs smoothly.

Example:

// DOESNT WORK
// If TFile is initialized here it crashes
TFile *f = new TFile(“out.root”,“RECREATE”);

TEfficiency* pEff = new TEfficiency(“eff”,“my efficiency;x;#epsilon”,20,0,10);
TRandom3 rand;
bool bPassed;
double x;
for(int i=0; i<10000; ++i)
{
x = rand.Uniform(10);
bPassed = rand.Rndm() < TMath::Gaus(x,5,4);
pEff->Fill(bPassed,x);
}

TF1* f2 = new TF1(“thres”,“0.8”,0,10);
pEff->GetListOfFunctions()->AddFirst(f2);

pEff->Draw(“AP”);

//
// WORKS if TFile is declared here instead
//

pEff->Write();
f->Close();

I went further and found out that the crash occurs in the following line in the destructor (TEfficiency.cxx)

// …
if(fFunctions) {
TIter next(fFunctions);
TObject* obj = 0;
while((obj = next())) {
delete obj; <<<-------------
}
fFunctions->Delete();
}
// …

If line indicated above is commented, no crash happens. Of course this can bring a memory leak if the delete (TList) fFunctions doesn’t delete all of it’s contents. But if it does, then is the above loop really necessary?

What can you tell about this issue? Is this a feature or should be filled as a bug??

Many thanks in advance,
Ricardo


#2

Hi,

Yes it is a bug in the destructor of TEfficiency, where the functions were deleted two times. It is now fixed in the trunk and 5.30 patches. Thank you for your post

Lorenzo