Skip to content

Commit

Permalink
Avoid calling the wrong constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Jan 16, 2025
1 parent c41f3a4 commit e2c6142
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion test/utils/test_PIDHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void checkHandlerValidReco(const edm4hep::utils::PIDHandler& handler, const edm4
TEST_CASE("ParticleIDMeta constructor") {
using namespace edm4hep::utils;

ParticleIDMeta pidMeta{"name", {}};
ParticleIDMeta pidMeta{"name"};
REQUIRE(pidMeta.algoName == "name");
REQUIRE(pidMeta.algoType() == -609270800); // 32 bit MurmurHash3 of "name"
}
Expand Down
10 changes: 8 additions & 2 deletions utils/include/edm4hep/utils/ParticleIDUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,19 @@ struct ParticleIDMeta {
/// There should be a parameter name for each parameter that
/// is stored in the ParticleID parameters field
ParticleIDMeta(const std::string& algName, int32_t algType, const std::vector<std::string>& parNames = {});
/// Main constructor for creating a ParticleIDMeta object

/// Main constructor for creating a ParticleIDMeta object without parameters
///
/// @param algName The name of the PID algorithm
ParticleIDMeta(const std::string& algName);

/// Main constructor for creating a ParticleIDMeta object with parameters
///
/// @param algName The name of the PID algorithm
/// @param parNames The (optional) parameter names for this PID algorithms.
/// There should be a parameter name for each parameter that
/// is stored in the ParticleID parameters field
ParticleIDMeta(const std::string& algName, const std::vector<std::string>& parNames = {});
ParticleIDMeta(const std::string& algName, const std::vector<std::string>& parNames);

~ParticleIDMeta() = default;
/// Default constructor
Expand Down
3 changes: 3 additions & 0 deletions utils/src/ParticleIDUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ ParticleIDMeta::ParticleIDMeta(const std::string& algName, const std::vector<std
algoName(algName), paramNames(parNames), m_algoType(getAlgoID(algName)) {
}

ParticleIDMeta::ParticleIDMeta(const std::string& algName) : ParticleIDMeta(algName, std::vector<std::string>{}) {
}

std::optional<int> getParamIndex(const ParticleIDMeta& pidMetaInfo, const std::string& param) {
const auto nameIt = std::ranges::find(pidMetaInfo.paramNames, param);
if (nameIt != pidMetaInfo.paramNames.end()) {
Expand Down

0 comments on commit e2c6142

Please sign in to comment.