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_particletooutput_particles, but ascloned_particleis 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. useunique_ptrin the right places, and distinguish between plain pointers andunique_ptr.)
to which @jzhuo responded:
- If you look at the current implementation of
LHCb::DecayTree, it simply usesnewand adds pointers to the decay and to thiscloneMap. So iterating over thecloneMapto persist particles is the best solution for the current design. This means all particles created byLHCb::DecayTreeshould be stored in the TES with this for-loop. WhenLHCb::DecayTree::release()is called, it checks whether the particle is already stored in the TES by checking if theKeyedObjecthas an associatedKeyedContainer. 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 modernizeLHCb::DecayTree, but it must be an independent MR and it should not block this one.
Edited by Gerhard Raven