Skip to content

Commit

Permalink
Move common functionality into header and include that in yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Apr 19, 2024
1 parent 509c7ef commit 6dcec4d
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 59 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/edm4hep/edm4hep/EDM4hepVersion.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/edm4hep )
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/python/edm4hep/__version__.py.in
${CMAKE_CURRENT_SOURCE_DIR}/python/edm4hep/__version__.py)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/edm4hep
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

#--- add CMake infrastructure --------------------------------------------------
include(cmake/EDM4HEPCreateConfig.cmake)
Expand Down
65 changes: 6 additions & 59 deletions edm4hep.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,8 @@ components:
constexpr CovMatrix2f& operator=(std::array<float, 3> v) { values = v; return *this; }\n
bool operator==(const CovMatrix2f& v) const { return v.values == values; }\n
bool operator!=(const CovMatrix2f& v) const { return v.values != values; }\n
constexpr float operator[](unsigned i) const { return values[i]; }\n
constexpr float& operator[](unsigned i) { return values[i]; }\n
constexpr auto begin() const { return values.begin(); }\n
constexpr auto begin() { return values.begin(); }\n
constexpr auto end() const { return values.begin(); }\n
constexpr auto end() { return values.begin(); }\n
float* data() { return values.data(); }\n
const float* data() const { return values.data(); }\n
/// Get the value of the covariance matrix for the two passed dimensions\n
template<typename DimEnum>\n
constexpr float getValue(DimEnum dimI, DimEnum dimJ) const { return utils::get_cov_value(values, dimI, dimJ); }\n
/// Set a value in the covariance matrix for the two passed dimensions\n
template<typename DimEnum>\n
constexpr void setValue(float value, DimEnum dimI, DimEnum dimJ) { utils::set_cov_value(value, values, dimI, dimJ); }\n
"

#include <edm4hep/detail/CovMatrixCommon.ipp>
"
edm4hep::CovMatrix3f:
Description: "A generic 3 dimensional covariance matrix with values stored in lower triangular form"
Members:
Expand All @@ -160,20 +146,7 @@ components:
constexpr CovMatrix3f& operator=(std::array<float, 6> v) { values = v; return *this; }\n
bool operator==(const CovMatrix3f& v) const { return v.values == values; }\n
bool operator!=(const CovMatrix3f& v) const { return v.values != values; }\n
constexpr float operator[](unsigned i) const { return values[i]; }\n
constexpr float& operator[](unsigned i) { return values[i]; }\n
constexpr auto begin() const { return values.begin(); }\n
constexpr auto begin() { return values.begin(); }\n
constexpr auto end() const { return values.begin(); }\n
constexpr auto end() { return values.begin(); }\n
float* data() { return values.data(); }\n
const float* data() const { return values.data(); }\n
/// Get the value of the covariance matrix for the two passed dimensions\n
template<typename DimEnum>\n
constexpr float getValue(DimEnum dimI, DimEnum dimJ) const { return utils::get_cov_value(values, dimI, dimJ); }\n
/// Set a value in the covariance matrix for the two passed dimensions\n
template<typename DimEnum>\n
constexpr void setValue(float value, DimEnum dimI, DimEnum dimJ) { utils::set_cov_value(value, values, dimI, dimJ); }\n
#include <edm4hep/detail/CovMatrixCommon.ipp>
"

edm4hep::CovMatrix4f:
Expand All @@ -188,21 +161,8 @@ components:
constexpr CovMatrix4f& operator=(std::array<float, 10> v) { values = v; return *this; }\n
bool operator==(const CovMatrix4f& v) const { return v.values == values; }\n
bool operator!=(const CovMatrix4f& v) const { return v.values != values; }\n
constexpr float operator[](unsigned i) const { return values[i]; }\n
constexpr float& operator[](unsigned i) { return values[i]; }\n
constexpr auto begin() const { return values.begin(); }\n
constexpr auto begin() { return values.begin(); }\n
constexpr auto end() const { return values.begin(); }\n
constexpr auto end() { return values.begin(); }\n
float* data() { return values.data(); }\n
const float* data() const { return values.data(); }\n
/// Get the value of the covariance matrix for the two passed dimensions\n
template<typename DimEnum>\n
constexpr float getValue(DimEnum dimI, DimEnum dimJ) const { return utils::get_cov_value(values, dimI, dimJ); }\n
/// Set a value in the covariance matrix for the two passed dimensions\n
template<typename DimEnum>\n
constexpr void setValue(float value, DimEnum dimI, DimEnum dimJ) { utils::set_cov_value(value, values, dimI, dimJ); }\n
"
#include <edm4hep/detail/CovMatrixCommon.ipp>
"

edm4hep::CovMatrix6f:
Description: "A generic 6 dimensional covariance matrix with values stored in lower triangular form"
Expand All @@ -216,20 +176,7 @@ components:
constexpr CovMatrix6f& operator=(std::array<float, 21> v) { values = v; return *this; }\n
bool operator==(const CovMatrix6f& v) const { return v.values == values; }\n
bool operator!=(const CovMatrix6f& v) const { return v.values != values; }\n
constexpr float operator[](unsigned i) const { return values[i]; }\n
constexpr float& operator[](unsigned i) { return values[i]; }\n
constexpr auto begin() const { return values.begin(); }\n
constexpr auto begin() { return values.begin(); }\n
constexpr auto end() const { return values.begin(); }\n
constexpr auto end() { return values.begin(); }\n
float* data() { return values.data(); }\n
const float* data() const { return values.data(); }\n
/// Get the value of the covariance matrix for the two passed dimensions\n
template<typename DimEnum>\n
constexpr float getValue(DimEnum dimI, DimEnum dimJ) const { return utils::get_cov_value(values, dimI, dimJ); }\n
/// Set a value in the covariance matrix for the two passed dimensions\n
template<typename DimEnum>\n
constexpr void setValue(float value, DimEnum dimI, DimEnum dimJ) { utils::set_cov_value(value, values, dimI, dimJ); }\n
#include <edm4hep/detail/CovMatrixCommon.ipp>\n
"

# Parametrized description of a particle track
Expand Down
90 changes: 90 additions & 0 deletions include/edm4hep/detail/CovMatrixCommon.ipp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// This file is meant to be included inside the declaration part of the
// ExtraCode for the CovMatrixNx components. They live in this file because they
// can be written very generically and reduce the clutter and code repetition in
// the edm4hep.yaml file
//
// NOTE: All of these functions are intended to be member functions, and the
// only member of a CovMatrixNx component is an apropriately sized std::array
// named values.
//
// NOTE: It is also assumed that the edm4hep/utils/cov_matrix_utils.h header is
// included via the corresponding ExtraCode: include directive

/// Get the i-th element of the underlying storage
///
/// \note The values are stored in a flat array assuming a lower
/// triangular matrix representation
constexpr float operator[](unsigned i) const {
return values[i];
}

/// Get the i-th element of the underlying storage
///
/// \note The values are stored in a flat array assuming a lower
/// triangular matrix representation
constexpr float& operator[](unsigned i) {
return values[i];
}

/// Get the begin iterator to the underlying storage
constexpr auto begin() const {
return values.begin();
}

/// Get the begin iterator to the underlying storage
constexpr auto begin() {
return values.begin();
}

/// Get the end iterator to the underlying storage
constexpr auto end() const {
return values.end();
}

/// Get the end iterator to the underlying storage
constexpr auto end() {
return values.end();
}

/// Get a pointer to the underlying storage data
auto* data() {
return values.data();
}

/// Get a pointer to the underlying storage data
const auto* data() const {
return values.data();
}

/// Get the value of the covariance matrix for the passed dimensions
///
/// @tparam DimEnum The enum (class) type that describes the dimenstions of this
/// covariance matrix. This will be deduced from the passed
/// arguments!
///
/// @param dimI The first dimension for which the covariance matrix value should
/// be obtained
/// @param dimJ The second dimension for which the covariance matrix value
/// should be obtained
///
/// @returns The value of the covariance matrix for dimension dimI and dimJ
template <typename DimEnum>
constexpr float getValue(DimEnum dimI, DimEnum dimJ) const {
return edm4hep::utils::get_cov_value(values, dimI, dimJ);
}

/// Set the value of the covariance matrix for the passed dimensions
///
/// @tparam DimEnum The enum (class) type that describes the dimenstions of this
/// covariance matrix. This will be deduced from the passed
/// arguments!
///
/// @param value The value to be set
/// @param dimI The first dimension for which the covariance matrix value
/// should be obtained
/// @param dimJ The second dimension for which the covariance matrix value
/// should be obtained
template <typename DimEnum>
constexpr void setValue(float value, DimEnum dimI, DimEnum dimJ) {
utils::set_cov_value(value, values, dimI, dimJ);
}

0 comments on commit 6dcec4d

Please sign in to comment.