Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-11-25 02:29:03

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 xml.sax import handler, make_parser
0028 from sys import stdin
0029 
0030 # Headers for the CSV file
0031 print("Alignable, wheel, station, sector, superlayer, layer, relativeto, x, y, z, angletype, phix, phiy, phiz, xx, xy, xz, yy, yz, zz")
0032 print(", endcap, station, ring, chamber, layer, , , , , , alpha, beta, gamma, , , , , , ")
0033 
0034 # This class is a subclass of something which knows how to parse XML
0035 class ContentHandler(handler.ContentHandler):
0036     # what to do when you get to a <startelement>
0037     def startElement(self, tag, attrib):
0038         attrib = dict(attrib.items())
0039         if "rawId" in attrib: raise Exception("Please use \"rawIds = false\"")
0040         if "aa" in attrib: raise Exception("Please use \"survey = false\"")
0041 
0042         # <DT...>: print wheel/station/sector/superlayer/layer
0043         if tag[0:2] == "DT":
0044             print(tag, end=' ')  # ending with a comma means "don't print end-of-line character"
0045             for a in "wheel", "station", "sector", "superlayer", "layer":
0046                 if a in attrib:
0047                     print((", %s" % attrib[a]), end=' ')
0048                 else:
0049                     print(", ", end=' ')
0050 
0051         # <CSC...>: print endcap/station/ring/chamber/layer
0052         elif tag[0:3] == "CSC":
0053             print(tag, end=' ')
0054             for a in "endcap", "station", "ring", "chamber", "layer":
0055                 if a in attrib:
0056                     print((", %s" % attrib[a]), end=' ')
0057                 else:
0058                     print(", ", end=' ')
0059 
0060         # <setposition>: print x, y, z and phix, phiy, phiz or alpha, beta, gamma
0061         elif tag == "setposition":
0062             print((", %(relativeto)s, %(x)s, %(y)s, %(z)s" % attrib), end=' ')
0063             if "phix" in attrib:
0064                 print((", phixyz, %(phix)s, %(phiy)s, %(phiz)s" % attrib), end=' ')
0065             else:
0066                 print((", Euler, %(alpha)s, %(beta)s, %(gamma)s" % attrib), end=' ')
0067 
0068         # <setape>: print xx, xy, xz, yy, yz, zz
0069         elif tag == "setape":
0070             print((", %(xx)s, %(xy)s, %(xz)s, %(yy)s, %(yz)s, %(zz)s" % attrib), end=' ')
0071 
0072     # what to do when you get to an </endelement>
0073     def endElement(self, tag):
0074         if tag == "operation":
0075             print("")  # end current line (note: no comma)
0076 
0077 # Actually make it and use it on "stdin" (a file object)
0078 parser = make_parser()
0079 parser.setContentHandler(ContentHandler())
0080 parser.parse(stdin)