@@ -62,19 +62,23 @@ def is_tree(obj):
62
62
63
63
with uproot .open (input_filenames ) as file :
64
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
-
71
65
for tree_name in file .keys ():
72
66
tree_name_clean = tree_name .rstrip (";1" )
73
67
tree = file [tree_name ]
74
68
75
69
if not is_tree (tree ):
76
70
continue
77
71
72
+ if tree_name_clean == "Metadata" :
73
+ fm_branches = [
74
+ b for b in tree .keys () if b .startswith ("FileMetaDataAuxDyn." )
75
+ ]
76
+ # remove the prefix in keys
77
+ meta_dict = {
78
+ p [19 :]: str (tree [p ].array (library = "ak" )[0 ]) for p in fm_branches
79
+ }
80
+ tree_dict ["FileMetaData" ] = meta_dict
81
+
78
82
branch_dict = {}
79
83
for branch_name , branch in tree .items ():
80
84
branch_type = str (branch .interpretation )
@@ -199,8 +203,11 @@ def print_structure_from_str(
199
203
200
204
# Get the metadata first
201
205
output_lines .append (f"\n File Metadata \u2139 \ufe0f :\n " )
202
- for key , value in structure_dict .get ("FileMetaData" , {}).items ():
203
- output_lines .append (f"── { key } : { value } " )
206
+ if "FileMetaData" not in structure_dict :
207
+ output_lines .append ("No FileMetaData found in dataset." )
208
+ else :
209
+ for key , value in structure_dict .get ("FileMetaData" , {}).items ():
210
+ output_lines .append (f"── { key } : { value } " )
204
211
output_lines .append ("\n ---------------------------" )
205
212
206
213
# drop the File metadata from the trees
@@ -278,6 +285,8 @@ def str_to_array(encoded_json_str):
278
285
"""
279
286
reconstructed_data = {}
280
287
structure_dict = json .loads (encoded_json_str )
288
+ # drop the File metadata from the trees
289
+ structure_dict .pop ("FileMetaData" , {})
281
290
282
291
for treename , branch_dict in structure_dict .items ():
283
292
branches = {}
0 commit comments