Segfault while unloading (RooFit) classes


I’m running into some trouble using RooFit from within Python. The attached example demonstrates the problem. The code is an excerpt from the rf102_dataimport RooFit tutorial. A tree is created (in a function) and turned into a RooDataSet. After the program finishes, a bus error occurs unloading the class RooArgSet. This does not happen when the tree-creation takes place inline instead of inside the function. (See also the `version’ variable in the example.) This makes me think that some link is made deep inside the RooDataSet that points to the tree buffer or so, and that goes out of scope (and is garbage-collected) upon leaving the tree-creating function. But I can’t find that link.

This is all running ROOT 5.21/05, Python 2.5.1, on an Intel MacBook with OS X 10.5.5.

This is the stacktrace that occurs:
Thread 1 (process 16623 thread 0x717):
#0 0x918cff69 in wait4 ()
#1 0x918cdabc in system$UNIX2003 ()
#2 0x010f2b23 in TUnixSystem::Exec (this=0x321110, shellcmd=0x803a10 “/usr/bin/gdb -batch -n -x /sw/share/root/current_gcc4.0/etc/gdb-backtrace-script -p 16623 > /tmp/rootstack.16623 2>&1”) at core/unix/src/TUnixSystem.cxx:1940
#3 0x010f2eb5 in TUnixSystem::StackTrace (this=0x321110) at core/unix/src/TUnixSystem.cxx:2031
#4 0x010f5c89 in TUnixSystem::DispatchSignals (this=0x321110, sig=kSigBus) at core/unix/src/TUnixSystem.cxx:1088
#5 0x010f5dba in SigHandler (sig=kSigBus) at core/unix/src/TUnixSystem.cxx:350
#6 0x010f4c64 in sighandler (sig=10) at core/unix/src/TUnixSystem.cxx:3354
#8 0x010ab92b in TList::Delete (this=0x5374f40, option=0x146b618 “”) at core/cont/src/TList.cxx:410
#9 0x010d759c in TFunction::~TFunction (this=0x533d9e0) at core/meta/src/TFunction.cxx:86
#10 0x010dd1a0 in TMethod::~TMethod (this=0x533d9e0) at core/meta/src/TMethod.cxx:109
#11 0x010a62ec in TCollection::GarbageCollect (obj=0x533d9e0) at core/cont/src/TCollection.cxx:585
#12 0x010ab91d in TList::Delete (this=0x533d540, option=0x146b618 “”) at core/cont/src/TList.cxx:408
#13 0x010c1f1d in TClass::SetUnloaded (this=0x5322720) at core/meta/src/TClass.cxx:4080
#14 0x010a1ad0 in ROOT::RemoveClass (cname=0x4e485fc “RooArgSet”) at core/cont/src/TClassTable.cxx:566
#15 0x00450135 in ROOT::TDefaultInitBehavior::Unregister ()
#16 0x010d8bc6 in ROOT::TGenericClassInfo::~TGenericClassInfo (this=0x4fa1d60) at core/meta/src/TGenericClassInfo.cxx:194
#17 0x04b4da29 in __tcf_1 ()
#18 0x9188afdc in __cxa_finalize ()
#19 0x9188aed0 in exit ()
#20 0x00001fd3 in ?? ()

Any help would be appreciated.

Jeroen (1.33 KB)


your arrays ‘px’ and ‘py’ go out of scope, even though the branches take and keep their addresses. Easiest way of keeping these arrays alive, is to make them members of the tree: tree.px = array("d", [0.]) = array("d", [0.]) tree.Branch("x", tree.px, "x/D") tree.Branch("y",, "y/D")
at which point they will have the same lifetime as the tree.


Sweet, thanks Wim. I completely forgot that you can do that in Python. Nice trick actually.