diff --git a/include/podio/Reader.h b/include/podio/Reader.h index d8209197e..3cc27120e 100644 --- a/include/podio/Reader.h +++ b/include/podio/Reader.h @@ -22,8 +22,8 @@ class Reader { struct ReaderConcept { virtual ~ReaderConcept() = default; - virtual podio::Frame readNextFrame(const std::string& name) = 0; - virtual podio::Frame readFrame(const std::string& name, size_t index) = 0; + virtual podio::Frame readNextFrame(const std::string& name, const std::vector&) = 0; + virtual podio::Frame readFrame(const std::string& name, size_t index, const std::vector&) = 0; virtual size_t getEntries(const std::string& name) const = 0; virtual podio::version::Version currentFileVersion() const = 0; virtual std::optional currentFileVersion(const std::string& name) const = 0; @@ -44,16 +44,17 @@ class Reader { ~ReaderModel() = default; - podio::Frame readNextFrame(const std::string& name) override { - auto maybeFrame = m_reader->readNextEntry(name); + podio::Frame readNextFrame(const std::string& name, const std::vector& collsToRead) override { + auto maybeFrame = m_reader->readNextEntry(name, collsToRead); if (maybeFrame) { return maybeFrame; } throw std::runtime_error("Failed reading category " + name + " (reading beyond bounds?)"); } - podio::Frame readFrame(const std::string& name, size_t index) override { - auto maybeFrame = m_reader->readEntry(name, index); + podio::Frame readFrame(const std::string& name, size_t index, + const std::vector& collsToRead) override { + auto maybeFrame = m_reader->readEntry(name, index, collsToRead); if (maybeFrame) { return maybeFrame; } @@ -110,8 +111,8 @@ class Reader { /// /// @throws std::invalid_argument in case the category is not available or in /// case no more entries are available - podio::Frame readNextFrame(const std::string& name) { - return m_self->readNextFrame(name); + podio::Frame readNextFrame(const std::string& name, const std::vector& collsToRead = {}) { + return m_self->readNextFrame(name, collsToRead); } /// Read the next frame of the "events" category @@ -119,8 +120,8 @@ class Reader { /// @returns A fully constructed Frame with the contents read from file /// /// @throws std::invalid_argument in case no (more) events are available - podio::Frame readNextEvent() { - return readNextFrame(podio::Category::Event); + podio::Frame readNextEvent(const std::vector& collsToRead = {}) { + return readNextFrame(podio::Category::Event, collsToRead); } /// Read a specific frame for a given category @@ -132,8 +133,8 @@ class Reader { /// /// @throws std::invalid_argument in case the category is not available or in /// case the specified entry is not available - podio::Frame readFrame(const std::string& name, size_t index) { - return m_self->readFrame(name, index); + podio::Frame readFrame(const std::string& name, size_t index, const std::vector& collsToRead = {}) { + return m_self->readFrame(name, index, collsToRead); } /// Read a specific frame of the "events" category @@ -143,8 +144,8 @@ class Reader { /// @returns A fully constructed Frame with the contents read from file /// /// @throws std::invalid_argument in case the desired event is not available - podio::Frame readEvent(size_t index) { - return readFrame(podio::Category::Event, index); + podio::Frame readEvent(size_t index, const std::vector& collsToRead = {}) { + return readFrame(podio::Category::Event, index, collsToRead); } /// Get the number of entries for the given name diff --git a/tests/read_frame.h b/tests/read_frame.h index 855cbf823..96049cfbc 100644 --- a/tests/read_frame.h +++ b/tests/read_frame.h @@ -15,6 +15,7 @@ #include "interface_extension_model/TestInterfaceLinkCollection.h" #include "podio/Frame.h" +#include "podio/Reader.h" #include @@ -274,14 +275,17 @@ int read_frames(const std::string& filename, bool assertBuildVersion = true) { return 0; } -// /// Check that reading only a subset of collections works as expected template -int test_read_frame_limited(const std::string& inputFile) { - auto reader = ReaderT(); - reader.openFile(inputFile); +int test_read_frame_limited(ReaderT& reader) { const std::vector collsToRead = {"mcparticles", "clusters"}; - const auto event = podio::Frame(reader.readNextEntry("events", collsToRead)); + const auto event = [&]() { + if constexpr (std::is_same_v) { + return podio::Frame(reader.readFrame("events", 1, collsToRead)); + } else { + return podio::Frame(reader.readEntry("events", 1, collsToRead)); + } + }(); const auto& availColls = event.getAvailableCollections(); @@ -313,7 +317,7 @@ int test_read_frame_limited(const std::string& inputFile) { return 1; } - const auto& clusters = event.get("clusters"); + const auto& clusters = event.template get("clusters"); const auto clu0 = clusters[0]; const auto hits = clu0.Hits(); if (hits.size() != 1 || hits[0].isAvailable()) { @@ -324,4 +328,13 @@ int test_read_frame_limited(const std::string& inputFile) { return 0; } +/// Check that reading only a subset of collections works as expected +template +int test_read_frame_limited(const std::string& inputFile) { + auto reader = ReaderT(); + reader.openFile(inputFile); + + return test_read_frame_limited(reader); +} + #endif // PODIO_TESTS_READ_FRAME_H diff --git a/tests/root_io/read_interface_root.cpp b/tests/root_io/read_interface_root.cpp index 8d33ec1c3..b43546ec0 100644 --- a/tests/root_io/read_interface_root.cpp +++ b/tests/root_io/read_interface_root.cpp @@ -1,11 +1,9 @@ +#include "read_frame.h" #include "read_interface.h" -int main(int, char**) { +#include "podio/Reader.h" +int main(int, char**) { auto reader = podio::makeReader("example_frame_interface.root"); - if (read_frames(reader)) { - return 1; - } - - return 0; + return read_frames(reader) + test_read_frame_limited(reader); } diff --git a/tests/sio_io/read_interface_sio.cpp b/tests/sio_io/read_interface_sio.cpp index e411f2a96..6b7c0d46a 100644 --- a/tests/sio_io/read_interface_sio.cpp +++ b/tests/sio_io/read_interface_sio.cpp @@ -1,11 +1,10 @@ +#include "read_frame.h" #include "read_interface.h" int main(int, char**) { auto readerSIO = podio::makeReader("example_frame_sio_interface.sio"); - if (read_frames(readerSIO)) { - return 1; - } + return read_frames(readerSIO) + test_read_frame_limited(readerSIO); return 0; }