From 71eeece346118d9bdf02ec8b08801ac52e0499b9 Mon Sep 17 00:00:00 2001 From: tmadlener Date: Wed, 11 Oct 2023 16:52:48 +0200 Subject: [PATCH] Add test case for checking whether reading limited set works --- tests/root_io/read_frame_root.cpp | 43 ++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/tests/root_io/read_frame_root.cpp b/tests/root_io/read_frame_root.cpp index b687fa83e..935200736 100644 --- a/tests/root_io/read_frame_root.cpp +++ b/tests/root_io/read_frame_root.cpp @@ -1,10 +1,51 @@ #include "read_frame.h" #include "read_frame_auxiliary.h" +#include "podio/Frame.h" #include "podio/ROOTFrameReader.h" #include +#include #include +#include + +int test_read_frame_limited(const std::string& inputFile) { + auto reader = podio::ROOTFrameReader(); + reader.openFile(inputFile); + const std::vector collsToRead = {"mcparticles", "clusters"}; + + const auto event = podio::Frame(reader.readNextEntry("events", collsToRead)); + + const auto& availColls = event.getAvailableCollections(); + + const bool validColls = + std::set(availColls.begin(), availColls.end()) != std::set(collsToRead.begin(), collsToRead.end()); + + if (validColls) { + std::cerr << "The available collections are not as expected" << std::endl; + return 1; + } + + if (!event.get("mcparticles")) { + std::cerr << "Collection 'mcparticles' should be available" << std::endl; + return 1; + } + + if (event.get("hits")) { + std::cerr << "Collection 'hits' is available, but should not be" << std::endl; + return 1; + } + + const auto& clusters = event.get("clusters"); + const auto clu0 = clusters[0]; + const auto hits = clu0.Hits(); + if (hits.size() != 1 || hits[0].isAvailable()) { + std::cerr << "Hit in clusters are available but shouldn't be" << std::endl; + return 1; + } + + return 0; +} int main(int argc, char* argv[]) { std::string inputFile = "example_frame.root"; @@ -15,5 +56,5 @@ int main(int argc, char* argv[]) { } return read_frames(inputFile, assertBuildVersion) + - test_frame_aux_info(inputFile); + test_frame_aux_info(inputFile) + test_read_frame_limited(inputFile); }