64 filename = os.path.basename(sys.argv[1]).
replace(
'.dat',
'.xml')
65 xml =
open(filename,
"w")
66 print(
'<?xml version="1.0" ?>\n', file=xml)
67 print(
'<!DOCTYPE MuCTPiGeometry SYSTEM "MUCTPIGeometry.dtd">\n', file=xml)
68 print(
'<MuCTPiGeometry>', file=xml)
69 for mioct
in sorted(g.keys()):
72 allSectorNames =
set()
73 for sector
in g[mioct].
values():
74 allSlots.update( [e.slot
for e
in sector] )
75 allSectorNames.update( [e.sectorname
for e
in sector] )
76 if len(allSlots) != 1:
77 raise RuntimeError(
"More than one slot defined for MIOCT %i" % mioct)
79 allSectorNames =
sorted(
list( allSectorNames ))
81 print(
' <MIOCT id="%i" slot="%s">' % ( mioct, slot ), file=xml)
82 print(
' <!-- contains sectors %s -->' %
", ".
join(allSectorNames), file=xml)
84 sector =
sorted(g[mioct][connector], key=attrgetter(
'eta',
'phi',
'etacode',
'phicode'))
85 print(
' <Sector connector="%s" name="%s">' % (connector,
", ".
join(
set([
str(e.sectorname)
for e
in sector])) ), file=xml)
86 print(
' <!-- contains %i ROIs -->' % len(sector), file=xml)
87 print(
' <!-- mapping from ROI to coding scheme -->', file=xml)
89 print(
' <ROI eta="%f" phi="%f" etacode="%s" phicode="%s" etamin="%f" etamax="%f" phimin="%f" phimax="%f" roiid="%i"/>' % (e.eta, e.phi, e.etacode, e.phicode, e.etamin, e.etamax, e.phimin, e.phimax, e.roi), file=xml)
90 print(
' </Sector>', file=xml)
93 map(allROIsInMIOCT.extend, g[mioct].
values())
95 print(
' <Decode>', file=xml)
97 for (eta_code,phi_code), rois
in groupby(
sorted(allROIsInMIOCT,key=attrgetter(
'etacode',
'phicode')), key=attrgetter(
'etacode',
'phicode')):
101 print(
' <TopoCell etacode="%s" phicode="%s" eta="%f" phi="%f" ieta="%i" iphi="%i" etamin="%f" etamax="%f" phimin="%f" phimax="%f"/>' % (eta_code, phi_code, eta, phi, ieta, iphi, etamin, etamax, phimin, phimax), file=xml)
102 print(
' </Decode>', file=xml)
103 print(
' </MIOCT>', file=xml)
105 print(
' <PtEncoding>', file=xml)
106 print(
' <PtCodeElement pt="1" code="0" value="4"/>', file=xml)
107 print(
' <PtCodeElement pt="2" code="1" value="6"/>', file=xml)
108 print(
' <PtCodeElement pt="3" code="2" value="10"/>', file=xml)
109 print(
' <PtCodeElement pt="4" code="2" value="11"/>', file=xml)
110 print(
' <PtCodeElement pt="5" code="2" value="15"/>', file=xml)
111 print(
' <PtCodeElement pt="6" code="2" value="20"/>', file=xml)
112 print(
' </PtEncoding>', file=xml)
113 print(
'</MuCTPiGeometry>', file=xml)
115 print(
"Wrote %s" % filename)