Skip to content

Commit

Permalink
Make deprecation fixes version dependent
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Mar 11, 2024
1 parent 22835cb commit 552a8c7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "k4EDM4hep2LcioConv/MappingUtils.h"

#include "edm4hep/EDM4hepVersion.h"

#include <cassert>

namespace EDM4hep2LCIOConv {
Expand Down Expand Up @@ -224,7 +226,11 @@ namespace EDM4hep2LCIOConv {
lcio_strh->setProducedBySecondary(edm_strh.isProducedBySecondary());

// Link converted MCParticle to the SimTrackerHit if found
#if EDM4HEP_BUILD_VERSION > EDM4HEP_VERSION(0, 10, 5)
const auto edm_strh_mcp = edm_strh.getParticle();
#else
const auto edm_strh_mcp = edm_strh.getMCParticle();
endif
if (edm_strh_mcp.isAvailable()) {
if (const auto& lcio_mcp = k4EDM4hep2LcioConv::detail::mapLookupFrom(edm_strh_mcp, mcparticles_vec)) {
lcio_strh->setMCParticle(lcio_mcp.value());
Expand Down Expand Up @@ -558,7 +564,11 @@ namespace EDM4hep2LCIOConv {
auto* lcio_pid = new lcio::ParticleIDImpl;

lcio_pid->setType(edm_pid.getType());
#if EDM4HEP_BUILD_VERSION > EDM4HEP_VERSION(0, 10, 5)
lcio_pid->setPDG(edm_pid.getPDG());
#else
lcio_pid->setPDG(edm_pid.getType());
#endif
lcio_pid->setLikelihood(edm_pid.getLikelihood());
lcio_pid->setAlgorithmType(edm_pid.getAlgorithmType());
for (const auto& param : edm_pid.getParameters()) {
Expand Down Expand Up @@ -839,7 +849,11 @@ namespace EDM4hep2LCIOConv {
for (auto& [lcio_strh, edm_strh] : update_pairs.simTrackerHits) {
const auto lcio_strh_mcp = lcio_strh->getMCParticle();
if (lcio_strh_mcp == nullptr) {
#if EDM4HEP_BUILD_VERSION > EDM4HEP_VERSION(0, 10, 5)
const auto edm_strh_mcp = edm_strh.getParticle();
#else
const auto edm_strh_mcp = edm_strh.getMCParticle();
#endif
if (const auto lcio_mcp = k4EDM4hep2LcioConv::detail::mapLookupFrom(edm_strh_mcp, lookup_pairs.mcParticles)) {
lcio_strh->setMCParticle(lcio_mcp.value());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#include "k4EDM4hep2LcioConv/MappingUtils.h"
#include "k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.h"

#include "edm4hep/EDM4hepVersion.h"

namespace LCIO2EDM4hepConv {
template<typename LCIOType>
Expand Down Expand Up @@ -100,8 +103,13 @@ namespace LCIO2EDM4hepConv {
lval.setColorFlow(edm4hep::Vector2i(rval->getColorFlow()));
lval.setVertex(edm4hep::Vector3d(rval->getVertex()));
lval.setEndpoint(edm4hep::Vector3d(rval->getEndpoint()));
#if EDM4HEP_BUILD_VERSION > EDM4HEP_VERSION(0, 10, 5)
lval.setMomentum(rval->getMomentum());
lval.setMomentumAtEndpoint(rval->getMomentumAtEndpoint());
#else
lval.setMomentum(Vector3fFrom(rval->getMomentum()));
lval.setMomentumAtEndpoint(Vector3fFrom(rval->getMomentumAtEndpoint()));
#endif

const auto [iterator, inserted] = k4EDM4hep2LcioConv::detail::mapInsert(rval, lval, mcparticlesMap);
if (!inserted) {
Expand Down Expand Up @@ -135,7 +143,11 @@ namespace LCIO2EDM4hepConv {
lval.setMass(rval->getMass());
lval.setMomentum(Vector3fFrom(rval->getMomentum()));
lval.setReferencePoint(rval->getReferencePoint());
#if EDM4HEP_BUILD_VERSION > EDM4HEP_VERSION(0, 10, 5)
lval.setPDG(rval->getType());
#else
lval.setType(rval->getType());
#endif

const auto [iterator, inserted] = k4EDM4hep2LcioConv::detail::mapInsert(rval, lval, recoparticlesMap);
if (!inserted) {
Expand Down Expand Up @@ -657,7 +669,11 @@ namespace LCIO2EDM4hepConv {
continue;
}
if (const auto edmP = k4EDM4hep2LcioConv::detail::mapLookupTo(mcps, mcparticlesMap)) {
#if EDM4HEP_BUILD_VERSION > EDM4HEP_VERSION(0, 10, 5)
edm.setParticle(edmP.value());
#else
edm.setMCParticle(edmP.value());
#endif
}
else {
std::cerr << "Cannot find corresponding EDM4hep MCParticle for the LCIO MCParticle, "
Expand Down
10 changes: 10 additions & 0 deletions tests/src/CompareEDM4hepLCIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

#include "IMPL/TrackerHitImpl.h"

#include "edm4hep/EDM4hepVersion.h"

#include <cstdint>

/**
Expand Down Expand Up @@ -180,7 +182,11 @@ bool compare(
const edm4hep::ReconstructedParticle& edm4hepElem,
const ObjectMappings& objectMaps)
{
#if EDM4HEP_BUILD_VERSION > EDM4HEP_VERSION(0, 10, 5)
ASSERT_COMPARE_VALS(lcioElem->getType(), edm4hepElem.getPDG(), "type/PDG in ReconstructedParticle");
#else
ASSERT_COMPARE(lcioElem, edm4hepElem, getType, "type in ReconstructedParticle");
#endif
ASSERT_COMPARE(lcioElem, edm4hepElem, getEnergy, "energy in ReconstructedParticle");
ASSERT_COMPARE(lcioElem, edm4hepElem, getMomentum, "momentum in ReconstructedParticle");
ASSERT_COMPARE(lcioElem, edm4hepElem, getReferencePoint, "referencePoint in ReconstructedParticle");
Expand Down Expand Up @@ -298,10 +304,14 @@ bool compare(
ASSERT_COMPARE(lcioElem, edm4hepElem, getPosition, "position in SimTrackerHit");
ASSERT_COMPARE(lcioElem, edm4hepElem, getMomentum, "momentum in SimTrackerHit");

#if EDM4HEP_BUILD_VERSION > EDM4HEP_VERSION(0, 10, 5)
if (!compareRelation(
lcioElem->getMCParticle(), edm4hepElem.getParticle(), objectMaps.mcParticles, "MC particle in SimTrackerHit")) {
return false;
}
#else
ASSERT_COMPARE_RELATION(lcioElem, edm4hepElem, getMCParticle, objectMaps.mcParticles, "MCParticle in SimTrackerHit");
#endif

return true;
}
Expand Down

0 comments on commit 552a8c7

Please sign in to comment.