Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move ROOTFrameData implementation into .cc file #623

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 5 additions & 34 deletions include/podio/ROOTFrameData.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,37 +25,15 @@ class ROOTFrameData {
ROOTFrameData(const ROOTFrameData&) = delete;
ROOTFrameData& operator=(const ROOTFrameData&) = delete;

ROOTFrameData(BufferMap&& buffers, CollIDPtr&& idTable, podio::GenericParameters&& params) :
m_buffers(std::move(buffers)), m_idTable(std::move(idTable)), m_parameters(std::move(params)) {
}
ROOTFrameData(BufferMap&& buffers, CollIDPtr&& idTable, podio::GenericParameters&& params);

std::optional<podio::CollectionReadBuffers> getCollectionBuffers(const std::string& name) {
const auto bufferHandle = m_buffers.extract(name);
if (bufferHandle.empty()) {
return std::nullopt;
}
std::optional<podio::CollectionReadBuffers> getCollectionBuffers(const std::string& name);

return {bufferHandle.mapped()};
}
podio::CollectionIDTable getIDTable() const;

podio::CollectionIDTable getIDTable() const {
// Construct a copy of the internal table
return {m_idTable->ids(), m_idTable->names()};
}
std::unique_ptr<podio::GenericParameters> getParameters();

std::unique_ptr<podio::GenericParameters> getParameters() {
return std::make_unique<podio::GenericParameters>(std::move(m_parameters));
}

std::vector<std::string> getAvailableCollections() const {
std::vector<std::string> collections;
collections.reserve(m_buffers.size());
for (const auto& [name, _] : m_buffers) {
collections.push_back(name);
}

return collections;
}
std::vector<std::string> getAvailableCollections() const;

private:
// TODO: switch to something more elegant once the basic functionality and
Expand All @@ -66,13 +44,6 @@ class ROOTFrameData {
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
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ SET(root_sources
ROOTWriter.cc
ROOTReader.cc
ROOTLegacyReader.cc
ROOTFrameData.cc
)
if(ENABLE_RNTUPLE)
list(APPEND root_sources
Expand All @@ -92,6 +93,7 @@ SET(root_headers
${PROJECT_SOURCE_DIR}/include/podio/ROOTReader.h
${PROJECT_SOURCE_DIR}/include/podio/ROOTLegacyReader.h
${PROJECT_SOURCE_DIR}/include/podio/ROOTWriter.h
${PROJECT_SOURCE_DIR}/include/podio/ROOTFrameData.h
)
if(ENABLE_RNTUPLE)
list(APPEND root_headers
Expand Down
44 changes: 44 additions & 0 deletions src/ROOTFrameData.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "podio/ROOTFrameData.h"

namespace podio {

ROOTFrameData::ROOTFrameData(BufferMap&& buffers, CollIDPtr&& idTable, podio::GenericParameters&& params) :
m_buffers(std::move(buffers)), m_idTable(std::move(idTable)), m_parameters(std::move(params)) {
}

// Interim workaround for https://github.com/AIDASoft/podio#500
ROOTFrameData::~ROOTFrameData() {
for (auto& [_, buffer] : m_buffers) {
buffer.deleteBuffers(buffer);
}
}

std::optional<podio::CollectionReadBuffers> ROOTFrameData::getCollectionBuffers(const std::string& name) {
const auto bufferHandle = m_buffers.extract(name);
if (bufferHandle.empty()) {
return std::nullopt;
}

return {bufferHandle.mapped()};
}

podio::CollectionIDTable ROOTFrameData::getIDTable() const {
// Construct a copy of the internal table
return {m_idTable->ids(), m_idTable->names()};
}

std::unique_ptr<podio::GenericParameters> ROOTFrameData::getParameters() {
return std::make_unique<podio::GenericParameters>(std::move(m_parameters));
}

std::vector<std::string> ROOTFrameData::getAvailableCollections() const {
std::vector<std::string> collections;
collections.reserve(m_buffers.size());
for (const auto& [name, _] : m_buffers) {
collections.push_back(name);
}

return collections;
}

} // namespace podio