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 from __future__ import print_function
5 import sys, argparse
6 from TrigConfMuctpi.XMLReader import MioctGeometryXMLReader
7 
8 def readXML(filename):
9  return MioctGeometryXMLReader(filename)
10 
11 
12 def mioctAsXML(mioct, depth, filter, stats):
13  attr = ["id", "slot"]
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'
16  sectorList = []
17  for sector in mioct.Sectors:
18  if not filter(sector):
19  continue
20  sectorList += [sector['name']]
21  s += sectorAsXML(sector, depth + 4, stats )
22  s += ' '*depth + "</%s>\n" % mioct.tag
23  s = s.replace('__SECTORS__', ", ".join(sorted(sectorList)) )
24  stats['sectors'] += len(sectorList)
25  return s
26 
27 
28 def sectorAsXML(sector, depth, stats):
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'])):
34  s += roiAsXML(roi, depth + 4 )
35  s += ' '*depth + "</%s>\n" % sector.tag
36  stats['rois'] += len(sector.ROIs)
37  return s
38 
39 def roiAsXML(roi, depth):
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]) )
42  return s
43 
44 
45 def writeXML(geometry, dettype):
46 
47  if dettype != "RPC" and dettype != "TGC":
48  return
49 
50  stats = {'miocts' : 0, 'sectors' : 0, 'rois' : 0}
51 
52  infile = geometry.getFileName()
53  outfile = infile.replace(".","_%s." % dettype)
54 
55  if dettype == 'RPC':
56  sectorFilter = lambda s : s['name'].startswith('B') # noqa: E731
57  else:
58  sectorFilter = lambda s : s['name'].startswith('E') or s['name'].startswith('F') # noqa: E731
59 
60  f = open(outfile,"write")
61 
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():
66  print(mioctAsXML(mioct, 4, sectorFilter, stats), file=f)
67 
68  print("</%s>" % geometry.MuCTPiGeometry.tag, file=f)
69  stats['miocts'] = len(geometry.getMIOCTs())
70  print("Wrote %s" % outfile)
71 
72  print("Numbers for %s" % dettype)
73  print("#MIOCTs : %i" % stats['miocts'])
74  print("#Sectors : %i" % stats['sectors'])
75  print("#ROIs : %i" % stats['rois'])
76 
77  f.close()
78 
79 
80 
81 def main(args):
82 
83  print("Using input %s" % args.infile)
84  geometry = readXML( args.infile )
85 
86  writeXML(geometry, "RPC")
87  writeXML(geometry, "TGC")
88 
89 
90 
91 if __name__=="__main__":
92 
93 
94  parser = argparse.ArgumentParser( description=__doc__,
95  formatter_class = argparse.RawTextHelpFormatter)
96 
97  parser.add_argument('-i', dest='infile', default="TrigConfMuctpi/TestMioctGeometry.xml", type=str,
98  help='name of input combined muon geometry file')
99 
100  args = parser.parse_args()
101 
102  #try:
103  sys.exit( main(args) )
104  #except Exception, ex:
105  # print "exception caught %r" % ex
106  # sys.exit(1)
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
SeparateEncodingFile.mioctAsXML
def mioctAsXML(mioct, depth, filter, stats)
Definition: SeparateEncodingFile.py:12
covarianceTool.filter
filter
Definition: covarianceTool.py:514
SeparateEncodingFile.main
def main(args)
Definition: SeparateEncodingFile.py:81
DerivationFramework::TriggerMatchingUtils::sorted
std::vector< typename T::value_type > sorted(T begin, T end)
Helper function to create a sorted vector from an unsorted one.
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:28
SeparateEncodingFile.writeXML
def writeXML(geometry, dettype)
Definition: SeparateEncodingFile.py:45
Trk::open
@ open
Definition: BinningType.h:40
Muon::print
std::string print(const MuPatSegment &)
Definition: MuonTrackSteering.cxx:28
SeparateEncodingFile.roiAsXML
def roiAsXML(roi, depth)
Definition: SeparateEncodingFile.py:39
SeparateEncodingFile.readXML
def readXML(filename)
Definition: SeparateEncodingFile.py:8