Skip to content

Commit

Permalink
Make the association coll creation work with all map types
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Sep 27, 2023
1 parent 71bac47 commit 0a3ce71
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
25 changes: 25 additions & 0 deletions k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/MappingUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,31 @@ namespace k4EDM4hep2LcioConv {
template<typename T>
using mapped_t = typename map_t_helper<T>::mapped_type;

template<typename T>
using has_object_type = typename T::object_type;

/// Detector for whether a type T is a Mutable user facing type.
template<typename T>
constexpr static bool is_mutable_v = det::is_detected_v<has_object_type, T>;

/// Helper struct to determine the Mutable type for a user facing type
/// NOTE: Not SFINAE safe for anything that is not a podio generated class
template<typename T, typename IsMutable = std::bool_constant<is_mutable_v<T>>>
struct mutable_t_helper {};

template<typename T>
struct mutable_t_helper<T, std::bool_constant<true>> {
using type = T;
};

template<typename T>
struct mutable_t_helper<T, std::bool_constant<false>> {
using type = typename T::mutable_type;
};

template<typename T>
using mutable_t = typename mutable_t_helper<T>::type;

/// bool constant to determine whether type T is a valid type to be used as
/// a key in the generic mapping functionality defined below. In this case
/// it checks for type equality or makes sure that KeyT is a base of T or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,7 @@ namespace LCIO2EDM4hepConv {
const auto edm4hepFrom = k4EDM4hep2LcioConv::detail::mapLookupTo(lcioFrom, fromMap);
if (edm4hepTo.has_value() && edm4hepFrom.has_value()) {
if constexpr (Reverse) {
if constexpr (std::is_same_v<ToEDM4hepT, edm4hep::MutableVertex>) {
if constexpr (std::is_same_v<k4EDM4hep2LcioConv::detail::mutable_t<ToEDM4hepT>, edm4hep::MutableVertex>) {
assoc.setVertex(*edm4hepTo);
}
else {
Expand All @@ -906,7 +906,7 @@ namespace LCIO2EDM4hepConv {
assoc.setRec(*edm4hepFrom);
}
else {
if constexpr (std::is_same_v<FromEDM4hepT, edm4hep::MutableVertex>) {
if constexpr (std::is_same_v<k4EDM4hep2LcioConv::detail::mutable_t<FromEDM4hepT>, edm4hep::MutableVertex>) {
assoc.setVertex(*edm4hepFrom);
}
else {
Expand Down

0 comments on commit 0a3ce71

Please sign in to comment.