CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Public Attributes | Private Attributes
geometryXMLparser.MuonGeometry Class Reference
Inheritance diagram for geometryXMLparser.MuonGeometry:

Public Member Functions

def __init__
 
def endElement
 
def startElement
 
def xml
 

Public Attributes

 csc
 
 dt
 

Private Attributes

 _operation
 

Detailed Description

Definition at line 99 of file geometryXMLparser.py.

Constructor & Destructor Documentation

def geometryXMLparser.MuonGeometry.__init__ (   self,
  stream = None 
)

Definition at line 100 of file geometryXMLparser.py.

101  def __init__(self, stream=None):
102  self.dt = {}
103  self.csc = {}
104  self._operation = None
105 
106  if stream is not None:
107  parser = xml.sax.make_parser()
108  parser.setContentHandler(self)
109  parser.parse(stream)

Member Function Documentation

def geometryXMLparser.MuonGeometry.endElement (   self,
  tag 
)

Definition at line 157 of file geometryXMLparser.py.

References geometryXMLparser.MuonGeometry._operation, geometryXMLparser.MuonGeometry.csc, and geometryXMLparser.MuonGeometry.dt.

158  def endElement(self, tag):
159  if tag == "operation":
160  if self._operation is None: raise Exception, "Unbalanced <operation></operation>"
161  for c in self._operation.chambers:
162  c.__dict__.update(self._operation.setposition)
163  c.__dict__.update(self._operation.setape)
164  if isinstance(c, DTAlignable): self.dt[c.index()] = c
165  elif isinstance(c, CSCAlignable): self.csc[c.index()] = c
def geometryXMLparser.MuonGeometry.startElement (   self,
  tag,
  attrib 
)

Definition at line 111 of file geometryXMLparser.py.

References geometryXMLparser.MuonGeometry._operation, and python.multivaluedict.dict.

112  def startElement(self, tag, attrib):
113  attrib = dict(attrib.items())
114  if "rawId" in attrib: raise Exception, "Please use \"rawIds = false\""
115  if "aa" in attrib: raise Exception, "Please use \"survey = false\""
116 
117  if tag == "MuonAlignment": pass
118 
119  elif tag == "collection": raise NotImplementedError, "<collection /> and <collection> blocks aren't implemented yet"
120 
121  elif tag == "operation":
122  self._operation = Operation()
123 
124  elif self._operation is None: raise Exception, "All chambers and positions must be enclosed in <operation> blocks"
125 
126  elif tag == "setposition":
127  self._operation.setposition["relativeto"] = str(attrib["relativeto"])
128 
129  for name in "x", "y", "z":
130  self._operation.setposition[name] = float(attrib[name])
131  try:
132  for name in "phix", "phiy", "phiz":
133  self._operation.setposition[name] = float(attrib[name])
134  except KeyError:
135  for name in "alpha", "beta", "gamma":
136  self._operation.setposition[name] = float(attrib[name])
137 
138  elif tag == "setape":
139  for name in "xx", "xy", "xz", "yy", "yz", "zz":
140  self._operation.setposition[name] = float(attrib[name])
141 
142  elif tag[0:2] == "DT":
143  alignable = DTAlignable()
144  for name in "wheel", "station", "sector", "superlayer", "layer":
145  if name in attrib:
146  alignable.__dict__[name] = int(attrib[name])
147  self._operation.chambers.append(alignable)
148 
149  # <CSC...>: print endcap/station/ring/chamber/layer
150  elif tag[0:3] == "CSC":
151  alignable = CSCAlignable()
152  for name in "endcap", "station", "ring", "chamber", "layer":
153  if name in attrib:
154  alignable.__dict__[name] = int(attrib[name])
155  self._operation.chambers.append(alignable)
def geometryXMLparser.MuonGeometry.xml (   self,
  stream = None,
  precision = 8 
)

Definition at line 167 of file geometryXMLparser.py.

References geometryXMLparser.MuonGeometry.csc, geometryXMLparser.MuonGeometry.dt, f, and join().

168  def xml(self, stream=None, precision=8):
169  if precision == None: format = "%g"
170  else: format = "%." + str(precision) + "f"
171 
172  if stream == None:
173  output = []
174  writeline = lambda x: output.append(x)
175  else:
176  writeline = lambda x: stream.write(x)
177 
178  writeline("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n")
179  writeline("<?xml-stylesheet type=\"text/xml\" href=\"MuonAlignment.xsl\"?>\n")
180  writeline("<MuonAlignment>\n\n")
181 
182  dtkeys = self.dt.keys()
183  dtkeys.sort(dtorder)
184  csckeys = self.csc.keys()
185  csckeys.sort(cscorder)
186 
187  def f(number): return format % number
188 
189  def position_ape(ali, attributes):
190  writeline(" <%s%s />\n" % (level, attributes))
191  writeline(" <setposition relativeto=\"%s\" x=\"%s\" y=\"%s\" z=\"%s\" phix=\"%s\" phiy=\"%s\" phiz=\"%s\" />\n" % \
192  (ali.relativeto, f(ali.x), f(ali.y), f(ali.z), f(ali.phix), f(ali.phiy), f(ali.phiz)))
193 
194  if "xx" in ali.__dict__:
195  writeline(" <setape xx=\"%s\" xy=\"%s\" xz=\"%s\" yy=\"%s\" yz=\"%s\" zz=\"%s\" />\n" % \
196  (f(ali.xx), f(ali.xy), f(ali.xz), f(ali.yy), f(ali.yz), f(ali.zz)))
197 
198  for key in dtkeys:
199  writeline("<operation>\n")
200 
201  if len(key) == 0: level = "DTBarrel"
202  elif len(key) == 1: level = "DTWheel "
203  elif len(key) == 2: level = "DTStation "
204  elif len(key) == 3: level = "DTChamber "
205  elif len(key) == 4: level = "DTSuperLayer "
206  elif len(key) == 5: level = "DTLayer "
207 
208  ali = self.dt[key]
209  attributes = " ".join(["%s=\"%d\"" % (name, value) for name, value in zip(("wheel", "station", "sector", "superlayer", "layer"), key)])
210  position_ape(ali, attributes)
211 
212  writeline("</operation>\n\n")
213 
214  for key in csckeys:
215  writeline("<operation>\n")
216 
217  if len(key) == 1: level = "CSCEndcap "
218  elif len(key) == 2: level = "CSCStation "
219  elif len(key) == 3: level = "CSCRing "
220  elif len(key) == 4: level = "CSCChamber "
221  elif len(key) == 5: level = "CSCLayer "
222 
223  ali = self.csc[key]
224  attributes = " ".join(["%s=\"%d\"" % (name, value) for name, value in zip(("endcap", "station", "ring", "chamber", "layer"), key)])
225  position_ape(ali, attributes)
226 
227  writeline("</operation>\n\n")
228 
229  writeline("</MuonAlignment>\n")
230  if stream == None: return "".join(output)
double f[11][100]
static std::string join(char **cmd)
Definition: RemoteFile.cc:18

Member Data Documentation

geometryXMLparser.MuonGeometry._operation
private

Definition at line 103 of file geometryXMLparser.py.

Referenced by geometryXMLparser.MuonGeometry.endElement(), and geometryXMLparser.MuonGeometry.startElement().

geometryXMLparser.MuonGeometry.csc

Definition at line 102 of file geometryXMLparser.py.

Referenced by geometryXMLparser.MuonGeometry.endElement(), and geometryXMLparser.MuonGeometry.xml().

geometryXMLparser.MuonGeometry.dt

Definition at line 101 of file geometryXMLparser.py.

Referenced by geometryXMLparser.MuonGeometry.endElement(), and geometryXMLparser.MuonGeometry.xml().