FairShip
Loading...
Searching...
No Matches
config_tester.py
Go to the documentation of this file.
1#!/usr/bin/env python
2# SPDX-License-Identifier: LGPL-3.0-or-later
3# SPDX-FileCopyrightText: Copyright CERN for the benefit of the SHiP Collaboration
4
5import argparse
6import importlib.util
7import json
8import logging
9import os
10
11logging.info("")
12logger = logging.getLogger()
13logger.setLevel(logging.INFO)
14
15
17 ap = argparse.ArgumentParser(description="test configuration file")
18 ap.add_argument("-d", "--debug", action="store_true")
19 ap.add_argument(
20 "-p", "--params", type=json.loads, help="""config parameters in json form '{"a": 1, "b": 2}' """, default={}
21 )
22
23 ap.add_argument("config_file", help="config file to test")
24 args = ap.parse_args()
25 if args.debug:
26 logger.setLevel(logging.DEBUG)
27 assert os.path.exists(args.config_file)
28 return args
29
30
31def main(arguments):
32 logger.info("file: %s" % arguments.config_file)
33 if arguments.params:
34 logger.info("parameters: %s" % arguments.params)
35
36 # Load the geometry config module
37 spec = importlib.util.spec_from_file_location("geometry_config", arguments.config_file)
38 if spec is None or spec.loader is None:
39 raise ImportError(f"Could not load geometry config from {arguments.config_file}")
40 geometry_config = importlib.util.module_from_spec(spec)
41 spec.loader.exec_module(geometry_config)
42
43 # Create config with parameters
44 config = geometry_config.create_config(**arguments.params)
45
46 # Print configuration
47 for k, v in config.items():
48 print(f"{k}: {v}")
49
50
51if __name__ == "__main__":
create_config(str DecayVolumeMedium="helium", float Yheight=6.0, int strawDesign=10, str shieldName="TRY_2026", int nuTargetPassive=1, bool SND=True, SND_design=None, TARGET_YAML=None)