Reading & deleting RooFitResults causes seg violation

This belongs in bug reports, but I could not submit one just now. Sorry! Instead of attaching my root file, I have placed it at

dls.physics.ucdavis.edu/~croat/P … sults.root


I created a root file which contains the “RooFitResults” of many fits. When I try to read them back in a loop as in the macro below, I find the RooFitResults start taking up lots of memory, so I try to delete them. This eventually causes a seg violation, as in logfile below. Note that the seg violation seems to occur upon reading one of the results, though removing the ‘delete’ line from the macro allows it to complete.

I suspect something regarding RooDirItem, but I do not understand it’s purpose enough to try and debug it.

Cheers,
Chris

void results() {

TFile f(“results.root”);
TList *keylist= f.GetListOfKeys();

TIterator *iter= keylist->MakeIterator();

TKey key;
while ( key= (TKey
)iter->Next() ) {

cout << "Attempt to read " << key->GetName() << endl;

RooFitResult *res= dynamic_cast<RooFitResult*>( key->ReadObjectAny( RooFitResult::Class() ) );

if ( !res ) {
  cerr << "Couldn't read object " << key->GetName() << endl;
  continue;
}

cout << "Deleting... " << endl;
delete res;
cout << "Done." <<endl;

}

}

root -b -q results.C

RooFit v2.04 – Developed by Wouter Verkerke and David Kirkby
Copyright (C) 2000-2005 NIKHEF, University of California & Stanford University
All rights reserved, please read roofit.sourceforge.net/license.txt

root [0]
Processing results.C…
Attempt to read catEntry18
Deleting…
Done.
Attempt to read catEntry31
Deleting…
Done.
Attempt to read catEntry100
Deleting…
Done.
Attempt to read catEntry118

*** Break *** segmentation violation
Generating stack trace…
0x401ff7f0 in THashTable::Add(TObject*) + 0x46 from /usr/lib/root/libCore.so.5.04
0x401fff62 in THashTable::Rehash(int, bool) + 0x112 from /usr/lib/root/libCore.so.5.04
0x401ff91a in THashTable::Add(TObject*) + 0x170 from /usr/lib/root/libCore.so.5.04
0x401fecb5 in THashList::AddLast(TObject*) + 0x41 from /usr/lib/root/libCore.so.5.04
0x4019d56d in TList::Add(TObject*) + 0x1b from /usr/lib/root/libCore.so.5.04
0x4015eb5b in TDirectory::Append(TObject*) + 0x3f from /usr/lib/root/libCore.so.5.04
0x41da3030 in RooDirItem::appendToDir(TObject*, bool) + 0xe8 from /usr/lib/root/5.04/libRooFit.so
0x41da9c28 in RooFitResult::RooFitResult(char const*, char const*) + 0x16c from /usr/lib/root/5.04/libRooFit.so
0x41f40261 in from /usr/lib/root/5.04/libRooFit.so
0x40219a70 in TClass::New(TClass::ENewType) + 0x3e from /usr/lib/root/libCore.so.5.04
0x4017714e in TKey::ReadObjectAny(TClass const*) + 0x23a from /usr/lib/root/libCore.so.5.04
0x403e4044 in from /usr/lib/root/libCore.so.5.04
0x40836091 in G__ExceptionWrapper + 0x5d from /usr/lib/root/libCint.so.5.04
0x40861ef5 in G__exec_asm + 0x9ef from /usr/lib/root/libCint.so.5.04
0x408f569e in G__exec_loop + 0x592 from /usr/lib/root/libCint.so.5.04
0x408f58e6 in G__exec_while + 0x92 from /usr/lib/root/libCint.so.5.04
0x408f84a7 in G__exec_statement + 0x2561 from /usr/lib/root/libCint.so.5.04
0x408c47d4 in G__interpret_func + 0x23dc from /usr/lib/root/libCint.so.5.04
0x408a9752 in G__getfunction + 0x235e from /usr/lib/root/libCint.so.5.04
0x4089e43f in G__getitem + 0x767 from /usr/lib/root/libCint.so.5.04
0x4089c8d2 in G__getexpr + 0xc27e from /usr/lib/root/libCint.so.5.04
0x4089017a in G__calc_internal + 0x312 from /usr/lib/root/libCint.so.5.04
0x408ff037 in G__process_cmd + 0x2359 from /usr/lib/root/libCint.so.5.04
0x4020c4a4 in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) + 0xba from /usr/lib/root/libCore.so.5.04
0x4020c5eb in TCint::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) + 0x4f from /usr/lib/root/libCore.so.5.04
0x40148329 in TApplication::ProcessFile(char const*, int*) + 0x9d5 from /usr/lib/root/libCore.so.5.04
0x401478d1 in TApplication::ProcessLine(char const*, bool, int*) + 0x5f9 from /usr/lib/root/libCore.so.5.04
0x4141d10a in TRint::Run(bool) + 0x298 from /usr/lib/root/libRint.so.5.04
0x08048e64 in main + 0x90 from /usr/bin/root.exe
0x41553ec0 in __libc_start_main + 0xd0 from /lib/tls/libc.so.6
0x08048d31 in TApplicationImp::ShowMembers(TMemberInspector&, char*) + 0x3d from /usr/bin/root.exe

I have fixed the problem and reported it to Wouter Verkerke.
The RooFitResult class required changes and protections to make it persistent.

Rene

Thanks for the quick response, Rene. How did you fix the problem and where is the fix now? (Will CVS only contain a recent .src.tgz for the near future?)

Also, it seems that RooDataSets may need a similar fix. With a ROOT file containing a single RooDataSet

dls.physics.ucdavis.edu/~croat/P … asets.root

and the macro below, I see a crash when deleting a dataset the second time it is read.

void datasets() {

TFile f(“datasets.root”);

Int_t nAttempts=0;

while (1) {

++nAttempts;

cout << "Read attempt " << nAttempts << endl;

RooDataHist* data= dynamic_cast<RooDataHist*>( f.Get("catEntry8500") );

if ( !data ) {
  cerr << "Couldn't read object" << endl;
  return;
}

cout << "Deleting..." << endl;
delete data;
cout << "Done." <<endl;

}

}

root -b -q datasets.C

RooFit v2.04 – Developed by Wouter Verkerke and David Kirkby
Copyright (C) 2000-2005 NIKHEF, University of California & Stanf ord University
All rights reserved, please read roofit.sourceforge.net/l icense.txt

root [0]
Processing datasets.C…
Read attempt 1
Deleting…
Done.
Read attempt 2
Deleting…

*** Break *** segmentation violation
Generating stack trace…
0x415a5e69 in __libc_free + 0x49 from /lib/tls/libc.so.6
0x414d2d23 in operator delete(void*) + 0x23 from /usr/lib/libstdc++.so.5
0x414d2d7f in operator delete + 0x1f from /usr/lib/libstdc++.so.5
0x41d9b07c in RooDataHist::~RooDataHist() + 0x58 from /usr/lib/root/5.04/libRoo Fit.so
0x41d9b11d in RooDataHist::~RooDataHist() + 0xf9 from /usr/lib/root/5.04/libRoo Fit.so
0x41f6966d in from /usr/lib/root/5.04/libRooFit.so
0x40836091 in G__ExceptionWrapper + 0x5d from /usr/lib/root/libCint.so.5.04
0x40861ef5 in G__exec_asm + 0x9ef from /usr/lib/root/libCint.so.5.04
0x408f569e in G__exec_loop + 0x592 from /usr/lib/root/libCint.so.5.04
0x408f58e6 in G__exec_while + 0x92 from /usr/lib/root/libCint.so.5.04
0x408f84a7 in G__exec_statement + 0x2561 from /usr/lib/root/libCint.so.5.04
0x408c47d4 in G__interpret_func + 0x23dc from /usr/lib/root/libCint.so.5.04
0x408a9752 in G__getfunction + 0x235e from /usr/lib/root/libCint.so.5.04
0x4089e43f in G__getitem + 0x767 from /usr/lib/root/libCint.so.5.04
0x4089c8d2 in G__getexpr + 0xc27e from /usr/lib/root/libCint.so.5.04
0x4089017a in G__calc_internal + 0x312 from /usr/lib/root/libCint.so.5.04
0x408ff037 in G__process_cmd + 0x2359 from /usr/lib/root/libCint.so.5.04
0x4020c4a4 in TCint::ProcessLine(char const*, TInterpreter::EErrorCode*) + 0xba from /usr/lib/root/libCore.so.5.04
0x4020c5eb in TCint::ProcessLineSynch(char const*, TInterpreter::EErrorCode*) + 0x4f from /usr/lib/root/libCore.so.5.04
0x40148329 in TApplication::ProcessFile(char const*, int*) + 0x9d5 from /usr/li b/root/libCore.so.5.04
0x401478d1 in TApplication::ProcessLine(char const*, bool, int*) + 0x5f9 from / usr/lib/root/libCore.so.5.04
0x4141d10a in TRint::Run(bool) + 0x298 from /usr/lib/root/libRint.so.5.04
0x08048e64 in main + 0x90 from /usr/bin/root.exe
0x41553ec0 in __libc_start_main + 0xd0 from /lib/tls/libc.so.6
0x08048d31 in TApplicationImp::ShowMembers(TMemberInspector&, char*) + 0x3d fro m /usr/bin/root.exe
Root > Function datasets() busy flag cleared

This is the end of ROOT – Goodbye

Hi Chris,

Here is the mail I sent to Wouter

[quote]I have implemented RooFitResult::Streamer to call appendDirectory.
In the constructor, I have protected the call to appendDir when name=0.

In the LinkDef files, I have specified the option “+” for all classes.
This will enable auto schema evolution.

Could you put the changes in your version and send me an updated tar file?
[/quote]

and in attachement the tar file with the diffs wrt CVS head.

I assume that Wouter will also implement the necessary changes in the other class (and may be more classes) with the same pathology.

Rene
roofit_diff.tar.gz (7.68 KB)