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
__future__
import
print_function
28
from
xml.sax
import
handler, make_parser
29
from
sys
import
stdin
30
31
# Headers for the CSV file
32
print
(
"Alignable, wheel, station, sector, superlayer, layer, relativeto, x, y, z, angletype, phix, phiy, phiz, xx, xy, xz, yy, yz, zz"
)
33
print
(
", endcap, station, ring, chamber, layer, , , , , , alpha, beta, gamma, , , , , , "
)
34
35
# This class is a subclass of something which knows how to parse XML
36
class
ContentHandler
(handler.ContentHandler):
37
# what to do when you get to a <startelement>
38
def
startElement
(self, tag, attrib):
39
attrib =
dict
(attrib.items())
40
if
"rawId"
in
attrib:
raise
Exception
(
"Please use \"rawIds = false\""
)
41
if
"aa"
in
attrib:
raise
Exception
(
"Please use \"survey = false\""
)
42
43
# <DT...>: print wheel/station/sector/superlayer/layer
44
if
tag[0:2] ==
"DT"
:
45
print
(tag, end=
' '
)
# ending with a comma means "don't print end-of-line character"
46
for
a
in
"wheel"
,
"station"
,
"sector"
,
"superlayer"
,
"layer"
:
47
if
a
in
attrib:
48
print
((
", %s"
% attrib[a]), end=
' '
)
49
else
:
50
print
(
", "
, end=
' '
)
51
52
# <CSC...>: print endcap/station/ring/chamber/layer
53
elif
tag[0:3] ==
"CSC"
:
54
print
(tag, end=
' '
)
55
for
a
in
"endcap"
,
"station"
,
"ring"
,
"chamber"
,
"layer"
:
56
if
a
in
attrib:
57
print
((
", %s"
% attrib[a]), end=
' '
)
58
else
:
59
print
(
", "
, end=
' '
)
60
61
# <setposition>: print x, y, z and phix, phiy, phiz or alpha, beta, gamma
62
elif
tag ==
"setposition"
:
63
print
((
", %(relativeto)s, %(x)s, %(y)s, %(z)s"
% attrib), end=
' '
)
64
if
"phix"
in
attrib:
65
print
((
", phixyz, %(phix)s, %(phiy)s, %(phiz)s"
% attrib), end=
' '
)
66
else
:
67
print
((
", Euler, %(alpha)s, %(beta)s, %(gamma)s"
% attrib), end=
' '
)
68
69
# <setape>: print xx, xy, xz, yy, yz, zz
70
elif
tag ==
"setape"
:
71
print
((
", %(xx)s, %(xy)s, %(xz)s, %(yy)s, %(yz)s, %(zz)s"
% attrib), end=
' '
)
72
73
# what to do when you get to an </endelement>
74
def
endElement
(self, tag):
75
if
tag ==
"operation"
:
76
print
(
""
)
# end current line (note: no comma)
77
78
# Actually make it and use it on "stdin" (a file object)
79
parser = make_parser()
80
parser.setContentHandler(
ContentHandler
())
81
parser.parse(stdin)
geometryXMLtoCSV.ContentHandler
Definition:
geometryXMLtoCSV.py:36
edm::print
S & print(S &os, JobReport::InputFile const &f)
Definition:
JobReport.cc:66
geometryXMLtoCSV.ContentHandler.endElement
def endElement(self, tag)
Definition:
geometryXMLtoCSV.py:74
cmsPerfStripChart.dict
dict
Definition:
cmsPerfStripChart.py:309
Exception
geometryXMLtoCSV.ContentHandler.startElement
def startElement(self, tag, attrib)
Definition:
geometryXMLtoCSV.py:38
Generated for CMSSW Reference Manual by
1.8.11