From 56b34727c6a86ff621b1c799c227bd4ce8e1f085 Mon Sep 17 00:00:00 2001 From: tmadlener Date: Thu, 13 Jul 2023 11:05:13 +0200 Subject: [PATCH] Add I/O tests for put_parameter --- python/podio/test_utils.py | 4 ++++ tests/read_python_frame.h | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/python/podio/test_utils.py b/python/podio/test_utils.py index 3680f7a78..310e3f964 100644 --- a/python/podio/test_utils.py +++ b/python/podio/test_utils.py @@ -40,6 +40,10 @@ def create_frame(): clusters = create_cluster_collection() frame.put(clusters, "clusters_from_python") + frame.put_parameter("an_int", 42) + frame.put_parameter("some_floats", [1.23, 7.89, 3.14]) + frame.put_parameter("greetings", ["from", "python"]) + return frame diff --git a/tests/read_python_frame.h b/tests/read_python_frame.h index 003d95812..791905c18 100644 --- a/tests/read_python_frame.h +++ b/tests/read_python_frame.h @@ -46,6 +46,39 @@ int checkClusters(const ExampleClusterCollection& clusters) { return 0; } +template +std::ostream& operator<<(std::ostream& o, const std::vector& vec) { + auto delim = "["; + for (const auto& v : vec) { + o << std::exchange(delim, ", ") << v; + } + return o << "]"; +} + +int checkParameters(const podio::Frame& frame) { + const auto iVal = frame.getParameter("an_int"); + if (iVal != 42) { + std::cerr << "Parameter an_int was not stored correctly (expected 42, actual " << iVal << ")" << std::endl; + return 1; + } + + const auto& dVal = frame.getParameter>("some_floats"); + if (dVal.size() != 3 || dVal[0] != 1.23 || dVal[1] != 7.89 || dVal[2] != 3.14) { + std::cerr << "Parameter some_floats was not stored correctly (expected [1.23, 7.89, 3.14], actual " << dVal << ")" + << std::endl; + return 1; + } + + const auto& strVal = frame.getParameter>("greetings"); + if (strVal.size() != 2 || strVal[0] != "from" || strVal[1] != "python") { + std::cerr << "Parameter greetings was not stored correctly (expected [from, python], actual " << strVal << ")" + << std::endl; + return 1; + } + + return 0; +} + template int read_frame(const std::string& filename) { auto reader = ReaderT(); @@ -54,7 +87,7 @@ int read_frame(const std::string& filename) { auto event = podio::Frame(reader.readEntry("events", 0)); return checkHits(event.get("hits_from_python")) + - checkClusters(event.get("clusters_from_python")); + checkClusters(event.get("clusters_from_python")) + checkParameters(event); } #endif // PODIO_TESTS_READ_PYTHON_FRAME_H