Skip to content

Commit

Permalink
Move ROOTFrameData implementation into .cc file (#623)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener authored Jun 11, 2024
1 parent e674c04 commit af28f30
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 34 deletions.
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

0 comments on commit af28f30

Please sign in to comment.