Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transparently introduce switch to optional param values #305

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions test/read_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@

// podio specific includes
#include "podio/Frame.h"
#include "podio/podioVersion.h"

// STL
#include <cassert>
#include <exception>
#include <iostream>
#include <vector>

void processEvent(const podio::Frame& event) {
auto& mcps = event.get<edm4hep::MCParticleCollection>("MCParticles");
Expand Down Expand Up @@ -240,7 +238,11 @@ void processEvent(const podio::Frame& event) {
// throw std::runtime_error("Collection 'SimCalorimeterHitContributions' should be present");
// }

#if PODIO_BUILD_VERSION > PODIO_VERSION(0, 99, 0)
const auto evtType = event.getParameter<std::string>("EventType").value();
#else
const auto& evtType = event.getParameter<std::string>("EventType");
#endif
std::cout << "Event Type: " << evtType << std::endl;
}

Expand Down
17 changes: 16 additions & 1 deletion utils/src/ParticleIDUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include "edm4hep/Constants.h"

#include <podio/FrameCategories.h>
#include <podio/podioVersion.h>

#include <cassert>
#include <iterator>
#include <stdexcept>
#include <string>
Expand Down Expand Up @@ -123,6 +123,20 @@ std::optional<edm4hep::utils::ParticleIDMeta> PIDHandler::getAlgoInfo(const podi
const std::string& collName) {
ParticleIDMeta pidInfo{};

#if PODIO_BUILD_VERSION > PODIO_VERSION(0, 99, 0)
auto maybeAlgoName = metadata.getParameter<std::string>(podio::collMetadataParamName(collName, edm4hep::pidAlgoName));
if (!maybeAlgoName.has_value()) {
return std::nullopt;
}

pidInfo.algoName = std::move(maybeAlgoName.value());
pidInfo.algoType = metadata.getParameter<int>(podio::collMetadataParamName(collName, edm4hep::pidAlgoType)).value();
pidInfo.paramNames =
metadata
.getParameter<std::vector<std::string>>(podio::collMetadataParamName(collName, edm4hep::pidParameterNames))
.value();

#else
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
Expand All @@ -133,6 +147,7 @@ std::optional<edm4hep::utils::ParticleIDMeta> PIDHandler::getAlgoInfo(const podi
pidInfo.algoType = metadata.getParameter<int>(podio::collMetadataParamName(collName, edm4hep::pidAlgoType));
pidInfo.paramNames = metadata.getParameter<std::vector<std::string>>(
podio::collMetadataParamName(collName, edm4hep::pidParameterNames));
#endif

return pidInfo;
}
Expand Down
Loading