Public Member Functions | |
def | __init__ |
def | endElement |
def | startElement |
def | xml |
Public Attributes | |
csc | |
dt | |
Private Attributes | |
_operation |
Definition at line 99 of file geometryXMLparser.py.
def geometryXMLparser::MuonGeometry::__init__ | ( | self, | ||
stream = None | ||||
) |
Definition at line 100 of file geometryXMLparser.py.
00100 : 00101 self.dt = {} 00102 self.csc = {} 00103 self._operation = None 00104 00105 if stream is not None: 00106 parser = xml.sax.make_parser() 00107 parser.setContentHandler(self) 00108 parser.parse(stream) 00109 00110 # what to do when you get to a <startelement> def startElement(self, tag, attrib):
def geometryXMLparser::MuonGeometry::endElement | ( | self, | ||
tag | ||||
) |
Definition at line 157 of file geometryXMLparser.py.
00157 : 00158 if tag == "operation": 00159 if self._operation is None: raise Exception, "Unbalanced <operation></operation>" 00160 for c in self._operation.chambers: 00161 c.__dict__.update(self._operation.setposition) 00162 c.__dict__.update(self._operation.setape) 00163 if isinstance(c, DTAlignable): self.dt[c.index()] = c 00164 elif isinstance(c, CSCAlignable): self.csc[c.index()] = c 00165 00166 # writing back to xml def xml(self, stream=None, precision=8):
def geometryXMLparser::MuonGeometry::startElement | ( | self, | ||
tag, | ||||
attrib | ||||
) |
Definition at line 111 of file geometryXMLparser.py.
00111 : 00112 attrib = dict(attrib.items()) 00113 if "rawId" in attrib: raise Exception, "Please use \"rawIds = false\"" 00114 if "aa" in attrib: raise Exception, "Please use \"survey = false\"" 00115 00116 if tag == "MuonAlignment": pass 00117 00118 elif tag == "collection": raise NotImplementedError, "<collection /> and <collection> blocks aren't implemented yet" 00119 00120 elif tag == "operation": 00121 self._operation = Operation() 00122 00123 elif self._operation is None: raise Exception, "All chambers and positions must be enclosed in <operation> blocks" 00124 00125 elif tag == "setposition": 00126 self._operation.setposition["relativeto"] = str(attrib["relativeto"]) 00127 00128 for name in "x", "y", "z": 00129 self._operation.setposition[name] = float(attrib[name]) 00130 try: 00131 for name in "phix", "phiy", "phiz": 00132 self._operation.setposition[name] = float(attrib[name]) 00133 except KeyError: 00134 for name in "alpha", "beta", "gamma": 00135 self._operation.setposition[name] = float(attrib[name]) 00136 00137 elif tag == "setape": 00138 for name in "xx", "xy", "xz", "yy", "yz", "zz": 00139 self._operation.setposition[name] = float(attrib[name]) 00140 00141 elif tag[0:2] == "DT": 00142 alignable = DTAlignable() 00143 for name in "wheel", "station", "sector", "superlayer", "layer": 00144 if name in attrib: 00145 alignable.__dict__[name] = int(attrib[name]) 00146 self._operation.chambers.append(alignable) 00147 00148 # <CSC...>: print endcap/station/ring/chamber/layer 00149 elif tag[0:3] == "CSC": 00150 alignable = CSCAlignable() 00151 for name in "endcap", "station", "ring", "chamber", "layer": 00152 if name in attrib: 00153 alignable.__dict__[name] = int(attrib[name]) 00154 self._operation.chambers.append(alignable) 00155 00156 # what to do when you get to an </endelement> def endElement(self, tag):
def geometryXMLparser::MuonGeometry::xml | ( | self, | ||
stream = None , |
||||
precision = 8 | ||||
) |
Definition at line 167 of file geometryXMLparser.py.
00167 : 00168 if precision == None: format = "%g" 00169 else: format = "%." + str(precision) + "f" 00170 00171 if stream == None: 00172 output = [] 00173 writeline = lambda x: output.append(x) 00174 else: 00175 writeline = lambda x: stream.write(x) 00176 00177 writeline("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") 00178 writeline("<?xml-stylesheet type=\"text/xml\" href=\"MuonAlignment.xsl\"?>\n") 00179 writeline("<MuonAlignment>\n\n") 00180 00181 dtkeys = self.dt.keys() 00182 dtkeys.sort(dtorder) 00183 csckeys = self.csc.keys() 00184 csckeys.sort(cscorder) 00185 00186 def f(number): return format % number 00187 00188 def position_ape(ali, attributes): 00189 writeline(" <%s%s />\n" % (level, attributes)) 00190 writeline(" <setposition relativeto=\"%s\" x=\"%s\" y=\"%s\" z=\"%s\" phix=\"%s\" phiy=\"%s\" phiz=\"%s\" />\n" % \ 00191 (ali.relativeto, f(ali.x), f(ali.y), f(ali.z), f(ali.phix), f(ali.phiy), f(ali.phiz))) 00192 00193 if "xx" in ali.__dict__: 00194 writeline(" <setape xx=\"%s\" xy=\"%s\" xz=\"%s\" yy=\"%s\" yz=\"%s\" zz=\"%s\" />\n" % \ 00195 (f(ali.xx), f(ali.xy), f(ali.xz), f(ali.yy), f(ali.yz), f(ali.zz))) 00196 00197 for key in dtkeys: 00198 writeline("<operation>\n") 00199 00200 if len(key) == 0: level = "DTBarrel" 00201 elif len(key) == 1: level = "DTWheel " 00202 elif len(key) == 2: level = "DTStation " 00203 elif len(key) == 3: level = "DTChamber " 00204 elif len(key) == 4: level = "DTSuperLayer " 00205 elif len(key) == 5: level = "DTLayer " 00206 00207 ali = self.dt[key] 00208 attributes = " ".join(["%s=\"%d\"" % (name, value) for name, value in zip(("wheel", "station", "sector", "superlayer", "layer"), key)]) 00209 position_ape(ali, attributes) 00210 00211 writeline("</operation>\n\n") 00212 00213 for key in csckeys: 00214 writeline("<operation>\n") 00215 00216 if len(key) == 1: level = "CSCEndcap " 00217 elif len(key) == 2: level = "CSCStation " 00218 elif len(key) == 3: level = "CSCRing " 00219 elif len(key) == 4: level = "CSCChamber " 00220 elif len(key) == 5: level = "CSCLayer " 00221 00222 ali = self.csc[key] 00223 attributes = " ".join(["%s=\"%d\"" % (name, value) for name, value in zip(("endcap", "station", "ring", "chamber", "layer"), key)]) 00224 position_ape(ali, attributes) 00225 00226 writeline("</operation>\n\n") 00227 00228 writeline("</MuonAlignment>\n") 00229 if stream == None: return "".join(output) if stream == None: return "".join(output)
Definition at line 103 of file geometryXMLparser.py.
Definition at line 102 of file geometryXMLparser.py.
Definition at line 101 of file geometryXMLparser.py.