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