Index: trunk/ippTools/share/Makefile.am
===================================================================
--- trunk/ippTools/share/Makefile.am	(revision 23736)
+++ trunk/ippTools/share/Makefile.am	(revision 23737)
@@ -1,4 +1,6 @@
 dist_pkgdata_DATA = \
      camtool_donecleanup.sql \
+     camtool_export_processed_exp.sql \
+     camtool_export_run.sql \
      camtool_find_chip_id.sql \
      camtool_find_pendingexp.sql \
@@ -21,7 +23,7 @@
      chiptool_revertprocessedimfile.sql \
      chiptool_run.sql \
-     chiptool_export_run.sql \
      chiptool_export_imfile.sql \
      chiptool_export_processed_imfile.sql \
+     chiptool_export_run.sql \
      chiptool_unmasked.sql \
      detselect_search.sql \
@@ -96,4 +98,6 @@
      faketool_completely_processed_exp.sql \
      faketool_donecleanup.sql \
+     faketool_export_processed_imfile.sql \
+     faketool_export_run.sql \
      faketool_find_camrun.sql \
      faketool_find_pendingexp.sql \
@@ -179,6 +183,6 @@
      warptool_donecleanup.sql \
      warptool_exp.sql \
+     warptool_export_imfile.sql \
      warptool_export_run.sql \
-     warptool_export_imfile.sql \
      warptool_export_skyfile.sql \
      warptool_export_skycell_map.sql \
Index: trunk/ippTools/share/camtool_export_processed_exp.sql
===================================================================
--- trunk/ippTools/share/camtool_export_processed_exp.sql	(revision 23737)
+++ trunk/ippTools/share/camtool_export_processed_exp.sql	(revision 23737)
@@ -0,0 +1,1 @@
+SELECT * from camProcessedExp
Index: trunk/ippTools/share/camtool_export_run.sql
===================================================================
--- trunk/ippTools/share/camtool_export_run.sql	(revision 23737)
+++ trunk/ippTools/share/camtool_export_run.sql	(revision 23737)
@@ -0,0 +1,1 @@
+SELECT camRun.* from camRun
Index: trunk/ippTools/share/disttool_pendingcomponent.sql
===================================================================
--- trunk/ippTools/share/disttool_pendingcomponent.sql	(revision 23736)
+++ trunk/ippTools/share/disttool_pendingcomponent.sql	(revision 23737)
@@ -84,24 +84,25 @@
     stage,
     stage_id,
-    chipProcessedImfile.class_id AS component,
+    'exposure' AS component,
+--    chipProcessedImfile.class_id AS component,
     clean,
     rawExp.camera,
     outroot,
     camProcessedExp.path_base,
-    chipProcessedImfile.path_base as chip_path_base,
+    NULL as chip_path_base,
     camRun.state,
     NULL,
     camProcessedExp.quality,
     distRun.no_magic,
-    chipProcessedImfile.magicked
+    chipRun.magicked
 FROM distRun
 JOIN camRun ON camRun.cam_id = distRun.stage_id
 JOIN camProcessedExp USING(cam_id)
 JOIN chipRun USING(chip_id)
-JOIN chipProcessedImfile USING(exp_id, chip_id)
-JOIN rawExp using(exp_id)
-LEFT JOIN distComponent 
-    ON distRun.dist_id = distComponent.dist_id 
-    AND chipProcessedImfile.class_id = distComponent.component
+-- JOIN chipProcessedImfile USING(exp_id, chip_id)
+JOIN rawExp using(exp_id)
+LEFT JOIN distComponent 
+    ON distRun.dist_id = distComponent.dist_id 
+--    AND chipProcessedImfile.class_id = distComponent.component
 WHERE
     distRun.state = 'new'
Index: trunk/ippTools/share/disttool_toadvance.sql
===================================================================
--- trunk/ippTools/share/disttool_toadvance.sql	(revision 23736)
+++ 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
Index: trunk/ippTools/share/faketool_export_processed_imfile.sql
===================================================================
--- trunk/ippTools/share/faketool_export_processed_imfile.sql	(revision 23737)
+++ trunk/ippTools/share/faketool_export_processed_imfile.sql	(revision 23737)
@@ -0,0 +1,1 @@
+SELECT fakeProcessedImfile.* FROM fakeProcessedImfile
Index: trunk/ippTools/share/faketool_export_run.sql
===================================================================
--- trunk/ippTools/share/faketool_export_run.sql	(revision 23737)
+++ trunk/ippTools/share/faketool_export_run.sql	(revision 23737)
@@ -0,0 +1,1 @@
+SELECT fakeRun.* FROM fakeRun
