Skip to content

Commit d5f8efe

Browse files
committed
Temporary implementation return form and type at Back-end level
1 parent ef39103 commit d5f8efe

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

servicex_analysis_utils/file_peeking.py

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,43 +39,35 @@ def run_query(input_filenames):
3939
import awkward as ak
4040
import json
4141

42-
def is_tree(obj):
43-
"""Helper to check if a root file item is TTree."""
44-
if hasattr(obj, "classname"):
45-
cls_attr = obj.classname
46-
cls_value = cls_attr() if callable(cls_attr) else cls_attr
47-
return "TTree" in cls_value
48-
elif hasattr(obj, "classnames"):
49-
cls_attr = obj.classnames
50-
cls_values = cls_attr() if callable(cls_attr) else cls_attr
51-
return any("TTree" in cls for cls in cls_values)
52-
return False
53-
5442
"""
55-
Opens a ROOT file and returns a JSON-formatted string describing the structure,
56-
encoded inside an ak.Array for ServiceX.
43+
Opens a ROOT file and returns a JSON-formatted string describing each tree's layout form and type.
44+
This function is ran by trasnformers in the ServiceX backend.
5745
"""
46+
5847
tree_dict = {}
5948

6049
with uproot.open(input_filenames) as file:
6150
for tree_name in file.keys():
6251
tree_name_clean = tree_name.rstrip(";1")
6352
tree = file[tree_name]
6453

65-
if not is_tree(tree):
54+
# Skip non-TTree objects
55+
if not hasattr(tree, "arrays"):
6656
continue
6757

68-
branch_dict = {}
69-
for branch_name, branch in tree.items():
70-
branch_type = str(branch.interpretation)
71-
branch_dict[branch_name] = branch_type
58+
# Load a minimal awkward array (only 1 event)
59+
try:
60+
array = tree.arrays(entry_stop=1, library="ak")
61+
except Exception:
62+
continue # In case array reading fails, skip tree
7263

73-
tree_dict[tree_name_clean] = branch_dict
64+
tree_dict[tree_name_clean] = {
65+
"form": array.layout.form.to_dict(), # full layout form
66+
"type": str(array.type), # human-readable type
67+
}
7468

75-
# Serialize tree_dict to JSON string
69+
# Serialize as JSON and wrap in ak.Array
7670
json_str = json.dumps(tree_dict)
77-
78-
# Return JSON string wrapped in an awkward array
7971
return ak.Array([json_str])
8072

8173

0 commit comments

Comments
 (0)