5 from TrigConfMuctpi.XMLReader
import MioctGeometryXMLReader
8 return MioctGeometryXMLReader(filename)
13 s =
' '*depth +
"<%s %s>\n" % (mioct.tag,
" ".
join([
'%s="%s"' % (a, mioct[a])
for a
in attr]) )
14 s +=
' '*depth +
' <!-- contains sectors __SECTORS__ -->\n'
16 for sector
in mioct.Sectors:
19 sectorList += [sector[
'name']]
21 s +=
' '*depth +
"</%s>\n" % mioct.tag
22 s = s.replace(
'__SECTORS__',
", ".
join(
sorted(sectorList)) )
23 stats[
'sectors'] += len(sectorList)
28 attr = [
"connector",
"name"]
29 s =
' '*depth +
"<%s %s>\n" % (sector.tag,
" ".
join([
'%s="%s"' % (a, sector[a])
for a
in attr]) )
30 s +=
' '*depth +
' <!-- contains %i ROIs -->\n' % len(sector.ROIs)
31 s +=
' '*depth +
' <!-- mapping from ROI to coding scheme -->\n'
32 for roi
in sorted(sector.ROIs, key=
lambda roi:
int(roi[
'roiid'])):
34 s +=
' '*depth +
"</%s>\n" % sector.tag
35 stats[
'rois'] += len(sector.ROIs)
39 attr = [
"eta",
"phi",
"etacode",
"phicode",
"etamin",
"etamax",
"phimin",
"phimax",
"roiid"]
40 s =
' ' * depth +
"<ROI %s/>\n" % (
" ".
join([
'%s="%s"' % (a, roi[a])
for a
in attr]) )
46 if dettype !=
"RPC" and dettype !=
"TGC":
49 stats = {
'miocts' : 0,
'sectors' : 0,
'rois' : 0}
51 infile = geometry.getFileName()
52 outfile = infile.replace(
".",
"_%s." % dettype)
55 sectorFilter =
lambda s : s[
'name'].startswith(
'B')
57 sectorFilter =
lambda s : s[
'name'].startswith(
'E')
or s[
'name'].startswith(
'F')
59 f =
open(outfile,
"write")
61 print(
'<?xml version="1.0" ?>\n', file=f)
62 print(
'<!DOCTYPE MuCTPiGeometry SYSTEM "MUCTPIGeometry.dtd">\n', file=f)
63 print(geometry.MuCTPiGeometry, file=f)
64 for mioct
in geometry.getMIOCTs():
67 print(
"</%s>" % geometry.MuCTPiGeometry.tag, file=f)
68 stats[
'miocts'] = len(geometry.getMIOCTs())
69 print(
"Wrote %s" % outfile)
71 print(
"Numbers for %s" % dettype)
72 print(
"#MIOCTs : %i" % stats[
'miocts'])
73 print(
"#Sectors : %i" % stats[
'sectors'])
74 print(
"#ROIs : %i" % stats[
'rois'])
82 print(
"Using input %s" % args.infile)
83 geometry =
readXML( args.infile )
90 if __name__==
"__main__":
93 parser = argparse.ArgumentParser( description=__doc__,
94 formatter_class = argparse.RawTextHelpFormatter)
96 parser.add_argument(
'-i', dest=
'infile', default=
"TrigConfMuctpi/TestMioctGeometry.xml", type=str,
97 help=
'name of input combined muon geometry file')
99 args = parser.parse_args()
102 sys.exit(
main(args) )