Skip to content

Modernize LHCb::DecayTree, and make it be explicit about ownership transfers.

The following discussion @graven started from !4645 should be addressed:

  • this line transfers ownership from cloned_particle to output_particles, but as cloned_particle is a plain pointer, there is no way to track this. Please modify the code such that ownership is actually reflected by the types used (i.e. use unique_ptr in the right places, and distinguish between plain pointers and unique_ptr.)

to which @jzhuo responded:

  • If you look at the current implementation of LHCb::DecayTree, it simply uses new and adds pointers to the decay and to this cloneMap. So iterating over the cloneMap to persist particles is the best solution for the current design. This means all particles created by LHCb::DecayTree should be stored in the TES with this for-loop. When LHCb::DecayTree::release() is called, it checks whether the particle is already stored in the TES by checking if the KeyedObject has an associated KeyedContainer. It only frees resources if the particle is not stored in any TES location. See: https://gitlab.cern.ch/lhcb/Rec/-/blob/jzhuo_DTFNeutrino/Phys/DaVinciTypes/src/TreeCloners.cpp#L244. I am happy to modernize LHCb::DecayTree, but it must be an independent MR and it should not block this one.
Edited by Gerhard Raven