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