4 from __future__
import print_function
6 from TrigConfMuctpi.XMLReader
import MioctGeometryXMLReader
9 return MioctGeometryXMLReader(filename)
14 s =
' '*depth +
"<%s %s>\n" % (mioct.tag,
" ".
join([
'%s="%s"' % (a, mioct[a])
for a
in attr]) )
15 s +=
' '*depth +
' <!-- contains sectors __SECTORS__ -->\n'
17 for sector
in mioct.Sectors:
20 sectorList += [sector[
'name']]
22 s +=
' '*depth +
"</%s>\n" % mioct.tag
23 s = s.replace(
'__SECTORS__',
", ".
join(
sorted(sectorList)) )
24 stats[
'sectors'] += len(sectorList)
29 attr = [
"connector",
"name"]
30 s =
' '*depth +
"<%s %s>\n" % (sector.tag,
" ".
join([
'%s="%s"' % (a, sector[a])
for a
in attr]) )
31 s +=
' '*depth +
' <!-- contains %i ROIs -->\n' % len(sector.ROIs)
32 s +=
' '*depth +
' <!-- mapping from ROI to coding scheme -->\n'
33 for roi
in sorted(sector.ROIs, key=
lambda roi:
int(roi[
'roiid'])):
35 s +=
' '*depth +
"</%s>\n" % sector.tag
36 stats[
'rois'] += len(sector.ROIs)
40 attr = [
"eta",
"phi",
"etacode",
"phicode",
"etamin",
"etamax",
"phimin",
"phimax",
"roiid"]
41 s =
' ' * depth +
"<ROI %s/>\n" % (
" ".
join([
'%s="%s"' % (a, roi[a])
for a
in attr]) )
47 if dettype !=
"RPC" and dettype !=
"TGC":
50 stats = {
'miocts' : 0,
'sectors' : 0,
'rois' : 0}
52 infile = geometry.getFileName()
53 outfile = infile.replace(
".",
"_%s." % dettype)
56 sectorFilter =
lambda s : s[
'name'].startswith(
'B')
58 sectorFilter =
lambda s : s[
'name'].startswith(
'E')
or s[
'name'].startswith(
'F')
60 f =
open(outfile,
"write")
62 print(
'<?xml version="1.0" ?>\n', file=f)
63 print(
'<!DOCTYPE MuCTPiGeometry SYSTEM "MUCTPIGeometry.dtd">\n', file=f)
64 print(geometry.MuCTPiGeometry, file=f)
65 for mioct
in geometry.getMIOCTs():
68 print(
"</%s>" % geometry.MuCTPiGeometry.tag, file=f)
69 stats[
'miocts'] = len(geometry.getMIOCTs())
70 print(
"Wrote %s" % outfile)
72 print(
"Numbers for %s" % dettype)
73 print(
"#MIOCTs : %i" % stats[
'miocts'])
74 print(
"#Sectors : %i" % stats[
'sectors'])
75 print(
"#ROIs : %i" % stats[
'rois'])
83 print(
"Using input %s" % args.infile)
84 geometry =
readXML( args.infile )
91 if __name__==
"__main__":
94 parser = argparse.ArgumentParser( description=__doc__,
95 formatter_class = argparse.RawTextHelpFormatter)
97 parser.add_argument(
'-i', dest=
'infile', default=
"TrigConfMuctpi/TestMioctGeometry.xml", type=str,
98 help=
'name of input combined muon geometry file')
100 args = parser.parse_args()
103 sys.exit(
main(args) )