From 1374baab7433e367bf41a9f2c69af6624f8a2d19 Mon Sep 17 00:00:00 2001 From: Andreas Stefl Date: Sat, 6 Apr 2024 10:38:34 +0200 Subject: [PATCH] refactor: Remove `constexpr` from `MultiTrajectory` functions (#3073) I believe the `constexpr` cannot be guaranteed with C++17 for the vector backend and even with C++20 it would limit other backends to be `constexpr`. From https://en.cppreference.com/w/cpp/language/constexpr > The constexpr specifier declares that it is possible to evaluate the value of the function or variable at compile time. Such variables and functions can then be used where only compile time [constant expressions](https://en.cppreference.com/w/cpp/language/constant_expression) are allowed (provided that appropriate function arguments are given). If not all backends can be guaranteed to be `constexpr`, the frontend cannot be `constexpr`. --- .../Acts/EventData/MultiTrajectory.hpp | 60 +++++++++---------- .../Acts/EventData/VectorMultiTrajectory.hpp | 12 ++-- 2 files changed, 33 insertions(+), 39 deletions(-) diff --git a/Core/include/Acts/EventData/MultiTrajectory.hpp b/Core/include/Acts/EventData/MultiTrajectory.hpp index 309c50139e3..d25e1ec72e7 100644 --- a/Core/include/Acts/EventData/MultiTrajectory.hpp +++ b/Core/include/Acts/EventData/MultiTrajectory.hpp @@ -191,7 +191,7 @@ class MultiTrajectory { /// Helper function to check if a component exists IF it is an optional one. /// Used in assertions - constexpr bool checkOptional(HashedString key, IndexType istate) const { + bool checkOptional(HashedString key, IndexType istate) const { using namespace Acts::HashedStringLiteral; switch (key) { case "predicted"_hash: @@ -240,9 +240,8 @@ class MultiTrajectory { /// @param iprevious index of the previous state, kInvalid if first /// @return Index of the newly added track state template > - constexpr IndexType addTrackState( - TrackStatePropMask mask = TrackStatePropMask::All, - IndexType iprevious = kInvalid) { + IndexType addTrackState(TrackStatePropMask mask = TrackStatePropMask::All, + IndexType iprevious = kInvalid) { return self().addTrackState_impl(mask, iprevious); } @@ -388,29 +387,27 @@ class MultiTrajectory { /// compatibility with backends. /// @note Only available if the MultiTrajectory is not read-only template > - constexpr void addColumn(const std::string& key) { + void addColumn(const std::string& key) { self().template addColumn_impl(key); } /// Check if a column with a key @p key exists. /// @param key Key to check for a column with /// @return True if the column exists, false if not. - constexpr bool hasColumn(HashedString key) const { - return self().hasColumn_impl(key); - } + bool hasColumn(HashedString key) const { return self().hasColumn_impl(key); } /// @} /// Clear the @c MultiTrajectory. Leaves the underlying storage untouched /// @note Only available if the MultiTrajectory is not read-only template > - constexpr void clear() { + void clear() { self().clear_impl(); } /// Returns the number of track states contained /// @return The number of track states - constexpr IndexType size() const { return self().size_impl(); } + IndexType size() const { return self().size_impl(); } protected: // These are internal helper functions which the @c TrackStateProxy class talks to @@ -419,7 +416,7 @@ class MultiTrajectory { /// @param key The key for which to check /// @param istate The track state index to check /// @return True if the component exists, false if not - constexpr bool has(HashedString key, IndexType istate) const { + bool has(HashedString key, IndexType istate) const { return self().has_impl(key, istate); } @@ -428,7 +425,7 @@ class MultiTrajectory { /// @param istate The track state index to check /// @return True if the component exists, false if not template - constexpr bool has(IndexType istate) const { + bool has(IndexType istate) const { return self().has_impl(key, istate); } @@ -436,15 +433,14 @@ class MultiTrajectory { /// @param parIdx Index into the parameter column /// @return Mutable proxy template > - constexpr typename TrackStateProxy::Parameters parameters(IndexType parIdx) { + typename TrackStateProxy::Parameters parameters(IndexType parIdx) { return self().parameters_impl(parIdx); } /// Retrieve a parameter proxy instance for parameters at a given index /// @param parIdx Index into the parameter column /// @return Const proxy - constexpr typename ConstTrackStateProxy::Parameters parameters( - IndexType parIdx) const { + typename ConstTrackStateProxy::Parameters parameters(IndexType parIdx) const { return self().parameters_impl(parIdx); } @@ -452,15 +448,14 @@ class MultiTrajectory { /// @param covIdx Index into the covariance column /// @return Mutable proxy template > - constexpr typename TrackStateProxy::Covariance covariance(IndexType covIdx) { + typename TrackStateProxy::Covariance covariance(IndexType covIdx) { return self().covariance_impl(covIdx); } /// Retrieve a covariance proxy instance for a covariance at a given index /// @param covIdx Index into the covariance column /// @return Const proxy - constexpr typename ConstTrackStateProxy::Covariance covariance( - IndexType covIdx) const { + typename ConstTrackStateProxy::Covariance covariance(IndexType covIdx) const { return self().covariance_impl(covIdx); } @@ -468,15 +463,14 @@ class MultiTrajectory { /// @param jacIdx Index into the jacobian column /// @return Mutable proxy template > - constexpr typename TrackStateProxy::Covariance jacobian(IndexType jacIdx) { + typename TrackStateProxy::Covariance jacobian(IndexType jacIdx) { return self().jacobian_impl(jacIdx); } /// Retrieve a jacobian proxy instance for a jacobian at a given index /// @param jacIdx Index into the jacobian column /// @return Const proxy - constexpr typename ConstTrackStateProxy::Covariance jacobian( - IndexType jacIdx) const { + typename ConstTrackStateProxy::Covariance jacobian(IndexType jacIdx) const { return self().jacobian_impl(jacIdx); } @@ -486,7 +480,7 @@ class MultiTrajectory { /// @return Mutable proxy template > - constexpr typename TrackStateProxy::template Measurement measurement( + typename TrackStateProxy::template Measurement measurement( IndexType measIdx) { return self().template measurement_impl(measIdx); } @@ -496,8 +490,8 @@ class MultiTrajectory { /// @param measIdx Index into the measurement column /// @return Const proxy template - constexpr typename ConstTrackStateProxy::template Measurement - measurement(IndexType measIdx) const { + typename ConstTrackStateProxy::template Measurement measurement( + IndexType measIdx) const { return self().template measurement_impl(measIdx); } @@ -508,7 +502,7 @@ class MultiTrajectory { /// @return Mutable proxy template > - constexpr typename TrackStateProxy::template MeasurementCovariance + typename TrackStateProxy::template MeasurementCovariance measurementCovariance(IndexType covIdx) { return self().template measurementCovariance_impl(covIdx); } @@ -542,9 +536,9 @@ class MultiTrajectory { /// @note The track states both need to be stored in the /// same @c MultiTrajectory instance template > - constexpr void shareFrom(IndexType iself, IndexType iother, - TrackStatePropMask shareSource, - TrackStatePropMask shareTarget) { + void shareFrom(IndexType iself, IndexType iother, + TrackStatePropMask shareSource, + TrackStatePropMask shareTarget) { self().shareFrom_impl(iself, iother, shareSource, shareTarget); } @@ -552,7 +546,7 @@ class MultiTrajectory { /// @param target The component to unset /// @param istate The track state index to operate on template > - constexpr void unset(TrackStatePropMask target, IndexType istate) { + void unset(TrackStatePropMask target, IndexType istate) { self().unset_impl(target, istate); } @@ -572,7 +566,7 @@ class MultiTrajectory { /// @return Mutable reference to the component given by @p key template > - constexpr T& component(IndexType istate) { + T& component(IndexType istate) { assert(checkOptional(key, istate)); return *std::any_cast(self().component_impl(key, istate)); } @@ -583,7 +577,7 @@ class MultiTrajectory { /// @param istate The track state index to operate on /// @return Mutable reference to the component given by @p key template > - constexpr T& component(HashedString key, IndexType istate) { + T& component(HashedString key, IndexType istate) { assert(checkOptional(key, istate)); return *std::any_cast(self().component_impl(key, istate)); } @@ -594,7 +588,7 @@ class MultiTrajectory { /// @param istate The track state index to operate on /// @return Const reference to the component given by @p key template - constexpr const T& component(IndexType istate) const { + const T& component(IndexType istate) const { assert(checkOptional(key, istate)); return *std::any_cast(self().component_impl(key, istate)); } @@ -605,7 +599,7 @@ class MultiTrajectory { /// @param istate The track state index to operate on /// @return Const reference to the component given by @p key template - constexpr const T& component(HashedString key, IndexType istate) const { + const T& component(HashedString key, IndexType istate) const { assert(checkOptional(key, istate)); return *std::any_cast(self().component_impl(key, istate)); } diff --git a/Core/include/Acts/EventData/VectorMultiTrajectory.hpp b/Core/include/Acts/EventData/VectorMultiTrajectory.hpp index ae5c3dfcb74..8bcb34d8c9c 100644 --- a/Core/include/Acts/EventData/VectorMultiTrajectory.hpp +++ b/Core/include/Acts/EventData/VectorMultiTrajectory.hpp @@ -266,7 +266,7 @@ class VectorMultiTrajectoryBase { } template - static constexpr bool hasColumn_impl(T& instance, HashedString key) { + static bool hasColumn_impl(T& instance, HashedString key) { using namespace Acts::HashedStringLiteral; switch (key) { case "predicted"_hash: @@ -434,7 +434,7 @@ class VectorMultiTrajectory final void unset_impl(TrackStatePropMask target, IndexType istate); - constexpr bool has_impl(HashedString key, IndexType istate) const { + bool has_impl(HashedString key, IndexType istate) const { return detail_vmt::VectorMultiTrajectoryBase::has_impl(*this, key, istate); } @@ -455,12 +455,12 @@ class VectorMultiTrajectory final } template - constexpr void addColumn_impl(const std::string& key) { + void addColumn_impl(const std::string& key) { Acts::HashedString hashedKey = hashString(key); m_dynamic.insert({hashedKey, std::make_unique>()}); } - constexpr bool hasColumn_impl(HashedString key) const { + bool hasColumn_impl(HashedString key) const { return detail_vmt::VectorMultiTrajectoryBase::hasColumn_impl(*this, key); } @@ -561,7 +561,7 @@ class ConstVectorMultiTrajectory final &m_measCov[offset]}; } - constexpr bool has_impl(HashedString key, IndexType istate) const { + bool has_impl(HashedString key, IndexType istate) const { return detail_vmt::VectorMultiTrajectoryBase::has_impl(*this, key, istate); } @@ -574,7 +574,7 @@ class ConstVectorMultiTrajectory final *this, key, istate); } - constexpr bool hasColumn_impl(HashedString key) const { + bool hasColumn_impl(HashedString key) const { return detail_vmt::VectorMultiTrajectoryBase::hasColumn_impl(*this, key); }