Index: trunk/ippToPsps/jython/dvodetections.py
===================================================================
--- trunk/ippToPsps/jython/dvodetections.py	(revision 33686)
+++ trunk/ippToPsps/jython/dvodetections.py	(revision 34630)
@@ -44,5 +44,5 @@
            self.importFits(
                    cpmPath,
-                   "IMAGE_ID DET_ID OBJ_ID CAT_ID EXT_ID DB_FLAGS",
+                   "IMAGE_ID DET_ID OBJ_ID CAT_ID EXT_ID DB_FLAGS PHOTCODE AIRMASS M_TIME M_CAL MAG_CAL_ERR D_RA D_DEC PLTSCALE X_CCD_ERR Y_CCD_ERR",
                    cpmTableName)
 
@@ -50,4 +50,6 @@
            self.scratchDb.createIndex(cpmTableName, "CAT_ID")
            self.scratchDb.createIndex(cpmTableName, "OBJ_ID")
+
+           # XXX: Should we create index on PHOTCODE?
 
            # we can now report that we have imported this table
@@ -60,5 +62,5 @@
        self.importFits(
                cptPath,
-               "OBJ_ID CAT_ID EXT_ID",
+               "OBJ_ID CAT_ID EXT_ID RA DEC",
                cptTableName)
 
@@ -67,17 +69,35 @@
        self.scratchDb.createIndex(cptTableName, "OBJ_ID")
 
+       # SA10
+       # Columns needed for DetectionCalib and StackDetectionCalib
+       # zp      = photcode.K * (AIRMASS - 1) + photcode.C_LAM * 0.001 - cpm.M_CAL
+       # zpErr   = cpm.MAG_CAL_ERR
+       # airMass = cpm.AIRMASS
+       # expTime = POW(10.0, 0.4 * cpm.M_TIME)
+       # ra      = cpt.RA  - (cpm.D_RA  / 3600.0)
+       # dec     = cpt.DEC - (cpm.D_DEC / 3600.0)
+       # raErr   = cpm.X_CCD_ERR * cpm.PLTSCALE
+       # decErr  = cpm.Y_CCD_ERR * cpm.PLTSCALE
+
        self.logger.infoPair("Adding","PSPS objIDs")
-       # first try to add a column for PSPS_OBJ_ID. catch failure and continue
+       # first try to add the new columns. catch failure and continue
        try:
-           sql = "ALTER TABLE " + cpmTableName + " ADD COLUMN (PSPS_OBJ_ID BIGINT)"
+           sql = "ALTER TABLE " + cpmTableName + " ADD COLUMN (PSPS_OBJ_ID BIGINT), (ZP REAL), (RA FLOAT), (DEC FLOAT)"
            self.scratchDb.execute(sql)
        except:
            self.logger.infoPair("Already added PSPS_OBJ_ID column to", cpmTableName)
                
-       # shove PSPS objIDs from cpt table into measurement table
-       sql = "UPDATE " + cpmTableName + " AS a, " + cptTableName + " AS b \
-              SET a.PSPS_OBJ_ID = b.EXT_ID \
+       # shove PSPS objIDs from cpt table and the calibrated zero point and coordinates which are formed 
+       # by combining values from multiple tables into cpt table
+       sql = "UPDATE " + cpmTableName + " AS a, " + cptTableName + " AS b, " \
+              + self.scratchDb.dvoPhotcodesTable + " AS c \
+              SET a.PSPS_OBJ_ID = b.EXT_ID, \
+              b.ZP  = c.C_LAM * 0.001 + c.K * (b.AIRMASS - 1) - b.M_CAL, \
+              b.RA  = a.RA  - (b.D_RA  / 3600.0), \
+              b.DEC = a.DEC - (b.D_DEC / 3600.0) \
               WHERE a.CAT_ID = b.CAT_ID \
-              AND a.OBJ_ID = b.OBJ_ID"
+              AND a.OBJ_ID = b.OBJ_ID   \
+              AND b.PHOTCODE = c.CODE"
+
        self.scratchDb.execute(sql)
 
@@ -86,4 +106,5 @@
        # PSPS object IDs assigned in the corresponding cpt file. This is believed to be a chip-boundary 
        # issue within DVO. So, for now, we take the first IMAGE_ID/DET_ID detection we find, and ignore the rest
+       # XXX: Bills 2012-10031 Does this problem still exist?
        self.logger.infoPair("Merging into", self.scratchDb.dvoDetectionTable)
        sql = "INSERT IGNORE INTO " + self.scratchDb.dvoDetectionTable + " (\
@@ -94,4 +115,12 @@
               ,objID \
               ,flags \
+              ,zp   \
+              ,zpErr    \
+              ,airMass  \
+              ,expTime  \
+              ,ra   \
+              ,dec_  \
+              ,raErr    \
+              ,decErr   \
               ,fileID \
               ) SELECT \
@@ -102,6 +131,15 @@
               ,PSPS_OBJ_ID \
               ,DB_FLAGS \
+              ,ZP   \
+              ,MAG_CAL_ERR  \
+              ,AIRMASS  \
+              ,POW(10.0, 0.4 * M_TIME)  \
+              ,RA   \
+              ,DEC  \
+              ,X_CCD_ERR*PLTSCALE   \
+              ,Y_CCD_ERR*PLTSCALE   \
               , " + str(fileId) + " \
               FROM " + cpmTableName
+
        try:
            self.scratchDb.execute(sql)
