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

In This Package:

DQDumpPmt.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # useage: nuwa.py --no-history -n -1 -m"RollingGain" -m"DQDump.DQDumpPmt" rawdata 
00003 
00004 # Load DybPython
00005 from DybPython.DybPythonAlg import DybPythonAlg
00006 from GaudiPython import SUCCESS, FAILURE
00007 from GaudiPython import gbl
00008 import GaudiKernel.SystemOfUnits as units
00009 DetectorSensor = gbl.DayaBay.DetectorSensor
00010 ServiceMode = gbl.ServiceMode
00011 
00012 from DybDbi import gDbi
00013 from DybDbi import GDataQualityPmt as DQPmt
00014 from DybDbi import ContextRange,Site,SimFlag,TimeStamp
00015 
00016 import os,sys
00017 import MySQLdb
00018 os.environ['DBCONF'] = 'tmp_ligs_offline_db'
00019 
00020 # Make your algorithm
00021 class DumpPmtToDbAlg(DybPythonAlg):
00022     "Template Python Algorithm"
00023     def __init__(self,name):
00024         DybPythonAlg.__init__(self,name)
00025         self.runNo = 0
00026         self.fileNo = 0
00027         return
00028 
00029     def getSeqNo(self, runNo, fileNo):
00030         """Get file seqno by runno and fileno"""
00031         try:
00032             con = MySQLdb.connect( host = "dayabaydb.lbl.gov",
00033                                    user = "dayabay",
00034                                    passwd = "3quarks",
00035                                    db = "offline_db" )
00036             cursor = con.cursor()
00037             cursor.execute("SELECT seqno FROM DaqRawDataFileInfo WHERE runNo = "
00038                             + str(runNo) + " AND " + "fileNo = " + str(fileNo))
00039             row = cursor.fetchone()
00040             if row:
00041                 print "get seqno successful"
00042         except MySQLdb.Error,e:
00043             print "Error %d: %s" % (e.args[0], e.args[1])
00044             sys.exit(1)
00045         cursor.close()
00046         con.close()
00047         return row[0]
00048 
00049     def getFileTimeInfo(self, seqNo):
00050         """Talk to offline DB and get the time range of the run"""
00051         try:
00052             con = MySQLdb.connect( host = "dayabaydb.lbl.gov",
00053                                    user = "dayabay",
00054                                    passwd = "3quarks",
00055                                    db = "offline_db" )
00056             cursor = con.cursor()
00057             cursor.execute("SELECT timestart,timeend FROM DaqRawDataFileInfoVld WHERE seqno = " + str(seqNo))
00058             row = cursor.fetchone()
00059             if row:
00060                 print "get file time info successfully"
00061         except MySQLdb.Error,e:
00062             print "Error %d: %s" % (e.args[0], e.args[1])
00063             sys.exit(1)
00064 
00065         cursor.close()
00066         con.close()
00067         return row
00068 
00069     def dumptodb(self):
00070         seqNo = self.getSeqNo(self.runNo, self.fileNo)
00071         fileTime = self.getFileTimeInfo(seqNo)
00072         import calendar
00073         starttime = calendar.timegm( fileTime[0].timetuple() )
00074         endtime = calendar.timegm( fileTime[1].timetuple() )
00075         
00076         wrt = DQPmt.Wrt()
00077         cr = ContextRange( Site.kAll,
00078                            SimFlag.kData|SimFlag.kMC,
00079                            TimeStamp(starttime),
00080                            TimeStamp(endtime) )
00081         wrt.ctx(contextrange=cr, versiondate=TimeStamp(0,0))
00082 
00083         FILENAME='pmtDataTable_01.txt'
00084         f = open(FILENAME,'r')
00085         for line in f:
00086             if line[0] != '#':
00087                 line = line.strip()
00088                 para = line.split()
00089                 status = int( para[2] )
00090                 chi2ndf = float( para[5] )
00091                 pmtID = para[0]
00092                 pmtInfo = para[1]
00093                 gain = float( para[6] )
00094                 gainErr = float( para[7] )
00095                 darkRate = float( para[15] )
00096                 darkRateErr = float( para[16] )
00097                 elecNoiseRate = float( para[17] )
00098                 elecNoiseRateErr = float( para[18] )
00099                 preAdc = float( para[19] )
00100                 preAdcErr = float( para[20] )
00101                 record = DQPmt.Create( RunNo = self.runNo,
00102                                        FileNo = self.fileNo,
00103                                        PmtId = DetectorSensor( int(pmtID) ),
00104                                        Describ = pmtInfo,
00105                                        Status = status,
00106                                        Chi2ndf = chi2ndf,
00107                                        Gain = gain,
00108                                        GainErr = gainErr,
00109                                        DarkRate = darkRate,
00110                                        DarkRateErr = darkRateErr,
00111                                        ElecNoiseRate = elecNoiseRate,
00112                                        ElecNoiseRateErr = elecNoiseRateErr,
00113                                        PreAdc = preAdc,
00114                                        PreAdcErr = preAdcErr )
00115                 wrt.Write(record)
00116         wrt.Close()
00117         return
00118 
00119     def initialize(self):
00120         status = DybPythonAlg.initialize(self)
00121         if status.isFailure(): return status
00122         
00123         self.daqDetailsSvc = self.svc('IDaqDetailsSvc','DetailsFromRecordSvc')
00124         if self.daqDetailsSvc == None:
00125             self.error("Failed to get IDaqDetailsSvc")
00126             return FAILURE
00127         
00128         self.info("initializing")
00129         return SUCCESS
00130 
00131     def execute(self):
00132         if((self.runNo == 0) and (self.fileNo == 0) ):
00133             evt = self.evtSvc()
00134             readoutHdr = evt["/Event/Readout/ReadoutHeader"]
00135             if readoutHdr == None:
00136                 self.error("Failed to get current readout header")
00137                 return FAILURE
00138             svcMode = ServiceMode(readoutHdr.context(), 0)
00139             self.runNo = self.daqDetailsSvc.runDetails(svcMode).runNumber()
00140             self.fileNo = self.daqDetailsSvc.fileDetails(svcMode).fileNumber() 
00141         return SUCCESS
00142         
00143     def finalize(self):
00144         self.info("finalizing")
00145         self.dumptodb()
00146         os.system("mv pmtDataTable_01.txt pmtDataTable_01_finished.txt")
00147         status = DybPythonAlg.finalize(self)
00148         return status
00149 
00150 #####  Job Configuration for nuwa.py ########################################
00151 def configure():
00152     """ Template job module """
00153     return
00154 
00155 def run(app):
00156     '''
00157     Configure and add the algorithm to job
00158     '''
00159     app.ExtSvc += ["DetailsFromRecordSvc"]
00160     # Add Python algorithm to job here
00161     myAlg = DumpPmtToDbAlg("MyDumpPmtAlg")
00162     # Add algorithm to job
00163     app.addAlgorithm(myAlg)
00164     pass
00165 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 09:54:23 for DQDump by doxygen 1.7.4