From 810194464ac86d7b2a9e16cc2aefee2438b2280b Mon Sep 17 00:00:00 2001 From: tmadlener Date: Thu, 11 Apr 2024 21:05:45 +0200 Subject: [PATCH] Add helper function to get all meta info in one go --- test/utils/test_PIDHandler.cpp | 7 +++++++ utils/include/edm4hep/utils/ParticleIDUtils.h | 3 +++ utils/src/ParticleIDUtils.cc | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/test/utils/test_PIDHandler.cpp b/test/utils/test_PIDHandler.cpp index 9fdfde85e..412bcedb0 100644 --- a/test/utils/test_PIDHandler.cpp +++ b/test/utils/test_PIDHandler.cpp @@ -152,6 +152,13 @@ TEST_CASE("PIDHandler from Frame w/ metadata", "[pid_utils]") { REQUIRE_FALSE(handler.getParamIndex(pidAlgo1, "non-existant-param").has_value()); // Invalid algorithm, the parameter name is not even checked in this case REQUIRE_FALSE(handler.getParamIndex(-1, "doesnot matter").has_value()); + + const auto pidInfo = utils::PIDHandler::getAlgoInfo(metadata, "particleIds_1").value(); + REQUIRE(pidInfo.algoName == "pidAlgo_1"); + REQUIRE(pidInfo.algoType == 42); + REQUIRE(pidInfo.paramNames.size() == 2); + REQUIRE(pidInfo.paramNames[0] == "first_param"); + REQUIRE(pidInfo.paramNames[1] == "second_param"); } TEST_CASE("PIDHandler from Frame w/o metadata", "[pid_utils]") { diff --git a/utils/include/edm4hep/utils/ParticleIDUtils.h b/utils/include/edm4hep/utils/ParticleIDUtils.h index 56ea1f2c6..a1ceabb19 100644 --- a/utils/include/edm4hep/utils/ParticleIDUtils.h +++ b/utils/include/edm4hep/utils/ParticleIDUtils.h @@ -77,6 +77,9 @@ class PIDHandler { static void setAlgoInfo(podio::Frame& metadata, const std::string& collname, const edm4hep::utils::ParticleIDMeta& pidMetaInfo); + + static std::optional getAlgoInfo(const podio::Frame& metadata, + const std::string& collName); }; } // namespace edm4hep::utils diff --git a/utils/src/ParticleIDUtils.cc b/utils/src/ParticleIDUtils.cc index 3d36f7863..70d14b947 100644 --- a/utils/src/ParticleIDUtils.cc +++ b/utils/src/ParticleIDUtils.cc @@ -108,4 +108,22 @@ void PIDHandler::setAlgoInfo(podio::Frame& metadata, const std::string& collName metadata.putParameter(podio::collMetadataParamName(collName, edm4hep::pidParameterNames), pidMetaInfo.paramNames); } +std::optional PIDHandler::getAlgoInfo(const podio::Frame& metadata, + const std::string& collName) { + ParticleIDMeta pidInfo{}; + + pidInfo.algoName = metadata.getParameter(podio::collMetadataParamName(collName, edm4hep::pidAlgoName)); + // Use the algoName as proxy to see whether we could actually get the + // information from the metadata + if (pidInfo.algoName.empty()) { + return std::nullopt; + } + + pidInfo.algoType = metadata.getParameter(podio::collMetadataParamName(collName, edm4hep::pidAlgoType)); + pidInfo.paramNames = metadata.getParameter>( + podio::collMetadataParamName(collName, edm4hep::pidParameterNames)); + + return pidInfo; +} + } // namespace edm4hep::utils