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

In This Package:

gen.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 """
00003 Generate AD volumes
00004 """
00005 
00006 class Cylinder:
00007     NAMES = ["sst","oil"]
00008 
00009     def __init__(self,name,rthick,hthick,material,parent=None,child=None):
00010         self.name = name
00011         self.rthick = rthick
00012         self.hthick = hthick
00013         self.material=material
00014         self.parent = parent
00015         self.child = child
00016         self.params = []
00017         self.lv = None
00018         return
00019 
00020     def parameters(self):
00021         """
00022         Build up the parameters for a cylinder based on thicknesses and parent values.
00023         """
00024         if self.params: return self.params
00025 
00026         from XmlDetDescGen.parameter import Parameter
00027 
00028         ts = []
00029         ps = []
00030         for thing,thick in [("Radius",self.rthick),
00031                             ("Height",self.hthick)]:
00032             t = Parameter("AD%s%sThickness"%(self.name,thing),
00033                           thick,
00034                           "%s thickness for %s"%(thing,self.name.upper()))
00035             ts.append(t)
00036 
00037             pname = ""
00038             if self.child:
00039                 pname = "AD%s%s + "%(self.child.name,thing)
00040 
00041             double=""
00042             if thing == "Height": double = "*2.0"
00043             p = Parameter("AD%s%s"%(self.name,thing),
00044                           "%sAD%s%sThickness%s"%(pname,self.name,thing,double),
00045                           "%s for %s"%(thing,self.name.upper()))
00046             ps.append(p)
00047             continue
00048         if self.name=="sst":
00049             p = [Parameter("ADsstBotRibHeight",
00050                            "430*mm",
00051                            "Height for %s bottom ribs."%(self.name.upper())),
00052                  Parameter("SstFotHeight",
00053                            "10*mm",
00054                            "Height for %s feet."%(self.name.upper())),
00055                  Parameter("SstBotThickness",
00056                            "20*mm",
00057                            "%s bottom thickness."%(self.name.upper())),
00058                  Parameter("SstLidThickness",
00059                            "15*mm",
00060                            "%s bottom thickness."%(self.name.upper()))
00061                  ]
00062             ps.extend(p)
00063         if self.name=="oil":
00064             p=[Parameter("ADrftBotHeight",
00065                          "30*mm",
00066                          "Height for the bottom reflector in %s."
00067                          %(self.name.upper()))]               
00068             ps.extend(p)
00069         self.params = ps+ts
00070         return self.params
00071 
00072     def logvol(self):
00073         if self.lv: return self.lv
00074 
00075         from XmlDetDescGen.geometry import Tubs,Logvol,Physvol,PosXYZ
00076         from XmlDetDescGen.util import ExternalEntity
00077 
00078         pv = []
00079         if self.child:
00080             if self.name == 'oil':
00081                 pv.append(Physvol("pv"+self.child.name.upper(),
00082                                   self.child.logvol(),
00083                                   #PosXYZ(0, 0, "ADrftBotHeight+ADsstBotRibHeight-ADoilHeight/2")))
00084                                   PosXYZ(0, 0, "ADrftBotHeight+ADsstBotRibHeight")))
00085             else:
00086                 pv.append(Physvol("pv"+self.child.name.upper(),
00087                                   self.child.logvol()))
00088 
00089         pv.append(ExternalEntity("HandWrittenPhysVols"))
00090 
00091         self.lv = Logvol("lv"+self.name.upper(),self.material,
00092                          Tubs(self.name,
00093                               'AD%sHeight'%self.name,
00094                               'AD%sRadius'%self.name),
00095                          pv)
00096         return self.lv
00097 
00098 class CylinderSelf:
00099     def __init__(self,name,radius,height,material,parent=None,child=None):
00100         self.name = name
00101         self.radius = radius
00102         self.height = height
00103         self.material=material
00104         self.parent = parent
00105         self.child = child
00106         self.params = []
00107         self.lv = None
00108         return
00109 
00110     def parameters(self):
00111         """
00112         Build up the parameters for a cylinder based on thicknesses and parent values.
00113         """
00114         if self.params: return self.params
00115 
00116         from XmlDetDescGen.parameter import Parameter
00117 
00118         ts = []
00119         ps = []
00120         for thing,size in [("Radius",self.radius),
00121                             ("Height",self.height)]:
00122             t = Parameter("AD%s%s"%(self.name,thing),
00123                           size,
00124                           "%s for %s"%(thing,self.name.upper()))
00125             ts.append(t)
00126         if self.name=="sst":
00127             p = [Parameter("ADsstBotRibHeight",
00128                           "430*mm",
00129                            "Height for %s bottom ribs."%(self.name.upper())),
00130                  Parameter("SstFotHeight",
00131                            "10*mm",
00132                            "Height for %s feet."%(self.name.upper())),
00133                  Parameter("SstBotThickness",
00134                            "20*mm",
00135                            "%s bottom thickness."%(self.name.upper())),
00136                  Parameter("SstLidThickness",
00137                            "15*mm",
00138                            "%s bottom thickness."%(self.name.upper()))
00139                  ]
00140             ps.extend(p)
00141 
00142         if self.name=="oil":
00143             p = [Parameter("ADrftBotHeight",
00144                            "30*mm",
00145                            "Height for the bottom reflector in %s."
00146                            %(self.name.upper()))
00147                  ]
00148             ps.extend(p)
00149 
00150         self.params = ts + ps
00151         return self.params
00152     
00153     def logvol(self):
00154         if self.lv: return self.lv
00155 
00156         from XmlDetDescGen.geometry import Tubs,Logvol,Physvol,PosXYZ
00157         from XmlDetDescGen.util import ExternalEntity
00158 
00159         pv = []
00160         if self.child:
00161             if self.name == 'sst':
00162                 pv.append(Physvol("pv"+self.child.name.upper(),
00163                                   self.child.logvol(),
00164                                   PosXYZ(0, 0,"(SstFotHeight+SstBotThickness-SstLidThickness)/2")))
00165             elif self.name == 'oil':
00166                 pv.append(Physvol("pv"+self.child.name.upper(),
00167                                   self.child.logvol(),
00168                                   #PosXYZ(0, 0, "ADrftBotHeight+ADsstBotRibHeight-ADoilHeight/2")))
00169                                   PosXYZ(0, 0, "ADrftBotHeight+ADsstBotRibHeight-ADoilHeight/2+(OavBrlHeight-OavBrlFlgThickness)/2")))
00170             else:
00171                 pv.append(Physvol("pv"+self.child.name.upper(),
00172                                   self.child.logvol()))
00173 
00174         pv.append(ExternalEntity("HandWrittenPhysVols"))
00175 
00176         self.lv = Logvol("lv"+self.name.upper(),self.material,
00177                          Tubs(self.name,
00178                               'AD%sHeight'%self.name,
00179                               'AD%sRadius'%self.name),
00180                          pv)
00181         return self.lv
00182 
00183 class PolyCone:
00184     NAMES = ["oav","lso", "iav", "gds"]
00185     def __init__(self,name,corner,material,parent=None,child=None):
00186         self.zpos=[]
00187         self.radius=[]
00188         self.corner=[]
00189         self.name = name
00190         self.corner=corner
00191         for zpos, radius in self.corner:
00192             self.zpos.append(zpos)
00193             self.radius.append(radius)
00194         self.nsec=len(corner)
00195         self.material=material
00196         self.parent = parent
00197         self.child = child
00198         self.params = []
00199         self.lv = None
00200         return
00201 
00202     def parameters(self):
00203         """
00204         Build up the parameters for a polycone based on the zpos' and radii.
00205         """
00206         if self.params: return self.params
00207 
00208         from XmlDetDescGen.parameter import Parameter
00209 
00210         ts = []
00211         if self.name == "oav":
00212             t = [Parameter("OavThickness", "18*mm",
00213                            "Oav wall&lid thickness"),
00214                  Parameter("OavBrlHeight", "3982*mm",
00215                            "Oav barrel height"),
00216                  Parameter("OavBrlOutRadius", "2000*mm",
00217                            "Oav barrel outer radius"),
00218                  Parameter("OavBrlFlgThickness", "45*mm",
00219                            "Oav barrel flange thickness"),
00220                  Parameter("OavBrlFlgRadius", "2040*mm",
00221                            "Oav barrel flange radius"),
00222                  Parameter("OavLidFlgThickness", "39*mm",
00223                            "Oav lid flange thickness"),
00224                  Parameter("OavLidFlgWidth", "110*mm",
00225                            "Oav lid flange width"),
00226                  Parameter("OavLidConAngle", "3.*degree",
00227                            "Oav lid conical angle"),
00228                  Parameter("OavLidConBotRadius", 
00229                            "OavBrlFlgRadius-OavLidFlgWidth",
00230                            "Oav conical lid bottom radius"),
00231                  Parameter("OavLidConTopRadius", "125*mm",
00232                            "Oav conical lid top radius"),
00233                  Parameter("OavLidConHeight", 
00234                            "(OavLidConBotRadius-OavLidConTopRadius)*tan(OavLidConAngle)",
00235                            "Oav cone height from the turning point"),
00236                  Parameter("OavHeight", 
00237                            "OavBrlHeight+OavThickness/cos(OavLidConAngle)+OavLidConHeight", 
00238                            "Oav height to the top of the cone"),
00239                  Parameter("OavLidHeight", "OavHeight-OavBrlHeight",
00240                            "Oav lid height from barrel top to the cone top"),
00241                  Parameter("OavBotRibHeight", "197*mm",
00242                            "Oav bottom rib height")
00243                  ]
00244             ts.extend(t)
00245 
00246         if self.name == "lso":
00247             t = [Parameter("LsoBrlRadius", "OavBrlOutRadius - OavThickness",
00248                            "Lso barrel radius"),
00249                  Parameter("LsoBrlHeight", "OavBrlHeight-OavThickness",
00250                            "Lso barrel height"),
00251                  Parameter("LsoConBotRadius","OavLidConBotRadius",
00252                            "Lso cone bottom radius"),
00253                  Parameter("LsoConTopRadius", "OavLidConTopRadius",
00254                            "Lso cone top radius (same as the OAV lid top)"),
00255                  Parameter("LsoConTopTipRadius", "50*mm",
00256                            "The tip of LSO (with thickness of OAV lid flange) so LSO is filled to the very top of its container: OAV"),
00257                  Parameter("LsoConHeight", 
00258                            "(LsoConBotRadius-LsoConTopRadius)*tan(OavLidConAngle)",
00259                            "Lso cone height"),
00260                  Parameter("LsoHeight",
00261                            "LsoBrlHeight+OavThickness/cos(OavLidConAngle)+OavLidConHeight",
00262                            "Lso total height (till the bot of hub, or the very top of OAV)")
00263                  ]
00264             ts.extend(t)
00265 
00266         if self.name == "iav":
00267             t = [Parameter("IavBrlThickness", "10*mm",
00268                            "Iav barrel thickness"),
00269                  Parameter("ADiavRadiusThickness", "IavBrlThickness",
00270                            "Iav barrel thickness"),
00271                  Parameter("IavBotThickness", "15*mm",
00272                            "Iav bottom thickness"),
00273                  Parameter("ADiavHeightThickness", "IavBotThickness",
00274                            "Iav bottom thickness (close enough for top)"),
00275                  Parameter("IavBrlHeight", "3085*mm",
00276                            "Iav barrel height"),
00277                  Parameter("IavBrlOutRadius", "1560*mm",
00278                            "Iav barrel outer radius"),
00279                  Parameter("ADiavRadius", "IavBrlOutRadius",
00280                            "Iav barrel outer radius"),
00281                  Parameter("IavLidRadius","1565*mm",
00282                            "Iav lid radius"),
00283                  Parameter("IavLidThickness","15*mm",
00284                            "Iav lid thickness"),
00285                  Parameter("IavLidFlgThickness", "15*mm",
00286                            "Iav lid flange thickness"),
00287                  Parameter("IavLidConInrRadius", "1520*mm",
00288                            "Iav lid cone inside radius"),
00289                  Parameter("IavLidConAngle", "3.*degree",
00290                            "Iav lid conical angle"),
00291                  Parameter("IavLidConBotRadius", 
00292                            "IavLidConInrRadius+IavLidFlgThickness*tan(IavLidConAngle/2.)",
00293                            "Iav lid cone bottom radius"),
00294                  Parameter("IavLidConTopRadius", "100*mm",
00295                            "Iav lid cone top radius"),
00296                  Parameter("IavLidConHeight", 
00297                            "(IavLidConBotRadius-IavLidConTopRadius)*tan(IavLidConAngle)",
00298                            "Iav lid cone height"),
00299                  Parameter("IavBotRibHeight", "200*mm",
00300                            "Iav bottom rib height"),
00301                  Parameter("IavBotVitHeight", "45*mm",
00302                            "Iav bottom viton height"),
00303                  Parameter("IavCtrOflTubFlgHeight", "200*mm",
00304                            "Iav central overflow tube flange height"),
00305                  Parameter("IavCtrOflTubFlgThickness", "25*mm",
00306                            "Iav central overflow tube flange thickness"),
00307                  Parameter("IavCtrOflTubFlgRadius", "150*mm",
00308                            "Iav central overflow tube flange radius"),
00309                  Parameter("IavHeight", 
00310                            "IavBrlHeight+IavLidFlgThickness+IavLidConHeight", 
00311                            "Iav height to the top of the cone"),
00312                  Parameter("IavLidHeight", "IavHeight-IavBrlHeight",
00313                            "Iav lid height from barrel top the cone top")
00314                  ]
00315             ts.extend(t)
00316             
00317         if self.name == "gds":
00318             t = [Parameter("GdsConTopRadius", "75*mm",
00319                            "Gds cone top radius"),
00320                  Parameter("GdsConBotRadius", "IavLidConInrRadius",
00321                            "Gds cone bottom radius (same as IAV lid cone inner radius"),
00322                  Parameter("GdsBrlRadius", "IavBrlOutRadius-IavBrlThickness",
00323                            "Gds barrel radius"),
00324                  Parameter("GdsBrlHeight", "IavBrlHeight-IavBotThickness",
00325                            "Gds barrel height"),
00326                  Parameter("GdsConHeight", 
00327                            "(GdsConBotRadius-GdsConTopRadius)*tan(IavLidConAngle)",
00328                            "Gds cone height"),
00329                  Parameter("GdsHeight", 
00330                            "GdsBrlHeight+IavLidFlgThickness+IavLidConHeight",
00331                            "Gds total height (till the bot of IAV hub)")
00332                  ]
00333             ts.extend(t)
00334             
00335         i=0
00336         for zpos, radius in self.corner:
00337             i = i + 1
00338             t = Parameter("AD%sSec%szPos"%(self.name,i),
00339                           zpos,
00340                           "The %sth corner z pos of %s"%(i,self.name.upper()))
00341             ts.append(t)
00342             
00343             t = Parameter("AD%sSec%sRad"%(self.name,i),
00344                           radius,
00345                           "The %sth radius for %s"%(i,self.name.upper()))
00346             ts.append(t)
00347 
00348         self.params=ts
00349         return self.params
00350 
00351     def logvol(self):
00352         if self.lv: return self.lv
00353 
00354         from XmlDetDescGen.geometry import polyCone, Logvol, Physvol, PosXYZ
00355         from XmlDetDescGen.util import ExternalEntity
00356 
00357         pv = []
00358         if self.child:
00359             if self.name == "oav":
00360                 posZ = "OavThickness-(OavBrlHeight-OavBrlFlgThickness)/2"
00361                 if self.child.name == "lso":
00362                     posZ += "+LsoBrlHeight/2"
00363                 pv.append(Physvol("pv"+self.child.name.upper(),
00364                                   self.child.logvol(),
00365                                   PosXYZ(Z=posZ)))
00366             if self.name == "lso":
00367                 posZ = "OavBotRibHeight+IavBotVitHeight+IavBotRibHeight-LsoBrlHeight/2"
00368                 if self.child.name == "iav":
00369                     posZ += "+IavBrlHeight/2"
00370 #                pv.append(Physvol("pv"+self.child.name.upper(),
00371 #                                  self.child.logvol(),
00372 #                                  PosXYZ(Z=posZ)))
00373             if self.name == "iav":
00374                 posZ = "IavBotThickness-IavBrlHeight/2"
00375                 if self.child.name == "gds":
00376                     posZ += "+GdsBrlHeight/2"
00377 #                pv.append(Physvol("pv"+self.child.name.upper(),
00378 #                                  self.child.logvol(),
00379 #                                  PosXYZ(Z=posZ)))
00380 
00381         pv.append(ExternalEntity("HandWrittenPhysVols"))
00382 
00383         self.lv = Logvol("lv"+self.name.upper(),self.material,
00384                          polyCone(self.name,
00385                                   self.zpos,
00386                                   self.radius),
00387                          pv)
00388         return self.lv
00389 
00390 # special case, child is not placed in center, handle separately
00391 class ADECylinder:
00392     def __init__(self):
00393         self.name = "ade"
00394         self.child = None
00395         self.lv = None
00396         return
00397 
00398     def parameters(self):
00399         from XmlDetDescGen.parameter import Parameter
00400         ade = [ 
00401                 Parameter("ADadeWall","0.25*m","ADE extention beyond SST in radius"),
00402                 Parameter("ADadeHead","1.0*m","ADE head gap above tank"),
00403                 Parameter("ADadeFoot","1.0*cm","ADE foot gap below tank"),
00404                 Parameter("ADadeRadius","ADsstRadius+ADadeWall","ADE radius"),
00405                 Parameter("ADadeHeight","ADadeFoot+ADsstHeight+ADadeHead","ADE height"),
00406                 Parameter("ADadeZoffset","-0.5*(ADadeHeight-ADsstHeight) + ADadeFoot","Z-offset from ADE center to AD center."),
00407               ]
00408         return ade
00409 
00410     def logvol(self):
00411         if self.lv: return self.lv
00412 
00413         from XmlDetDescGen.geometry import Tubs,Logvol,Physvol,PosXYZ
00414         from XmlDetDescGen.util import ExternalEntity
00415 
00416         pv = Physvol("pv"+self.child.name.upper(), self.child.logvol(),
00417                      PosXYZ(X="0*m",Y="0*m",Z="ADadeZoffset"))
00418 
00419         # for mini-dry run, change ADE material IwsWater to Vacuum
00420         print " --- for mini-dry run, change ADE material from IwsWater to Vacuum ---"
00421         self.lv = Logvol("lv"+self.name.upper(),'Vacuum',
00422                          Tubs(self.name,
00423                               'AD%sHeight'%self.name,
00424                               'AD%sRadius'%self.name),
00425                          [pv,ExternalEntity("HandWrittenPhysVols")])
00426         return self.lv
00427 
00428 class Parameters:
00429     from math import tan, cos
00430     filename = "parameters.xml"
00431 
00432     OavCon = [("0*mm","OavBrlOutRadius" ),
00433               ("OavBrlHeight-OavBrlFlgThickness", 
00434                "OavBrlOutRadius"),
00435               ("OavBrlHeight-OavBrlFlgThickness",
00436                "OavBrlFlgRadius"),
00437               ("OavBrlHeight+OavThickness/cos(OavLidConAngle)",
00438                "OavBrlFlgRadius"),
00439               ("OavBrlHeight+OavThickness/cos(OavLidConAngle)", 
00440                "OavLidConBotRadius"),
00441               ("OavHeight",
00442                "OavLidConTopRadius")
00443               ]
00444 
00445     LsoCon = [("0*mm", "LsoBrlRadius"), 
00446               ("LsoBrlHeight", "LsoBrlRadius"), 
00447               ("LsoBrlHeight", "LsoConBotRadius"), 
00448               ("LsoBrlHeight+LsoConHeight", "LsoConTopRadius"),
00449               ("LsoBrlHeight+LsoConHeight", "LsoConTopTipRadius"),
00450               ("LsoHeight", "LsoConTopTipRadius")
00451               ]
00452                
00453     IavCon = [("0*mm", "IavBrlOutRadius"), 
00454               ("IavBrlHeight", "IavBrlOutRadius"),
00455               ("IavBrlHeight", "IavLidRadius"), 
00456               ("IavBrlHeight+IavLidFlgThickness", "IavLidRadius"), 
00457               ("IavBrlHeight+IavLidFlgThickness", 
00458                "IavLidConBotRadius"), 
00459               ("IavHeight", "IavLidConTopRadius")
00460               ]
00461                
00462     GdsCon = [("0*mm", "GdsBrlRadius"),
00463               ("GdsBrlHeight", "GdsBrlRadius"), 
00464               ("GdsBrlHeight", "GdsConBotRadius"),
00465               ("GdsBrlHeight+GdsConHeight", "GdsConTopRadius"),
00466               ("GdsHeight", "GdsConTopRadius")
00467               ]
00468     
00469     def __init__(self):
00470         ade = ADECylinder()
00471 #        sst = Cylinder("sst","0.012*m","0.020*m",'StainlessSteel',None)
00472 #        oil = Cylinder("oil","0.488*m","0.475*m",'MineralOil',sst)
00473         sst = CylinderSelf("sst","2500*mm","5000*mm",'StainlessSteel',None)
00474         oil = CylinderSelf("oil","2488*mm","ADsstHeight-SstFotHeight-SstBotThickness-SstLidThickness",'MineralOil',sst)
00475         oav = PolyCone("oav", self.OavCon, 'Acrylic',oil)
00476         lso = PolyCone("lso", self.LsoCon, 'LiquidScintillator',oav)
00477         iav = PolyCone("iav", self.IavCon, 'Acrylic',lso)
00478         gds = PolyCone("gds", self.GdsCon, 'GdDopedLS',iav)
00479         self.cyl = [ade,sst,oil,oav,lso,iav,gds]
00480         last = None
00481         for c in self.cyl:
00482             if last: last.child = c
00483             last = c
00484             continue
00485         return
00486 
00487     def cylinders(self):
00488         return self.cyl
00489 
00490     def header(self):
00491         s = """
00492 This defines the basic AD geometry.  It consists of these layers:
00493 
00494 ADE = AD envelope
00495 SST = Stainless Steel Tank
00496 OIL = Oil layer
00497 OAV = Outer Acrylic Vessel
00498 LSO = Liquid Scintillator Oil
00499 IAV = Inner Acrylic Vessel
00500 GDS = Gadolinium Doped Scintillator
00501 
00502 All volumes inside the SST are concentric.  
00503 
00504 The ADE cylinder of water is radially concentric with the SST,
00505 coplanar at the SST base and extended above the SST top and in radius.
00506 The SST and any structure external to the SST should be placed in this
00507 envelope.  The center of the SST is offset from the center of the ADE
00508 by the parameter ADadeZoffset.  
00509 
00510 """
00511 
00512         from XmlDetDescGen.util import Comment
00513         return Comment(s)
00514     
00515     def write(self,outdir):
00516         from XmlDetDescGen.util import XmlFile
00517         objects = [self.header()]
00518         for c in self.cylinders():
00519             objects += c.parameters()
00520         file = XmlFile(objects=objects)
00521         file.write(outdir+"/"+self.filename)
00522         return
00523         
00524 class Geometry:
00525     filename = "geometry.xml"
00526     def __init__(self,parameters):
00527 
00528         self.parameters = parameters
00529         self.adcat = None
00530         return
00531 
00532     def catalog(self):
00533 
00534         if self.adcat: return self.adcat
00535 
00536         from XmlDetDescGen.catalog import Catalog
00537         from XmlDetDescGen.reference import Reference
00538 
00539         topcat = Catalog("Geometry")
00540         ac = Catalog("AD")
00541         # This is fake, just to get the right /dd/Geometry path
00542         topcat.refs = [ Reference("#AD",ac) ]
00543 
00544         for c in self.parameters.cylinders():
00545             NAME = c.name.upper()
00546             name = '%(name)s.xml#lv%(name)s'%{'name':NAME}
00547             #print name
00548             ac.refs.append(Reference(name,c.logvol()))
00549             continue
00550 
00551         # Important, needed so full_paths can be set
00552         topcat.update()
00553 
00554         self.adcat = ac
00555         return self.adcat
00556 
00557     def write(self,outdir):
00558         from XmlDetDescGen.util import XmlFile
00559         objects = [self.catalog()]
00560         file = XmlFile(dtd="../DTD/geometry.dtd",
00561                        objects=objects)
00562         file.write(outdir+"/"+self.filename)
00563 
00564         params = ("ADParameters",self.parameters.filename)
00565         AdDetailParams = ("AdDetailParameters","../AdDetails/%s"%self.parameters.filename)
00566         OverflowParams = ("OverflowParameters","../OverflowTanks/%s"%self.parameters.filename)
00567         CalibrationBoxParams = ("CalibrationBoxParameters","../CalibrationBox/%s"%self.parameters.filename)
00568         for c in self.parameters.cylinders():
00569             from XmlDetDescGen.util import ExternalEntity
00570             
00571             details = ("HandWrittenPhysVols","../AdDetails/%sPhysVols.xml"%c.name.upper())
00572 
00573             file = XmlFile(dtd="../DTD/geometry.dtd",
00574                            objects=[ExternalEntity("ADParameters"),ExternalEntity("AdDetailParameters"), ExternalEntity("OverflowParameters"), ExternalEntity("CalibrationBoxParameters"),c.logvol()],
00575                            external_entities=[params, AdDetailParams, OverflowParams, CalibrationBoxParams, details])
00576             file.write(outdir+"/"+c.name.upper()+".xml")
00577 
00578         return
00579 
00580 
00581 class Structure:
00582     def __init__(self):
00583         return
00584 
00585     def detid(self,loc,adn):
00586         # All hard coded numbers from Conventions/DetectorId.h
00587         if loc.lower() == 'db':
00588             iloc = 0x01
00589         elif loc.lower() == 'la':
00590             iloc = 0x02
00591         elif loc.lower() == 'far':
00592             iloc = 0x04
00593         else:
00594             iloc = 0x00
00595         detid = ((iloc<<24)|(adn<<16))
00596         from XmlDetDescGen.structure import UserParameter
00597         return UserParameter("DetectorID","int", ['0x%x'%detid],
00598                              desc="Packed Detector ID")
00599 
00600     def refframe(self,loc,adn):
00601         'Return parameter indicating a coordinate system'
00602         from XmlDetDescGen.structure import UserParameter
00603         return UserParameter("CoordinateSystem","int",[0],
00604                              desc="Indicate this is a user coordinate system, value indicates the level of localness of the coordinate sytem")
00605 
00606 
00607     def write(self,outdir):
00608         from XmlDetDescGen.util import XmlFile, Comment,ExternalEntity
00609         from XmlDetDescGen.structure import DetElem
00610         from XmlDetDescGen.catalog import Catalog
00611         from XmlDetDescGen.reference import Reference
00612 
00613         topcat = Catalog('Structure');
00614         adcat = Catalog('AD');
00615         # Clear our refs because some how this is filled with the
00616         # contents of the /Geometry/Pool catalog!  Python bug???
00617         adcat.refs = []       
00618         topcat.refs = [ adcat ]
00619 
00620         base = "/dd/Structure/AD/"
00621 
00622         ees = []
00623         nf="Near"
00624         nads=2
00625         for loc in ["db","la","far"]:
00626             if loc == "far": 
00627                 nf="Far"
00628                 nads=4
00629 
00630             adcat.things.append(Comment("\n%s %s site AD things\n"%(loc.upper(),nf)))
00631 
00632             last_support = "/dd/Structure/Pool/%s-iws"%loc
00633 
00634             ithing = -1
00635             things = ['ade','sst','oil','oav','lso']
00636             for thing in things:
00637                 ithing += 1
00638                 if thing == 'ade':
00639                     npath = 'pv'+nf+thing.upper()+'%(adn)d'
00640                 else:
00641                     npath = 'pv'+thing.upper()
00642                 for adn in range(1,nads+1):
00643                     de = DetElem("%s-%s%d"%(loc,thing,adn),
00644                                  "/dd/Geometry/AD/lv%s"%thing.upper(),
00645                                  npath=npath%{'adn':adn},
00646                                  support=last_support%{'adn':adn})
00647                     de.refs = []
00648                     if thing != 'lso' and thing != 'iav' and thing != 'gds':
00649                         href="#%s-%s%d"%(loc,things[ithing+1],adn)
00650                         de.refs.append(Reference(href,de))
00651                     if thing == 'oil':
00652                         eename = '%s%dpmts'%(loc,adn)
00653                         ees.append((eename,'../AdPmtStructure/%s%d.xml'%(loc,adn)))
00654                         de.refs.append(ExternalEntity(eename))
00655 
00656                         adrefname = '%s%dreflectors'%(loc,adn)
00657                         ees.append((adrefname,'../AdReflectorStructure/%s%d.xml'%(loc,adn)))
00658                         de.refs.append(ExternalEntity(adrefname))
00659 
00660                         de.refs.append(self.detid(loc,adn))
00661                         de.refs.append(self.refframe(loc,adn))
00662                     adcat.things.append(de)
00663                     continue
00664                 last_support=base+loc+"-"+thing+"%(adn)d"
00665                 continue
00666             continue
00667         file = XmlFile(dtd="../DTD/structure.dtd",
00668                        external_entities=ees)
00669         file.objects = [ adcat ]
00670         file.write(outdir+"/structure.xml")
00671         return
00672 
00673 class AD:
00674     def __init__(self):
00675         self.parameters = Parameters()
00676         self.geometry = Geometry(self.parameters)
00677         self.structure = Structure()
00678         return
00679 
00680 
00681     def write(self,outdir):
00682         self.parameters.write(outdir)
00683         self.geometry.write(outdir)
00684         self.structure.write(outdir)
00685         return
00686         
00687 if '__main__' == __name__:
00688 
00689     ad = AD()
00690     import sys
00691     import os
00692         
00693     try:
00694         xddroot = sys.argv[1]
00695     except IndexError:
00696         xddroot = os.getenv("XMLDETDESCROOT")
00697 
00698     if not xddroot:
00699         print "No XMLDETDESCROOT directory given by environment or command line"
00700         print "Using current working directory"
00701         xddroot="."
00702 
00703     xddroot = ".."
00704 
00705     outdir=xddroot + "/DDDB/AD"
00706     if not os.path.exists(outdir):
00707         print "Directory does not exist, please make first"
00708         print outdir
00709         sys.exit(1)
00710 
00711     ad.write(outdir)
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:13:45 2011 for MiniDryRunXmlDetDesc by doxygen 1.4.7