Skip to content

Commit

Permalink
Simplify signatures a bit by introducing helper struct
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Apr 10, 2024
1 parent 32f0698 commit bb58856
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
6 changes: 3 additions & 3 deletions test/utils/test_PIDHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ std::tuple<podio::Frame, podio::Frame> 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");
Expand Down
16 changes: 11 additions & 5 deletions utils/include/edm4hep/utils/ParticleIDUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> paramNames{}; ///< The names of the parameters
};

/// Utility class to invert the ParticleID to ReconstructedParticle relation
class PIDHandler {

Expand Down Expand Up @@ -65,12 +72,11 @@ class PIDHandler {
/// Retrieve the algoType for a given algorithm name
std::optional<int32_t> 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<std::string>& 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<std::string>& paramNames);
static void setAlgoInfo(podio::Frame& metadata, const std::string& collname,
const edm4hep::utils::ParticleIDMeta& pidMetaInfo);
};
} // namespace edm4hep::utils

Expand Down
17 changes: 8 additions & 9 deletions utils/src/ParticleIDUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,19 @@ std::optional<int32_t> 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<std::string>& 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<std::string>& 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

0 comments on commit bb58856

Please sign in to comment.