forked from acts-project/acts
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathwriteMapConfig.py
More file actions
130 lines (113 loc) · 4.59 KB
/
writeMapConfig.py
File metadata and controls
130 lines (113 loc) · 4.59 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
# 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 parse a Json surfaces map to create an easy to use json config file for the mapping
# Take two arguments in input : The path to the surfaces map and the path of the json config file
# By default the input is : 'geometry-map.json' and the output is : '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
def getSurfaceMaterial(mat):
outputmat = {}
value = {}
material = {}
bound = {}
outputmat["volume"] = mat["volume"]
if "boundary" in mat:
outputmat["boundary"] = mat["boundary"]
if "layer" in mat:
if "approach" not in entry:
if "sensitive" not in entry:
outputmat["layer"] = "X"
if "approach" in mat:
outputmat["approach"] = mat["approach"]
if "sensitive" in mat:
outputmat["layer"] = mat["layer"]
outputmat["sensitive"] = "X"
material["binUtility"] = mat["value"]["material"]["binUtility"]
material["mapMaterial"] = False
material["mappingType"] = mat["value"]["material"]["mappingType"]
bound["type"] = mat["value"]["bounds"]["type"]
value["material"] = material
value["bounds"] = bound
outputmat["value"] = value
return outputmat
if sys.version_info[0] < 3:
print("Using Python 2")
print("To obtain the proper ordering in the Json files Python 3 is recommended")
if len(sys.argv) < 2:
inFileName = "geometry-map.json"
else:
inFileName = sys.argv[1]
with open(inFileName, "r") as json_file:
config = {}
config["Surfaces"] = {}
data = json.load(json_file)
lastVol = -1
for entry in data["Surfaces"]["entries"]:
if lastVol != entry["volume"]:
if lastVol != -1:
config["Surfaces"][lastVol] = vconfig
vconfig = []
lastVol = entry["volume"]
typeLayer = []
createdApproach1 = False
createdApproach2 = False
typeSensitive = {}
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:
if entry["value"]["bounds"]["type"] not in typeLayer:
typeLayer.append(entry["value"]["bounds"]["type"])
surface = getSurfaceMaterial(entry)
vconfig.append(surface)
continue
if "boundary" in entry:
if "layer" not in entry:
surface = getSurfaceMaterial(entry)
vconfig.append(surface)
continue
if "approach" in entry:
if "sensitive" not in entry:
if entry["approach"] == 1 and createdApproach1 == False:
createdApproach1 = True
surface = getSurfaceMaterial(entry)
vconfig.append(surface)
continue
if entry["approach"] == 2 and createdApproach2 == False:
createdApproach2 = True
surface = getSurfaceMaterial(entry)
vconfig.append(surface)
continue
if "sensitive" in entry:
if "approach" not in entry:
if entry["value"]["material"]["binUtility"]["binningdata"] != None:
if not entry["layer"] in typeSensitive:
typeSensitive[entry["layer"]] = []
if (
entry["value"]["bounds"]["type"]
not in typeSensitive[entry["layer"]]
):
typeSensitive[entry["layer"]].append(
entry["value"]["bounds"]["type"]
)
surface = getSurfaceMaterial(entry)
vconfig.append(surface)
continue
if lastVol != -1:
config["Surfaces"][lastVol] = vconfig
config["Volumes"] = data["Volumes"]
if len(sys.argv) < 3:
outFileName = "config-map.json"
else:
outFileName = sys.argv[2]
with open(outFileName, "w") as outfile:
json.dump(config, outfile, indent=4)