From 9656cef88d829017e8e242f79615b8a7bbcc2ee5 Mon Sep 17 00:00:00 2001 From: Juan Miguel Carceller <22276694+jmcarcell@users.noreply.github.com> Date: Wed, 24 Jan 2024 18:05:50 +0100 Subject: [PATCH] Change ROOTNTuple{Reader,Writer} to RNTuple{Reader,Writer} (#543) --- include/podio/GenericParameters.h | 8 +++---- .../{ROOTNTupleReader.h => RNTupleReader.h} | 14 +++++------ .../{ROOTNTupleWriter.h => RNTupleWriter.h} | 16 ++++++------- include/podio/ROOTFrameReader.h | 1 - python/podio/root_io.py | 4 ++-- src/CMakeLists.txt | 8 +++---- src/{ROOTNTupleReader.cc => RNTupleReader.cc} | 20 ++++++++-------- src/{ROOTNTupleWriter.cc => RNTupleWriter.cc} | 24 +++++++++---------- src/root_selection.xml | 4 ++-- tests/root_io/read_python_frame_rntuple.cpp | 4 ++-- tests/root_io/read_rntuple.cpp | 4 ++-- tests/root_io/write_rntuple.cpp | 4 ++-- tests/unittests/unittest.cpp | 10 ++++---- 13 files changed, 60 insertions(+), 61 deletions(-) rename include/podio/{ROOTNTupleReader.h => RNTupleReader.h} (92%) rename include/podio/{ROOTNTupleWriter.h => RNTupleWriter.h} (89%) rename src/{ROOTNTupleReader.cc => RNTupleReader.cc} (90%) rename src/{ROOTNTupleWriter.cc => RNTupleWriter.cc} (92%) diff --git a/include/podio/GenericParameters.h b/include/podio/GenericParameters.h index 0705fbfba..b82a7869e 100644 --- a/include/podio/GenericParameters.h +++ b/include/podio/GenericParameters.h @@ -20,8 +20,8 @@ using version_type = uint32_t; // from sio/definitions #if PODIO_ENABLE_RNTUPLE namespace podio { -class ROOTNTupleReader; -class ROOTNTupleWriter; +class RNTupleReader; +class RNTupleWriter; } // namespace podio #endif @@ -151,8 +151,8 @@ class GenericParameters { friend void readGenericParameters(sio::read_device& device, GenericParameters& parameters, sio::version_type version); #if PODIO_ENABLE_RNTUPLE - friend ROOTNTupleWriter; - friend ROOTNTupleReader; + friend RNTupleReader; + friend RNTupleWriter; #endif /// Get a reference to the internal map for a given type diff --git a/include/podio/ROOTNTupleReader.h b/include/podio/RNTupleReader.h similarity index 92% rename from include/podio/ROOTNTupleReader.h rename to include/podio/RNTupleReader.h index 30783c901..ef13aec27 100644 --- a/include/podio/ROOTNTupleReader.h +++ b/include/podio/RNTupleReader.h @@ -1,5 +1,5 @@ -#ifndef PODIO_ROOTNTUPLEREADER_H -#define PODIO_ROOTNTUPLEREADER_H +#ifndef PODIO_RNTUPLEREADER_H +#define PODIO_RNTUPLEREADER_H #include "podio/CollectionBranches.h" #include "podio/ICollectionProvider.h" @@ -22,14 +22,14 @@ namespace podio { This class has the function to read available data from disk and to prepare collections and buffers. **/ -class ROOTNTupleReader { +class RNTupleReader { public: - ROOTNTupleReader() = default; - ~ROOTNTupleReader() = default; + RNTupleReader() = default; + ~RNTupleReader() = default; - ROOTNTupleReader(const ROOTNTupleReader&) = delete; - ROOTNTupleReader& operator=(const ROOTNTupleReader&) = delete; + RNTupleReader(const RNTupleReader&) = delete; + RNTupleReader& operator=(const RNTupleReader&) = delete; void openFile(const std::string& filename); void openFiles(const std::vector& filename); diff --git a/include/podio/ROOTNTupleWriter.h b/include/podio/RNTupleWriter.h similarity index 89% rename from include/podio/ROOTNTupleWriter.h rename to include/podio/RNTupleWriter.h index 6a1b4cd71..2583e56db 100644 --- a/include/podio/ROOTNTupleWriter.h +++ b/include/podio/RNTupleWriter.h @@ -1,5 +1,5 @@ -#ifndef PODIO_ROOTNTUPLEWRITER_H -#define PODIO_ROOTNTUPLEWRITER_H +#ifndef PODIO_RNTUPLEWRITER_H +#define PODIO_RNTUPLEWRITER_H #include "podio/CollectionBase.h" #include "podio/Frame.h" @@ -17,13 +17,13 @@ namespace podio { -class ROOTNTupleWriter { +class RNTupleWriter { public: - ROOTNTupleWriter(const std::string& filename); - ~ROOTNTupleWriter(); + RNTupleWriter(const std::string& filename); + ~RNTupleWriter(); - ROOTNTupleWriter(const ROOTNTupleWriter&) = delete; - ROOTNTupleWriter& operator=(const ROOTNTupleWriter&) = delete; + RNTupleWriter(const RNTupleWriter&) = delete; + RNTupleWriter& operator=(const RNTupleWriter&) = delete; template void fillParams(GenericParameters& params, ROOT::Experimental::REntry* entry); @@ -86,4 +86,4 @@ class ROOTNTupleWriter { } // namespace podio -#endif // PODIO_ROOTNTUPLEWRITER_H +#endif // PODIO_RNTUPLEWRITER_H diff --git a/include/podio/ROOTFrameReader.h b/include/podio/ROOTFrameReader.h index b0e689cd1..f2d0033a3 100644 --- a/include/podio/ROOTFrameReader.h +++ b/include/podio/ROOTFrameReader.h @@ -18,7 +18,6 @@ // forward declarations class TClass; -// class TChain; class TFile; class TTree; diff --git a/python/podio/root_io.py b/python/podio/root_io.py index c4e0a14f2..0fcc75c83 100644 --- a/python/podio/root_io.py +++ b/python/podio/root_io.py @@ -39,7 +39,7 @@ def __init__(self, filenames): if isinstance(filenames, str): filenames = (filenames,) - self._reader = podio.ROOTNTupleReader() + self._reader = podio.RNTupleReader() self._reader.openFiles(filenames) super().__init__() @@ -88,5 +88,5 @@ def __init__(self, filename): Args: filename (str): The name of the output file """ - self._writer = podio.ROOTNTupleWriter(filename) + self._writer = podio.RNTupleWriter(filename) super().__init__() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b284abbd8..77388a439 100755 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -83,8 +83,8 @@ SET(root_sources ) if(ENABLE_RNTUPLE) list(APPEND root_sources - ROOTNTupleReader.cc - ROOTNTupleWriter.cc + RNTupleReader.cc + RNTupleWriter.cc ) endif() @@ -95,8 +95,8 @@ SET(root_headers ) if(ENABLE_RNTUPLE) list(APPEND root_headers - ${PROJECT_SOURCE_DIR}/include/podio/ROOTNTupleReader.h - ${PROJECT_SOURCE_DIR}/include/podio/ROOTNTupleWriter.h + ${PROJECT_SOURCE_DIR}/include/podio/RNTupleReader.h + ${PROJECT_SOURCE_DIR}/include/podio/RNTupleWriter.h ) endif() diff --git a/src/ROOTNTupleReader.cc b/src/RNTupleReader.cc similarity index 90% rename from src/ROOTNTupleReader.cc rename to src/RNTupleReader.cc index b4db7f991..f81a53ba0 100644 --- a/src/ROOTNTupleReader.cc +++ b/src/RNTupleReader.cc @@ -1,4 +1,4 @@ -#include "podio/ROOTNTupleReader.h" +#include "podio/RNTupleReader.h" #include "podio/CollectionBase.h" #include "podio/CollectionBufferFactory.h" #include "podio/CollectionBuffers.h" @@ -14,7 +14,7 @@ namespace podio { template -void ROOTNTupleReader::readParams(const std::string& name, unsigned entNum, GenericParameters& params) { +void RNTupleReader::readParams(const std::string& name, unsigned entNum, GenericParameters& params) { auto keyView = m_readers[name][0]->GetView>(root_utils::getGPKeyName()); auto valueView = m_readers[name][0]->GetView>>(root_utils::getGPValueName()); @@ -23,7 +23,7 @@ void ROOTNTupleReader::readParams(const std::string& name, unsigned entNum, Gene } } -GenericParameters ROOTNTupleReader::readEventMetaData(const std::string& name, unsigned entNum) { +GenericParameters RNTupleReader::readEventMetaData(const std::string& name, unsigned entNum) { GenericParameters params; readParams(name, entNum, params); @@ -34,7 +34,7 @@ GenericParameters ROOTNTupleReader::readEventMetaData(const std::string& name, u return params; } -bool ROOTNTupleReader::initCategory(const std::string& category) { +bool RNTupleReader::initCategory(const std::string& category) { if (std::find(m_availableCategories.begin(), m_availableCategories.end(), category) == m_availableCategories.end()) { return false; } @@ -65,11 +65,11 @@ bool ROOTNTupleReader::initCategory(const std::string& category) { return true; } -void ROOTNTupleReader::openFile(const std::string& filename) { +void RNTupleReader::openFile(const std::string& filename) { openFiles({filename}); } -void ROOTNTupleReader::openFiles(const std::vector& filenames) { +void RNTupleReader::openFiles(const std::vector& filenames) { m_filenames.insert(m_filenames.end(), filenames.begin(), filenames.end()); for (auto& filename : filenames) { @@ -93,7 +93,7 @@ void ROOTNTupleReader::openFiles(const std::vector& filenames) { m_availableCategories = availableCategoriesField(0); } -unsigned ROOTNTupleReader::getEntries(const std::string& name) { +unsigned RNTupleReader::getEntries(const std::string& name) { if (m_readers.find(name) == m_readers.end()) { for (auto& filename : m_filenames) { try { @@ -108,7 +108,7 @@ unsigned ROOTNTupleReader::getEntries(const std::string& name) { return m_totalEntries[name]; } -std::vector ROOTNTupleReader::getAvailableCategories() const { +std::vector RNTupleReader::getAvailableCategories() const { std::vector cats; cats.reserve(m_availableCategories.size()); for (const auto& cat : m_availableCategories) { @@ -117,11 +117,11 @@ std::vector ROOTNTupleReader::getAvailableCategories() const { return cats; } -std::unique_ptr ROOTNTupleReader::readNextEntry(const std::string& name) { +std::unique_ptr RNTupleReader::readNextEntry(const std::string& name) { return readEntry(name, m_entries[name]); } -std::unique_ptr ROOTNTupleReader::readEntry(const std::string& category, const unsigned entNum) { +std::unique_ptr RNTupleReader::readEntry(const std::string& category, const unsigned entNum) { if (m_totalEntries.find(category) == m_totalEntries.end()) { getEntries(category); } diff --git a/src/ROOTNTupleWriter.cc b/src/RNTupleWriter.cc similarity index 92% rename from src/ROOTNTupleWriter.cc rename to src/RNTupleWriter.cc index 79fc982c9..79360f1e9 100644 --- a/src/ROOTNTupleWriter.cc +++ b/src/RNTupleWriter.cc @@ -1,4 +1,4 @@ -#include "podio/ROOTNTupleWriter.h" +#include "podio/RNTupleWriter.h" #include "podio/CollectionBase.h" #include "podio/DatamodelRegistry.h" #include "podio/GenericParameters.h" @@ -15,19 +15,19 @@ namespace podio { -ROOTNTupleWriter::ROOTNTupleWriter(const std::string& filename) : +RNTupleWriter::RNTupleWriter(const std::string& filename) : m_metadata(ROOT::Experimental::RNTupleModel::Create()), m_file(new TFile(filename.c_str(), "RECREATE", "data file")) { } -ROOTNTupleWriter::~ROOTNTupleWriter() { +RNTupleWriter::~RNTupleWriter() { if (!m_finished) { finish(); } } template -std::pair&, std::vector>&> ROOTNTupleWriter::getKeyValueVectors() { +std::pair&, std::vector>&> RNTupleWriter::getKeyValueVectors() { if constexpr (std::is_same_v) { return {m_intkeys, m_intvalues}; } else if constexpr (std::is_same_v) { @@ -42,7 +42,7 @@ std::pair&, std::vector>&> ROOTNTupleWri } template -void ROOTNTupleWriter::fillParams(GenericParameters& params, ROOT::Experimental::REntry* entry) { +void RNTupleWriter::fillParams(GenericParameters& params, ROOT::Experimental::REntry* entry) { auto [key, value] = getKeyValueVectors(); entry->CaptureValueUnsafe(root_utils::getGPKeyName(), &key); entry->CaptureValueUnsafe(root_utils::getGPValueName(), &value); @@ -58,12 +58,12 @@ void ROOTNTupleWriter::fillParams(GenericParameters& params, ROOT::Experimental: } } -void ROOTNTupleWriter::writeFrame(const podio::Frame& frame, const std::string& category) { +void RNTupleWriter::writeFrame(const podio::Frame& frame, const std::string& category) { writeFrame(frame, category, frame.getAvailableCollections()); } -void ROOTNTupleWriter::writeFrame(const podio::Frame& frame, const std::string& category, - const std::vector& collsToWrite) { +void RNTupleWriter::writeFrame(const podio::Frame& frame, const std::string& category, + const std::vector& collsToWrite) { auto& catInfo = getCategoryInfo(category); // Use the writer as proxy to check whether this category has been initialized @@ -161,7 +161,7 @@ void ROOTNTupleWriter::writeFrame(const podio::Frame& frame, const std::string& } std::unique_ptr -ROOTNTupleWriter::createModels(const std::vector& collections) { +RNTupleWriter::createModels(const std::vector& collections) { auto model = ROOT::Experimental::RNTupleModel::CreateBare(); for (auto& [name, coll] : collections) { // For the first entry in each category we also record the datamodel @@ -238,7 +238,7 @@ ROOTNTupleWriter::createModels(const std::vector& collections) return model; } -ROOTNTupleWriter::CollectionInfo& ROOTNTupleWriter::getCategoryInfo(const std::string& category) { +RNTupleWriter::CollectionInfo& RNTupleWriter::getCategoryInfo(const std::string& category) { if (auto it = m_categories.find(category); it != m_categories.end()) { return it->second; } @@ -247,7 +247,7 @@ ROOTNTupleWriter::CollectionInfo& ROOTNTupleWriter::getCategoryInfo(const std::s return it->second; } -void ROOTNTupleWriter::finish() { +void RNTupleWriter::finish() { auto podioVersion = podio::version::build_version; auto versionField = m_metadata->MakeField>(root_utils::versionBranchName); @@ -295,7 +295,7 @@ void ROOTNTupleWriter::finish() { } std::tuple, std::vector> -ROOTNTupleWriter::checkConsistency(const std::vector& collsToWrite, const std::string& category) const { +RNTupleWriter::checkConsistency(const std::vector& collsToWrite, const std::string& category) const { if (const auto it = m_categories.find(category); it != m_categories.end()) { return root_utils::getInconsistentColls(it->second.name, collsToWrite); } diff --git a/src/root_selection.xml b/src/root_selection.xml index afda66935..604c58f13 100644 --- a/src/root_selection.xml +++ b/src/root_selection.xml @@ -3,7 +3,7 @@ - - + + diff --git a/tests/root_io/read_python_frame_rntuple.cpp b/tests/root_io/read_python_frame_rntuple.cpp index 52d7576d8..0d21563d4 100644 --- a/tests/root_io/read_python_frame_rntuple.cpp +++ b/tests/root_io/read_python_frame_rntuple.cpp @@ -1,7 +1,7 @@ #include "read_python_frame.h" -#include "podio/ROOTNTupleReader.h" +#include "podio/RNTupleReader.h" int main() { - return read_frame("example_frame_with_py_rntuple.root"); + return read_frame("example_frame_with_py_rntuple.root"); } diff --git a/tests/root_io/read_rntuple.cpp b/tests/root_io/read_rntuple.cpp index 59688b2f2..ddd98202b 100644 --- a/tests/root_io/read_rntuple.cpp +++ b/tests/root_io/read_rntuple.cpp @@ -1,6 +1,6 @@ -#include "podio/ROOTNTupleReader.h" +#include "podio/RNTupleReader.h" #include "read_frame.h" int main() { - return read_frames("example_rntuple.root"); + return read_frames("example_rntuple.root"); } diff --git a/tests/root_io/write_rntuple.cpp b/tests/root_io/write_rntuple.cpp index ce7810c53..853f3435f 100644 --- a/tests/root_io/write_rntuple.cpp +++ b/tests/root_io/write_rntuple.cpp @@ -1,6 +1,6 @@ -#include "podio/ROOTNTupleWriter.h" +#include "podio/RNTupleWriter.h" #include "write_frame.h" int main() { - write_frames("example_rntuple.root"); + write_frames("example_rntuple.root"); } diff --git a/tests/unittests/unittest.cpp b/tests/unittests/unittest.cpp index 1be4b89c5..4164c0ab6 100644 --- a/tests/unittests/unittest.cpp +++ b/tests/unittests/unittest.cpp @@ -28,7 +28,7 @@ #endif #if PODIO_ENABLE_RNTUPLE - #include "podio/ROOTNTupleWriter.h" + #include "podio/RNTupleWriter.h" #endif // Test data types @@ -1235,12 +1235,12 @@ TEST_CASE("ROOTFrameWriter check consistency", "[ASAN-FAIL][UBSAN-FAIL][basics][ } #if PODIO_ENABLE_RNTUPLE -TEST_CASE("ROOTNTupleWriter consistent frame contents", "[basics][root]") { - runConsistentFrameTest("unittests_frame_consistency_rntuple.root"); +TEST_CASE("RNTupleWriter consistent frame contents", "[basics][root]") { + runConsistentFrameTest("unittests_frame_consistency_rntuple.root"); } -TEST_CASE("ROOTNTupleWriter check consistency", "[basics][root]") { - runCheckConsistencyTest("unittests_frame_check_consistency_rntuple.root"); +TEST_CASE("RNTupleWriter check consistency", "[basics][root]") { + runCheckConsistencyTest("unittests_frame_check_consistency_rntuple.root"); } #endif