From aa6b5816690123ab619df8c14a07fae0c4ff0031 Mon Sep 17 00:00:00 2001 From: Carlo Varni Date: Sun, 2 Jul 2023 12:29:38 +0200 Subject: [PATCH] no any cast --- .../Acts/EventData/SpacePointContainer.hpp | 11 ++--- .../Acts/EventData/SpacePointContainer.ipp | 34 +++++++++------ .../include/Acts/EventData/SpacePointData.hpp | 23 ++++++----- .../include/Acts/EventData/SpacePointData.ipp | 41 +++++++++---------- .../Acts/EventData/SpacePointProxy.hpp | 9 ++-- .../Acts/EventData/SpacePointProxy.ipp | 25 +++++++++-- Core/include/Acts/Seeding/SeedFinderUtils.ipp | 12 ++---- 7 files changed, 90 insertions(+), 65 deletions(-) diff --git a/Core/include/Acts/EventData/SpacePointContainer.hpp b/Core/include/Acts/EventData/SpacePointContainer.hpp index 9edd925d6e1..a1bdc6ea409 100644 --- a/Core/include/Acts/EventData/SpacePointContainer.hpp +++ b/Core/include/Acts/EventData/SpacePointContainer.hpp @@ -192,14 +192,15 @@ class SpacePointContainer { void setQuality(const std::size_t& n, const float& value) const; void setDeltaR(const std::size_t& n, const float& value) const; - // component methods for additional quantities - template - const T& component(HashedString key, const std::size_t& n) const; - + const Acts::Vector3& topStripVector(const std::size_t& n) const; + const Acts::Vector3& bottomStripVector(const std::size_t& n) const; + const Acts::Vector3& stripCenterDistance(const std::size_t& n) const; + const Acts::Vector3& topStripCenterPosition(const std::size_t& n) const; + private: Acts::SpacePointContainerConfig m_config; Acts::SpacePointContainerOptions m_options; - mutable Acts::SpacePointData m_data; + Acts::SpacePointData m_data; holder_t m_container; std::vector m_proxies; }; diff --git a/Core/include/Acts/EventData/SpacePointContainer.ipp b/Core/include/Acts/EventData/SpacePointContainer.ipp index cb9901a721b..44fcbbb0d45 100644 --- a/Core/include/Acts/EventData/SpacePointContainer.ipp +++ b/Core/include/Acts/EventData/SpacePointContainer.ipp @@ -96,19 +96,27 @@ SpacePointContainer::SpacePointContainer( m_container(std::exchange(other.m_container.ptr, nullptr)) {} template class holder_t> -template -const T& SpacePointContainer::component( - HashedString key, const std::size_t& n) const { - using namespace Acts::HashedStringLiteral; - switch (key) { - case "TopStripVector"_hash: - case "BottomStripVector"_hash: - case "StripCenterDistance"_hash: - case "TopStripCenterPosition"_hash: - return *std::any_cast(m_data.component(key, n)); - default: - throw std::runtime_error("no such component " + std::to_string(key)); - } +inline const Acts::Vector3& +SpacePointContainer::topStripVector(const std::size_t& n) const { + return m_data.topStripVector(n); +} + +template class holder_t> +inline const Acts::Vector3& +SpacePointContainer::bottomStripVector(const std::size_t& n) const { + return m_data.bottomStripVector(n); +} + +template class holder_t> +inline const Acts::Vector3& +SpacePointContainer::stripCenterDistance(const std::size_t& n) const { + return m_data.stripCenterDistance(n); +} + +template class holder_t> +inline const Acts::Vector3& +SpacePointContainer::topStripCenterPosition(const std::size_t& n) const { + return m_data.topStripCenterPosition(n); } template class holder_t> diff --git a/Core/include/Acts/EventData/SpacePointData.hpp b/Core/include/Acts/EventData/SpacePointData.hpp index fecf9ddbed0..26a997895c2 100644 --- a/Core/include/Acts/EventData/SpacePointData.hpp +++ b/Core/include/Acts/EventData/SpacePointData.hpp @@ -61,8 +61,8 @@ class SpacePointData { void setVarianceZ(const std::size_t& idx, const float& value); void setVarianceR(const std::size_t& idx, const float& value); - void setQuality(const std::size_t& idx, const float& value); - void setDeltaR(const std::size_t& idx, const float& value); + void setQuality(const std::size_t& idx, const float& value) const; + void setDeltaR(const std::size_t& idx, const float& value) const; /// @brief Resize vectors void resize(const std::size_t& n, bool resizeDynamic = false); @@ -73,12 +73,15 @@ class SpacePointData { /// bool hasDynamicVariable() const; - std::any component(Acts::HashedString key, const std::size_t& n) const; - - void setTopStripVector(std::size_t idx, const Acts::Vector3& value); - void setBottomStripVector(std::size_t idx, const Acts::Vector3& value); - void setStripCenterDistance(std::size_t idx, const Acts::Vector3& value); - void setTopStripCenterPosition(std::size_t idx, const Acts::Vector3& value); + const Acts::Vector3& topStripVector(const std::size_t& idx) const; + const Acts::Vector3& bottomStripVector(const std::size_t& idx) const; + const Acts::Vector3& stripCenterDistance(const std::size_t& idx) const; + const Acts::Vector3& topStripCenterPosition(const std::size_t& idx) const; + + void setTopStripVector(const std::size_t& idx, const Acts::Vector3& value); + void setBottomStripVector(const std::size_t& idx, const Acts::Vector3& value); + void setStripCenterDistance(const std::size_t& idx, const Acts::Vector3& value); + void setTopStripCenterPosition(const std::size_t& idx, const Acts::Vector3& value); private: /// base variables @@ -91,8 +94,8 @@ class SpacePointData { std::vector m_varianceZ{}; /// Mutable variables - std::vector m_quality{}; - std::vector m_deltaR{}; + mutable std::vector m_quality{}; + mutable std::vector m_deltaR{}; /// dynamic variables std::vector m_topStripVector{}; diff --git a/Core/include/Acts/EventData/SpacePointData.ipp b/Core/include/Acts/EventData/SpacePointData.ipp index 7dd4ca52783..d8b787aa3c3 100644 --- a/Core/include/Acts/EventData/SpacePointData.ipp +++ b/Core/include/Acts/EventData/SpacePointData.ipp @@ -78,14 +78,14 @@ inline const float& SpacePointData::deltaR(const std::size_t& idx) const { } inline void SpacePointData::setQuality(const std::size_t& idx, - const float& value) { + const float& value) const { if (value > m_quality[idx]) { m_quality[idx] = value; } } inline void SpacePointData::setDeltaR(const std::size_t& idx, - const float& value) { + const float& value) const { m_deltaR[idx] = value; } @@ -93,40 +93,39 @@ inline bool SpacePointData::hasDynamicVariable() const { return not m_topStripVector.empty(); } -inline std::any SpacePointData::component(Acts::HashedString key, - const std::size_t& n) const { - using namespace Acts::HashedStringLiteral; - switch (key) { - case "TopStripVector"_hash: - return &m_topStripVector[n]; - case "BottomStripVector"_hash: - return &m_bottomStripVector[n]; - case "StripCenterDistance"_hash: - return &m_stripCenterDistance[n]; - case "TopStripCenterPosition"_hash: - return &m_topStripCenterPosition[n]; - default: - throw std::runtime_error("no such component " + std::to_string(key)); - } +inline const Acts::Vector3& SpacePointData::topStripVector(const std::size_t& idx) const { + return m_topStripVector[idx]; +} + +inline const Acts::Vector3& SpacePointData::bottomStripVector(const std::size_t& idx) const { + return m_bottomStripVector[idx]; } -inline void SpacePointData::setTopStripVector(std::size_t idx, +inline const Acts::Vector3& SpacePointData::stripCenterDistance(const std::size_t& idx) const { + return m_stripCenterDistance[idx]; +} + +inline const Acts::Vector3& SpacePointData::topStripCenterPosition(const std::size_t& idx) const { + return m_topStripCenterPosition[idx]; +} + +inline void SpacePointData::setTopStripVector(const std::size_t& idx, const Acts::Vector3& value) { m_topStripVector[idx] = value; } -inline void SpacePointData::setBottomStripVector(std::size_t idx, +inline void SpacePointData::setBottomStripVector(const std::size_t& idx, const Acts::Vector3& value) { m_bottomStripVector[idx] = value; } -inline void SpacePointData::setStripCenterDistance(std::size_t idx, +inline void SpacePointData::setStripCenterDistance(const std::size_t& idx, const Acts::Vector3& value) { m_stripCenterDistance[idx] = value; } inline void SpacePointData::setTopStripCenterPosition( - std::size_t idx, const Acts::Vector3& value) { + const std::size_t& idx, const Acts::Vector3& value) { m_topStripCenterPosition[idx] = value; } diff --git a/Core/include/Acts/EventData/SpacePointProxy.hpp b/Core/include/Acts/EventData/SpacePointProxy.hpp index e852bb59617..132fad220b5 100644 --- a/Core/include/Acts/EventData/SpacePointProxy.hpp +++ b/Core/include/Acts/EventData/SpacePointProxy.hpp @@ -60,10 +60,11 @@ class SpacePointProxy { void setQuality(const float& value) const; void setDeltaR(const float& value) const; - // component methods for additional quantities - template - const T& component(HashedString key) const; - + const Acts::Vector3& topStripVector() const; + const Acts::Vector3& bottomStripVector() const; + const Acts::Vector3& stripCenterDistance() const; + const Acts::Vector3& topStripCenterPosition() const; + private: ContainerType& container() const; diff --git a/Core/include/Acts/EventData/SpacePointProxy.ipp b/Core/include/Acts/EventData/SpacePointProxy.ipp index 6021dd27677..1328099234c 100644 --- a/Core/include/Acts/EventData/SpacePointProxy.ipp +++ b/Core/include/Acts/EventData/SpacePointProxy.ipp @@ -93,12 +93,29 @@ inline void SpacePointProxy::setDeltaR( } template -template -inline const T& SpacePointProxy::component( - HashedString key) const { - return container().template component(key, m_index); +inline const Acts::Vector3& +SpacePointProxy::topStripVector() const { + return container().topStripVector(m_index); } +template +inline const Acts::Vector3& +SpacePointProxy::bottomStripVector() const { + return container().bottomStripVector(m_index); +} + +template +inline const Acts::Vector3& +SpacePointProxy::stripCenterDistance() const { + return container().stripCenterDistance(m_index); +} + +template +inline const Acts::Vector3& +SpacePointProxy::topStripCenterPosition() const { + return container().topStripCenterPosition(m_index); +} + template inline typename SpacePointProxy::ContainerType& SpacePointProxy::container() const { diff --git a/Core/include/Acts/Seeding/SeedFinderUtils.ipp b/Core/include/Acts/Seeding/SeedFinderUtils.ipp index 2983035cb40..80ba8016513 100644 --- a/Core/include/Acts/Seeding/SeedFinderUtils.ipp +++ b/Core/include/Acts/Seeding/SeedFinderUtils.ipp @@ -128,12 +128,9 @@ inline bool xyzCoordinateCheck( // Bottom-Middle direction with the strip measurement details using namespace Acts::HashedStringLiteral; - const Acts::Vector3& topStripVector = - sp.template component("TopStripVector"_hash); - const Acts::Vector3& bottomStripVector = - sp.template component("BottomStripVector"_hash); - const Acts::Vector3& stripCenterDistance = - sp.template component("StripCenterDistance"_hash); + const Acts::Vector3& topStripVector = sp.topStripVector(); + const Acts::Vector3& bottomStripVector = sp.bottomStripVector(); + const Acts::Vector3& stripCenterDistance = sp.stripCenterDistance(); const double& xTopStripVector = topStripVector[0]; const double& yTopStripVector = topStripVector[1]; @@ -181,8 +178,7 @@ inline bool xyzCoordinateCheck( // if arrive here spacepointPosition is compatible with strip directions and // detector elements - const Acts::Vector3& topStripCenterPosition = - sp.template component("TopStripCenterPosition"_hash); + const Acts::Vector3& topStripCenterPosition = sp.topStripCenterPosition(); // spacepointPosition corrected with respect to the top strip position and // direction and the distance between the strips