5 Generate basic <map> section for SHE DSSD for the new pixie_ldf_c Config.xml file 6 based on old style map.txt 12 """Test how the data are loaded from map.txt file""" 14 print(
'Module: ', module[
'number'])
15 for channel
in module[
'channels']:
16 print(
' Ch: {} Loc: {} T: {} S: {}'.format(channel[
'number'],
20 print(
' cal: {}'.format(channel[
'calibration']))
23 if __name__ ==
'__main__':
26 with open(
"map.txt")
as map_file:
32 if line.startswith(
'%')
or len(line) < 1:
39 det_subtype = fields[4]
41 channel = {
'number': ch,
44 'subtype' : det_subtype}
46 module = {
'number' : mod,
'channels' : []}
47 elif module[
'number'] != mod:
49 module = {
'number' : mod,
'channels' : []}
50 module[
'channels'].append(channel)
53 with open(
"cal.txt")
as cal_file:
58 if line.startswith(
'%')
or len(line) < 1:
63 det_subtype = fields[2]
72 for channel
in module[
'channels']:
73 if (channel[
'type'] == det_type
and 74 channel[
'subtype'] == det_subtype
and 75 channel[
'location'] == loc):
76 channel.update({
'calibration' : [a0, a1]})
81 print(
'Could not find channel: type {} subtype {} loc {}'.
82 format(det_type, det_subtype, loc))
86 out = open(
'out.xml',
'w')
87 dom = xml.dom.minidom.getDOMImplementation()
88 table = dom.createDocument(
None,
"Map",
None)
89 root = table.documentElement
92 module = table.createElement(
"Module")
93 module.setAttribute(
"number", m[
'number'])
94 for c
in m[
'channels']:
95 channel = table.createElement(
"Channel")
97 channel.setAttribute(
"aa_number", c[
'number'])
98 channel.setAttribute(
"type", c[
'type'])
99 channel.setAttribute(
"subtype", c[
'subtype'])
100 channel.setAttribute(
"location", c[
'location'])
101 calibration = table.createElement(
"Calibration")
102 calibration.setAttribute(
"model",
"linear")
103 calibration.setAttribute(
"max", str(32000))
104 text_element = table.createTextNode(
'{} {}'.
105 format(c[
'calibration'][0], c[
'calibration'][1]))
106 calibration.appendChild(text_element)
107 channel.appendChild(calibration)
108 module.appendChild(channel)
109 root.appendChild(module)
112 table.toprettyxml(indent=
" ", encoding=
"utf-8").decode(
"utf-8"))