Index: trunk/ippToPsps/jython/forcedgalaxybatch.py
===================================================================
--- trunk/ippToPsps/jython/forcedgalaxybatch.py	(revision 38964)
+++ trunk/ippToPsps/jython/forcedgalaxybatch.py	(revision 38965)
@@ -142,5 +142,5 @@
         for filter in filters:
             filterID = self.scratchDb.getFilterId(filter[1])
-
+            photcode = self.scratchDb.getPhotoCalID("GPC1." + filter[1] + ".ForcedWarp")
 
             # This is going to need to join elsewhere to get all the fields?
@@ -148,22 +148,43 @@
             # Ra, Dec, RaErr, DecErr
             
-            # Should GalChiSq fold in Npix somehow?  
-            sql = "UPDATE ForcedGalaxyShape JOIN " \
-                + cpqTable + " AS cpq ON (cpq.row = (ForcedGalaxyShape.row* " + str(filterCount) + ")-(" + str(filterCount) + " - " + str(filter[0]) + ")) " \
-                + " SET " + \
-                + " ForcedGalaxyShape." + filter[1] + "ippDetectID                = DET_ID," \
-                + " ForcedGalaxyShape." + filter[1] + "forcedSummaryID            = IMAGE_ID," \
-                + " ForcedGalaxyShape." + filter[1] + "GalModelType               = MODEL_TYPE," \
-                + " ForcedGalaxyShape." + filter[1] + "GalMajor                   = MAJOR_AXIS," \
-                + " ForcedGalaxyShape." + filter[1] + "GalMajorErr                = MAJOR_AXIS_ERR," \
-                + " ForcedGalaxyShape." + filter[1] + "GalMinor                   = MINOR_AXIS," \
-                + " ForcedGalaxyShape." + filter[1] + "GalMinorErr                = MINOR_AXIS_ERR," \
-                + " ForcedGalaxyShape." + filter[1] + "GalMag                     = MAG," \
-                + " ForcedGalaxyShape." + filter[1] + "GalMagErr                  = MAG_ERR," \
-                + " ForcedGalaxyShape." + filter[1] + "GalRa                      = RA," \
-                + " ForcedGalaxyShape." + filter[1] + "GalDec                     = DEC," \
-                + " ForcedGalaxyShape." + filter[1] + "GalRaErr                   = RA_ERR," \
-                + " ForcedGalaxyShape." + filter[1] + "GalDecErr                  = DEC_ERR," \
-                + " ForcedGalaxyShape." + filter[1] + "GalChisq                   = CHISQ "
+            # This won't work, as we need to join on modeltype/obj_id/filter
+#                + cpqTable + " AS cpq ON (cpq.row = (ForcedGalaxyShape.row* " + str(filterCount) + ")-(" + str(filterCount) + " - " + str(filter[0]) + ")) " \ 
+#                + " ForcedGalaxyShape." + filter[1] + "GalModelType               = MODEL_TYPE," \
+
+            # Should GalChiSq fold in Npix somehow? 
+#             sql = "UPDATE ForcedGalaxyShape JOIN " \
+#                + cpqTable + " AS cpq ON (cpq.row = (ForcedGalaxyShape.row* " + str(filterCount) + ")-(" + str(filterCount) + " - " + str(filter[0]) + ")) " \ 
+#                 + " SET " + \
+#                 + " ForcedGalaxyShape." + filter[1] + "ippDetectID                = DET_ID," \
+#                 + " ForcedGalaxyShape." + filter[1] + "forcedSummaryID            = IMAGE_ID," \
+#                 + " ForcedGalaxyShape." + filter[1] + "GalMajor                   = MAJOR_AXIS," \
+#                 + " ForcedGalaxyShape." + filter[1] + "GalMajorErr                = MAJOR_AXIS_ERR," \
+#                 + " ForcedGalaxyShape." + filter[1] + "GalMinor                   = MINOR_AXIS," \
+#                 + " ForcedGalaxyShape." + filter[1] + "GalMinorErr                = MINOR_AXIS_ERR," \
+#                 + " ForcedGalaxyShape." + filter[1] + "GalMag                     = MAG," \
+#                 + " ForcedGalaxyShape." + filter[1] + "GalMagErr                  = MAG_ERR," \
+#                 + " ForcedGalaxyShape." + filter[1] + "GalRa                      = RA," \
+#                 + " ForcedGalaxyShape." + filter[1] + "GalDec                     = DEC," \
+#                 + " ForcedGalaxyShape." + filter[1] + "GalRaErr                   = RA_ERR," \
+#                 + " ForcedGalaxyShape." + filter[1] + "GalDecErr                  = DEC_ERR," \
+#                 + " ForcedGalaxyShape." + filter[1] + "GalChisq                   = CHISQ "
+
+            sqlLine = sqlUtility("UPDATE ForcedGalaxyShape AS a, " + cpqTable + " AS b SET")
+            sqlLine.group("a." + filter[1] + "ippDetectID",     "b.DET_ID")
+            sqlLine.group("a." + filter[1] + "forcedSummaryID", "b.IMAGE_ID")
+            sqlLine.group("a." + filter[1] + "GalMajor",        "b.MAJOR_AXIS")
+            sqlLine.group("a." + filter[1] + "GalMajorErr",     "b.MAJOR_AXIS_ERR")
+            sqlLine.group("a." + filter[1] + "GalMinor",        "b.MINOR_AXIS")
+            sqlLine.group("a." + filter[1] + "GalMinorErr",     "b.MINOR_AXIS_ERR")
+            sqlLine.group("a." + filter[1] + "GalMag",          "b.MAG")
+            sqlLine.group("a." + filter[1] + "GalMagErr",       "b.MAG_ERR")
+# These fields don't exist.
+#            sqlLine.group("a." + filter[1] + "GalRa",           "b.RA")
+#            sqlLine.group("a." + filter[1] + "GalDec",          "b.DEC")
+#            sqlLine.group("a." + filter[1] + "GalRaErr",        "b.RA_ERR")
+#            sqlLine.group("a." + filter[1] + "GalDecErr",       "b.DEC_ERR")
+            sqlLine.group("a." + filter[1] + "GalChisq",        "b.CHISQ")
+            sql = sqlLine.makeEquals("WHERE a.objID = b.OBJ_ID AND a.galModelType = b.MODEL_TYPE AND b.Photcode = " + photcode)
+            
 
             try: self.scratchDb.execute(sql)
@@ -215,3 +236,25 @@
 
         
-        
+        self.logger.infoPair("Dropping row column from ", "ForcedGalaxyShape table")
+        self.scratchDb.dropColumn("ForcedGalaxyShape", "row")
+
+        self.logger.infoPair("setting minmaxobjid for ", "ForcedGalaxyShape table")
+        self.setMinMaxObjID(["ForcedGalaxyShape"])
+        self.logger.infoPair("checking if we have detections", "ForcedGalaxyShape table")
+        rowcount = self.scratchDb.getRowCount("ForcedGalaxyShape")
+        if rowcount == 0:
+            self.logger.infoPair("skipping this one", "ForcedGalaxyShape")
+            self.skipBatch = False
+            return True
+        else:
+            return True
+
+    '''
+    Populate psps tables
+    '''
+    def populatePspsTables(self):
+        
+        if not self.populateForcedGalaxyShapeTable(): return False
+
+        # My example is removing objID duplicates.  Since ForcedGalaxyShape can have multiple models for a given object, I'm not doing that.
+
