Index: /branches/eam_branches/ipp-20130307/ippToPsps/jython/detectionbatch.py
===================================================================
--- /branches/eam_branches/ipp-20130307/ippToPsps/jython/detectionbatch.py	(revision 35368)
+++ /branches/eam_branches/ipp-20130307/ippToPsps/jython/detectionbatch.py	(revision 35369)
@@ -681,4 +681,5 @@
         # store these for later
         self.imageIDs[chipname] = header['IMAGEID']
+        self.sourceIDs[chipname] = header['SOURCEID']
             
         # populate ImageMeta
@@ -702,4 +703,5 @@
         # dictionary objects to hold imageIDs for later
         self.imageIDs = {}
+        self.sourceIDs = {}
 
         # loop through all OTAs and populate ImageMeta extensions
@@ -791,5 +793,5 @@
 
         # does this chip exist in the DVO image table (if NOT, then skip it)
-        if not self.scratchDb.haveThisChip(self.imageIDs[chipname]):
+        if not self.scratchDb.haveThisChip(self.imageIDs[chipname], self.sourceIDs[chipname]):
             self.logger.info("| %5s |            ------------- Chip not in DVO : rejecting ------------                    |" % chipname)
             return False
Index: /branches/eam_branches/ipp-20130307/ippToPsps/jython/scratchdb.py
===================================================================
--- /branches/eam_branches/ipp-20130307/ippToPsps/jython/scratchdb.py	(revision 35368)
+++ /branches/eam_branches/ipp-20130307/ippToPsps/jython/scratchdb.py	(revision 35369)
@@ -370,24 +370,40 @@
     Checks whether the given chipID is in the DVO Image table
     '''
-    def haveThisChip(self, imageID):
-
-        sql = "SELECT IMAGE_ID FROM " + self.dvoImagesTable + " WHERE IMAGE_ID = " + str(imageID)
-
-        try:
-            rs = self.executeQuery(sql)
-            rs.first()
+    def haveThisChip(self, imageID, sourceID):
+
+        sql = "SELECT EXTERN_ID FROM " \
+            + self.dvoImagesTable + \
+            " WHERE EXTERN_ID = " + str(imageID) + \
+            " AND SOURCE_ID = " + str(sourceID)
+
+        try:
+            rs = self.executeQuery(sql)
+            
+            if not rs:
+                print "missing result set for imageID query"
+                raise
+
+            # if no returned rows, return an error
+            if not rs.next():
+                print "DVO lacks imageID ", imageID
+                print "sql: ", sql
+                return False
+
             if rs.getInt(1) == int(imageID):
                 # print "DVO has imageID ", imageID
                 return True
+
             else:
-                print "DVO lacks imageID ", imageID
+                print "DVO has wrong imageID? ", imageID
                 print "result was ", rs.getInt(1)
                 print "sql: ", sql
-                return False
+                raise
+
         except:
             print "DVO imageID query failed ", imageID
             print "sql: ", sql
-            return False
-
+            raise
+
+        # how can I reach this?
         return True
 
