Skip to content

Commit

Permalink
Transparently introduce switch to optional param values
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed May 16, 2024
1 parent 1817459 commit 22a3f22
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
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

0 comments on commit 22a3f22

Please sign in to comment.