Skip to content

Commit

Permalink
Change ROOTNTuple{Reader,Writer} to RNTuple{Reader,Writer} (#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarcell authored Jan 24, 2024
1 parent 2e13979 commit 9656cef
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 61 deletions.
8 changes: 4 additions & 4 deletions include/podio/GenericParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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<std::string>& filename);
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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 <typename T>
void fillParams(GenericParameters& params, ROOT::Experimental::REntry* entry);
Expand Down Expand Up @@ -86,4 +86,4 @@ class ROOTNTupleWriter {

} // namespace podio

#endif // PODIO_ROOTNTUPLEWRITER_H
#endif // PODIO_RNTUPLEWRITER_H
1 change: 0 additions & 1 deletion include/podio/ROOTFrameReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

// forward declarations
class TClass;
// class TChain;
class TFile;
class TTree;

Expand Down
4 changes: 2 additions & 2 deletions python/podio/root_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__()
Expand Down Expand Up @@ -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__()
8 changes: 4 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ SET(root_sources
)
if(ENABLE_RNTUPLE)
list(APPEND root_sources
ROOTNTupleReader.cc
ROOTNTupleWriter.cc
RNTupleReader.cc
RNTupleWriter.cc
)
endif()

Expand All @@ -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()

Expand Down
20 changes: 10 additions & 10 deletions src/ROOTNTupleReader.cc → src/RNTupleReader.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "podio/ROOTNTupleReader.h"
#include "podio/RNTupleReader.h"
#include "podio/CollectionBase.h"
#include "podio/CollectionBufferFactory.h"
#include "podio/CollectionBuffers.h"
Expand All @@ -14,7 +14,7 @@
namespace podio {

template <typename T>
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<std::vector<std::string>>(root_utils::getGPKeyName<T>());
auto valueView = m_readers[name][0]->GetView<std::vector<std::vector<T>>>(root_utils::getGPValueName<T>());

Expand All @@ -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<int>(name, entNum, params);
Expand All @@ -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;
}
Expand Down Expand Up @@ -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<std::string>& filenames) {
void RNTupleReader::openFiles(const std::vector<std::string>& filenames) {

m_filenames.insert(m_filenames.end(), filenames.begin(), filenames.end());
for (auto& filename : filenames) {
Expand All @@ -93,7 +93,7 @@ void ROOTNTupleReader::openFiles(const std::vector<std::string>& 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 {
Expand All @@ -108,7 +108,7 @@ unsigned ROOTNTupleReader::getEntries(const std::string& name) {
return m_totalEntries[name];
}

std::vector<std::string_view> ROOTNTupleReader::getAvailableCategories() const {
std::vector<std::string_view> RNTupleReader::getAvailableCategories() const {
std::vector<std::string_view> cats;
cats.reserve(m_availableCategories.size());
for (const auto& cat : m_availableCategories) {
Expand All @@ -117,11 +117,11 @@ std::vector<std::string_view> ROOTNTupleReader::getAvailableCategories() const {
return cats;
}

std::unique_ptr<ROOTFrameData> ROOTNTupleReader::readNextEntry(const std::string& name) {
std::unique_ptr<ROOTFrameData> RNTupleReader::readNextEntry(const std::string& name) {
return readEntry(name, m_entries[name]);
}

std::unique_ptr<ROOTFrameData> ROOTNTupleReader::readEntry(const std::string& category, const unsigned entNum) {
std::unique_ptr<ROOTFrameData> RNTupleReader::readEntry(const std::string& category, const unsigned entNum) {
if (m_totalEntries.find(category) == m_totalEntries.end()) {
getEntries(category);
}
Expand Down
24 changes: 12 additions & 12 deletions src/ROOTNTupleWriter.cc → src/RNTupleWriter.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "podio/ROOTNTupleWriter.h"
#include "podio/RNTupleWriter.h"
#include "podio/CollectionBase.h"
#include "podio/DatamodelRegistry.h"
#include "podio/GenericParameters.h"
Expand All @@ -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 <typename T>
std::pair<std::vector<std::string>&, std::vector<std::vector<T>>&> ROOTNTupleWriter::getKeyValueVectors() {
std::pair<std::vector<std::string>&, std::vector<std::vector<T>>&> RNTupleWriter::getKeyValueVectors() {
if constexpr (std::is_same_v<T, int>) {
return {m_intkeys, m_intvalues};
} else if constexpr (std::is_same_v<T, float>) {
Expand All @@ -42,7 +42,7 @@ std::pair<std::vector<std::string>&, std::vector<std::vector<T>>&> ROOTNTupleWri
}

template <typename T>
void ROOTNTupleWriter::fillParams(GenericParameters& params, ROOT::Experimental::REntry* entry) {
void RNTupleWriter::fillParams(GenericParameters& params, ROOT::Experimental::REntry* entry) {
auto [key, value] = getKeyValueVectors<T>();
entry->CaptureValueUnsafe(root_utils::getGPKeyName<T>(), &key);
entry->CaptureValueUnsafe(root_utils::getGPValueName<T>(), &value);
Expand All @@ -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<std::string>& collsToWrite) {
void RNTupleWriter::writeFrame(const podio::Frame& frame, const std::string& category,
const std::vector<std::string>& collsToWrite) {
auto& catInfo = getCategoryInfo(category);

// Use the writer as proxy to check whether this category has been initialized
Expand Down Expand Up @@ -161,7 +161,7 @@ void ROOTNTupleWriter::writeFrame(const podio::Frame& frame, const std::string&
}

std::unique_ptr<ROOT::Experimental::RNTupleModel>
ROOTNTupleWriter::createModels(const std::vector<StoreCollection>& collections) {
RNTupleWriter::createModels(const std::vector<StoreCollection>& collections) {
auto model = ROOT::Experimental::RNTupleModel::CreateBare();
for (auto& [name, coll] : collections) {
// For the first entry in each category we also record the datamodel
Expand Down Expand Up @@ -238,7 +238,7 @@ ROOTNTupleWriter::createModels(const std::vector<StoreCollection>& 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;
}
Expand All @@ -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<std::vector<uint16_t>>(root_utils::versionBranchName);
Expand Down Expand Up @@ -295,7 +295,7 @@ void ROOTNTupleWriter::finish() {
}

std::tuple<std::vector<std::string>, std::vector<std::string>>
ROOTNTupleWriter::checkConsistency(const std::vector<std::string>& collsToWrite, const std::string& category) const {
RNTupleWriter::checkConsistency(const std::vector<std::string>& 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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/root_selection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<class name="podio::ROOTFrameReader"/>
<class name="podio::ROOTLegacyReader"/>
<class name="podio::ROOTFrameWriter"/>
<class name="podio::ROOTNTupleReader"/>
<class name="podio::ROOTNTupleWriter"/>
<class name="podio::RNTupleReader"/>
<class name="podio::RNTupleWriter"/>
</selection>
</lcgdict>
4 changes: 2 additions & 2 deletions tests/root_io/read_python_frame_rntuple.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "read_python_frame.h"

#include "podio/ROOTNTupleReader.h"
#include "podio/RNTupleReader.h"

int main() {
return read_frame<podio::ROOTNTupleReader>("example_frame_with_py_rntuple.root");
return read_frame<podio::RNTupleReader>("example_frame_with_py_rntuple.root");
}
4 changes: 2 additions & 2 deletions tests/root_io/read_rntuple.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "podio/ROOTNTupleReader.h"
#include "podio/RNTupleReader.h"
#include "read_frame.h"

int main() {
return read_frames<podio::ROOTNTupleReader>("example_rntuple.root");
return read_frames<podio::RNTupleReader>("example_rntuple.root");
}
4 changes: 2 additions & 2 deletions tests/root_io/write_rntuple.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "podio/ROOTNTupleWriter.h"
#include "podio/RNTupleWriter.h"
#include "write_frame.h"

int main() {
write_frames<podio::ROOTNTupleWriter>("example_rntuple.root");
write_frames<podio::RNTupleWriter>("example_rntuple.root");
}
10 changes: 5 additions & 5 deletions tests/unittests/unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#endif

#if PODIO_ENABLE_RNTUPLE
#include "podio/ROOTNTupleWriter.h"
#include "podio/RNTupleWriter.h"
#endif

// Test data types
Expand Down Expand Up @@ -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<podio::ROOTNTupleWriter>("unittests_frame_consistency_rntuple.root");
TEST_CASE("RNTupleWriter consistent frame contents", "[basics][root]") {
runConsistentFrameTest<podio::RNTupleWriter>("unittests_frame_consistency_rntuple.root");
}

TEST_CASE("ROOTNTupleWriter check consistency", "[basics][root]") {
runCheckConsistencyTest<podio::ROOTNTupleWriter>("unittests_frame_check_consistency_rntuple.root");
TEST_CASE("RNTupleWriter check consistency", "[basics][root]") {
runCheckConsistencyTest<podio::RNTupleWriter>("unittests_frame_check_consistency_rntuple.root");
}

#endif

0 comments on commit 9656cef

Please sign in to comment.