Skip to content

Make ElementLinks point to non-const containers

This wasn't at all obvious.

The compiler was complaining that there was no CLASS_DEF for const DataVector<xAOD::TruthParticle_v1>. I was confused for a bit because obviously there is one, and we're including it. But it turns out that I overlooked the const, and that turns out to be very important!

This left me a bit confused: how do we enforce that const containers are not modified when you access them via element links? How do we ensure that no one modifies the ElementLink we're reading off the jet? As far as I can tell we keep everything const by:

  • Inheriting the const-state for the link from the jet, when we access it.
  • Always returning const references when we dereference an ElementLink.

Merge request reports