Skip to content

Commit

Permalink
Add tool to transform between TTrees and RNTuples (#541)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcarcell authored Jan 25, 2024
1 parent 9656cef commit da7b0d2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
install(PROGRAMS ${CMAKE_CURRENT_LIST_DIR}/podio-dump DESTINATION ${CMAKE_INSTALL_BINDIR})
install(PROGRAMS ${CMAKE_CURRENT_LIST_DIR}/podio-vis DESTINATION ${CMAKE_INSTALL_BINDIR})
if(ENABLE_RNTUPLE)
install(PROGRAMS ${CMAKE_CURRENT_LIST_DIR}/podio-ttree-to-rntuple DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()

# Add a very basic tests here to make sure that podio-dump at least runs
if(BUILD_TESTING)
Expand Down
24 changes: 24 additions & 0 deletions tools/podio-ttree-to-rntuple
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python3
"""podio-ttree-to-rntuple tool to create an rntuple file from a ttree file or viceversa"""

import argparse
import podio.root_io

parser = argparse.ArgumentParser(description='podio-ttree-to-rntuple tool to create'
'an rntuple file from a ttree file or viceversa')
parser.add_argument('input_file', help='input file')
parser.add_argument('output_file', help='output file')
parser.add_argument('-r', '--reverse', action='store_true',
help='reverse the conversion (from RNTuple to TTree)')
args = parser.parse_args()

if not args.reverse:
reader = podio.root_io.Reader(args.input_file)
writer = podio.root_io.RNTupleWriter(args.output_file)
else:
reader = podio.root_io.RNTupleReader(args.input_file)
writer = podio.root_io.Writer(args.output_file)

for category in reader.categories:
for frame in reader.get(category):
writer.write_frame(frame, category)

0 comments on commit da7b0d2

Please sign in to comment.