8 from PyUtils.MetaReader
import read_metadata
9 from typing
import Dict, List
11 logging.basicConfig(level=logging.INFO, format=
"%(levelname)s: %(message)s")
15 metadata: Dict[str, any], keys_prefixes: List[str]
18 Filters a dictionary to include only keys that start with any of the specified prefixes.
21 metadata (dict): The dictionary to filter.
22 keys_prefixes (list): A list of prefixes to include in the filtered dictionary.
25 dict: The filtered dictionary.
27 filtered_metadata: Dict[str, any] = {}
28 for key, value
in metadata.items():
29 for prefix
in keys_prefixes:
30 if key.startswith(prefix):
31 filtered_metadata[prefix] = value
33 return filtered_metadata
38 rntuple_file_path: str,
39 keys_to_compare: List[str],
40 fmd_keys_to_compare: List[str],
43 Compares metadata from two files to check if they are the same.
46 ttree_file_path (str): The path to the first metadata file.
47 rntuple_file_path (str): The path to the second metadata file.
48 keys_to_compare (list): List of keys to compare in the metadata.
49 fmd_keys_to_compare (list): List of keys to compare in the 'FileMetaData' section.
52 int: 0 if metadata is the same, 1 if metadata is different.
57 ttree_file_path, mode=
"full"
60 ttree_file_path, mode=
"peeker"
64 rntuple_metadata_full: Dict[str, any] =
read_metadata(rntuple_file_path)[
69 logging.error(f
"Error accessing metadata for file: {e}")
74 ttree_metadata_full, [
"EventFormat"]
77 ttree_metadata_peeker, keys_to_compare
80 rntuple_metadata_full, keys_to_compare
83 rntuple_metadata_full, [
"EventFormat"]
88 ttree_peeker_metadata.get(
"FileMetaData", {}), fmd_keys_to_compare
91 rntuple_metadata.get(
"FileMetaData", {}), fmd_keys_to_compare
96 ttree_peeker_metadata == rntuple_metadata
97 and ttree_event_format_metadata == rntuple_event_format_metadata
100 f
"Selected metadata keys ({keys_to_compare=}, {fmd_keys_to_compare=}) are the same"
105 f
"Selected metadata keys ({keys_to_compare=}, {fmd_keys_to_compare=}) are different"
111 parser = argparse.ArgumentParser(description=
"Compare metadata between two files.")
116 help=
"Path to the TTree metadata file.",
119 "--rntuple-file-path",
122 help=
"Path to the RNTuple metadata file.",
129 help=
"List of keys to compare in the metadata. Provide as space-separated values.",
132 "--fmd-keys-to-compare",
136 help=
"List of keys to compare in the 'FileMetaData' section. Provide as space-separated values.",
139 args = parser.parse_args()
143 args.ttree_file_path,
144 args.rntuple_file_path,
145 args.keys_to_compare,
146 args.fmd_keys_to_compare,
151 if __name__ ==
"__main__":