diff --git a/include/podio/CollectionBuffers.h b/include/podio/CollectionBuffers.h index b51161c2d..dcf864c95 100644 --- a/include/podio/CollectionBuffers.h +++ b/include/podio/CollectionBuffers.h @@ -53,6 +53,8 @@ struct CollectionReadBuffers { using CreateFuncT = std::function(podio::CollectionReadBuffers, bool)>; using RecastFuncT = std::function; + using DeletFuncT = std::function; + CollectionReadBuffers(void* d, CollRefCollection* ref, VectorMembersInfo* vec, SchemaVersionT version, std::string_view typ, CreateFuncT&& createFunc, RecastFuncT&& recastFunc) : data(d), @@ -105,6 +107,11 @@ struct CollectionReadBuffers { // generation) to do the second cast and assign the result of that to the data // field again. RecastFuncT recast{}; + + // Workaround for https://github.com/AIDASoft/podio#500 + // We need a function that explicitly deletes the buffers, but for this we + // need type information, so we attach a delete function at generation time + DeletFuncT deleteBuffers{}; }; } // namespace podio diff --git a/include/podio/ROOTFrameData.h b/include/podio/ROOTFrameData.h index 157e3fbea..3cc63d04a 100644 --- a/include/podio/ROOTFrameData.h +++ b/include/podio/ROOTFrameData.h @@ -19,7 +19,7 @@ class ROOTFrameData { using BufferMap = std::unordered_map; ROOTFrameData() = delete; - ~ROOTFrameData() = default; + ~ROOTFrameData(); ROOTFrameData(ROOTFrameData&&) = default; ROOTFrameData& operator=(ROOTFrameData&&) = default; ROOTFrameData(const ROOTFrameData&) = delete; @@ -65,6 +65,14 @@ class ROOTFrameData { CollIDPtr m_idTable{nullptr}; podio::GenericParameters m_parameters{}; }; + +// Interim workaround for https://github.com/AIDASoft/podio#500 +inline ROOTFrameData::~ROOTFrameData() { + for (auto& [_, buffer] : m_buffers) { + buffer.deleteBuffers(buffer); + } +} + } // namespace podio #endif // PODIO_ROOTFRAMEDATA_H diff --git a/python/templates/macros/collections.jinja2 b/python/templates/macros/collections.jinja2 index efc7c24cb..7065d29c5 100644 --- a/python/templates/macros/collections.jinja2 +++ b/python/templates/macros/collections.jinja2 @@ -203,6 +203,17 @@ podio::CollectionReadBuffers createBuffersV{{ schemaVersion }}(bool isSubset) { } }; + readBuffers.deleteBuffers = [](podio::CollectionReadBuffers& buffers) { + if (buffers.data) { + delete static_cast<{{ class.full_type }}DataContainer*>(buffers.data); + } + delete buffers.references; +{% for member in VectorMembers %} + delete static_cast*>((*buffers.vectorMembers)[0].second); +{% endfor %} + delete buffers.vectorMembers; + }; + return readBuffers; }