Index: trunk/ippToPsps/jython/scratchdb.py
===================================================================
--- trunk/ippToPsps/jython/scratchdb.py	(revision 33677)
+++ trunk/ippToPsps/jython/scratchdb.py	(revision 33678)
@@ -24,5 +24,5 @@
         self.dvoDoneTable = "dvoDone"
         self.dvoSkyTable = "dvoSkyTable"
-
+        self.dvoPhotcodesTable = "dvoPhotcodes"
 
     '''
@@ -249,21 +249,4 @@
 
     '''
-    Gets the id for the cpm file for the provided region
-    '''
-    def getDvoCpmFileIdForRegion(self, region):
-
-        id = -1
-        sql = "SELECT id FROM " + self.dvoDoneTable + " WHERE region = '" + region + "' AND path LIKE '%.cpm'";
-        try:
-            rs = self.executeQuery(sql)
-            rs.first()
-            id = rs.getInt(1)
-        except:
-            self.logger.errorPair("Could not get file id from " + self.dvoDoneTable, "for region: " + region)
-
-        return id
-
-
-    '''
     Gets the id for the provided file
     '''
@@ -277,5 +260,5 @@
             id = rs.getInt(1)
         except:
-            self.logger.errprPair("Could not get file id from " + self.dvoDoneTable + "for", path)
+            self.logger.errorPair("Could not get file id from " + self.dvoDoneTable + "for", path)
 
         return id
@@ -337,5 +320,6 @@
                 return False
 
-        except:
+        except Exception, e:
+            print str(e)
             self.logger.errorPair("No DVO files ingested for this path", path)
             return False
@@ -343,5 +327,5 @@
     '''
     Checks whether the astrometric solution is ok for this chip
-    TODO the value of 50 for numAstroRef is hardcoded here, but this should be temporary anyway
+    TODO the value of 50 for numAstroRef (provided by Gene) is hardcoded here, but this should be temporary anyway
     '''
     def astrometricSolutionOK(self, ota):
@@ -411,29 +395,28 @@
     '''
     Removes the provided DVO FITS files from from dvoDone and dvoDetection tables
-    Returns a count of the number of detections deleted
-    '''
-    def purgeTheseDvoRegions(self, regions):
+    Returns a count of the number of detections deleted, if any
+    '''
+    def purgeTheseDvoRegions(self, regions, fileTypes):
 
         detectionCount = self.getRowCount(self.dvoDetectionTable)
         for region in regions:
-           
-           fileId = self.getDvoCpmFileIdForRegion(region)
-
-           if fileId < 0:
-               self.logger.errorPair("Unable to get file ID to delete " + region + " from", self.dvoDoneTable)
-               continue
-
-           sql = "DELETE FROM " + self.dvoDoneTable + " WHERE region = '" + region + "'"
-           try: self.execute(sql)
-           except:
-               self.logger.errorPair("Unable to delete " + region + " from", self.dvoDoneTable)
-
-        finalCount = detectionCount - self.getRowCount(self.dvoDetectionTable)
-
-        # after a big delete, we should OPTIMIZE the table
-        self.logger.infoPair("Running OPTIMIZE on ", self.dvoDetectionTable)
-        if finalCount > 0: self.optimizeTable(self.dvoDetectionTable)
-
-        return finalCount
+          
+           for fileType in fileTypes:
+               sql = "DELETE FROM " + self.dvoDoneTable + " WHERE region = '" + region + "' AND path LIKE '%" + fileType + "'"
+               try: self.execute(sql)
+               except:
+                    self.logger.errorPair("Unable to delete " + fileType + " file from", self.dvoDoneTable)
+
+               sql = "DROP TABLE " + self.getDbFriendlyTableName(region + "." + fileType)
+               self.execute(sql)
+
+        deletedDetectionCount = detectionCount - self.getRowCount(self.dvoDetectionTable)
+
+        # after a big detection delete, we should OPTIMIZE the table
+        if deletedDetectionCount > 0:
+            self.logger.infoPair("Running OPTIMIZE on ", self.dvoDetectionTable)
+            self.optimizeTable(self.dvoDetectionTable)
+
+        return deletedDetectionCount
            
     '''
@@ -515,5 +498,10 @@
     def getDvoRegionsForThisBox(self, regions, minRa, maxRa, minDec, maxDec):
 
-        sql = "SELECT name FROM " + self.dvoSkyTable + " \
+        sql = "SELECT \
+               INDEX_, \
+               R_MIN+ (R_MAX - R_MIN)/2.0, \
+               D_MIN + (D_MAX - D_MIN)/2.0, \
+               NAME \
+               FROM " + self.dvoSkyTable + " \
                WHERE NOT ((" + str(maxRa) + " <= R_MIN) OR \
                        (" + str(minRa) + " >= R_MAX) OR \
@@ -523,5 +511,10 @@
         try:
             rs = self.executeQuery(sql)
-            while (rs.next()): regions.append(rs.getString(1))
+            while (rs.next()): regions.append([
+                    rs.getInt(1), 
+                    rs.getFloat(2), 
+                    rs.getFloat(3), 
+                    rs.getString(4)])
+
             rs.close()
         except:
@@ -529,2 +522,19 @@
 
 
+    '''
+    Gets the id for the provided file
+    '''
+    def getRegionNameFromThisDvoIndex(self, index):
+
+        region = ""
+        sql = "SELECT NAME FROM " + self.dvoSkyTable + " WHERE INDEX_ = " + str(index)
+        try:
+            rs = self.executeQuery(sql)
+            rs.first()
+            region = rs.getString(1)
+            rs.close()
+        except:
+            self.logger.errorPair("Could not get region using index", sql )
+
+        return region
+
