Skip to content

Commit 020be35

Browse files
committed
New section in run_query and print structure to retrieve metadata
1 parent f286db0 commit 020be35

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

servicex_analysis_utils/file_peeking.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
from servicex.dataset_identifier import DataSetIdentifier
3636

3737

38-
def run_query(input_filenames):
38+
def run_query(
39+
input_filenames,
40+
):
3941
import uproot
4042
import awkward as ak
4143
import json
@@ -59,6 +61,13 @@ def is_tree(obj):
5961
tree_dict = {}
6062

6163
with uproot.open(input_filenames) as file:
64+
65+
meta = file["MetaData"]
66+
fm_branches = [b for b in meta.keys() if b.startswith("FileMetaDataAuxDyn.")]
67+
# remove the prefix in keys
68+
meta_dict = {p[19:]: str(meta[p].array(library="ak")[0]) for p in fm_branches}
69+
tree_dict["FileMetaData"] = meta_dict
70+
6271
for tree_name in file.keys():
6372
tree_name_clean = tree_name.rstrip(";1")
6473
tree = file[tree_name]
@@ -174,9 +183,6 @@ def print_structure_from_str(
174183
import json
175184

176185
output_lines = []
177-
output_lines.append(
178-
f"\nFile structure of all samples with branch filter '{filter_branch}':"
179-
)
180186

181187
for sample_name, path in deliver_dict.items():
182188
structure_str = open_delivered_file(sample_name, path)
@@ -191,6 +197,19 @@ def print_structure_from_str(
191197
f"---------------------------"
192198
)
193199

200+
# Get the metadata first
201+
output_lines.append(f"\nFile Metadata \u2139\ufe0f :\n")
202+
for key, value in structure_dict.get("FileMetaData", {}).items():
203+
output_lines.append(f"── {key}: {value}")
204+
output_lines.append("\n---------------------------")
205+
206+
# drop the File metadata from the trees
207+
structure_dict.pop("FileMetaData", {})
208+
209+
output_lines.append(
210+
f"\nFile structure with branch filter \U0001f33f '{filter_branch}':\n"
211+
)
212+
194213
for tree_name, branches in structure_dict.items():
195214
output_lines.append(f"\n\U0001f333 Tree: {tree_name}")
196215
output_lines.append(" ├── Branches:")

0 commit comments

Comments
 (0)