-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tool to transform between TTrees and RNTuples (#541)
- Loading branch information
Showing
2 changed files
with
27 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |