Skip to content

Commit

Permalink
python print migration Alignment/MuonAlignment
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlange6 committed Jul 25, 2018
1 parent e30b382 commit abf5f11
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 92 deletions.
53 changes: 27 additions & 26 deletions Alignment/MuonAlignment/python/geometryCSVtoXML.py
@@ -1,63 +1,64 @@
#!/usr/bin/env python

# External libraries (standard in Python >= 2.4, at least)
from __future__ import print_function
from sys import stdin
from re import split, sub

# Skip the first two lines (headers)
next(stdin)
next(stdin)

print "<MuonAlignment>"
print ""
print("<MuonAlignment>")
print("")

for line in stdin:
line = sub("[ \t\n]+$", "", line)
Alignable, struct1, struct2, struct3, struct4, struct5, \
relativeto, x, y, z, angletype, angle1, angle2, angle3, \
xx, xy, xz, yy, yz, zz = split("[ \t]*,[ \t]", line)

print "<operation>"
print("<operation>")
if Alignable[0:2] == "DT":
print (" <%s " % Alignable),
print((" <%s " % Alignable), end=' ')
if struct1 != "":
print ("wheel=\"%s\" " % struct1),
print(("wheel=\"%s\" " % struct1), end=' ')
if struct2 != "":
print ("station=\"%s\" " % struct2),
print(("station=\"%s\" " % struct2), end=' ')
if struct3 != "":
print ("sector=\"%s\" " % struct3),
print(("sector=\"%s\" " % struct3), end=' ')
if struct4 != "":
print ("superlayer=\"%s\" " % struct4),
print(("superlayer=\"%s\" " % struct4), end=' ')
if struct5 != "":
print ("layer=\"%s\" " % struct5),
print "/>"
print(("layer=\"%s\" " % struct5), end=' ')
print("/>")

if Alignable[0:3] == "CSC":
print (" <%s " % Alignable),
print((" <%s " % Alignable), end=' ')
if struct1 != "":
print ("endcap=\"%s\" " % struct1),
print(("endcap=\"%s\" " % struct1), end=' ')
if struct2 != "":
print ("station=\"%s\" " % struct2),
print(("station=\"%s\" " % struct2), end=' ')
if struct3 != "":
print ("ring=\"%s\" " % struct3),
print(("ring=\"%s\" " % struct3), end=' ')
if struct4 != "":
print ("chamber=\"%s\" " % struct4),
print(("chamber=\"%s\" " % struct4), end=' ')
if struct5 != "":
print ("layer=\"%s\" " % struct5),
print "/>"
print(("layer=\"%s\" " % struct5), end=' ')
print("/>")

if angletype == "phixyz":
print " <setposition relativeto=\"%s\" x=\"%s\" y=\"%s\" z=\"%s\" phix=\"%s\" phiy=\"%s\" phiz=\"%s\" />" \
% (relativeto, x, y, z, angle1, angle2, angle3)
print(" <setposition relativeto=\"%s\" x=\"%s\" y=\"%s\" z=\"%s\" phix=\"%s\" phiy=\"%s\" phiz=\"%s\" />" \
% (relativeto, x, y, z, angle1, angle2, angle3))
else:
print " <setposition relativeto=\"%s\" x=\"%s\" y=\"%s\" z=\"%s\" alpha=\"%s\" beta=\"%s\" gamma=\"%s\" />" \
% (relativeto, x, y, z, angle1, angle2, angle3)
print(" <setposition relativeto=\"%s\" x=\"%s\" y=\"%s\" z=\"%s\" alpha=\"%s\" beta=\"%s\" gamma=\"%s\" />" \
% (relativeto, x, y, z, angle1, angle2, angle3))

print " <setape xx=\"%s\" xy=\"%s\" xz=\"%s\" yy=\"%s\" yz=\"%s\" zz=\"%s\" />" \
% (xx, xy, xz, yy, yz, zz)
print(" <setape xx=\"%s\" xy=\"%s\" xz=\"%s\" yy=\"%s\" yz=\"%s\" zz=\"%s\" />" \
% (xx, xy, xz, yy, yz, zz))

print "</operation>"
print ""
print("</operation>")
print("")

print "</MuonAlignment>"
print("</MuonAlignment>")

17 changes: 9 additions & 8 deletions Alignment/MuonAlignment/python/geometryDiff.py
@@ -1,5 +1,6 @@
#!/usr/bin/env python

from __future__ import print_function
from Alignment.MuonAlignment.geometryXMLparser import MuonGeometry, dtorder, cscorder
import sys, getopt

Expand All @@ -8,17 +9,17 @@
try:
opts, args = getopt.getopt(sys.argv[1:], "he:", ["help", "epsilon="])
except getopt.GetoptError as msg:
print >>sys.stderr, usage
print(usage, file=sys.stderr)
sys.exit(2)

if len(args) != 2:
print >>sys.stderr, usage
print(usage, file=sys.stderr)
sys.exit(2)

opts = dict(opts)

if "-h" in opts or "--help" in opts:
print usage
print(usage)
sys.exit(0)

epsilon = 1e-6
Expand Down Expand Up @@ -77,11 +78,11 @@ def loopover(which):
g2 = geom2.csc[key]

if g1.relativeto != g2.relativeto:
print "%s %s relativeto=\"%s\" versus relativeto=\"%s\"" % (which, str(key), g1.relativeto, g2.relativeto)
print("%s %s relativeto=\"%s\" versus relativeto=\"%s\"" % (which, str(key), g1.relativeto, g2.relativeto))

if abs(g1.x - g2.x) > epsilon or abs(g1.y - g2.y) > epsilon or abs(g1.z - g2.z) > epsilon:
print "%s %s position difference: (%g, %g, %g) - (%g, %g, %g) = (%g, %g, %g)" % \
(which, str(key), g1.x, g1.y, g1.z, g2.x, g2.y, g2.z, g1.x - g2.x, g1.y - g2.y, g1.z - g2.z)
print("%s %s position difference: (%g, %g, %g) - (%g, %g, %g) = (%g, %g, %g)" % \
(which, str(key), g1.x, g1.y, g1.z, g2.x, g2.y, g2.z, g1.x - g2.x, g1.y - g2.y, g1.z - g2.z))

if "phix" in g1.__dict__:
g1type = "phi"
Expand All @@ -104,8 +105,8 @@ def loopover(which):
diff = matrixmult(g1rot, transpose(g2rot))
if abs(diff[0][0] - 1.) > sqrtepsilon or abs(diff[1][1] - 1.) > sqrtepsilon or abs(diff[2][2] - 1.) > sqrtepsilon or \
abs(diff[0][1]) > epsilon or abs(diff[0][2]) > epsilon or abs(diff[1][2]) > epsilon:
print "%s %s rotation difference: %s(%g, %g, %g) - %s(%g, %g, %g) = %s" % \
(which, str(key), g1type, g1a, g1b, g1c, g2type, g2a, g2b, g2c, str(diff))
print("%s %s rotation difference: %s(%g, %g, %g) - %s(%g, %g, %g) = %s" % \
(which, str(key), g1type, g1a, g1b, g1c, g2type, g2a, g2b, g2c, str(diff)))

loopover("DT")
loopover("CSC")
Expand Down
27 changes: 14 additions & 13 deletions Alignment/MuonAlignment/python/geometryXMLtoCSV.py
Expand Up @@ -24,12 +24,13 @@
# }

# External libraries (standard in Python >= 2.4, at least)
from __future__ import print_function
from xml.sax import handler, make_parser
from sys import stdin

# Headers for the CSV file
print "Alignable, wheel, station, sector, superlayer, layer, relativeto, x, y, z, angletype, phix, phiy, phiz, xx, xy, xz, yy, yz, zz"
print ", endcap, station, ring, chamber, layer, , , , , , alpha, beta, gamma, , , , , , "
print("Alignable, wheel, station, sector, superlayer, layer, relativeto, x, y, z, angletype, phix, phiy, phiz, xx, xy, xz, yy, yz, zz")
print(", endcap, station, ring, chamber, layer, , , , , , alpha, beta, gamma, , , , , , ")

# This class is a subclass of something which knows how to parse XML
class ContentHandler(handler.ContentHandler):
Expand All @@ -41,38 +42,38 @@ def startElement(self, tag, attrib):

# <DT...>: print wheel/station/sector/superlayer/layer
if tag[0:2] == "DT":
print tag, # ending with a comma means "don't print end-of-line character"
print(tag, end=' ') # ending with a comma means "don't print end-of-line character"
for a in "wheel", "station", "sector", "superlayer", "layer":
if a in attrib:
print (", %s" % attrib[a]),
print((", %s" % attrib[a]), end=' ')
else:
print ", ",
print(", ", end=' ')

# <CSC...>: print endcap/station/ring/chamber/layer
elif tag[0:3] == "CSC":
print tag,
print(tag, end=' ')
for a in "endcap", "station", "ring", "chamber", "layer":
if a in attrib:
print (", %s" % attrib[a]),
print((", %s" % attrib[a]), end=' ')
else:
print ", ",
print(", ", end=' ')

# <setposition>: print x, y, z and phix, phiy, phiz or alpha, beta, gamma
elif tag == "setposition":
print (", %(relativeto)s, %(x)s, %(y)s, %(z)s" % attrib),
print((", %(relativeto)s, %(x)s, %(y)s, %(z)s" % attrib), end=' ')
if "phix" in attrib:
print (", phixyz, %(phix)s, %(phiy)s, %(phiz)s" % attrib),
print((", phixyz, %(phix)s, %(phiy)s, %(phiz)s" % attrib), end=' ')
else:
print (", Euler, %(alpha)s, %(beta)s, %(gamma)s" % attrib),
print((", Euler, %(alpha)s, %(beta)s, %(gamma)s" % attrib), end=' ')

# <setape>: print xx, xy, xz, yy, yz, zz
elif tag == "setape":
print (", %(xx)s, %(xy)s, %(xz)s, %(yy)s, %(yz)s, %(zz)s" % attrib),
print((", %(xx)s, %(xy)s, %(xz)s, %(yy)s, %(yz)s, %(zz)s" % attrib), end=' ')

# what to do when you get to an </endelement>
def endElement(self, tag):
if tag == "operation":
print "" # end current line (note: no comma)
print("") # end current line (note: no comma)

# Actually make it and use it on "stdin" (a file object)
parser = make_parser()
Expand Down

0 comments on commit abf5f11

Please sign in to comment.