Index: /trunk/ippToPsps/jython/diffbatch.py
===================================================================
--- /trunk/ippToPsps/jython/diffbatch.py	(revision 37748)
+++ /trunk/ippToPsps/jython/diffbatch.py	(revision 37749)
@@ -297,4 +297,31 @@
 
 
+    '''
+    Populates the DiffToImage table
+    '''
+    def populateDiffToImage(self):
+
+        self.logger.infoPair("Procesing table", "DiffToImage")
+
+        imageIDs = self.gpc1Db.getImageIDsForThisDiffID(diffkmetaID)
+
+        for imageID in imageIDs:
+
+            sql = "INSERT INTO DiffToImage (diffMetaID, imageID) \
+            VALUES (\
+            " + str(diffmetaID) + ", " + imageID + ")"
+            self.scratchDb.execute(sql)
+
+            # now update StackMeta with correct number of inputs
+            #sql = "UPDATE "+filter+"StackMeta SET nP2Images = (SELECT COUNT(distinct(floor(imageID/100))) FROM StackToImage where stackMetaID = "+str(stackmetaID)+")"
+            #self.scratchDb.execute(sql)
+
+        self.tablesToExport.append("DiffToImage")
+
+
+
+
+
+
 
     '''
@@ -461,65 +488,20 @@
     '''
     def populatePspsTables(self):
-
+        self.logger.infoPair("starting","populatePspsTables for diffBatch")
         # loop through all OTAs again to update with DVO IDs
         self.skipBatch = False
-        self.validChips = []    
         self.tablesToExport = []    
         self.tablesToExport.append("DiffMeta")
-        tables = []    
-        otaCount = 0
-        results = {}
-        self.totalOriginal = self.totalSatDet = self.totalNulIInstFlux = self.totalNullPeakFlux = self.totalNullObjID = self.totalDetections = 0
-        self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+")
-        self.logger.info("|  OTA  | Initial total |   Sat Det     | NULL instFlux | NULL obj ID   |  Remainder    |")
-        self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+")
-        for x in range(self.startX, self.endX):
-            for y in range(self.startY, self.endY):
-               
-                # dodge the corners
-                if x==0 and y==0: continue
-                if x==0 and y==7: continue
-                if x==7 and y==0: continue
-                if x==7 and y==7: continue
-
-                ota = "XY%d%d" % (x, y)
-                if ota not in self.imageIDs: continue
-
-                if False and self.config.test and not ((x == 0) and (y == 1)):
-                    print "skipping ota " + ota
-                    continue
-
-                if self.populatePspsTablesChip(ota, x, y, results, tables): otaCount = otaCount + 1
-                if self.skipBatch: 
-                    self.logger.error("fatal problem for exposure, skipping")
-                    return False
-
-        if "Chip" in self.imageIDs:
-            if self.populatePspsTablesChip("Chip", 0, 0, results, tables): otaCount = otaCount + 1
-            if self.skipBatch: 
-                self.logger.error("fatal problem for exposure, skipping")
-                return False
-
-        # print totals
-        self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+")
-        self.logger.info("| Total | %13d | %13d | %13d | %13d | %13d | %13d |", 
-                self.totalOriginal, 
-                self.totalSatDet, 
-                self.totalNulIInstFlux, 
-                self.totalNullPeakFlux, 
-                self.totalNullObjID,
-                self.totalDetections)
-        self.logger.info("+-------+---------------+---------------+---------------+---------------+---------------+")
-
-        # if we only have one table export, i.e. FrameMeta, then get out of here (skip batch, but do not abort)
-        if len(self.tablesToExport) == 1:
-            self.skipBatch = True
-            self.logger.error("No tables to export")
-            return False
-
-        # XXX EAM : turn this on (and fix up the code) if we need it 
-        # self.removeDuplicateObjects()
-
-        self.setMinMaxObjID(tables)
+        self.populateDiffMeta()
+        self.tablesToExport.append("DiffToImage")
+        self.populateDiffToImage()
+        self.tablesToExport.append("DiffDetection")
+        self.populateDiffDetection()
+        
+
+
+
+        
+        self.setMinMaxObjID("DiffDetection")
 
         # update FrameMeta with count OTAs in this file and total number of photometric reference sources
Index: /trunk/ippToPsps/jython/gpc1db.py
===================================================================
--- /trunk/ippToPsps/jython/gpc1db.py	(revision 37748)
+++ /trunk/ippToPsps/jython/gpc1db.py	(revision 37749)
@@ -343,4 +343,35 @@
 
     '''
+    Gets a list of PSPS image IDs for this diff ID
+    '''
+    def getImageIDsForThisDiffID(self, diffID):
+
+        self.logger.debug("Querying GPC1 for image IDs for diff ID: " + str(diffID))
+
+        # JOIN stackInputSkyfile shoule use stack_id as well as warp_id, right? (maybe not -- the join to warp is first)
+        sql = "SELECT DISTINCT CONCAT(exp_id, SUBSTR(class_id, 3, 4)) FROM ( \
+               SELECT DISTINCT exp_id,class_id \
+               FROM warpSkyCellMap \
+               JOIN warpRun USING(warp_id) \
+               JOIN diffInputSkyfile on warp1 = warp_id \ 
+               WHERE diffInputSkyfile.diff_skyfile_id = " + str(diffID) + " AS a"
+
+        try:
+            rs = self.executeQuery(sql)
+        except:
+            self.logger.exception("Can't query for imageIDs")
+
+        imageIDs = []
+        while (rs.next()):
+            imageIDs.append(rs.getString(1))
+        rs.close()
+
+        return imageIDs
+
+    
+
+
+    
+    '''
     Gets some camera-stage meta data for this cam_id
     '''
