Skip to content

Commit

Permalink
no any cast
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlo Varni committed Jul 2, 2023
1 parent 70a90ba commit aa6b581
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 65 deletions.
11 changes: 6 additions & 5 deletions Core/include/Acts/EventData/SpacePointContainer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T>
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<container_t> m_container;
std::vector<ProxyType> m_proxies;
};
Expand Down
34 changes: 21 additions & 13 deletions Core/include/Acts/EventData/SpacePointContainer.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,27 @@ SpacePointContainer<container_t, holder_t>::SpacePointContainer(
m_container(std::exchange(other.m_container.ptr, nullptr)) {}

template <typename container_t, template <typename> class holder_t>
template <typename T>
const T& SpacePointContainer<container_t, holder_t>::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<const T*>(m_data.component(key, n));
default:
throw std::runtime_error("no such component " + std::to_string(key));
}
inline const Acts::Vector3&
SpacePointContainer<container_t, holder_t>::topStripVector(const std::size_t& n) const {
return m_data.topStripVector(n);
}

template <typename container_t, template <typename> class holder_t>
inline const Acts::Vector3&
SpacePointContainer<container_t, holder_t>::bottomStripVector(const std::size_t& n) const {
return m_data.bottomStripVector(n);
}

template <typename container_t, template <typename> class holder_t>
inline const Acts::Vector3&
SpacePointContainer<container_t, holder_t>::stripCenterDistance(const std::size_t& n) const {
return m_data.stripCenterDistance(n);
}

template <typename container_t, template <typename> class holder_t>
inline const Acts::Vector3&
SpacePointContainer<container_t, holder_t>::topStripCenterPosition(const std::size_t& n) const {
return m_data.topStripCenterPosition(n);
}

template <typename container_t, template <typename> class holder_t>
Expand Down
23 changes: 13 additions & 10 deletions Core/include/Acts/EventData/SpacePointData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -91,8 +94,8 @@ class SpacePointData {
std::vector<float> m_varianceZ{};

/// Mutable variables
std::vector<float> m_quality{};
std::vector<float> m_deltaR{};
mutable std::vector<float> m_quality{};
mutable std::vector<float> m_deltaR{};

/// dynamic variables
std::vector<Acts::Vector3> m_topStripVector{};
Expand Down
41 changes: 20 additions & 21 deletions Core/include/Acts/EventData/SpacePointData.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -78,55 +78,54 @@ 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;
}

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;
}

Expand Down
9 changes: 5 additions & 4 deletions Core/include/Acts/EventData/SpacePointProxy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ class SpacePointProxy {
void setQuality(const float& value) const;
void setDeltaR(const float& value) const;

// component methods for additional quantities
template <typename T>
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;

Expand Down
25 changes: 21 additions & 4 deletions Core/include/Acts/EventData/SpacePointProxy.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,29 @@ inline void SpacePointProxy<container_t, read_only>::setDeltaR(
}

template <typename container_t, bool read_only>
template <typename T>
inline const T& SpacePointProxy<container_t, read_only>::component(
HashedString key) const {
return container().template component<T>(key, m_index);
inline const Acts::Vector3&
SpacePointProxy<container_t, read_only>::topStripVector() const {
return container().topStripVector(m_index);
}

template <typename container_t, bool read_only>
inline const Acts::Vector3&
SpacePointProxy<container_t, read_only>::bottomStripVector() const {
return container().bottomStripVector(m_index);
}

template <typename container_t, bool read_only>
inline const Acts::Vector3&
SpacePointProxy<container_t, read_only>::stripCenterDistance() const {
return container().stripCenterDistance(m_index);
}

template <typename container_t, bool read_only>
inline const Acts::Vector3&
SpacePointProxy<container_t, read_only>::topStripCenterPosition() const {
return container().topStripCenterPosition(m_index);
}

template <typename container_t, bool read_only>
inline typename SpacePointProxy<container_t, read_only>::ContainerType&
SpacePointProxy<container_t, read_only>::container() const {
Expand Down
12 changes: 4 additions & 8 deletions Core/include/Acts/Seeding/SeedFinderUtils.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Acts::Vector3>("TopStripVector"_hash);
const Acts::Vector3& bottomStripVector =
sp.template component<Acts::Vector3>("BottomStripVector"_hash);
const Acts::Vector3& stripCenterDistance =
sp.template component<Acts::Vector3>("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];
Expand Down Expand Up @@ -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<Acts::Vector3>("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
Expand Down

0 comments on commit aa6b581

Please sign in to comment.