Main Page
Namespaces
Classes
Package Documentation
Alignment
MuonAlignment
python
geometryXMLtoCSV.py
Go to the documentation of this file.
1
#!/usr/bin/env python
2
3
# XML must come from MuonGeometryDBConverter; it must not be hand-made
4
# Example configuration that will work
5
#
6
# PSet outputXML = {
7
# string fileName = "tmp.xml"
8
# string relativeto = "container" # keep in mind which relativeto you used when interpreting positions and angles!
9
# bool survey = false # important: survey must be false
10
# bool rawIds = false # important: rawIds must be false
11
# bool eulerAngles = false
12
#
13
# untracked bool suppressDTBarrel = true
14
# untracked bool suppressDTWheels = true
15
# untracked bool suppressDTStations = true
16
# untracked bool suppressDTChambers = true
17
# untracked bool suppressDTSuperLayers = true
18
# untracked bool suppressDTLayers = true
19
# untracked bool suppressCSCEndcaps = true
20
# untracked bool suppressCSCStations = true
21
# untracked bool suppressCSCRings = true
22
# untracked bool suppressCSCChambers = true
23
# untracked bool suppressCSCLayers = false
24
# }
25
26
# External libraries (standard in Python >= 2.4, at least)
27
from
xml.sax
import
handler, make_parser
28
from
sys
import
stdin
29
30
# Headers for the CSV file
31
print
"Alignable, wheel, station, sector, superlayer, layer, relativeto, x, y, z, angletype, phix, phiy, phiz, xx, xy, xz, yy, yz, zz"
32
print
", endcap, station, ring, chamber, layer, , , , , , alpha, beta, gamma, , , , , , "
33
34
# This class is a subclass of something which knows how to parse XML
35
class
ContentHandler
(handler.ContentHandler):
36
# what to do when you get to a <startelement>
37
def
startElement
(self, tag, attrib):
38
attrib =
dict
(attrib.items())
39
if
"rawId"
in
attrib:
raise
Exception
(
"Please use \"rawIds = false\""
)
40
if
"aa"
in
attrib:
raise
Exception
(
"Please use \"survey = false\""
)
41
42
# <DT...>: print wheel/station/sector/superlayer/layer
43
if
tag[0:2] ==
"DT"
:
44
print
tag,
# ending with a comma means "don't print end-of-line character"
45
for
a
in
"wheel"
,
"station"
,
"sector"
,
"superlayer"
,
"layer"
:
46
if
a
in
attrib:
47
print
(
", %s"
% attrib[a]),
48
else
:
49
print
", "
,
50
51
# <CSC...>: print endcap/station/ring/chamber/layer
52
elif
tag[0:3] ==
"CSC"
:
53
print
tag,
54
for
a
in
"endcap"
,
"station"
,
"ring"
,
"chamber"
,
"layer"
:
55
if
a
in
attrib:
56
print
(
", %s"
% attrib[a]),
57
else
:
58
print
", "
,
59
60
# <setposition>: print x, y, z and phix, phiy, phiz or alpha, beta, gamma
61
elif
tag ==
"setposition"
:
62
print
(
", %(relativeto)s, %(x)s, %(y)s, %(z)s"
% attrib),
63
if
"phix"
in
attrib:
64
print
(
", phixyz, %(phix)s, %(phiy)s, %(phiz)s"
% attrib),
65
else
:
66
print
(
", Euler, %(alpha)s, %(beta)s, %(gamma)s"
% attrib),
67
68
# <setape>: print xx, xy, xz, yy, yz, zz
69
elif
tag ==
"setape"
:
70
print
(
", %(xx)s, %(xy)s, %(xz)s, %(yy)s, %(yz)s, %(zz)s"
% attrib),
71
72
# what to do when you get to an </endelement>
73
def
endElement
(self, tag):
74
if
tag ==
"operation"
:
75
print
""
# end current line (note: no comma)
76
77
# Actually make it and use it on "stdin" (a file object)
78
parser = make_parser()
79
parser.setContentHandler(
ContentHandler
())
80
parser.parse(stdin)
geometryXMLtoCSV.ContentHandler
Definition:
geometryXMLtoCSV.py:35
geometryXMLtoCSV.ContentHandler.endElement
def endElement(self, tag)
Definition:
geometryXMLtoCSV.py:73
cmsPerfStripChart.dict
dict
Definition:
cmsPerfStripChart.py:307
Exception
geometryXMLtoCSV.ContentHandler.startElement
def startElement(self, tag, attrib)
Definition:
geometryXMLtoCSV.py:37
Generated for CMSSW Reference Manual by
1.8.11