File indexing completed on 2025-08-05 08:15:17
0001
0002
0003 import xml.etree.ElementTree
0004 from xml.dom import minidom
0005 import sys
0006 import re
0007
0008
0009 root = xml.etree.ElementTree.parse(sys.argv[1]).getroot()
0010
0011
0012 for pv in root.iter('physvol'):
0013
0014 posname = pv.find('positionref').attrib['ref']
0015
0016 posinfo = re.split(r'(\d+)in', posname.strip())
0017 pvname = posinfo[0] + posinfo[1]
0018
0019
0020 pv.attrib['name'] = pvname
0021
0022
0023 for lv in root.iter('volume'):
0024 if not 'Sensor' in lv.attrib['name']:
0025 continue
0026
0027 element = xml.etree.ElementTree.SubElement(lv, 'auxiliary')
0028 element.set('auxtype', 'SensDet')
0029 element.set('auxvalue', lv.attrib['name'])
0030
0031
0032 rough_string = xml.etree.ElementTree.tostring(root, 'utf-8')
0033 reparsed_string = minidom.parseString(rough_string).toprettyxml(indent = ' ', newl = '\n', encoding = 'utf-8')
0034
0035
0036 final_string = '\n'.join(line for line in reparsed_string.split('\n') if line.strip())
0037
0038
0039 fout = open(sys.argv[2], 'w')
0040 fout.write(final_string)
0041 fout.close()