Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 11:56:40

0001 #!/usr/bin/env python
0002 
0003 # XML must come from MuonGeometryDBConverter; it must not be hand-made
0004 # Example configuration that will work
0005 # 
0006 # PSet outputXML = {
0007 #     string fileName = "tmp.xml"
0008 #     string relativeto = "container"   # keep in mind which relativeto you used when interpreting positions and angles!
0009 #     bool survey = false               # important: survey must be false
0010 #     bool rawIds = false               # important: rawIds must be false
0011 #     bool eulerAngles = false
0012 # 
0013 #     untracked bool suppressDTBarrel = true
0014 #     untracked bool suppressDTWheels = true
0015 #     untracked bool suppressDTStations = true
0016 #     untracked bool suppressDTChambers = true
0017 #     untracked bool suppressDTSuperLayers = true
0018 #     untracked bool suppressDTLayers = true
0019 #     untracked bool suppressCSCEndcaps = true
0020 #     untracked bool suppressCSCStations = true
0021 #     untracked bool suppressCSCRings = true
0022 #     untracked bool suppressCSCChambers = true
0023 #     untracked bool suppressCSCLayers = false
0024 # }
0025 
0026 # External libraries (standard in Python >= 2.4, at least)
0027 from __future__ import print_function
0028 from xml.sax import handler, make_parser
0029 from sys import stdin
0030 
0031 # Headers for the CSV file
0032 print("Alignable, wheel, station, sector, superlayer, layer, relativeto, x, y, z, angletype, phix, phiy, phiz, xx, xy, xz, yy, yz, zz")
0033 print(", endcap, station, ring, chamber, layer, , , , , , alpha, beta, gamma, , , , , , ")
0034 
0035 # This class is a subclass of something which knows how to parse XML
0036 class ContentHandler(handler.ContentHandler):
0037     # what to do when you get to a <startelement>
0038     def startElement(self, tag, attrib):
0039         attrib = dict(attrib.items())
0040         if "rawId" in attrib: raise Exception("Please use \"rawIds = false\"")
0041         if "aa" in attrib: raise Exception("Please use \"survey = false\"")
0042 
0043         # <DT...>: print wheel/station/sector/superlayer/layer
0044         if tag[0:2] == "DT":
0045             print(tag, end=' ')  # ending with a comma means "don't print end-of-line character"
0046             for a in "wheel", "station", "sector", "superlayer", "layer":
0047                 if a in attrib:
0048                     print((", %s" % attrib[a]), end=' ')
0049                 else:
0050                     print(", ", end=' ')
0051 
0052         # <CSC...>: print endcap/station/ring/chamber/layer
0053         elif tag[0:3] == "CSC":
0054             print(tag, end=' ')
0055             for a in "endcap", "station", "ring", "chamber", "layer":
0056                 if a in attrib:
0057                     print((", %s" % attrib[a]), end=' ')
0058                 else:
0059                     print(", ", end=' ')
0060 
0061         # <setposition>: print x, y, z and phix, phiy, phiz or alpha, beta, gamma
0062         elif tag == "setposition":
0063             print((", %(relativeto)s, %(x)s, %(y)s, %(z)s" % attrib), end=' ')
0064             if "phix" in attrib:
0065                 print((", phixyz, %(phix)s, %(phiy)s, %(phiz)s" % attrib), end=' ')
0066             else:
0067                 print((", Euler, %(alpha)s, %(beta)s, %(gamma)s" % attrib), end=' ')
0068 
0069         # <setape>: print xx, xy, xz, yy, yz, zz
0070         elif tag == "setape":
0071             print((", %(xx)s, %(xy)s, %(xz)s, %(yy)s, %(yz)s, %(zz)s" % attrib), end=' ')
0072 
0073     # what to do when you get to an </endelement>
0074     def endElement(self, tag):
0075         if tag == "operation":
0076             print("")  # end current line (note: no comma)
0077 
0078 # Actually make it and use it on "stdin" (a file object)
0079 parser = make_parser()
0080 parser.setContentHandler(ContentHandler())
0081 parser.parse(stdin)