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
5
import
argparse
6
import
importlib.util
7
import
json
8
import
logging
9
import
os
10
11
logging.info(
""
)
12
logger = logging.getLogger()
13
logger.setLevel(logging.INFO)
14
15
16
def
parse_arguments
():
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
31
def
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
51
if
__name__ ==
"__main__"
:
52
main
(
parse_arguments
())
config_tester.parse_arguments
parse_arguments()
Definition
config_tester.py:16
geometry_config.create_config
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)
Definition
geometry_config.py:133
main
int main()
Definition
test_acts_straw_geometry.cxx:114
geometry
config_tester.py
Generated by
Doxygen
1.15.0