From 950773177a63945b65094e9dd8e80f433c5c35a5 Mon Sep 17 00:00:00 2001 From: Roel Aaij <roel.aaij@cern.ch> Date: Fri, 1 Mar 2024 15:47:38 +0100 Subject: [PATCH] Allow allen.py to configure from python options --- Dumpers/BinaryDumpers/options/allen.py | 27 ++++++++++++++++++++++---- Rec/Allen/python/Allen/config.py | 3 ++- Rec/Allen/python/Allen/tck.py | 6 ++++-- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Dumpers/BinaryDumpers/options/allen.py b/Dumpers/BinaryDumpers/options/allen.py index d544b1b11ba..978830d4e88 100755 --- a/Dumpers/BinaryDumpers/options/allen.py +++ b/Dumpers/BinaryDumpers/options/allen.py @@ -13,6 +13,8 @@ import os import sys import zmq import re +import json +from pathlib import Path from Configurables import ApplicationMgr from Configurables import Gaudi__RootCnvSvc as RootCnvSvc @@ -163,6 +165,14 @@ parser.add_argument( dest="bindings", action="store_false", default=True) +parser.add_argument( + "--python-hlt1-node", + type=str, + help= + "Name of the variable that stores the configuration in the python module or file", + default="hlt1_node", + dest="hlt1_node", +) args = parser.parse_args() @@ -215,10 +225,10 @@ rootSvc = RootCnvSvc("RootCnvSvc", EnableIncident=1) ApplicationMgr().ExtSvc += ["Gaudi::IODataManager/IODataManager", rootSvc] # Get Allen JSON configuration -sequence = os.path.expandvars(args.sequence) +sequence = Path(os.path.expandvars(args.sequence)) sequence_json = "" tck_option = re.compile(r"([^:]+):(0x[a-fA-F0-9]{8})") -if (m := tck_option.match(sequence)): +if (m := tck_option.match(str(sequence))): from Allen.tck import sequence_from_git, dependencies_from_build_manifest import json @@ -241,9 +251,18 @@ if (m := tck_option.match(sequence)): print( f"Loaded TCK {tck} with sequence type {tck_info['type']} and label {tck_info['label']}." ) -else: - with open(sequence) as f: +elif sequence.suffix in (".py", ""): + from Allen.tck import sequence_from_python + from AllenCore.configuration_options import is_allen_standalone + is_allen_standalone.global_bind(standalone=True) + sequence_json = json.dumps( + sequence_from_python(sequence, node_name=args.hlt1_node, verbose=True), + sort_keys=True) +elif sequence.suffix in (".json", ): + with sequence.open() as f: sequence_json = f.read() +else: + raise ValueError(f"Unknown type of sequence specified: {str(sequence)}") if args.mep: extSvc += ["AllenConfiguration", "MEPProvider"] diff --git a/Rec/Allen/python/Allen/config.py b/Rec/Allen/python/Allen/config.py index 5c1fe4ec3b3..703813ab58d 100755 --- a/Rec/Allen/python/Allen/config.py +++ b/Rec/Allen/python/Allen/config.py @@ -95,7 +95,8 @@ def allen_detectors(allen_node): def configured_bank_types(sequence_json): - sequence_json = json.loads(sequence_json) + if type(sequence_json) == str: + sequence_json = json.loads(sequence_json) bank_types = set() for t, n, c in sequence_json["sequence"]["configured_algorithms"]: props = sequence_json.get(n, {}) diff --git a/Rec/Allen/python/Allen/tck.py b/Rec/Allen/python/Allen/tck.py index a854f536093..fb013e13681 100644 --- a/Rec/Allen/python/Allen/tck.py +++ b/Rec/Allen/python/Allen/tck.py @@ -202,7 +202,9 @@ def json_tck_db(configuration: dict, sequence_type: str, metadata: dict, return {"manifest": manifest, digest: tck_config} -def sequence_from_python(python_file: Path, node_name="hlt1_node") -> dict: +def sequence_from_python(python_file: Path, + node_name="hlt1_node", + verbose=False) -> dict: """Retrieve an Allen configuration in JSON format from a python module """ @@ -231,7 +233,7 @@ def sequence_from_python(python_file: Path, node_name="hlt1_node") -> dict: f"Failed to get {node_name} from sequence file {str(python_file)}") return None - algorithms = build_sequence(node, verbose=False) + algorithms = build_sequence(node, verbose=verbose) return generate_json_configuration(algorithms) -- GitLab