Index: trunk/ippTools/share/chiptool_pendingimfile.sql
===================================================================
--- trunk/ippTools/share/chiptool_pendingimfile.sql	(revision 12259)
+++ trunk/ippTools/share/chiptool_pendingimfile.sql	(revision 14018)
@@ -1,17 +1,29 @@
 SELECT
-    chipPendingExp.*,
-    chipPendingImfile.class_id,
-    chipPendingImfile.uri,
+    chipRun.*,
+    chipInputImfile.exp_tag,
+    chipInputImfile.class_id,
+    rawImfile.uri,
     rawExp.exp_id,
     rawExp.camera,
     rawExp.telescope,
     rawExp.filelevel
-FROM chipPendingImfile
-JOIN chipPendingExp
+FROM chipRun
+JOIN chipInputImfile
     USING(chip_id)
+LEFT JOIN chipProcessedImfile
+    ON chipInputImfile.chip_id = chipProcessedImfile.chip_id
+    AND chipInputImfile.exp_tag = chipProcessedImfile.exp_tag
+    AND chipInputImfile.class_id = chipProcessedImfile.class_id
+JOIN rawImfile
+    ON chipInputImfile.exp_tag = rawImfile.exp_tag
+    AND chipInputImfile.class_id = rawImfile.class_id
 JOIN rawExp
-    ON chipPendingExp.exp_tag = rawExp.exp_tag
+    ON rawImfile.exp_tag = rawExp.exp_tag
 LEFT JOIN chipMask
-    ON chipPendingExp.label = chipMask.label
+    ON chipRun.label = chipMask.label
 WHERE
-    chipMask.label IS NULL
+    chipRun.state = 'run'
+    AND chipProcessedImfile.chip_id IS NULL
+    AND chipProcessedImfile.exp_tag IS NULL
+    AND chipProcessedImfile.class_id IS NULL
+    AND chipMask.label IS NULL
