Skip to content

Add support to ToolHandle for const tool interfaces

Christopher Rob Jones requested to merge ConstInterfacesWithToolHandle into future

The current model for using ToolHandles has something like

ToolHandle<ITrackExtrapolator> m_trExt{ "TrackRungeKuttaExtrapolator", this };

as an algorithm data member. This works fine, but I just noticed that this model allows access to non-const methods of the tool, even in const methods of the parent algorithm. This is a problem if we want to enforce usage of only const interface methods in functional algorithms.

With raw pointers I explicitly declare them const

const ITrackExtrapolator m_trExt{nullptr};

But the equivalent does not work with ToolHandle, as some methods require non-const access (for instance to release the tool).

This update uses a little bit of type traits and const_casting to allow the user to declare they only want const access to the tool

ToolHandle<const ITrackExtrapolator> m_trExt{ "TrackRungeKuttaExtrapolator", this };

but internally allows the handle to discard the const qualifier only where needed.

I've submitted this against the future branch, but actually I see no reason why it could not be pushed to master as well. I've tested it against the current LHCb, Lbcom and Rec projects and all builds and runs fine. In fact in places that do not use const the changes do nothing (cast from non const to the same non const type).

Merge request reports

Loading