forked from acts-project/acts
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathconfigureMap.py
More file actions
152 lines (139 loc) · 6.83 KB
/
configureMap.py
File metadata and controls
152 lines (139 loc) · 6.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# This file is part of the ACTS project.
#
# Copyright (C) 2016 CERN for the benefit of the ACTS project
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
import json
import sys
# Should be run with Python 3 if possible
# Script that use the json config file to configure the Json surfaces map for the material mapping
# Take two arguments in input : The path to the surfaces map and the path of the json config file
# By default the inputs are : 'geometry-map.json' and 'config-map.json'
# The config file can be used to define a binning for all the surfaces in a given volume
# It can also be used to define the binning for volume mapping
if sys.version_info[0] < 3:
print("Using Python 2")
print("To obtain the proper ordering in the Json files Python 3 is recomanded")
if len(sys.argv) < 2:
inFileName = "geometry-map.json"
confFileName = "config-map.json"
if len(sys.argv) < 3:
confFileName = "config-map.json"
else:
inFileName = sys.argv[1]
confFileName = sys.argv[2]
with open(inFileName, "r+") as json_file:
with open(confFileName, "r") as config_file:
config = json.load(config_file)
data = json.load(json_file)
for entry in data["Surfaces"]["entries"]:
if "type" not in entry["value"]["bounds"]:
entry["value"]["bounds"]["type"] = ""
if "layer" in entry:
if "approach" not in entry:
if "sensitive" not in entry:
for conf in config["Surfaces"][str(entry["volume"])]:
if (
"layer" in conf
and conf["layer"] == "X"
and conf["value"]["bounds"]["type"]
== entry["value"]["bounds"]["type"]
):
entry["value"]["material"]["mapMaterial"] = conf[
"value"
]["material"]["mapMaterial"]
entry["value"]["material"]["mappingType"] = conf[
"value"
]["material"]["mappingType"]
ibin = 0
for bin in entry["value"]["material"]["binUtility"][
"binningdata"
]:
bin["bins"] = conf["value"]["material"][
"binUtility"
]["binningdata"][ibin]["bins"]
ibin = ibin + 1
continue
continue
if "boundary" in entry:
if "layer" not in entry:
for conf in config["Surfaces"][str(entry["volume"])]:
if (
"boundary" in conf
and conf["boundary"] == entry["boundary"]
and conf["value"]["bounds"]["type"]
== entry["value"]["bounds"]["type"]
):
entry["value"]["material"]["mapMaterial"] = conf["value"][
"material"
]["mapMaterial"]
entry["value"]["material"]["mappingType"] = conf["value"][
"material"
]["mappingType"]
ibin = 0
for bin in entry["value"]["material"]["binUtility"][
"binningdata"
]:
bin["bins"] = conf["value"]["material"]["binUtility"][
"binningdata"
][ibin]["bins"]
ibin = ibin + 1
continue
continue
if "approach" in entry:
if "sensitive" not in entry:
for conf in config["Surfaces"][str(entry["volume"])]:
if (
"approach" in conf
and conf["approach"] == entry["approach"]
and conf["value"]["bounds"]["type"]
== entry["value"]["bounds"]["type"]
):
entry["value"]["material"]["mapMaterial"] = conf["value"][
"material"
]["mapMaterial"]
entry["value"]["material"]["mappingType"] = conf["value"][
"material"
]["mappingType"]
ibin = 0
for bin in entry["value"]["material"]["binUtility"][
"binningdata"
]:
bin["bins"] = conf["value"]["material"]["binUtility"][
"binningdata"
][ibin]["bins"]
ibin = ibin + 1
continue
continue
if "sensitive" in entry:
if "approach" not in entry:
for conf in config["Surfaces"][str(entry["volume"])]:
if (
"sensitive" in conf
and conf["sensitive"] == "X"
and conf["layer"] == entry["layer"]
and conf["value"]["bounds"]["type"]
== entry["value"]["bounds"]["type"]
):
entry["value"]["material"]["mapMaterial"] = conf["value"][
"material"
]["mapMaterial"]
entry["value"]["material"]["mappingType"] = conf["value"][
"material"
]["mappingType"]
ibin = 0
for bin in entry["value"]["material"]["binUtility"][
"binningdata"
]:
bin["bins"] = conf["value"]["material"]["binUtility"][
"binningdata"
][ibin]["bins"]
ibin = ibin + 1
continue
continue
data["Volumes"] = config["Volumes"]
json_file.seek(0)
json.dump(data, json_file, indent=4)
json_file.truncate()