Skip to content

Commit 6af81b7

Browse files
committed
return form per tree + variable renaming
1 parent 49dbf27 commit 6af81b7

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

servicex_analysis_utils/file_peeking.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def parse_jagged_depth_and_dtype(dtype_str):
212212
return depth, None
213213

214214

215-
def str_to_array(encoded_json_str, return_form=False):
215+
def str_to_array(encoded_json_str, tree_forms=False):
216216
"""
217217
Helper to reconstruct ak.Arrays from a JSON-formatted file-structure string.
218218
Returns an array mimicking TTrees and TBranches with correct field names and dtypes.
@@ -223,7 +223,7 @@ def str_to_array(encoded_json_str, return_form=False):
223223
Returns:
224224
ak.Array: An array containing a dictionary of trees with branch structures and dummy typed values.
225225
"""
226-
reconstructed_data = {}
226+
reconstructed_file_data = {}
227227
structure_dict = json.loads(encoded_json_str)
228228

229229
for treename, branch_dict in structure_dict.items():
@@ -249,12 +249,17 @@ def str_to_array(encoded_json_str, return_form=False):
249249
branches[branch_name] = ak.Array([dummy])
250250

251251
if branches:
252-
reconstructed_data[treename] = ak.Array([branches])
252+
reconstructed_file_data[treename] = ak.Array([branches])
253253

254-
if return_form:
255-
return ak.Array(reconstructed_data).layout.form
254+
if tree_forms:
255+
# Dictionary of each tree's RecordForm
256+
tree_forms = {
257+
tree: arr.layout.form for tree, arr in reconstructed_file_data.items()
258+
}
259+
return tree_forms
256260
else:
257-
return ak.Array(reconstructed_data).type
261+
# ak.Array type with all trees and branches
262+
return ak.Array(reconstructed_file_data).type
258263

259264

260265
def get_structure(datasets, array_out=False, **kwargs):
@@ -273,13 +278,13 @@ def get_structure(datasets, array_out=False, **kwargs):
273278
output = deliver(spec_python)
274279

275280
if array_out == True:
276-
all_arrays = {}
281+
all_requests = {}
277282
for sample, path in output.items():
278283
with uproot.open(path[0]) as f:
279284
structure_str = f["servicex"]["branch"].array()[0]
280-
sample_array = str_to_array(structure_str, **kwargs)
281-
all_arrays[sample] = sample_array
282-
return all_arrays
285+
ak_structure = str_to_array(structure_str, **kwargs)
286+
all_requests[sample] = ak_structure
287+
return all_requests
283288

284289
else:
285290
return print_structure_from_str(output, **kwargs)

0 commit comments

Comments
 (0)