root icon indicating copy to clipboard operation
root copied to clipboard

[RF] Deletion order of objects in RooFit/RooStats tutorials should not matter in Python

Open guitargeek opened this issue 3 years ago • 1 comments

Different from C++, any objects created in Python are not deleted in the inverse order of their creation.

This causes crashes in some RooFit user code, for examples when some object has only a non-owing reference/pointer as a data member, this data member is used in the constructor, and then the referenced object is destructed first.

Hence, the user is sometimes forced to use del explicitly in Python, for example in these tutorials:

  • rf207_comptools.py: https://github.com/root-project/root/blob/master/tutorials/roofit/rf207_comptools.py#L116
  • rf514_RooCustomizer.py: https://github.com/root-project/root/blob/master/tutorials/roofit/rf514_RooCustomizer.py#L95
  • rs101_limitexample.py: https://github.com/root-project/root/blob/master/tutorials/roostats/rs101_limitexample.py#L184

The RooFit/RooStats code needs some Pythonizations that manage ownership such that the deletion order doesn't matter anymore.

guitargeek avatar Jul 04 '22 14:07 guitargeek

These problems are probably similar to the ones reported for TMVA in this forum post: https://root-forum.cern.ch/t/tmva-crossvalidation-crashes-on-destructor-pyroot/51195

Just like in that post, using valgrind could help. Or running the Python tutorials with an ASAN build.

guitargeek avatar Sep 01 '22 13:09 guitargeek