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

Generated on Fri May 16 2014 09:56:07 for XmlDetDesc by doxygen 1.7.4