Skip to content

Commit

Permalink
Add helper function to get all meta info in one go
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Apr 12, 2024
1 parent 43a3b3d commit 8101944
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/utils/test_PIDHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]") {
Expand Down
3 changes: 3 additions & 0 deletions utils/include/edm4hep/utils/ParticleIDUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ class PIDHandler {

static void setAlgoInfo(podio::Frame& metadata, const std::string& collname,
const edm4hep::utils::ParticleIDMeta& pidMetaInfo);

static std::optional<edm4hep::utils::ParticleIDMeta> getAlgoInfo(const podio::Frame& metadata,
const std::string& collName);
};
} // namespace edm4hep::utils

Expand Down
18 changes: 18 additions & 0 deletions utils/src/ParticleIDUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<edm4hep::utils::ParticleIDMeta> PIDHandler::getAlgoInfo(const podio::Frame& metadata,
const std::string& collName) {
ParticleIDMeta pidInfo{};

pidInfo.algoName = metadata.getParameter<std::string>(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<int>(podio::collMetadataParamName(collName, edm4hep::pidAlgoType));
pidInfo.paramNames = metadata.getParameter<std::vector<std::string>>(
podio::collMetadataParamName(collName, edm4hep::pidParameterNames));

return pidInfo;
}

} // namespace edm4hep::utils

0 comments on commit 8101944

Please sign in to comment.