Index: branches/czw_branch/cleanup/ippScripts/scripts/ipp_cleanup.pl
===================================================================
--- branches/czw_branch/cleanup/ippScripts/scripts/ipp_cleanup.pl	(revision 24835)
+++ branches/czw_branch/cleanup/ippScripts/scripts/ipp_cleanup.pl	(revision 24902)
@@ -759,5 +759,5 @@
     # XXX may need a different my_die for each stage
     my $imfiles;                      # Array of component files
-    my $command = "$dettool -pendingcleanup_processedimfile -chip_id $stage_id"; # Command to run
+    my $command = "$dettool -pendingcleanup_processedimfile -det_id $stage_id"; # Command to run
     $command .= " -dbname $dbname" if defined $dbname;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
@@ -1239,5 +1239,5 @@
     # XXX may need a different my_die for each stage
     my $imfiles;                      # Array of component files
-    my $command = "$dettool -pendingcleanup_residimfile -chip_id $stage_id"; # Command to run
+    my $command = "$dettool -pendingcleanup_residimfile -det_id $stage_id"; # Command to run
     $command .= " -dbname $dbname" if defined $dbname;
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
@@ -1326,5 +1326,5 @@
 
         if ($status)  {
-            my $command = "$dettool -updateresidimfile -chip_id $stage_id -exp_id $exp_id -iteration $iteration -class_id $class_id";
+            my $command = "$dettool -updateresidimfile -det_id $stage_id -exp_id $exp_id -iteration $iteration -class_id $class_id";
             if ($mode eq "goto_purged") {
                 $command .= " -data_state purged";
@@ -1346,5 +1346,5 @@
             }
         } else {
-	    my $command = "$dettool -updateresidimfile -chip_id $stage_id -exp_id $exp_id -iteration $iteration -class_id $class_id -data_state $error_state";
+	    my $command = "$dettool -updateresidimfile -det_id $stage_id -exp_id $exp_id -iteration $iteration -class_id $class_id -data_state $error_state";
 	    $command .= " -dbname $dbname" if defined $dbname;
 
Index: branches/czw_branch/cleanup/ippTools/share/dettool_donecleanup_normalizedexp.sql
===================================================================
--- branches/czw_branch/cleanup/ippTools/share/dettool_donecleanup_normalizedexp.sql	(revision 24902)
+++ branches/czw_branch/cleanup/ippTools/share/dettool_donecleanup_normalizedexp.sql	(revision 24902)
@@ -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: branches/czw_branch/cleanup/ippTools/share/dettool_donecleanup_normalizedimfile.sql
===================================================================
--- branches/czw_branch/cleanup/ippTools/share/dettool_donecleanup_normalizedimfile.sql	(revision 24902)
+++ branches/czw_branch/cleanup/ippTools/share/dettool_donecleanup_normalizedimfile.sql	(revision 24902)
@@ -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: branches/czw_branch/cleanup/ippTools/share/dettool_donecleanup_normalizedstat.sql
===================================================================
--- branches/czw_branch/cleanup/ippTools/share/dettool_donecleanup_normalizedstat.sql	(revision 24902)
+++ branches/czw_branch/cleanup/ippTools/share/dettool_donecleanup_normalizedstat.sql	(revision 24902)
@@ -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: branches/czw_branch/cleanup/ippTools/share/dettool_donecleanup_processedexp.sql
===================================================================
--- branches/czw_branch/cleanup/ippTools/share/dettool_donecleanup_processedexp.sql	(revision 24902)
+++ branches/czw_branch/cleanup/ippTools/share/dettool_donecleanup_processedexp.sql	(revision 24902)
@@ -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: branches/czw_branch/cleanup/ippTools/share/dettool_donecleanup_processedimfile.sql
===================================================================
--- branches/czw_branch/cleanup/ippTools/share/dettool_donecleanup_processedimfile.sql	(revision 24902)
+++ branches/czw_branch/cleanup/ippTools/share/dettool_donecleanup_processedimfile.sql	(revision 24902)
@@ -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: branches/czw_branch/cleanup/ippTools/share/dettool_donecleanup_residexp.sql
===================================================================
--- branches/czw_branch/cleanup/ippTools/share/dettool_donecleanup_residexp.sql	(revision 24902)
+++ branches/czw_branch/cleanup/ippTools/share/dettool_donecleanup_residexp.sql	(revision 24902)
@@ -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: branches/czw_branch/cleanup/ippTools/share/dettool_donecleanup_residimfile.sql
===================================================================
--- branches/czw_branch/cleanup/ippTools/share/dettool_donecleanup_residimfile.sql	(revision 24902)
+++ branches/czw_branch/cleanup/ippTools/share/dettool_donecleanup_residimfile.sql	(revision 24902)
@@ -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: branches/czw_branch/cleanup/ippTools/share/dettool_donecleanup_stacked.sql
===================================================================
--- branches/czw_branch/cleanup/ippTools/share/dettool_donecleanup_stacked.sql	(revision 24902)
+++ branches/czw_branch/cleanup/ippTools/share/dettool_donecleanup_stacked.sql	(revision 24902)
@@ -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: branches/czw_branch/cleanup/ippTools/share/dettool_pendingcleanup_normalizedexp.sql
===================================================================
--- branches/czw_branch/cleanup/ippTools/share/dettool_pendingcleanup_normalizedexp.sql	(revision 24835)
+++ branches/czw_branch/cleanup/ippTools/share/dettool_pendingcleanup_normalizedexp.sql	(revision 24902)
@@ -6,4 +6,12 @@
     USING(det_id,iteration)
 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: branches/czw_branch/cleanup/ippTools/share/dettool_pendingcleanup_normalizedimfile.sql
===================================================================
--- branches/czw_branch/cleanup/ippTools/share/dettool_pendingcleanup_normalizedimfile.sql	(revision 24835)
+++ branches/czw_branch/cleanup/ippTools/share/dettool_pendingcleanup_normalizedimfile.sql	(revision 24902)
@@ -6,4 +6,12 @@
     USING(det_id,iteration)
 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: branches/czw_branch/cleanup/ippTools/share/dettool_pendingcleanup_normalizedstat.sql
===================================================================
--- branches/czw_branch/cleanup/ippTools/share/dettool_pendingcleanup_normalizedstat.sql	(revision 24835)
+++ branches/czw_branch/cleanup/ippTools/share/dettool_pendingcleanup_normalizedstat.sql	(revision 24902)
@@ -6,4 +6,12 @@
     USING(det_id,iteration)
 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: branches/czw_branch/cleanup/ippTools/share/dettool_pendingcleanup_processedexp.sql
===================================================================
--- branches/czw_branch/cleanup/ippTools/share/dettool_pendingcleanup_processedexp.sql	(revision 24835)
+++ branches/czw_branch/cleanup/ippTools/share/dettool_pendingcleanup_processedexp.sql	(revision 24902)
@@ -7,4 +7,11 @@
     USING(det_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: branches/czw_branch/cleanup/ippTools/share/dettool_pendingcleanup_processedimfile.sql
===================================================================
--- branches/czw_branch/cleanup/ippTools/share/dettool_pendingcleanup_processedimfile.sql	(revision 24835)
+++ branches/czw_branch/cleanup/ippTools/share/dettool_pendingcleanup_processedimfile.sql	(revision 24902)
@@ -7,4 +7,11 @@
     USING(det_id)
 WHERE
-    detRunSummary.data_state = 'goto_cleaned'
-AND detProcessedImfile.data_state = 'full'
+    ((detRunSummary.data_state = 'goto_cleaned'
+      AND detProcessedImfile.data_state = 'full')
+     OR (detRunSummary.data_state = 'goto_scrubbed'
+         AND detProcessedImfile.data_state = 'full')
+     OR (detRunSummary.data_state = 'goto_purged'
+         AND detProcessedImfile.data_state = 'full')
+     OR detProcessedImfile.data_state = 'goto_cleaned'
+     OR detProcessedImfile.data_state = 'goto_scrubbed'
+     OR detProcessedImfile.data_state = 'goto_purged')
Index: branches/czw_branch/cleanup/ippTools/share/dettool_pendingcleanup_residexp.sql
===================================================================
--- branches/czw_branch/cleanup/ippTools/share/dettool_pendingcleanup_residexp.sql	(revision 24835)
+++ branches/czw_branch/cleanup/ippTools/share/dettool_pendingcleanup_residexp.sql	(revision 24902)
@@ -6,4 +6,11 @@
     USING(det_id,iteration)
 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: branches/czw_branch/cleanup/ippTools/share/dettool_pendingcleanup_residimfile.sql
===================================================================
--- branches/czw_branch/cleanup/ippTools/share/dettool_pendingcleanup_residimfile.sql	(revision 24835)
+++ branches/czw_branch/cleanup/ippTools/share/dettool_pendingcleanup_residimfile.sql	(revision 24902)
@@ -6,4 +6,13 @@
     USING(det_id,iteration)
 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: branches/czw_branch/cleanup/ippTools/share/dettool_pendingcleanup_stacked.sql
===================================================================
--- branches/czw_branch/cleanup/ippTools/share/dettool_pendingcleanup_stacked.sql	(revision 24835)
+++ branches/czw_branch/cleanup/ippTools/share/dettool_pendingcleanup_stacked.sql	(revision 24902)
@@ -6,4 +6,11 @@
     USING(det_id,iteration)
 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: branches/czw_branch/cleanup/ippTools/src/dettool.c
===================================================================
--- branches/czw_branch/cleanup/ippTools/src/dettool.c	(revision 24835)
+++ branches/czw_branch/cleanup/ippTools/src/dettool.c	(revision 24902)
@@ -1854,5 +1854,5 @@
 
     if (!isValidDataState (data_state)) return false;
-
+    
     char *query = "UPDATE detProcessedImfile SET data_state = '%s'"
 	" WHERE det_id = %" PRId64
