ATLAS Offline Software
Loading...
Searching...
No Matches
SeparateEncodingFile.py
Go to the documentation of this file.
1#!/usr/bin/env python
2
3# Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
4import sys, argparse
5from TrigConfMuctpi.XMLReader import MioctGeometryXMLReader
6
7def readXML(filename):
8 return MioctGeometryXMLReader(filename)
9
10
11def mioctAsXML(mioct, depth, filter, stats):
12 attr = ["id", "slot"]
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'
15 sectorList = []
16 for sector in mioct.Sectors:
17 if not filter(sector):
18 continue
19 sectorList += [sector['name']]
20 s += sectorAsXML(sector, depth + 4, stats )
21 s += ' '*depth + "</%s>\n" % mioct.tag
22 s = s.replace('__SECTORS__', ", ".join(sorted(sectorList)) )
23 stats['sectors'] += len(sectorList)
24 return s
25
26
27def sectorAsXML(sector, depth, stats):
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'])):
33 s += roiAsXML(roi, depth + 4 )
34 s += ' '*depth + "</%s>\n" % sector.tag
35 stats['rois'] += len(sector.ROIs)
36 return s
37
38def roiAsXML(roi, depth):
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]) )
41 return s
42
43
44def writeXML(geometry, dettype):
45
46 if dettype != "RPC" and dettype != "TGC":
47 return
48
49 stats = {'miocts' : 0, 'sectors' : 0, 'rois' : 0}
50
51 infile = geometry.getFileName()
52 outfile = infile.replace(".","_%s." % dettype)
53
54 if dettype == 'RPC':
55 sectorFilter = lambda s : s['name'].startswith('B') # noqa: E731
56 else:
57 sectorFilter = lambda s : s['name'].startswith('E') or s['name'].startswith('F') # noqa: E731
58
59 f = open(outfile,"write")
60
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():
65 print(mioctAsXML(mioct, 4, sectorFilter, stats), file=f)
66
67 print("</%s>" % geometry.MuCTPiGeometry.tag, file=f)
68 stats['miocts'] = len(geometry.getMIOCTs())
69 print("Wrote %s" % outfile)
70
71 print("Numbers for %s" % dettype)
72 print("#MIOCTs : %i" % stats['miocts'])
73 print("#Sectors : %i" % stats['sectors'])
74 print("#ROIs : %i" % stats['rois'])
75
76 f.close()
77
78
79
80def main(args):
81
82 print("Using input %s" % args.infile)
83 geometry = readXML( args.infile )
84
85 writeXML(geometry, "RPC")
86 writeXML(geometry, "TGC")
87
88
89
90if __name__=="__main__":
91
92
93 parser = argparse.ArgumentParser( description=__doc__,
94 formatter_class = argparse.RawTextHelpFormatter)
95
96 parser.add_argument('-i', dest='infile', default="TrigConfMuctpi/TestMioctGeometry.xml", type=str,
97 help='name of input combined muon geometry file')
98
99 args = parser.parse_args()
100
101 #try:
102 sys.exit( main(args) )
103 #except Exception, ex:
104 # print "exception caught %r" % ex
105 # sys.exit(1)
void print(char *figname, TCanvas *c1)
int main()
Definition hello.cxx:18
mioctAsXML(mioct, depth, filter, stats)
sectorAsXML(sector, depth, stats)
writeXML(geometry, dettype)