| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

structure.py

Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 """
00004 module to help generate DetDesc structure.xml content.
00005 """
00006 
00007 import reference
00008 
00009 class DetElem(reference.Referable):
00010     """
00011     A class to hold detelem information
00012     """
00013     def __init__(self,name,logvol,npath=None,support=None,refs=[]):
00014         "Create a DetElem"
00015         reference.Referable.__init__(self,name)
00016         self.npath = npath
00017         self.logvol = logvol
00018         self.support = support
00019         self.refs = refs
00020         return
00021 
00022     def xml(self,fo,pre="  "):
00023         "Write XML representation to file object fo, prefacing each line with pre."
00024 
00025         from geometry import Logvol
00026         if self.logvol.__class__ == Logvol:
00027             lvname = self.logvol.full_path
00028         else:
00029             lvname = self.logvol
00030 
00031         fo.write('''
00032 %(pre)s<!-- Detector Element "%(name)s" -->
00033 %(pre)s<detelem name="%(name)s">
00034 %(pre)s  <geometryinfo lvname="%(lvname)s"'''
00035                  %{"pre":pre, "name":self.name, "lvname":lvname})
00036         if self.npath:
00037             fo.write('''
00038 %(pre)s                npath="%(npath)s"
00039 %(pre)s                support="%(support)s" />\n'''
00040                      %{"pre":pre, "npath":self.npath, "support":self.support})
00041         else:
00042             fo.write(' />\n')
00043 
00044         for der in self.refs:
00045             der.xml(fo,pre+'  ')
00046             continue
00047         fo.write('%s</detelem>\n'%pre)
00048         return
00049 
00050 class UserParameter:
00051     def __init__(self,name,type="double",values=[],desc=None):
00052         self.name = name
00053         self.type = type
00054         self.desc = desc
00055         self.values = values
00056 
00057     def xml(self,fo,pre):
00058         whatiam = "userParameter"
00059         if len(self.values) > 1:
00060             whatiam = "userparameterVector"
00061         if self.desc:
00062             from util import Comment
00063             Comment(self.desc).xml(fo,pre)
00064         fo.write('%s<%s name="%s" type="%s" comment="%s">\n'%\
00065                      (pre,whatiam,self.name,self.type,self.desc))
00066         for value in self.values:
00067             fo.write('%s  %s\n'%(pre,value))
00068         fo.write('%s</%s>\n'%(pre,whatiam))
00069         return
00070 
00071 if '__main__' == __name__:
00072     import sys
00073 
00074     from geometry import *
00075     # Logical volumes
00076     world = Logvol('lvWorld','Air',Box('world_box','10*m','10*m','10*m'))
00077     sd = Logvol('lvSubDetector','Water',Box('subdet_box','1*m','1*m','1*m'))
00078     ssd = Logvol('lvSubSubDetector','Iron',Box('subsubdet_box','10*cm','10*cm','10*cm'))
00079 
00080     # Catalogs
00081     from catalog import *
00082     from reference import *
00083     top = Catalog("Geometry", [world])
00084     sc = Catalog("Sub",[sd])
00085     ssc = Catalog("SubSub",[ssd])
00086     top.refs = [ Reference("#Sub",sc), Reference("#SubSub",ssc) ]
00087 
00088     # Physical volumes
00089     world.physvols = [Physvol('pvSubDet1',sd,PosXYZ(Z="5*m")),
00090                       Physvol('pvSubDet2',sd,PosXYZ(Z="-5*m"))]
00091     sd.physvols = [Physvol('pvSubSubDet',ssd,RotXYZ(rotZ="45*degree"))]
00092 
00093 
00094 
00095     top = DetElem('top',world)
00096     s1 = DetElem('sub1',sd,'pvSubDet1','/dd/Structure/top')
00097     s2 = DetElem('sub2',sd,'pvSubDet2','/dd/Structure/top')
00098     top.refs = [ Reference("#sub1",s1), Reference("#sub2",s2) ]
00099     s1s = DetElem('sub1_sub',ssd,'pvSubSubDet','/dd/Structure/sub1');
00100     s1.refs = [ Reference("#sub1_sub",s1s) ]
00101     s2s = DetElem('sub2_sub',ssd,'pvSubSubDet','/dd/Structure/sub2');
00102     s2.refs = [ Reference("#sub2_sub",s2s) ]
00103 
00104     for d in [ top, s1, s2, s1s, s2s ]:
00105         d.xml(sys.stdout)
00106         continue
00107     
00108 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:14:01 2011 for XmlDetDesc by doxygen 1.4.7