/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

PrintPMTMap.py
Go to the documentation of this file.
00001 # nuwa.py -n 0 --dbconf="offline_db" -m"Quickstart.PrintPMTMap -s dayabay -d iws"
00002 # chao@bnl.gov 2011-11-08
00003 
00004 from DybPython.DybPythonAlg import DybPythonAlg
00005 from GaudiPython import SUCCESS, FAILURE
00006 from GaudiPython import gbl
00007 import PyCintex
00008 from DybPython.Util.decorators import register_svc, initialize_alg, finalize_alg
00009 
00010 FeeChannelId = gbl.DayaBay.FeeChannelId
00011 AdPmtSensor = gbl.DayaBay.AdPmtSensor
00012 PoolPmtSensor = gbl.DayaBay.PoolPmtSensor
00013 
00014 TimeStamp = gbl.TimeStamp
00015 Detector = gbl.DayaBay.Detector
00016 ServiceMode = gbl.ServiceMode
00017 Site = gbl.Site
00018 SimFlag = gbl.SimFlag
00019 Context = gbl.Context
00020 DetectorId = gbl.DetectorId
00021 
00022 class PrintPMTMap(DybPythonAlg):
00023     
00024     def __init__(self, name):
00025         DybPythonAlg.__init__(self, name)
00026         self.pmtCount = 0
00027         self.site = 'dayabay'
00028         self.detector = 'iws'
00029         self.timestamp = ''
00030         self.detId_dict = {
00031             'ad1' : DetectorId.kAD1,
00032             'ad2' : DetectorId.kAD2,
00033             'ad3' : DetectorId.kAD3,
00034             'ad4' : DetectorId.kAD4,
00035             'iws' : DetectorId.kIWS,
00036             'ows' : DetectorId.kOWS,
00037         }
00038         self.siteId_dict = {
00039             'dayabay' : Site.kDayaBay,
00040             'lingao' : Site.kLingAo,
00041             'far' : Site.kFar,
00042         }
00043     
00044     # -------------------------------------- 
00045     @register_svc('pmtGeomSvc', ('IPmtGeomInfoSvc','PmtGeomInfoSvc'))
00046     @register_svc('cableSvc', ('ICableSvc','CableSvc'))
00047     @initialize_alg
00048     def initialize(self):
00049         try:
00050             self.siteId = self.siteId_dict[self.site]
00051             self.detId = self.detId_dict[self.detector]
00052         except IndexError:
00053             self.error("Site:Detector not found: %s:%s" % (self.site, self.detector))
00054             return FAILURE
00055         
00056         if not self.timestamp:
00057             import time
00058             self.t = TimeStamp(time.time()) # now
00059         else:
00060             year, month, day = self.timestamp.split(':')
00061             self.t = TimeStamp(int(year), int(month), int(day), 0, 0, 0)
00062                         
00063         if (self.detId in (DetectorId.kIWS, DetectorId.kOWS)):
00064             self.printPoolPMTMap()                                        
00065         else:
00066             self.printAdPMTMap()
00067         return SUCCESS
00068         
00069     # --------------------------------------
00070     def printPoolPMTMap(self):
00071         Gaudi = PyCintex.makeNamespace('Gaudi')
00072         simFlag = SimFlag.kData
00073         context = Context(self.siteId, simFlag, self.t, self.detId)
00074         svcMode = ServiceMode(context, 0)
00075         
00076         de_dict = {
00077             'dayabay' : '/dd/Structure/Pool/db-ows',
00078             'lingao' : '/dd/Structure/Pool/la-ows',
00079             'far' : '/dd/Structure/Pool/far-ows',
00080         }  # center is center of ows
00081         de = self.getDet(de_dict[self.site]) 
00082         
00083         print "# id detector wall spot inward-facing board connector x[mm] y[mm] z[mm]"
00084         
00085         for pmtId in self.cableSvc.poolPmtSensors(svcMode):
00086             if pmtId.bogus(): continue
00087             channelId = self.cableSvc.feeChannelId(pmtId, svcMode)
00088             pmtGeomInfo = self.pmtGeomSvc.get(pmtId.fullPackedData())
00089             if (pmtGeomInfo):
00090                 globalVector = pmtGeomInfo.globalPosition()
00091                 globalXYZ = Gaudi.XYZPoint(globalVector.x(), globalVector.y(), globalVector.z())
00092                 localXYZ = de.geometry().toLocal(globalXYZ)
00093                 
00094                 print "%s %4d %4d %4d %4d %4d %10.1f %10.1f %10.1f" % (pmtId.asString(), 
00095                     pmtId.wallNumber(), pmtId.wallSpot(), pmtId.inwardFacing(), 
00096                     channelId.board(), channelId.connector(),
00097                     localXYZ.x(), localXYZ.y(), localXYZ.z())
00098                 self.pmtCount += 1
00099 
00100         # the other way around:
00101         # 
00102         # chanId = FeeChannelId(board, connector, self.siteId, self.detId)
00103         # pmtId = self.cableSvc.poolPmtSensor(chanId, svcMode)
00104 
00105 
00106     # --------------------------------------
00107     def printAdPMTMap(self):
00108         Gaudi = PyCintex.makeNamespace('Gaudi')
00109         simFlag = SimFlag.kData
00110         context = Context(self.siteId, simFlag, self.t, self.detId)
00111         svcMode = ServiceMode(context, 0)
00112         
00113         de_dict = {
00114             'dayabay' : '/dd/Structure/AD/db-'+self.detector.replace('ad', 'sst'),
00115             'lingao' : '/dd/Structure/AD/la-'+self.detector.replace('ad', 'sst'),
00116             'far' : '/dd/Structure/AD/far-'+self.detector.replace('ad', 'sst'),
00117         } # center is the center of sst
00118         de = self.getDet(de_dict[self.site]) 
00119                 
00120         print "# id detector ring column board connector x[mm] y[mm] z[mm]"
00121         
00122         for pmtId in self.cableSvc.adPmtSensors(svcMode):
00123             if pmtId.bogus(): continue
00124             channelId = self.cableSvc.feeChannelId(pmtId, svcMode)
00125             pmtGeomInfo = self.pmtGeomSvc.get(pmtId.fullPackedData())
00126             if (pmtGeomInfo):
00127                 globalVector = pmtGeomInfo.globalPosition()
00128                 globalXYZ = Gaudi.XYZPoint(globalVector.x(), globalVector.y(), globalVector.z())
00129                 localXYZ = de.geometry().toLocal(globalXYZ)
00130                 
00131                 print "%s %4d %4d %4d %4d %10.1f %10.1f %10.1f" % (pmtId.asString(), 
00132                     pmtId.ring(), pmtId.column(),
00133                     channelId.board(), channelId.connector(),
00134                     localXYZ.x(), localXYZ.y(), localXYZ.z())
00135                 self.pmtCount += 1                      
00136                     
00137     # --------------------------------------         
00138     def execute(self):
00139         self.info("bogus execution")
00140         return SUCCESS
00141         
00142     # -------------------------------------- 
00143     @finalize_alg
00144     def finalize(self):
00145         self.info("%s %s: Total PMT Count: %d" % (self.site.title(), self.detector.title(), self.pmtCount))
00146         return SUCCESS
00147 
00148 
00149 #####  Job Configuration for nuwa.py ########################################
00150 options = None
00151 
00152 def configure(argv=[]):
00153     """Configuration with command line arguments"""   
00154     global options 
00155     from optparse import OptionParser
00156 
00157     parser = OptionParser()
00158     parser.add_option("-d", "--detector", type="string",
00159         default='iws', help="detector name")
00160     parser.add_option("-s", "--site", type="string",
00161         default='dayabay', help="site name")
00162     parser.add_option("-t", "--timestamp", type="string",
00163         default='', help="timestamp of dbi query [y:m:d]")        
00164     (options, args) = parser.parse_args(args=argv)
00165     
00166 def run(app):
00167     app.ExtSvc += ["CableSvc", "PmtGeomInfoSvc"]
00168     alg = PrintPMTMap("PrintPMTMap")
00169     alg.detector = options.detector.lower()
00170     alg.site = options.site.lower()
00171     alg.timestamp = options.timestamp
00172     
00173     app.addAlgorithm(alg)
00174     
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:54:33 for Quickstart by doxygen 1.7.4