Skip to content

Commit 6f422b9

Browse files
authored
Introduce explicitly named getLinked[From|To] and deprecate tag-dispatch versions (#936)
* Use function names to differentiate instead of tag-dispatch Calling the tag-dispatched versions is slightly clunky and we can still keep the getLinked that do the "right thing" automatically with this. The main difference is that for links with the same FromT and ToT we now need to call an explicitly named function. Given that most links have different types this should not be too big of a problem. * Fix copy-paste typo
1 parent 0fbdce7 commit 6f422b9

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

include/podio/LinkNavigator.h

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ namespace detail::links {
2828
};
2929

3030
/// Simple struct tag for overload selection in LinkNavigator below
31-
struct ReturnFromTag {};
31+
struct [[deprecated("The tagged versions of getLinked are deprecated use getLinkedFrom instead")]] ReturnFromTag {};
3232
/// Simple struct tag for overload selection in LinkNavigator below
33-
struct ReturnToTag {};
33+
struct [[deprecated("The tagged versions of getLinked are deprecated use getLinkedTo instead")]] ReturnToTag {};
3434
} // namespace detail::links
3535

36+
/// NOTE: This can go at the same time as the deprecated tags below are removed
3637
#if !defined(__CLING__)
3738
#define INLCONSTEXPR inline constexpr
3839
#else
@@ -41,11 +42,13 @@ namespace detail::links {
4142
/// Tag variable to select the lookup of *From* objects have links with a *To*
4243
/// object in podio::LinkNavigator::getLinked
4344
// INLCONSTEXPR detail::links::ReturnFromTag ReturnFrom;
44-
INLCONSTEXPR detail::links::ReturnFromTag ReturnFrom;
45+
[[deprecated("The tagged versions of getLinked are deprecated use getLinkedFrom instead")]] INLCONSTEXPR
46+
detail::links::ReturnFromTag ReturnFrom;
4547
/// Tag variable to select the lookup of *To* objects that have links with a
4648
/// *From* object in podio::LinkNavigator::getLinked
4749
// INLCONSTEXPR detail::links::ReturnToTag ReturnTo;
48-
INLCONSTEXPR detail::links::ReturnToTag ReturnTo;
50+
[[deprecated("The tagged versions of getLinked are deprecated use getLinkedTo instead")]] INLCONSTEXPR
51+
detail::links::ReturnToTag ReturnTo;
4952
#undef INLCONSTEXPR
5053

5154
/// A helper class to more easily handle one-to-many links.
@@ -92,7 +95,7 @@ class LinkNavigator {
9295
///
9396
/// @returns A vector of all objects and their weights that have links with
9497
/// the passed object
95-
std::vector<WeightedObject<FromT>> getLinked(const ToT& object, podio::detail::links::ReturnFromTag) const {
98+
std::vector<WeightedObject<FromT>> getLinkedFrom(const ToT& object) const {
9699
const auto& [begin, end] = m_to2from.equal_range(object);
97100
std::vector<WeightedObject<FromT>> result;
98101
result.reserve(std::distance(begin, end));
@@ -103,9 +106,15 @@ class LinkNavigator {
103106
return result;
104107
}
105108

109+
[[deprecated("Use getLinkedFrom instead")]]
110+
std::vector<WeightedObject<FromT>> getLinked(const ToT& object, podio::detail::links::ReturnFromTag) const {
111+
return getLinkedFrom(object);
112+
}
113+
114+
[[deprecated("Use getLinkedFrom instead")]]
106115
std::vector<WeightedObject<FromT>> getLinked(const typename ToT::mutable_type& object,
107116
podio::detail::links::ReturnFromTag) const {
108-
return getLinked(ToT(object), podio::ReturnFrom);
117+
return getLinkedFrom(ToT(object));
109118
}
110119

111120
/// Get all the *From* objects and weights that have links with the passed
@@ -122,15 +131,14 @@ class LinkNavigator {
122131
template <typename ToU = ToT>
123132
requires(!std::same_as<FromT, ToU>)
124133
std::vector<WeightedObject<FromT>> getLinked(const ToT& object) const {
125-
126-
return getLinked(object, podio::ReturnFrom);
134+
return getLinkedFrom(object);
127135
}
128136

129137
/// Overload for cppyy that makes things work with mutable handles
130138
template <typename ToU = ToT>
131139
requires(!std::same_as<FromT, ToU>)
132140
std::vector<WeightedObject<FromT>> getLinked(const typename ToT::mutable_type& object) const {
133-
return getLinked(ToT(object), podio::ReturnFrom);
141+
return getLinkedFrom(ToT(object));
134142
}
135143

136144
/// Get all the *To* objects and weights that have links with the passed
@@ -148,7 +156,7 @@ class LinkNavigator {
148156
///
149157
/// @returns A vector of all objects and their weights that have links with
150158
/// the passed object
151-
std::vector<WeightedObject<ToT>> getLinked(const FromT& object, podio::detail::links::ReturnToTag) const {
159+
std::vector<WeightedObject<ToT>> getLinkedTo(const FromT& object) const {
152160
const auto& [begin, end] = m_from2to.equal_range(object);
153161
std::vector<WeightedObject<ToT>> result;
154162
result.reserve(std::distance(begin, end));
@@ -159,9 +167,15 @@ class LinkNavigator {
159167
return result;
160168
}
161169

170+
[[deprecated("Use getLinkedTo instead")]]
171+
std::vector<WeightedObject<ToT>> getLinked(const FromT& object, podio::detail::links::ReturnToTag) const {
172+
return getLinkedTo(object);
173+
}
174+
175+
[[deprecated("Use getLinkedTo instead")]]
162176
std::vector<WeightedObject<ToT>> getLinked(const typename FromT::mutable_type& object,
163177
podio::detail::links::ReturnToTag) const {
164-
return getLinked(FromT(object), podio::ReturnTo);
178+
return getLinkedTo(FromT(object));
165179
}
166180

167181
/// Get all the *To* objects and weights that have links with the passed
@@ -178,14 +192,14 @@ class LinkNavigator {
178192
template <typename FromU = FromT>
179193
requires(!std::same_as<FromU, ToT>)
180194
std::vector<WeightedObject<ToT>> getLinked(const FromT& object) const {
181-
return getLinked(object, podio::ReturnTo);
195+
return getLinkedTo(object);
182196
}
183197

184198
/// Overload for cppyy that makes things work with mutable handles
185199
template <typename FromU = FromT>
186200
requires(!std::same_as<FromU, ToT>)
187201
std::vector<WeightedObject<ToT>> getLinked(const typename FromT::mutable_type& object) const {
188-
return getLinked(FromT(object), podio::ReturnTo);
202+
return getLinkedTo(FromT(object));
189203
}
190204

191205
private:

tests/unittests/links.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -748,24 +748,24 @@ TEST_CASE("LinkNavigator same types", "[links]") {
748748
link.setWeight(0.66f);
749749

750750
auto navigator = podio::LinkNavigator{linkColl};
751-
auto linkedClusters = navigator.getLinked(clusters[1], podio::ReturnTo);
751+
auto linkedClusters = navigator.getLinkedTo(clusters[1]);
752752
REQUIRE(linkedClusters.size() == 1);
753753
REQUIRE(linkedClusters[0].o == clusters[2]);
754754
REQUIRE(linkedClusters[0].weight == 0.66f);
755755

756-
linkedClusters = navigator.getLinked(clusters[1], podio::ReturnFrom);
756+
linkedClusters = navigator.getLinkedFrom(clusters[1]);
757757
REQUIRE(linkedClusters.size() == 1);
758758
REQUIRE(linkedClusters[0].o == clusters[0]);
759759
REQUIRE(linkedClusters[0].weight == 0.5f);
760760

761761
using Catch::Matchers::UnorderedEquals;
762762
using podio::detail::links::WeightedObject;
763763
using WeightedObjVec = std::vector<WeightedObject<ExampleCluster>>;
764-
linkedClusters = navigator.getLinked(clusters[0], podio::ReturnTo);
764+
linkedClusters = navigator.getLinkedTo(clusters[0]);
765765
REQUIRE_THAT(linkedClusters,
766766
UnorderedEquals(WeightedObjVec{WeightedObject(clusters[1], 0.5f), WeightedObject{clusters[2], 0.25f}}));
767767

768-
linkedClusters = navigator.getLinked(clusters[2], podio::ReturnFrom);
768+
linkedClusters = navigator.getLinkedFrom(clusters[2]);
769769
REQUIRE_THAT(linkedClusters,
770770
UnorderedEquals(WeightedObjVec{WeightedObject{clusters[0], 0.25f}, WeightedObject{clusters[1], 0.66f}}));
771771
}

0 commit comments

Comments
 (0)