@@ -26,20 +26,34 @@ def transform_single_file(file_path: str, output_path: Path, output_format: str)
26
26
27
27
ttime = time .time ()
28
28
29
- if output_format == 'root-file' :
29
+ if output_format in ( 'root-file' , 'root-rntuple' ) :
30
30
import uproot
31
31
etime = time .time ()
32
32
# opening the file with open() is a workaround for a bug handling multiple colons
33
33
# in the filename in uproot 5.3.9
34
34
with open (output_path , 'b+w' ) as wfile :
35
35
with uproot .recreate (wfile ) as writer :
36
36
for k , v in awkward_array_dict .items ():
37
- if v [0 ] is not None :
38
- writer [k ] = {field : v [0 ][field ] for field in
39
- v [0 ].fields } if v [0 ].fields \
40
- else v [0 ]
41
- else :
42
- writer .mktree (k , v [1 ])
37
+ if output_format == 'root-file' :
38
+ if v [0 ] is not None :
39
+ writer [k ] = {field : v [0 ][field ] for field in
40
+ v [0 ].fields }
41
+ else :
42
+ writer .mktree (k , dict (zip (v [1 ].form .columns (),
43
+ v [1 ].form .column_types ())))
44
+ else : # RNTuple
45
+ if v [0 ] is not None :
46
+ # Work around a limitation in uproot 5.6.0
47
+ # If a cut is specified, we'll get ListArrays which can't be
48
+ # written via uproot. Convert them to ListOffsetArrays
49
+ # Assume the ListArrays are only at top level
50
+ warr = ak .zip ({_ : v [0 ][_ ].layout .to_ListOffsetArray64 ()
51
+ if isinstance (v [0 ][_ ].layout , ak .contents .ListArray )
52
+ else v [0 ][_ ]
53
+ for _ in v [0 ].fields }, depth_limit = 1 )
54
+ writer .mkrntuple (k , warr )
55
+ else :
56
+ writer .mkrntuple (k , v [1 ].form )
43
57
for k , v in histograms .items ():
44
58
writer [k ] = v
45
59
wtime = time .time ()
0 commit comments