Skip to content

Commit

Permalink
Add a variadic overload for multiple metadata objects
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Dec 20, 2024
1 parent a504198 commit 1030e5b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
22 changes: 22 additions & 0 deletions test/utils/test_PIDHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,28 @@ TEST_CASE("PIDHandler w/ addMetaInfo", "[pid_utils]") {
REQUIRE(handler.getParamIndex(42, "p2").value_or(-1) == 1);
}

TEST_CASE("PIDHandler add multiple meta info objects", "[pid_utils]") {
using namespace edm4hep::utils;
auto handler = PIDHandler();

const auto pidInfo1 = ParticleIDMeta{"fancyAlgo", {"param1", "param2"}};
const auto pidInfo2 = ParticleIDMeta{"fancyAlgo2", {"p1", "p2"}};
const auto pidInfo3 = ParticleIDMeta{"fancyAlgo3", {"p1", "p2"}};

// Can add all of them at once or do it in steps
handler.addMetaInfos(pidInfo1);
handler.addMetaInfos(pidInfo2, pidInfo3);

REQUIRE(handler.getParamIndex(pidInfo1.algoType(), "param2").value() == 1);
REQUIRE(handler.getParamIndex(pidInfo2.algoType(), "p1").value() == 0);
REQUIRE(handler.getParamIndex(pidInfo3.algoType(), "p2").value() == 1);
REQUIRE(handler.getAlgoType("fancyAlgo").value() == pidInfo1.algoType());
REQUIRE(handler.getAlgoType("fancyAlgo3").value() == pidInfo3.algoType());

const auto duplicate = ParticleIDMeta{"fancyAlgo", {}};
REQUIRE_THROWS_AS(handler.addMetaInfos(duplicate), std::runtime_error);
}

TEST_CASE("PIDHandler from Frame w/ metadata", "[pid_utils]") {
using namespace edm4hep;
const auto& [event, metadata] = createEventAndMetadata();
Expand Down
8 changes: 8 additions & 0 deletions utils/include/edm4hep/utils/ParticleIDUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ class PIDHandler {
/// Add meta information for a collection
void addMetaInfo(const edm4hep::utils::ParticleIDMeta& pidInfo);

/// Add several meta informations simultaneously
template <typename... PIDMetas>
void addMetaInfos(const PIDMetas&... pidMetas) {
static_assert((std::is_same_v<PIDMetas, edm4hep::utils::ParticleIDMeta> && ...),
"Only ParticleIDMeta can be used to add metadata to a PIDHandler");
(addMetaInfo(pidMetas), ...);
}

/// Retrieve all ParticleIDs that are related to the passed
/// ReconstructedParticle
std::vector<edm4hep::ParticleID> getPIDs(const edm4hep::ReconstructedParticle& reco) const;
Expand Down

0 comments on commit 1030e5b

Please sign in to comment.