ATLAS Offline Software
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
4 import sys, argparse
5 from TrigConfMuctpi.XMLReader import MioctGeometryXMLReader
6 
7 def readXML(filename):
8  return MioctGeometryXMLReader(filename)
9 
10 
11 def 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 
27 def 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 
38 def 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 
44 def 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 
80 def 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 
90 if __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)
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename R::value_type > sorted(const R &r, PROJ proj={})
Helper function to create a sorted vector from an unsorted range.
SeparateEncodingFile.mioctAsXML
def mioctAsXML(mioct, depth, filter, stats)
Definition: SeparateEncodingFile.py:11
covarianceTool.filter
filter
Definition: covarianceTool.py:514
SeparateEncodingFile.main
def main(args)
Definition: SeparateEncodingFile.py:80
print
void print(char *figname, TCanvas *c1)
Definition: TRTCalib_StrawStatusPlots.cxx:25
TCS::join
std::string join(const std::vector< std::string > &v, const char c=',')
Definition: Trigger/TrigT1/L1Topo/L1TopoCommon/Root/StringUtils.cxx:10
SeparateEncodingFile.sectorAsXML
def sectorAsXML(sector, depth, stats)
Definition: SeparateEncodingFile.py:27
SeparateEncodingFile.writeXML
def writeXML(geometry, dettype)
Definition: SeparateEncodingFile.py:44
Trk::open
@ open
Definition: BinningType.h:40
python.CaloAddPedShiftConfig.int
int
Definition: CaloAddPedShiftConfig.py:45
SeparateEncodingFile.roiAsXML
def roiAsXML(roi, depth)
Definition: SeparateEncodingFile.py:38
SeparateEncodingFile.readXML
def readXML(filename)
Definition: SeparateEncodingFile.py:7