| 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 """
00004 Generate AD PMT Detector Elements.
00005 
00006 This generates the Structure XML for all AD PMTs into the TDS at
00007 /dd/Structure/AdPmts and files in to DDDB/AdPmtStructure/*.xml.
00008 
00009 This needs to match the hand-written XML in DDDB/AdPmts/geometry.xml.
00010 
00011 """
00012 
00013 class AdPmtStructure:
00014 
00015     sites = ['db', 'la', 'far']
00016 
00017     def write(self,outdir):
00018         from XmlDetDescGen.util import XmlFile, Comment
00019         from XmlDetDescGen.catalog import Catalog
00020         from XmlDetDescGen.reference import Reference
00021         from XmlDetDescGen.util import ExternalEntity
00022 
00023         topcat = Catalog('Structure');
00024         adcat = Catalog('AdPmtStructure');
00025         adcat.refs = []
00026         adcat.things = []
00027         topcat.refs = [ adcat ]
00028         topcat.things = []
00029 
00030         ees = []
00031         for site,adcount in zip(AdPmtStructure.sites,AdPmts.adcounts):
00032             cat = Catalog('%s-ad'%site);
00033             cat.refs=[]
00034             for iad in range(0,adcount):
00035                 iad += 1
00036                 eename="%s%dpmts"%(site,iad)
00037                 ees.append((eename,"%s%d.xml"%(site,iad)))
00038                 cat.refs.append(ExternalEntity(eename))
00039                 continue
00040             adcat.refs.append(cat)
00041 
00042         file = XmlFile(dtd="../DTD/structure.dtd",
00043                        external_entities=ees)
00044         file.objects = [ adcat ]
00045         file.write(outdir+"/structure.xml")
00046 
00047 
00048 class AdPmts:
00049 
00050     lvname="/dd/Geometry/PMT/lvPmtHemiwPmtHolder"
00051     lvname2="/dd/Geometry/PMT/lvHeadonPmtFrame"
00052     siteids = [0x01,0x02,0x04]
00053     adcounts = [ 2,    2,     4]
00054 
00055     def __init__(self,site,siteid,adcount):
00056         self.site = site
00057         self.siteid = siteid
00058         self.adcount = adcount
00059         pass
00060 
00061     # this must match what Conventions/Detectors does
00062     def pmtid(self,site,adn,icol,iring):
00063         return (site<<24)|(adn<<16)|(iring<<8)|icol
00064 
00065 
00066     def write(self,outdir):
00067 
00068         from XmlDetDescGen.util import XmlFile, Comment
00069         from XmlDetDescGen.structure import DetElem,UserParameter
00070 
00071         for adn in range(0,self.adcount):
00072             adn += 1
00073 
00074             pmts = []
00075 
00076             ipmt = 0
00077             for iring in range(0,8):
00078                 iring += 1
00079 
00080                 # 3 cols of PMTs on Ladder #1, 1 through 3
00081                 ladn = 1
00082                 for icol in range(0, 3):
00083                     icol += 1
00084                     ipmt = ipmt+1
00085                     coln = (ladn - 1)*3 + icol
00086                     pmtid = self.pmtid(siteid,adn,coln,iring)
00087                     data = {
00088                         'site':site,
00089                         'siteid':siteid,
00090                         'adnum':adn,
00091                         'ladnum':ladn,
00092                         'ringnum':iring,
00093                         'columnnum':icol,
00094                         'glbcoln':coln,
00095                         'pmtid':pmtid
00096                         }
00097                     
00098                     de = DetElem('%(site)s-ad%(adnum)d-ring%(ringnum)d-column%(glbcoln)d'%data,
00099                                  self.lvname,
00100                                  npath="pvAdPmtArray/pvAdPmtLadder1/pvAdPmtLadderArrayRotated/pvAdPmtLadderArrayRow:%(ringnum)s/pvAdPmtInCol:%(columnnum)d/pvAdPmtUnit"%data,
00101                                  support="/dd/Structure/AD/%(site)s-oil%(adnum)d"%data)
00102                     
00103                     de.refs = [UserParameter("PmtID","int",['0x%x'%pmtid],desc="Packed PMT ID")]
00104                     
00105                     pmts.append(de)
00106                     continue
00107 
00108                 # 3 cols of PMTs on Ladder #7
00109                 ladn = 7                
00110                 for icol in range(0, 3):
00111                     icol += 1
00112                     ipmt = ipmt+1
00113                     coln = (ladn - 1)*3 + icol
00114                     pmtid = self.pmtid(siteid,adn,coln,iring)
00115                     data = {
00116                         'site':site,
00117                         'siteid':siteid,
00118                         'adnum':adn,
00119                         'ladnum':ladn,
00120                         'ringnum':iring,
00121                         'columnnum':icol,
00122                         'glbcoln':coln,
00123                         'pmtid':pmtid
00124                         }
00125                     
00126                     de = DetElem('%(site)s-ad%(adnum)d-ring%(ringnum)d-column%(glbcoln)d'%data,
00127                                  self.lvname,
00128                                  npath="pvAdPmtArray/pvAdPmtLadder7/pvAdPmtLadderArrayRotated/pvAdPmtLadderArrayRow:%(ringnum)s/pvAdPmtInCol:%(columnnum)d/pvAdPmtUnit"%data,
00129                                  support="/dd/Structure/AD/%(site)s-oil%(adnum)d"%data)
00130                     
00131                     de.refs = [UserParameter("PmtID","int",['0x%x'%pmtid],desc="Packed PMT ID")]
00132                     
00133                     pmts.append(de)
00134                     continue
00135 
00136                 continue
00137 
00138             iring = 0      
00139             for icol in range(0,6):
00140                 icol += 1
00141                 ipmt = ipmt+1
00142                 pmtid = self.pmtid(siteid,adn,icol,iring)
00143                 data = {
00144                         'site':site,
00145                         'siteid':siteid,
00146                         'adnum':adn,
00147                         'ringnum':iring,
00148                         'columnnum':icol,
00149                         'pmtid':pmtid
00150                         }
00151                     
00152                 de = DetElem('%(site)s-ad%(adnum)d-ring%(ringnum)d-column%(columnnum)d'%data,
00153                              self.lvname2,
00154                              npath="pvAdCalibrationPmtArray/pvAd2inPmt:%(columnnum)d"%data,
00155                              support="/dd/Structure/AD/%(site)s-oil%(adnum)d"%data)
00156                     
00157                 de.refs = [UserParameter("PmtID","int",['0x%x'%pmtid],desc="Packed PMT ID")]
00158                     
00159                 pmts.append(de)
00160                 continue
00161 
00162             file = XmlFile()
00163             file.objects = pmts
00164             file.write(outdir+"/%s%d.xml"%(self.site,adn))
00165             continue
00166                              
00167 if '__main__' == __name__:
00168 
00169     import sys,os
00170     try:
00171         xddroot = sys.argv[1]
00172     except IndexError:
00173         xddroot = os.getenv("XMLDETDESCROOT")
00174 
00175     if not xddroot:
00176         print "No XMLDETDESCROOT directory given by environment or command line"
00177         print "Using current working directory"
00178         xddroot="."
00179 
00180     xddroot = ".."
00181 
00182     # to fix the local vs systematic path problem. --- Wei, Jan, 2010
00183     xddroot = ".."
00184 
00185     outdir=xddroot + "/DDDB/AdPmtStructure"
00186     if not os.path.exists(outdir):
00187         print "Directory does not exist, please make first"
00188         print outdir
00189         sys.exit(1)
00190 
00191 
00192     for site,siteid,adcount in zip(AdPmtStructure.sites,AdPmts.siteids,AdPmts.adcounts):
00193         aps = AdPmts(site,siteid,adcount)
00194         aps.write(outdir)
00195 
00196     aps = AdPmtStructure()
00197     aps.write(outdir)
00198 
00199 
| 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