From bb58856f472ec41cb62566cc1a6a81013395a228 Mon Sep 17 00:00:00 2001 From: tmadlener Date: Wed, 10 Apr 2024 17:23:11 +0200 Subject: [PATCH] Simplify signatures a bit by introducing helper struct --- test/utils/test_PIDHandler.cpp | 6 +++--- utils/include/edm4hep/utils/ParticleIDUtils.h | 16 +++++++++++----- utils/src/ParticleIDUtils.cc | 17 ++++++++--------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/test/utils/test_PIDHandler.cpp b/test/utils/test_PIDHandler.cpp index 980790c36..9fdfde85e 100644 --- a/test/utils/test_PIDHandler.cpp +++ b/test/utils/test_PIDHandler.cpp @@ -45,9 +45,9 @@ std::tuple createEventAndMetadata() { auto pidColl1 = createParticleIDs(recos, 1.0f); auto pidColl2 = createParticleIDs(recos, 2.0f); - edm4hep::utils::PIDHandler::setAlgoInfo(metadata, pidColl1, "particleIds_1", "pidAlgo_1", 42, - {"first_param", "second_param"}); - edm4hep::utils::PIDHandler::setAlgoInfo(metadata, pidColl2, "particleIds_2", "algo_2", 123, {"1", "2"}); + edm4hep::utils::PIDHandler::setAlgoInfo(metadata, pidColl1, "particleIds_1", + {"pidAlgo_1", 42, {"first_param", "second_param"}}); + edm4hep::utils::PIDHandler::setAlgoInfo(metadata, pidColl2, "particleIds_2", {"algo_2", 123, {"1", "2"}}); event.put(std::move(pidColl1), "particleIds_1"); event.put(std::move(pidColl2), "particleIds_2"); diff --git a/utils/include/edm4hep/utils/ParticleIDUtils.h b/utils/include/edm4hep/utils/ParticleIDUtils.h index 4ed22b160..56ea1f2c6 100644 --- a/utils/include/edm4hep/utils/ParticleIDUtils.h +++ b/utils/include/edm4hep/utils/ParticleIDUtils.h @@ -14,6 +14,13 @@ namespace edm4hep::utils { +/// A simple struct bundling relevant metadata for a ParticleID collection +struct ParticleIDMeta { + std::string algoName{}; ///< The name of the algorithm + int32_t algoType{0}; ///< The (user defined) algorithm type + std::vector paramNames{}; ///< The names of the parameters +}; + /// Utility class to invert the ParticleID to ReconstructedParticle relation class PIDHandler { @@ -65,12 +72,11 @@ class PIDHandler { /// Retrieve the algoType for a given algorithm name std::optional getAlgoType(const std::string& algoName) const; - static void setAlgoInfo(podio::Frame& metadata, edm4hep::ParticleIDCollection& pidColl, const std::string& collName, - const std::string& algoName, const int32_t algoType, - const std::vector& paramNames); + static void setAlgoInfo(podio::Frame& metadata, edm4hep::ParticleIDCollection& pidcoll, const std::string& collname, + const edm4hep::utils::ParticleIDMeta& pidMetaInfo); - static void setAlgoInfo(podio::Frame& metadata, const std::string& collName, const std::string& algoName, - const int32_t algoType, const std::vector& paramNames); + static void setAlgoInfo(podio::Frame& metadata, const std::string& collname, + const edm4hep::utils::ParticleIDMeta& pidMetaInfo); }; } // namespace edm4hep::utils diff --git a/utils/src/ParticleIDUtils.cc b/utils/src/ParticleIDUtils.cc index b040f5648..3d36f7863 100644 --- a/utils/src/ParticleIDUtils.cc +++ b/utils/src/ParticleIDUtils.cc @@ -93,20 +93,19 @@ std::optional PIDHandler::getAlgoType(const std::string& algoName) cons } void PIDHandler::setAlgoInfo(podio::Frame& metadata, edm4hep::ParticleIDCollection& pidColl, - const std::string& collName, const std::string& algoName, const int32_t algoType, - const std::vector& paramNames) { + const std::string& collName, const edm4hep::utils::ParticleIDMeta& pidMetaInfo) { for (auto pid : pidColl) { - pid.setAlgorithmType(algoType); + pid.setAlgorithmType(pidMetaInfo.algoType); } - PIDHandler::setAlgoInfo(metadata, collName, algoName, algoType, paramNames); + PIDHandler::setAlgoInfo(metadata, collName, pidMetaInfo); } -void PIDHandler::setAlgoInfo(podio::Frame& metadata, const std::string& collName, const std::string& algoName, - const int32_t algoType, const std::vector& paramNames) { - metadata.putParameter(podio::collMetadataParamName(collName, edm4hep::pidAlgoName), algoName); - metadata.putParameter(podio::collMetadataParamName(collName, edm4hep::pidAlgoType), algoType); - metadata.putParameter(podio::collMetadataParamName(collName, edm4hep::pidParameterNames), paramNames); +void PIDHandler::setAlgoInfo(podio::Frame& metadata, const std::string& collName, + const edm4hep::utils::ParticleIDMeta& pidMetaInfo) { + metadata.putParameter(podio::collMetadataParamName(collName, edm4hep::pidAlgoName), pidMetaInfo.algoName); + metadata.putParameter(podio::collMetadataParamName(collName, edm4hep::pidAlgoType), pidMetaInfo.algoType); + metadata.putParameter(podio::collMetadataParamName(collName, edm4hep::pidParameterNames), pidMetaInfo.paramNames); } } // namespace edm4hep::utils