From 8fa95c16bab274189f005ef2684fbd746bdc1f11 Mon Sep 17 00:00:00 2001 From: tmadlener Date: Mon, 23 Sep 2024 16:33:01 +0200 Subject: [PATCH] Simplify schema evolution code by reusing buffers --- .../schema_evolution/src/OldLinkEvolution.cc | 40 +++++++------------ 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/edm4hep/schema_evolution/src/OldLinkEvolution.cc b/edm4hep/schema_evolution/src/OldLinkEvolution.cc index 630e74d0d..c15b64c08 100644 --- a/edm4hep/schema_evolution/src/OldLinkEvolution.cc +++ b/edm4hep/schema_evolution/src/OldLinkEvolution.cc @@ -31,40 +31,30 @@ namespace { /// of the templated links. The most important bit is the re-definition of /// createCollection to actually create a templated LinkCollection template - auto evolveLinks(podio::CollectionReadBuffers oldBuffers, podio::SchemaVersionT) { - podio::CollectionReadBuffers newBuffers{}; - newBuffers.type = podio::detail::linkCollTypeName(); - newBuffers.schemaVersion = podio::LinkCollection::schemaVersion; - - // We can simply copy over all the buffer pointers since they are already - // created correctly by the factory function - newBuffers.data = oldBuffers.data; - oldBuffers.data = nullptr; - newBuffers.references = oldBuffers.references; - oldBuffers.references = nullptr; - newBuffers.vectorMembers = oldBuffers.vectorMembers; - oldBuffers.vectorMembers = nullptr; - - newBuffers.createCollection = [](const podio::CollectionReadBuffers& buffers, bool isSubsetColl) { - podio::LinkCollectionData data(buffers, isSubsetColl); + auto evolveLinks(podio::CollectionReadBuffers buffers, podio::SchemaVersionT) { + buffers.type = podio::detail::linkCollTypeName(); + buffers.schemaVersion = podio::LinkCollection::schemaVersion; + + buffers.createCollection = [](const podio::CollectionReadBuffers& buffs, bool isSubsetColl) { + podio::LinkCollectionData data(buffs, isSubsetColl); return std::make_unique>(std::move(data), isSubsetColl); }; - newBuffers.recast = [](podio::CollectionReadBuffers& buffers) { - if (buffers.data) { - buffers.data = podio::CollectionWriteBuffers::asVector(buffers.data); + buffers.recast = [](podio::CollectionReadBuffers& buffs) { + if (buffs.data) { + buffs.data = podio::CollectionWriteBuffers::asVector(buffs.data); } }; - newBuffers.deleteBuffers = [](podio::CollectionReadBuffers& buffers) { - if (buffers.data) { - delete static_cast*>(buffers.data); + buffers.deleteBuffers = [](podio::CollectionReadBuffers& buffs) { + if (buffs.data) { + delete static_cast*>(buffs.data); } - delete buffers.references; - delete buffers.vectorMembers; + delete buffs.references; + delete buffs.vectorMembers; }; - return newBuffers; + return buffers; } /// Function factory for stamping out buffer creation functions that can be