CMS 3D CMS Logo

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__ (self, stream=None)
 
def endElement (self, tag)
 
def startElement (self, tag, attrib)
 
def xml (self, stream=None, precision=10)
 

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.

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

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.

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

Definition at line 111 of file geometryXMLparser.py.

References geometryXMLparser.MuonGeometry._operation, cmsPerfStripChart.dict, objects.autophobj.float, createfilelist.int, and str.

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

Definition at line 167 of file geometryXMLparser.py.

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

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

Member Data Documentation

geometryXMLparser.MuonGeometry._operation
private
geometryXMLparser.MuonGeometry.csc
geometryXMLparser.MuonGeometry.dt