diff --git a/Control/AthenaConfiguration/python/iconfTool/iconfTool b/Control/AthenaConfiguration/python/iconfTool/iconfTool index c472ef6d3229d54e0c2b085eece2075732d15cb7..d63b1f1d1e4cd80be1362cf8e1f9318e4fb73f79 100755 --- a/Control/AthenaConfiguration/python/iconfTool/iconfTool +++ b/Control/AthenaConfiguration/python/iconfTool/iconfTool @@ -47,7 +47,7 @@ if __name__ == '__main__': checked_elements) gui_loader = DoublePad(loader) else: - loader = ComponentsFileLoader(args.input) + loader = ComponentsFileLoader(args.input, args) gui_loader = GuiLoader(loader) gui_loader.load_gui() diff --git a/Control/AthenaConfiguration/python/iconfTool/models/loaders.py b/Control/AthenaConfiguration/python/iconfTool/models/loaders.py index 94a9449094ed11ed5ee101c9c03b1d04026023e7..0ee3de4ad3cf6a151c50fdca9486a5d548944bd8 100755 --- a/Control/AthenaConfiguration/python/iconfTool/models/loaders.py +++ b/Control/AthenaConfiguration/python/iconfTool/models/loaders.py @@ -74,6 +74,14 @@ baseParser.add_argument( action="store_true" ) +baseParser.add_argument( + "--ignoreDefaultNamedComps", + help="""Ignores default handles that have full type specified. That is, if the setting is actually: Tool/A and the default value was just A, the Tool/A is assumed to be default and eliminated. + Beware that there is a caveat, the ignored class name may be actually different from the default (there is no way to check that in python).""", + action="store_true" +) + + baseParser.add_argument( "--shortenDefaultComponents", help="Automatically shorten componet names that have a default name i.e. ToolX/ToolX to ToolX. It helps comparing Run2 & Run3 configurations where these are handled differently", @@ -154,7 +162,7 @@ def renameComps(dic, args) -> Dict: conf[rename_comps(key)] = value return conf -def ignoreDefaults(dic, args) -> Dict: +def ignoreDefaults(allconf, args) -> Dict: name_to_type=dict() conf = {} @@ -167,7 +175,7 @@ def ignoreDefaults(dic, args) -> Dict: from AthenaConfiguration.ComponentFactory import CompFactory comp_cls = CompFactory.getComp(component_type) except Exception: - logger.debug("Could not find the configuration class %s no defaults for are eliminated", component_name) + logger.debug("Could not find the configuration class %s no defaults for it can be eliminated", component_name) return val_dict c = {} @@ -177,8 +185,10 @@ def ignoreDefaults(dic, args) -> Dict: else: default = str(comp_cls._descriptors[k].default) sv = str(v) - if default == sv or default.replace("StoreGateSvc+", "") == sv.replace("StoreGateSvc+", ""): - logger.debug("Dropped default value %s of property %s in %s", str(v), str(k), component_name) + if default == sv or default.replace("StoreGateSvc+", "") == sv.replace("StoreGateSvc+", ""): + logger.debug("Dropped default value %s of property %s in %s because the default is %s", sv, k, component_name, str(default)) + elif args.ignoreDefaultNamedComps and isinstance(v, str) and sv.endswith(f"/{default}"): + logger.debug("Dropped speculatively value %s of property %s in %s because the default it ends with %s", sv, k, component_name, str(default)) else: c[k] = v logger.debug("Keep value %s of property %s in %s because it is different from default %s", str(v), str(k), component_name, str(comp_cls._descriptors[k].default)) @@ -186,6 +196,7 @@ def ignoreDefaults(dic, args) -> Dict: # collect types for all componets (we look for A/B or lost of A/B strings) def collect_types(value): + """Updates name_to_type mapping""" parseable = False try: s = ast.literal_eval(str(value)) @@ -202,12 +213,12 @@ def ignoreDefaults(dic, args) -> Dict: if isinstance(value, dict): [ collect_types(v) for v in value.values() ] - for (key, value) in dic.items(): - collect_types(value) - for (key, value) in dic.items(): - remaining = drop_defaults(key, value) + for (comp_name, comp_settings) in allconf.items(): + collect_types(comp_settings) + for (comp_name, comp_settings) in allconf.items(): + remaining = drop_defaults(comp_name, comp_settings) if len(remaining) != 0: # ignore components that have only default settings - conf[key] = remaining + conf[comp_name] = remaining return conf def shortenDefaultComponents(dic, args) -> Dict: @@ -246,7 +257,7 @@ def loadConfigFile(fname, args) -> Dict: Supports reading: Pickled file with the CA or properties & JSON """ if args.debug: - print("Debugging info in ", logger.handlers[0].baseFilename) + print("Debugging info from reading ", fname, " in ", logger.handlers[0].baseFilename) logger.setLevel(logging.DEBUG) conf = {} @@ -324,15 +335,15 @@ def loadConfigFile(fname, args) -> Dict: return conf class ComponentsFileLoader: - def __init__(self, file_path: str, checked_elements=set()) -> None: + def __init__(self, file_path: str, args, checked_elements=set()) -> None: self.file_path: str = file_path self.checked_elements: Set[str] = checked_elements + self.args = args def _load_file_data(self) -> Dict: logger.info(f"Loading {self.file_path}") - return loadConfigFile(self.file_path) - with open(self.file_path, "rb") as f: - return dict(pickle.load(f)) + return loadConfigFile(self.file_path, self.args) + def load_structure(self) -> ComponentsStructure: data = self._load_file_data() diff --git a/Control/AthenaConfiguration/share/confTool.py b/Control/AthenaConfiguration/share/confTool.py index 6272a35a28e2111ad9c6505c9a61dace285698f9..b9763596a0640f251f151f9d23a30ecde2597665 100755 --- a/Control/AthenaConfiguration/share/confTool.py +++ b/Control/AthenaConfiguration/share/confTool.py @@ -4,8 +4,6 @@ # Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration # -from __future__ import print_function - import ast import json import pickle