Index: trunk/ippTools/share/Makefile.am
===================================================================
--- trunk/ippTools/share/Makefile.am	(revision 25299)
+++ trunk/ippTools/share/Makefile.am	(revision 25324)
@@ -47,4 +47,5 @@
      dettool_normalizedstat.sql \
      dettool_pending.sql \
+     dettool_pendingcleanup_detrunsummary.sql \
      dettool_pendingcleanup_normalizedexp.sql \
      dettool_pendingcleanup_normalizedimfile.sql \
Index: trunk/ippTools/share/camtool_pendingcleanupexp.sql
===================================================================
--- trunk/ippTools/share/camtool_pendingcleanupexp.sql	(revision 25299)
+++ trunk/ippTools/share/camtool_pendingcleanupexp.sql	(revision 25324)
@@ -13,4 +13,4 @@
     USING(cam_id)
 WHERE
-    (camRun.state = 'goto_cleaned' OR camRun.state = 'goto_purged')
+    (camRun.state = 'goto_cleaned' OR camRun.state = 'goto_purged' OR camRun.state = 'goto_scrubbed')
 
Index: trunk/ippTools/share/camtool_pendingcleanuprun.sql
===================================================================
--- trunk/ippTools/share/camtool_pendingcleanuprun.sql	(revision 25299)
+++ trunk/ippTools/share/camtool_pendingcleanuprun.sql	(revision 25324)
@@ -9,3 +9,3 @@
 USING (exp_id)
 WHERE
-    (camRun.state = 'goto_cleaned' OR camRun.state = 'goto_purged')
+    (camRun.state = 'goto_cleaned' OR camRun.state = 'goto_purged' OR camRun.state = 'goto_scrubbed')
Index: trunk/ippTools/share/dettool_donecleanup_normalizedexp.sql
===================================================================
--- trunk/ippTools/share/dettool_donecleanup_normalizedexp.sql	(revision 25324)
+++ trunk/ippTools/share/dettool_donecleanup_normalizedexp.sql	(revision 25324)
@@ -0,0 +1,11 @@
+SELECT
+    detNormalizedExp.*,
+    detRunSummary.data_state
+FROM detRunSummary
+JOIN detNormalizedExp
+    USING(det_id,iteration)
+WHERE
+    (detNormalizedExp.data_state = 'cleaned'
+     OR detNormalizedExp.data_state = 'scrubbed'
+     OR detNormalizedExp.data_state = 'purged')
+
Index: trunk/ippTools/share/dettool_donecleanup_normalizedimfile.sql
===================================================================
--- trunk/ippTools/share/dettool_donecleanup_normalizedimfile.sql	(revision 25324)
+++ trunk/ippTools/share/dettool_donecleanup_normalizedimfile.sql	(revision 25324)
@@ -0,0 +1,11 @@
+SELECT
+    detNormalizedImfile.*,
+    detRunSummary.data_state
+FROM detRunSummary
+JOIN detNormalizedImfile
+    USING(det_id,iteration)
+WHERE
+    (detNormalizedImfile.data_state = 'cleaned'
+     OR detNormalizedImfile.data_state = 'scrubbed'
+     OR detNormalizedImfile.data_state = 'purged')
+
Index: trunk/ippTools/share/dettool_donecleanup_normalizedstat.sql
===================================================================
--- trunk/ippTools/share/dettool_donecleanup_normalizedstat.sql	(revision 25324)
+++ trunk/ippTools/share/dettool_donecleanup_normalizedstat.sql	(revision 25324)
@@ -0,0 +1,11 @@
+SELECT
+    detNormalizedStatImfile.*,
+    detRunSummary.data_state
+FROM detRunSummary
+JOIN detNormalizedStatImfile
+    USING(det_id,iteration)
+WHERE
+    (detNormalizedStatImfile.data_state = 'cleaned'
+     OR detNormalizedStatImfile.data_state = 'scrubbed'
+     OR detNormalizedStatImfile.data_state = 'purged')
+
Index: trunk/ippTools/share/dettool_donecleanup_processedexp.sql
===================================================================
--- trunk/ippTools/share/dettool_donecleanup_processedexp.sql	(revision 25324)
+++ trunk/ippTools/share/dettool_donecleanup_processedexp.sql	(revision 25324)
@@ -0,0 +1,11 @@
+-- need to restrict to a single detRunSummary (require all to say 'cleaned'?)
+SELECT
+    detProcessedExp.*,
+    detRunSummary.data_state
+FROM detRunSummary
+JOIN detProcessedExp
+    USING(det_id)
+WHERE
+    (detProcessedExp.data_state = 'cleaned'
+     OR detProcessedExp.data_state = 'scrubbed'
+     OR detProcessedExp.data_state = 'purged')
Index: trunk/ippTools/share/dettool_donecleanup_processedimfile.sql
===================================================================
--- trunk/ippTools/share/dettool_donecleanup_processedimfile.sql	(revision 25324)
+++ trunk/ippTools/share/dettool_donecleanup_processedimfile.sql	(revision 25324)
@@ -0,0 +1,11 @@
+-- need to restrict to a single detRunSummary (require all to say 'cleaned'?)
+SELECT
+    detProcessedImfile.*,
+    detRunSummary.data_state
+FROM detRunSummary
+JOIN detProcessedImfile
+    USING(det_id)
+WHERE
+    (detProcessedImfile.data_state = 'cleaned'
+     OR detProcessedImfile.data_state = 'scrubbed'
+     OR detProcessedImfile.data_state = 'purged')
Index: trunk/ippTools/share/dettool_donecleanup_residexp.sql
===================================================================
--- trunk/ippTools/share/dettool_donecleanup_residexp.sql	(revision 25324)
+++ trunk/ippTools/share/dettool_donecleanup_residexp.sql	(revision 25324)
@@ -0,0 +1,10 @@
+SELECT
+    detResidExp.*,
+    detRunSummary.data_state
+FROM detRunSummary
+JOIN detResidExp
+    USING(det_id,iteration)
+WHERE
+    (detResidExp.data_state = 'cleaned'
+     OR detResidExp.data_state = 'scrubbed'
+     OR detResidExp.data_state = 'purged')
Index: trunk/ippTools/share/dettool_donecleanup_residimfile.sql
===================================================================
--- trunk/ippTools/share/dettool_donecleanup_residimfile.sql	(revision 25324)
+++ trunk/ippTools/share/dettool_donecleanup_residimfile.sql	(revision 25324)
@@ -0,0 +1,12 @@
+SELECT
+    detResidImfile.*,
+    detRunSummary.data_state
+FROM detRunSummary
+JOIN detResidImfile
+    USING(det_id,iteration)
+WHERE
+    (detResidImfile.data_state = 'cleaned'
+     OR detResidImfile.data_state = 'scrubbed'
+     OR detResidImfile.data_state = 'purged')
+
+
Index: trunk/ippTools/share/dettool_donecleanup_stacked.sql
===================================================================
--- trunk/ippTools/share/dettool_donecleanup_stacked.sql	(revision 25324)
+++ trunk/ippTools/share/dettool_donecleanup_stacked.sql	(revision 25324)
@@ -0,0 +1,10 @@
+SELECT
+    detStackedImfile.*,
+    detRunSummary.data_state
+FROM detRunSummary
+JOIN detStackedImfile
+     USING(det_id,iteration)
+WHERE
+     (detStackedImfile.data_state = 'cleaned'
+      OR detStackedImfile.data_state = 'scrubbed'
+      OR detStackedImfile.data_state = 'purged')
Index: trunk/ippTools/share/dettool_pendingcleanup_detrunsummary.sql
===================================================================
--- trunk/ippTools/share/dettool_pendingcleanup_detrunsummary.sql	(revision 25324)
+++ trunk/ippTools/share/dettool_pendingcleanup_detrunsummary.sql	(revision 25324)
@@ -0,0 +1,42 @@
+SELECT DISTINCT detRunSummary.*
+FROM detRunSummary
+     JOIN detProcessedImfile USING (det_id) 
+     JOIN detProcessedExp USING (det_id) 
+     JOIN detStackedImfile USING (det_id,iteration)
+     JOIN detResidExp USING (det_id,iteration) 
+     JOIN detResidImfile USING (det_id,iteration) 
+     JOIN detNormalizedStatImfile USING (det_id,iteration) 
+     JOIN detNormalizedImfile USING (det_id,iteration) 
+     JOIN detNormalizedExp USING (det_id,iteration) 
+WHERE (!(
+       (
+        detRunSummary.data_state = 'full' OR
+	detRunSummary.data_state = 'cleaned'
+       ) OR
+       (
+        !((detProcessedImfile.data_state = 'cleaned' OR
+           detProcessedImfile.data_state = 'scrubbed' OR
+           detProcessedImfile.data_state = 'purged') AND
+          (detProcessedExp.data_state = 'cleaned' OR
+           detProcessedExp.data_state = 'scrubbed' OR
+           detProcessedExp.data_state = 'purged') AND
+          (detStackedImfile.data_state = 'cleaned' OR
+           detStackedImfile.data_state = 'scrubbed' OR
+           detStackedImfile.data_state = 'purged') AND
+          (detResidExp.data_state = 'cleaned' OR
+           detResidExp.data_state = 'scrubbed' OR
+           detResidExp.data_state = 'purged') AND
+          (detResidImfile.data_state = 'cleaned' OR
+           detResidImfile.data_state = 'scrubbed' OR
+           detResidImfile.data_state = 'purged') AND
+          (detNormalizedStatImfile.data_state = 'cleaned' OR
+           detNormalizedStatImfile.data_state = 'scrubbed' OR
+           detNormalizedStatImfile.data_state = 'purged') AND
+          (detNormalizedImfile.data_state = 'cleaned' OR
+           detNormalizedImfile.data_state = 'scrubbed' OR
+           detNormalizedImfile.data_state = 'purged') AND
+          (detNormalizedExp.data_state = 'cleaned' OR
+           detNormalizedExp.data_state = 'scrubbed' OR
+           detNormalizedExp.data_state = 'purged')
+	 )
+       )))
Index: trunk/ippTools/share/dettool_pendingcleanup_normalizedexp.sql
===================================================================
--- trunk/ippTools/share/dettool_pendingcleanup_normalizedexp.sql	(revision 25299)
+++ trunk/ippTools/share/dettool_pendingcleanup_normalizedexp.sql	(revision 25324)
@@ -1,9 +1,21 @@
 SELECT
     detNormalizedExp.*,
-    detRunSummary.data_state
+    rawExp.camera    
 FROM detRunSummary
 JOIN detNormalizedExp
     USING(det_id,iteration)
+JOIN detInputExp
+     USING(det_id,iteration)
+JOIN rawExp
+     USING(exp_id)
 WHERE
-    detRunSummary.data_state = 'goto_cleaned'
-AND detNormalizedExp.data_state = 'full'
+    ((detRunSummary.data_state = 'goto_cleaned'
+      AND detNormalizedExp.data_state = 'full')
+     OR (detRunSummary.data_state = 'goto_scrubbed'
+      AND detNormalizedExp.data_state = 'full')
+     OR (detRunSummary.data_state = 'goto_purged'
+      AND detNormalizedExp.data_state = 'full')
+     OR detNormalizedExp.data_state = 'goto_cleaned'
+     OR detNormalizedExp.data_state = 'goto_scrubbed'
+     OR detNormalizedExp.data_state = 'goto_purged')
+
Index: trunk/ippTools/share/dettool_pendingcleanup_normalizedimfile.sql
===================================================================
--- trunk/ippTools/share/dettool_pendingcleanup_normalizedimfile.sql	(revision 25299)
+++ trunk/ippTools/share/dettool_pendingcleanup_normalizedimfile.sql	(revision 25324)
@@ -1,9 +1,21 @@
 SELECT DISTINCT
     detNormalizedImfile.*,
-    detRunSummary.data_state
+    rawExp.camera
 FROM detRunSummary
 JOIN detNormalizedImfile
     USING(det_id,iteration)
+JOIN detInputExp
+     USING(det_id,iteration)
+JOIN rawExp
+     USING(exp_id)
 WHERE
-    detRunSummary.data_state = 'goto_cleaned'
-AND detNormalizedImfile.data_state = 'full'
+    ((detRunSummary.data_state = 'goto_cleaned'
+      AND detNormalizedImfile.data_state = 'full')
+     OR (detRunSummary.data_state = 'goto_scrubbed'
+      AND detNormalizedImfile.data_state = 'full')
+     OR (detRunSummary.data_state = 'goto_purged'
+      AND detNormalizedImfile.data_state = 'full')
+     OR detNormalizedImfile.data_state = 'goto_cleaned'
+     OR detNormalizedImfile.data_state = 'goto_scrubbed'
+     OR detNormalizedImfile.data_state = 'goto_purged')
+
Index: trunk/ippTools/share/dettool_pendingcleanup_normalizedstat.sql
===================================================================
--- trunk/ippTools/share/dettool_pendingcleanup_normalizedstat.sql	(revision 25299)
+++ trunk/ippTools/share/dettool_pendingcleanup_normalizedstat.sql	(revision 25324)
@@ -1,9 +1,21 @@
-SELECT
+SELECT DISTINCT
     detNormalizedStatImfile.*,
-    detRunSummary.data_state
+    rawExp.camera
 FROM detRunSummary
 JOIN detNormalizedStatImfile
     USING(det_id,iteration)
+JOIN detInputExp
+     USING(det_id,iteration)
+JOIN rawExp
+     USING(exp_id)
 WHERE
-    detRunSummary.data_state = 'goto_cleaned'
-AND detNormalizedStatImfile.data_state = 'full'
+    ((detRunSummary.data_state = 'goto_cleaned'
+      AND detNormalizedStatImfile.data_state = 'full')
+     OR (detRunSummary.data_state = 'goto_scrubbed'
+      AND detNormalizedStatImfile.data_state = 'full')
+     OR (detRunSummary.data_state = 'goto_purged'
+      AND detNormalizedStatImfile.data_state = 'full')
+     OR detNormalizedStatImfile.data_state = 'goto_cleaned'
+     OR detNormalizedStatImfile.data_state = 'goto_scrubbed'
+     OR detNormalizedStatImfile.data_state = 'goto_purged')
+
Index: trunk/ippTools/share/dettool_pendingcleanup_processedexp.sql
===================================================================
--- trunk/ippTools/share/dettool_pendingcleanup_processedexp.sql	(revision 25299)
+++ trunk/ippTools/share/dettool_pendingcleanup_processedexp.sql	(revision 25324)
@@ -2,9 +2,18 @@
 SELECT
     detProcessedExp.*,
-    detRunSummary.data_state
+    rawExp.camera
 FROM detRunSummary
 JOIN detProcessedExp
     USING(det_id)
+JOIN rawExp
+     USING(exp_id)
 WHERE
-    detRunSummary.data_state = 'goto_cleaned'
-AND detProcessedExp.data_state = 'full'
+    ((detRunSummary.data_state = 'goto_cleaned'
+      AND detProcessedExp.data_state = 'full')
+     OR (detRunSummary.data_state = 'goto_scrubbed'
+         AND detProcessedExp.data_state = 'full')
+     OR (detRunSummary.data_state = 'goto_purged'
+         AND detProcessedExp.data_state = 'full')
+     OR detProcessedExp.data_state = 'goto_cleaned'
+     OR detProcessedExp.data_state = 'goto_scrubbed'
+     OR detProcessedExp.data_state = 'goto_purged')
Index: trunk/ippTools/share/dettool_pendingcleanup_processedimfile.sql
===================================================================
--- trunk/ippTools/share/dettool_pendingcleanup_processedimfile.sql	(revision 25299)
+++ trunk/ippTools/share/dettool_pendingcleanup_processedimfile.sql	(revision 25324)
@@ -1,10 +1,15 @@
--- need to restrict to a single detRunSummary (require all to say 'cleaned'?)
 SELECT
     detProcessedImfile.*,
-    detRunSummary.data_state
+    rawExp.camera
 FROM detRunSummary
 JOIN detProcessedImfile
     USING(det_id)
+JOIN detInputExp
+     USING(det_id,iteration,exp_id)
+JOIN rawExp
+     USING(exp_id)
 WHERE
-    detRunSummary.data_state = 'goto_cleaned'
-AND detProcessedImfile.data_state = 'full'
+     (detProcessedImfile.data_state = 'goto_cleaned'
+     OR detProcessedImfile.data_state = 'goto_scrubbed'
+     OR detProcessedImfile.data_state = 'goto_purged')
+
Index: trunk/ippTools/share/dettool_pendingcleanup_residexp.sql
===================================================================
--- trunk/ippTools/share/dettool_pendingcleanup_residexp.sql	(revision 25299)
+++ trunk/ippTools/share/dettool_pendingcleanup_residexp.sql	(revision 25324)
@@ -1,9 +1,20 @@
 SELECT
     detResidExp.*,
-    detRunSummary.data_state
+    rawExp.camera
 FROM detRunSummary
 JOIN detResidExp
     USING(det_id,iteration)
+JOIN detInputExp
+     USING(det_id,iteration,exp_id)
+JOIN rawExp
+    USING(exp_id)
 WHERE
-    detRunSummary.data_state = 'goto_cleaned'
-AND detResidExp.data_state = 'full'
+    ((detRunSummary.data_state = 'goto_cleaned'
+      AND detResidExp.data_state = 'full')
+     OR (detRunSummary.data_state = 'goto_scrubbed'
+         AND detResidExp.data_state = 'full')
+     OR (detRunSummary.data_state = 'goto_purged'
+         AND detResidExp.data_state = 'full')
+     OR detResidExp.data_state = 'goto_cleaned'
+     OR detResidExp.data_state = 'goto_scrubbed'
+     OR detResidExp.data_state = 'goto_purged')
Index: trunk/ippTools/share/dettool_pendingcleanup_residimfile.sql
===================================================================
--- trunk/ippTools/share/dettool_pendingcleanup_residimfile.sql	(revision 25299)
+++ trunk/ippTools/share/dettool_pendingcleanup_residimfile.sql	(revision 25324)
@@ -1,9 +1,22 @@
 SELECT
     detResidImfile.*,
-    detRunSummary.data_state
+    rawExp.camera
 FROM detRunSummary
 JOIN detResidImfile
     USING(det_id,iteration)
+JOIN detInputExp
+    USING(det_id,iteration,exp_id)
+JOIN rawExp
+    USING(exp_id)
 WHERE
-    detRunSummary.data_state = 'goto_cleaned'
-AND detResidImfile.data_state = 'full'
+    ((detRunSummary.data_state = 'goto_cleaned'
+      AND detResidImfile.data_state = 'full')
+     OR (detRunSummary.data_state = 'goto_scrubbed'
+      AND detResidImfile.data_state = 'full')
+     OR (detRunSummary.data_state = 'goto_purged'
+      AND detResidImfile.data_state = 'full')
+     OR detResidImfile.data_state = 'goto_cleaned'
+     OR detResidImfile.data_state = 'goto_scrubbed'
+     OR detResidImfile.data_state = 'goto_purged')
+
+
Index: trunk/ippTools/share/dettool_pendingcleanup_stacked.sql
===================================================================
--- trunk/ippTools/share/dettool_pendingcleanup_stacked.sql	(revision 25299)
+++ trunk/ippTools/share/dettool_pendingcleanup_stacked.sql	(revision 25324)
@@ -1,9 +1,20 @@
 SELECT DISTINCT
     detStackedImfile.*,
-    detRunSummary.data_state
+    rawExp.camera
 FROM detRunSummary
 JOIN detStackedImfile
-    USING(det_id,iteration)
+     USING(det_id,iteration)
+JOIN detInputExp
+     USING(det_id,iteration)
+JOIN rawExp
+     USING(exp_id)
 WHERE
-    detRunSummary.data_state = 'goto_cleaned'
-AND detStackedImfile.data_state = 'full'
+    ((detRunSummary.data_state = 'goto_cleaned'
+      AND detStackedImfile.data_state = 'full')
+     OR (detRunSummary.data_state = 'goto_scrubbed'
+      AND detStackedImfile.data_state = 'full')
+     OR (detRunSummary.data_state = 'goto_purged'
+      AND detStackedImfile.data_state = 'full')
+     OR detStackedImfile.data_state = 'goto_cleaned'
+     OR detStackedImfile.data_state = 'goto_scrubbed'
+     OR detStackedImfile.data_state = 'goto_purged')
Index: trunk/ippTools/share/faketool_pendingcleanupimfile.sql
===================================================================
--- trunk/ippTools/share/faketool_pendingcleanupimfile.sql	(revision 25299)
+++ trunk/ippTools/share/faketool_pendingcleanupimfile.sql	(revision 25324)
@@ -13,3 +13,7 @@
     USING(fake_id)
 WHERE
-    fakeRun.state = 'goto_cleaned'
+    ((fakeRun.state = 'goto_cleaned' AND fakeProcessedImfile.data_state = 'full')
+OR 
+    (fakeRun.state = 'goto_scrubbed' AND fakeProcessedImfile.data_state = 'full')
+OR 
+    (fakeRun.state = 'goto_purged' AND fakeProcessedImfile.data_state != 'purged'))
Index: trunk/ippTools/share/faketool_pendingcleanuprun.sql
===================================================================
--- trunk/ippTools/share/faketool_pendingcleanuprun.sql	(revision 25299)
+++ trunk/ippTools/share/faketool_pendingcleanuprun.sql	(revision 25324)
@@ -11,3 +11,4 @@
 USING (exp_id)
 WHERE
-    fakeRun.state = 'goto_cleaned'
+    (fakeRun.state = 'goto_cleaned' OR fakeRun.state = 'goto_scrubbed' OR fakeRun.state = 'goto_purged')
+
