Skip to content

Commit 96c3d37

Browse files
committed
Add python bindings for RNTuple writer
1 parent f20d0a1 commit 96c3d37

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

python/podio/root_io.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,14 @@ def __init__(self, filename):
7777
filename (str): The name of the output file
7878
"""
7979
self._writer = podio.ROOTFrameWriter(filename)
80+
81+
82+
class RNTupleWriter(BaseWriterMixin):
83+
"""Writer class for writing podio root files"""
84+
def __init__(self, filename):
85+
"""Create a writer for writing files
86+
87+
Args:
88+
filename (str): The name of the output file
89+
"""
90+
self._writer = podio.ROOTNTupleWriter(filename)

tests/root_io/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ if(ENABLE_RNTUPLE)
1919
${root_dependent_tests}
2020
write_rntuple.cpp
2121
read_rntuple.cpp
22+
read_python_frame_rntuple.cpp
2223
)
2324
endif()
2425
set(root_libs TestDataModelDict ExtensionDataModelDict podio::podioRootIO)
@@ -80,6 +81,13 @@ endforeach()
8081

8182
#--- Write via python and the ROOT backend and see if we can read it back in in
8283
#--- c++
83-
add_test(NAME write_python_frame_root COMMAND python3 ${PROJECT_SOURCE_DIR}/tests/write_frame.py example_frame_with_py.root)
84+
add_test(NAME write_python_frame_root COMMAND python3 ${PROJECT_SOURCE_DIR}/tests/write_frame.py example_frame_with_py.root root_io.Writer)
8485
PODIO_SET_TEST_ENV(write_python_frame_root)
8586
set_property(TEST read_python_frame_root PROPERTY DEPENDS write_python_frame_root)
87+
88+
if (ENABLE_RNTUPLE)
89+
add_test(NAME write_python_frame_rntuple COMMAND python3 ${PROJECT_SOURCE_DIR}/tests/write_frame.py example_frame_with_py_rntuple.root root_io.RNTupleWriter)
90+
PODIO_SET_TEST_ENV(write_python_frame_rntuple)
91+
92+
set_property(TEST read_python_frame_rntuple PROPERTY DEPENDS write_python_frame_rntuple)
93+
endif()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#include "read_python_frame.h"
2+
3+
#include "podio/ROOTNTupleReader.h"
4+
5+
int main() {
6+
return read_frame<podio::ROOTNTupleReader>("example_frame_with_py_rntuple.root");
7+
}

tests/sio_io/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ set_property(TEST check_benchmark_outputs_sio PROPERTY DEPENDS read_timed_sio wr
4040

4141
#--- Write via python and the SIO backend and see if we can read it back in in
4242
#--- c++
43-
add_test(NAME write_python_frame_sio COMMAND python3 ${PROJECT_SOURCE_DIR}/tests/write_frame.py example_frame_with_py.sio)
43+
add_test(NAME write_python_frame_sio COMMAND python3 ${PROJECT_SOURCE_DIR}/tests/write_frame.py example_frame_with_py.sio sio_io.Writer)
4444
PODIO_SET_TEST_ENV(write_python_frame_sio)
4545
set_property(TEST read_python_frame_sio PROPERTY DEPENDS write_python_frame_sio)

tests/write_frame.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,14 @@ def create_frame():
5454
return frame
5555

5656

57-
def write_file(io_backend, filename):
57+
def write_file(writer_type, filename):
5858
"""Write a file using the given Writer type and put one Frame into it under
5959
the events category
6060
"""
61+
io_backend, writer_name = writer_type.split(".")
6162
io_module = importlib.import_module(f"podio.{io_backend}")
6263

63-
writer = io_module.Writer(filename)
64+
writer = getattr(io_module, writer_name)(filename)
6465
event = create_frame()
6566
writer.write_frame(event, "events")
6667

@@ -70,9 +71,10 @@ def write_file(io_backend, filename):
7071

7172
parser = argparse.ArgumentParser()
7273
parser.add_argument("outputfile", help="Output file name")
74+
parser.add_argument("writer", help="The writer type to use")
7375

7476
args = parser.parse_args()
7577

7678
io_format = args.outputfile.split(".")[-1]
7779

78-
write_file(f"{io_format}_io", args.outputfile)
80+
write_file(args.writer, args.outputfile)

0 commit comments

Comments
 (0)