Skip to content

Commit

Permalink
Make the ROOTFrameData properly cleanup after itself
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Oct 10, 2023
1 parent acc4742 commit 9f8aaa0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
7 changes: 7 additions & 0 deletions include/podio/CollectionBuffers.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ struct CollectionReadBuffers {
using CreateFuncT = std::function<std::unique_ptr<podio::CollectionBase>(podio::CollectionReadBuffers, bool)>;
using RecastFuncT = std::function<void(CollectionReadBuffers&)>;

using DeletFuncT = std::function<void(CollectionReadBuffers&)>;

CollectionReadBuffers(void* d, CollRefCollection* ref, VectorMembersInfo* vec, SchemaVersionT version,
std::string_view typ, CreateFuncT&& createFunc, RecastFuncT&& recastFunc) :
data(d),
Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion include/podio/ROOTFrameData.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ROOTFrameData {
using BufferMap = std::unordered_map<std::string, podio::CollectionReadBuffers>;

ROOTFrameData() = delete;
~ROOTFrameData() = default;
~ROOTFrameData();
ROOTFrameData(ROOTFrameData&&) = default;
ROOTFrameData& operator=(ROOTFrameData&&) = default;
ROOTFrameData(const ROOTFrameData&) = delete;
Expand Down Expand Up @@ -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
11 changes: 11 additions & 0 deletions python/templates/macros/collections.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::vector<{{ member.full_type }}>*>((*buffers.vectorMembers)[0].second);
{% endfor %}
delete buffers.vectorMembers;
};

return readBuffers;
}

Expand Down

0 comments on commit 9f8aaa0

Please sign in to comment.