Skip to content

Commit

Permalink
Switch to non-deprecated methods
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Jul 30, 2024
1 parent 0e2feef commit 2864b8e
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "k4EDM4hep2LcioConv/MappingUtils.h"

#include <edm4hep/CaloHitSimCaloHitLinkCollection.h>
#include <edm4hep/CaloHitMCParticleLinkCollection.h>
#include <edm4hep/CaloHitSimCaloHitLinkCollection.h>
#include <edm4hep/ClusterMCParticleLinkCollection.h>
#include <edm4hep/RecoMCParticleLinkCollection.h>
#include <edm4hep/TrackMCParticleLinkCollection.h>
Expand Down Expand Up @@ -805,7 +805,7 @@ std::vector<std::tuple<std::string, std::unique_ptr<lcio::LCCollection>>> create
relationColls.emplace_back(name, createLCRelationCollection(*assocs, objectMaps.tracks, objectMaps.mcParticles));
} else if (const auto assocs = dynamic_cast<const edm4hep::VertexRecoParticleLinkCollection*>(coll)) {
relationColls.emplace_back(name,
createLCRelationCollection(*assocs, objectMaps.recoParticles, objectMaps.vertices));
createLCRelationCollection(*assocs, objectMaps.vertices, objectMaps.recoParticles));
} else {
std::cerr << "Trying to create an LCRelation collection from a " << coll->getTypeName()
<< " which is not supported" << std::endl;
Expand Down Expand Up @@ -856,7 +856,7 @@ std::unique_ptr<lcio::LCCollection> createLCRelationCollection(const AssocCollT&
auto lcioRel = new lcio::LCRelationImpl{};
lcioRel->setWeight(assoc.getWeight());

const auto edm4hepFrom = assoc.getRec();
const auto edm4hepFrom = assoc.getFrom();
const auto lcioFrom = k4EDM4hep2LcioConv::detail::mapLookupFrom(edm4hepFrom, fromMap);
if (lcioFrom) {
lcioRel->setFrom(lcioFrom.value());
Expand All @@ -865,24 +865,13 @@ std::unique_ptr<lcio::LCCollection> createLCRelationCollection(const AssocCollT&
<< std::endl;
}

if constexpr (std::is_same_v<AssocCollT, edm4hep::VertexRecoParticleLinkCollection>) {
const auto edm4hepTo = assoc.getVertex();
const auto lcioTo = k4EDM4hep2LcioConv::detail::mapLookupFrom(edm4hepTo, toMap);
if (lcioTo) {
lcioRel->setTo(lcioTo.value());
} else {
std::cerr << "Cannot find an objects for building an LCRelation of type " << detail::getTypeName<ToLCIOT>()
<< std::endl;
}
const auto edm4hepTo = assoc.getTo();
const auto lcioTo = k4EDM4hep2LcioConv::detail::mapLookupFrom(edm4hepTo, toMap);
if (lcioTo) {
lcioRel->setTo(lcioTo.value());
} else {
const auto edm4hepTo = assoc.getSim();
const auto lcioTo = k4EDM4hep2LcioConv::detail::mapLookupFrom(edm4hepTo, toMap);
if (lcioTo) {
lcioRel->setTo(lcioTo.value());
} else {
std::cerr << "Cannot find an objects for building an LCRelation of type " << detail::getTypeName<ToLCIOT>()
<< std::endl;
}
std::cerr << "Cannot find an objects for building an LCRelation of type " << detail::getTypeName<ToLCIOT>()
<< std::endl;
}

lcioColl->addElement(lcioRel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ std::vector<CollNamePair> convertReconstructedParticles(const std::string& name,
// Keep track of the startVertex associations
if (rval->getStartVertex() != nullptr) {
auto assoc = startVertexAssocs->create();
assoc.setRec(lval);
assoc.setTo(lval);
}
}

Expand Down Expand Up @@ -208,7 +208,7 @@ std::vector<CollNamePair> convertVertices(const std::string& name, EVENT::LCColl
}

auto assoc = assocParticles->create();
assoc.setVertex(lval);
assoc.setFrom(lval);

const auto [iterator, inserted] = k4EDM4hep2LcioConv::detail::mapInsert(rval, lval, vertexMap);
if (!inserted) {
Expand Down Expand Up @@ -787,15 +787,15 @@ template <typename VertexMapT, typename RecoParticleMapT>
void finalizeVertexRecoParticleLinks(edm4hep::VertexRecoParticleLinkCollection& associations,
const VertexMapT& vertexMap, const RecoParticleMapT& recoParticleMap) {
for (auto assoc : associations) {
auto assocRec = assoc.getRec();
auto assocVtx = assoc.getVertex();
auto assocRec = assoc.getTo();
auto assocVtx = assoc.getFrom();

if (assocRec.isAvailable()) {
// This is the association that points from the particles to their start vertex
if (const auto lcioRec = k4EDM4hep2LcioConv::detail::mapLookupFrom(assocRec, recoParticleMap)) {
const auto lcioStartVtx = lcioRec.value()->getStartVertex();
if (const auto startVtx = k4EDM4hep2LcioConv::detail::mapLookupTo(lcioStartVtx, vertexMap)) {
assoc.setVertex(startVtx.value());
assoc.setFrom(startVtx.value());
} else {
std::cerr << "Could not find start vertex while finalizing the RecoParticle - Vertex associations"
<< std::endl;
Expand All @@ -810,7 +810,7 @@ void finalizeVertexRecoParticleLinks(edm4hep::VertexRecoParticleLinkCollection&
if (const auto lcioVtx = k4EDM4hep2LcioConv::detail::mapLookupFrom(assocVtx, vertexMap)) {
const auto lcioAssocParticle = lcioVtx.value()->getAssociatedParticle();
if (const auto assocParticle = k4EDM4hep2LcioConv::detail::mapLookupTo(lcioAssocParticle, recoParticleMap)) {
assoc.setRec(assocParticle.value());
assoc.setTo(assocParticle.value());
} else {
std::cerr << "Could not find an associated particle while finalizing the RecoParticle - Vertex associations"
<< std::endl;
Expand Down Expand Up @@ -856,18 +856,20 @@ std::unique_ptr<CollT> createLinkCollection(EVENT::LCCollection* relations, cons
if (edm4hepTo.has_value() && edm4hepFrom.has_value()) {
if constexpr (Reverse) {
if constexpr (std::is_same_v<k4EDM4hep2LcioConv::detail::mutable_t<ToEDM4hepT>, edm4hep::MutableVertex>) {
assoc.setVertex(*edm4hepTo);
assoc.setFrom(*edm4hepTo);
assoc.setTo(*edm4hepFrom);
} else {
assoc.setSim(*edm4hepTo);
assoc.setTo(*edm4hepTo);
assoc.setFrom(*edm4hepFrom);
}
assoc.setRec(*edm4hepFrom);
} else {
if constexpr (std::is_same_v<k4EDM4hep2LcioConv::detail::mutable_t<FromEDM4hepT>, edm4hep::MutableVertex>) {
assoc.setVertex(*edm4hepFrom);
assoc.setFrom(*edm4hepFrom);
assoc.setTo(*edm4hepTo);
} else {
assoc.setSim(*edm4hepFrom);
assoc.setTo(*edm4hepFrom);
assoc.setFrom(*edm4hepTo);
}
assoc.setRec(*edm4hepTo);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/src/CompareEDM4hepEDM4hep.cc
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ bool compare(const edm4hep::VertexRecoParticleLinkCollection& origColl,
const auto assoc = roundtripColl[i];

REQUIRE_SAME(origAssoc.getWeight(), assoc.getWeight(), "weight in association " << i);
REQUIRE_SAME(origAssoc.getVertex().id(), assoc.getVertex().id(), "vertex in association " << i);
REQUIRE_SAME(origAssoc.getRec().id(), assoc.getRec().id(), "reco particle in association " << i);
REQUIRE_SAME(origAssoc.getFrom().id(), assoc.getFrom().id(), "vertex in association " << i);
REQUIRE_SAME(origAssoc.getTo().id(), assoc.getTo().id(), "reco particle in association " << i);
}

return true;
Expand Down
4 changes: 2 additions & 2 deletions tests/src/CompareEDM4hepEDM4hep.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ bool compare(const AssociationCollT& origColl, const AssociationCollT& roundtrip
const auto assoc = roundtripColl[i];

REQUIRE_SAME(origAssoc.getWeight(), assoc.getWeight(), "weight in association " << i);
REQUIRE_SAME(origAssoc.getSim().id(), assoc.getSim().id(), "MC part(icle) in association " << i);
REQUIRE_SAME(origAssoc.getRec().id(), assoc.getRec().id(), "reco part(icle) in association " << i);
REQUIRE_SAME(origAssoc.getTo().id(), assoc.getTo().id(), "MC part(icle) in association " << i);
REQUIRE_SAME(origAssoc.getFrom().id(), assoc.getFrom().id(), "reco part(icle) in association " << i);
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/src/CompareEDM4hepLCIO.cc
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ bool compareEventHeader(const EVENT::LCEvent* lcevt, const podio::Frame* edmEven
bool compareStartVertexRelations(const EVENT::ReconstructedParticle* lcioReco,
const edm4hep::VertexRecoParticleLink& association, const ObjectMappings& objectMaps) {
const auto lcioVertex = lcioReco->getStartVertex();
const auto edm4hepVertex = association.getVertex();
const auto edm4hepVertex = association.getFrom();
if (!compareRelation(lcioVertex, edm4hepVertex, objectMaps.vertices, "")) {
return false;
}
Expand Down
20 changes: 6 additions & 14 deletions tests/src/CompareEDM4hepLCIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,25 +210,17 @@ bool compare(const EVENT::LCRelation* lcio, const AssocT& edm4hep, const ObjectM
using LcioToT = detail::getLcioToType<AssocT>;

const auto lcioFrom = static_cast<LcioFromT*>(lcio->getFrom());
const auto edm4hepFrom = edm4hep.getRec();
const auto edm4hepFrom = edm4hep.getFrom();
if (!compareRelation(lcioFrom, edm4hepFrom, detail::getObjectMap<LcioFromT>(objectMaps),
"from / rec object in relation / association")) {
"from object in relation / association")) {
return false;
}

const auto lcioTo = static_cast<LcioToT*>(lcio->getTo());
if constexpr (std::is_same_v<AssocT, edm4hep::VertexRecoParticleLink>) {
const auto edm4hepTo = edm4hep.getVertex();
if (!compareRelation(lcioTo, edm4hepTo, detail::getObjectMap<LcioToT>(objectMaps),
"vertex object in relation / association")) {
return false;
}
} else {
const auto edm4hepTo = edm4hep.getSim();
if (!compareRelation(lcioTo, edm4hepTo, detail::getObjectMap<LcioToT>(objectMaps),
"to / mc object in relation / association")) {
return false;
}
const auto edm4hepTo = edm4hep.getTo();
if (!compareRelation(lcioTo, edm4hepTo, detail::getObjectMap<LcioToT>(objectMaps),
"to object in relation / association")) {
return false;
}

return true;
Expand Down
8 changes: 4 additions & 4 deletions tests/src/EDM4hep2LCIOUtilities.cc
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,8 @@ AssocCollT createAssociationCollection(const CollT& collA, const CollU& collB) {
for (size_t i = 0; i < maxSize; ++i) {
auto assoc = assocs.create();
assoc.setWeight(i * 10.f / maxSize);
assoc.setSim(collA[i]);
assoc.setRec(collB[maxSize - 1 - i]);
assoc.setTo(collA[i]);
assoc.setFrom(collB[maxSize - 1 - i]);
}

return assocs;
Expand Down Expand Up @@ -392,8 +392,8 @@ createVertices(const int nVertices, const edm4hep::ReconstructedParticleCollecti
for (const auto& [iV, iP] : recoIdcs) {
vtxColl[iV].addToParticles(particles[iP]);
auto assoc = assocColl.create();
assoc.setRec(particles[iP]);
assoc.setVertex(vtxColl[iV]);
assoc.setTo(particles[iP]);
assoc.setFrom(vtxColl[iV]);
}

for (const auto& [iP, iV] : vtxRecoIdcs) {
Expand Down

0 comments on commit 2864b8e

Please sign in to comment.