From 552a8c72a3855d793d6012840df4a3c59bfabf59 Mon Sep 17 00:00:00 2001 From: tmadlener Date: Mon, 11 Mar 2024 20:17:26 +0100 Subject: [PATCH] Make deprecation fixes version dependent --- .../k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.ipp | 14 ++++++++++++++ .../k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.ipp | 16 ++++++++++++++++ tests/src/CompareEDM4hepLCIO.cc | 10 ++++++++++ 3 files changed, 40 insertions(+) diff --git a/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.ipp b/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.ipp index 5176fe22..7c448ffd 100644 --- a/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.ipp +++ b/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4EDM4hep2LcioConv.ipp @@ -1,5 +1,7 @@ #include "k4EDM4hep2LcioConv/MappingUtils.h" +#include "edm4hep/EDM4hepVersion.h" + #include namespace EDM4hep2LCIOConv { @@ -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()); @@ -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()) { @@ -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()); } diff --git a/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.ipp b/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.ipp index 8a942e1b..76c844ba 100644 --- a/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.ipp +++ b/k4EDM4hep2LcioConv/include/k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.ipp @@ -1,4 +1,7 @@ #include "k4EDM4hep2LcioConv/MappingUtils.h" +#include "k4EDM4hep2LcioConv/k4Lcio2EDM4hepConv.h" + +#include "edm4hep/EDM4hepVersion.h" namespace LCIO2EDM4hepConv { template @@ -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) { @@ -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) { @@ -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, " diff --git a/tests/src/CompareEDM4hepLCIO.cc b/tests/src/CompareEDM4hepLCIO.cc index 791e9bb4..c21ecf9c 100644 --- a/tests/src/CompareEDM4hepLCIO.cc +++ b/tests/src/CompareEDM4hepLCIO.cc @@ -3,6 +3,8 @@ #include "IMPL/TrackerHitImpl.h" +#include "edm4hep/EDM4hepVersion.h" + #include /** @@ -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"); @@ -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; }