Index: trunk/ippTools/share/disttool_toadvance.sql
===================================================================
--- trunk/ippTools/share/disttool_toadvance.sql	(revision 23717)
+++ trunk/ippTools/share/disttool_toadvance.sql	(revision 23737)
@@ -4,5 +4,6 @@
     stage_id,
     outroot,
-    label
+    label,
+    clean
 FROM
     (
@@ -13,5 +14,6 @@
     stage_id,
     outroot,
-    label
+    label,
+    clean
     FROM distRun
     JOIN rawImfile ON stage_id = rawImfile.exp_id
@@ -36,5 +38,6 @@
     stage_id,
     outroot,
-    label
+    label,
+    clean
     FROM distRun
     JOIN chipProcessedImfile ON stage_id = chipProcessedImfile.chip_id
@@ -53,4 +56,47 @@
         AND SUM(distComponent.fault) = 0
 UNION
+-- camera stage
+SELECT distRun.dist_id,
+    stage,
+    stage_id,
+    outroot,
+    distRun.label,
+    clean
+    FROM distRun
+    JOIN camRun ON stage_id = cam_id
+    JOIN chipRun USING(chip_id)
+    LEFT JOIN distComponent  USING(dist_id)
+    WHERE
+        distRun.state = 'new'
+        AND distRun.fault = 0
+        AND distComponent.fault = 0
+        AND distRun.stage = 'camera'
+--        AND ((chipRun.magicked AND camRun.state = 'full') OR distRun.no_magic)
+--        AND (camRun.state = 'full' OR (distRun.clean and camRun.state = 'cleaned'))
+UNION
+-- fake stage
+SELECT
+    distRun.dist_id,
+    stage,
+    stage_id,
+    outroot,
+    label,
+    clean
+    FROM distRun
+    JOIN fakeProcessedImfile ON stage_id = fakeProcessedImfile.fake_id
+    LEFT JOIN distComponent
+        ON distComponent.dist_id = distRun.dist_id
+        AND distComponent.component = fakeProcessedImfile.class_id
+    WHERE
+        distRun.state = 'new'
+        AND distRun.fault = 0
+        AND distRun.stage = 'fake'
+    GROUP BY
+        dist_id,
+        fakeProcessedImfile.fake_id
+    HAVING
+        COUNT(fakeProcessedImfile.class_id) = COUNT(distComponent.component)
+        AND SUM(distComponent.fault) = 0
+UNION
 -- warp stage
 SELECT
@@ -59,5 +105,6 @@
     stage_id,
     outroot,
-    label
+    label,
+    clean
     FROM distRun
     JOIN warpSkyfile on stage_id = warp_id
@@ -84,5 +131,6 @@
     stage_id,
     outroot,
-    label
+    label,
+    clean
     FROM distRun
     JOIN diffSkyfile
@@ -109,5 +157,6 @@
     stage_id,
     outroot,
-    label
+    label,
+    clean
     FROM distRun
     JOIN stackSumSkyfile on stage_id = stack_id
