Index: trunk/ippTools/share/camtool_find_pendingexp.sql
===================================================================
--- trunk/ippTools/share/camtool_find_pendingexp.sql	(revision 26557)
+++ trunk/ippTools/share/camtool_find_pendingexp.sql	(revision 26567)
@@ -9,5 +9,6 @@
     rawExp.camera,
     rawExp.telescope,
-    rawExp.filelevel
+    rawExp.filelevel,
+    chipRun.magicked AS chip_magicked
 FROM camRun
 JOIN chipRun
Index: trunk/ippTools/share/camtool_queue_chip_id.sql
===================================================================
--- trunk/ippTools/share/camtool_queue_chip_id.sql	(revision 26557)
+++ trunk/ippTools/share/camtool_queue_chip_id.sql	(revision 26567)
@@ -16,6 +16,6 @@
         '%s',           -- tess_id
         '%s',           -- end_stage
-        0,              -- magicked
-        '%s'           -- note
+        %lld,           -- magicked
+        '%s'            -- note
     FROM chipRun
     WHERE
Index: trunk/ippTools/share/chiptool_change_exp_state.sql
===================================================================
--- trunk/ippTools/share/chiptool_change_exp_state.sql	(revision 26557)
+++ trunk/ippTools/share/chiptool_change_exp_state.sql	(revision 26567)
@@ -4,5 +4,7 @@
 -- the chipProcessedImfile sub query
 UPDATE chipRun
-    SET state = '%s'
+JOIN rawExp using(exp_id)
+    SET chipRun.state = '%s'
+    -- set magicked hook %s
     WHERE
     chipRun.chip_id = %lld
Index: trunk/ippTools/share/chiptool_completely_processed_exp.sql
===================================================================
--- trunk/ippTools/share/chiptool_completely_processed_exp.sql	(revision 26557)
+++ trunk/ippTools/share/chiptool_completely_processed_exp.sql	(revision 26567)
@@ -14,5 +14,5 @@
     tess_id,
     end_stage,
-    all_files_magicked as magicked,
+    imfile_magicked as magicked,
     note
 FROM
@@ -21,5 +21,11 @@
         rawImfile.class_id as rawimfile_class_id,
         chipProcessedImfile.class_id,
-        SUM(!chipProcessedImfile.magicked) = 0 as all_files_magicked
+        -- XXX using chipProcessedImfile assumes that all imfile's have
+        -- the same magicked value if that isn't right then more than one 
+        -- row will be returned. In practice this is the case but bugs could
+        -- cause it to not be true.
+        -- We could use rawExp.magicked but that would make it possible for
+        -- the chipRun to have a different magicked value than the imfiles
+        chipProcessedImfile.magicked AS imfile_magicked
     FROM chipRun
     JOIN rawImfile
Index: trunk/ippTools/share/difftool_change_run_state.sql
===================================================================
--- trunk/ippTools/share/difftool_change_run_state.sql	(revision 26557)
+++ trunk/ippTools/share/difftool_change_run_state.sql	(revision 26567)
@@ -5,4 +5,5 @@
 UPDATE diffRun
     SET state = '%s'
+    -- set magicked hook %s
     WHERE
     diffRun.diff_id = %lld
Index: trunk/ippTools/share/difftool_change_skyfile_data_state.sql
===================================================================
--- trunk/ippTools/share/difftool_change_skyfile_data_state.sql	(revision 26557)
+++ trunk/ippTools/share/difftool_change_skyfile_data_state.sql	(revision 26567)
@@ -5,4 +5,5 @@
     SET 
     data_state = '%s'
+    -- magicked hook %s
 WHERE
     diff_id = %lld
Index: trunk/ippTools/share/difftool_todiffskyfile.sql
===================================================================
--- trunk/ippTools/share/difftool_todiffskyfile.sql	(revision 26557)
+++ trunk/ippTools/share/difftool_todiffskyfile.sql	(revision 26567)
@@ -65,5 +65,5 @@
     OR (diffRun.state = 'update'
     AND diffSkyfile.fault = 0
-    AND diffSkyfile.quality = 0)
+    AND diffSkyfile.data_state = 'cleaned')
     )
 -- Ensure input warps are available
Index: trunk/ippTools/share/disttool_pending_camera.sql
===================================================================
--- trunk/ippTools/share/disttool_pending_camera.sql	(revision 26557)
+++ trunk/ippTools/share/disttool_pending_camera.sql	(revision 26567)
@@ -30,4 +30,4 @@
     AND distRun.stage = 'camera'
     AND distComponent.dist_id IS NULL
-    AND (distRun.clean OR (chipRun.magicked AND camRun.magicked) OR distRun.no_magic)
+    AND (((chipRun.magicked > 0) AND (camRun.magicked > 0)) OR distRun.no_magic)
     AND (camRun.state = 'full' OR (distRun.clean AND camRun.state = 'cleaned'))
Index: trunk/ippTools/share/disttool_pending_chip.sql
===================================================================
--- trunk/ippTools/share/disttool_pending_chip.sql	(revision 26557)
+++ trunk/ippTools/share/disttool_pending_chip.sql	(revision 26567)
@@ -28,4 +28,4 @@
     AND distRun.stage = 'chip'
     AND distComponent.dist_id IS NULL
-    AND (distRun.clean OR chipRun.magicked OR distRun.no_magic)
+    AND ((chipRun.magicked > 0) OR distRun.no_magic)
     AND (chipRun.state = 'full' OR (distRun.clean AND chipRun.state = 'cleaned'))
Index: trunk/ippTools/share/disttool_pending_diff.sql
===================================================================
--- trunk/ippTools/share/disttool_pending_diff.sql	(revision 26557)
+++ trunk/ippTools/share/disttool_pending_diff.sql	(revision 26567)
@@ -36,4 +36,4 @@
     AND distRun.stage = 'diff'
     AND distComponent.dist_id IS NULL
-    AND (distRun.clean OR diffRun.magicked OR distRun.no_magic)
+    AND ((diffRun.magicked > 0) OR distRun.no_magic)
     AND (diffRun.state = 'full' OR (distRun.clean AND diffRun.state = 'cleaned'))
Index: trunk/ippTools/share/disttool_pending_warp.sql
===================================================================
--- trunk/ippTools/share/disttool_pending_warp.sql	(revision 26557)
+++ trunk/ippTools/share/disttool_pending_warp.sql	(revision 26567)
@@ -31,4 +31,4 @@
     AND distRun.stage = 'warp'
     AND distComponent.dist_id IS NULL
-    AND (distRun.clean OR warpRun.magicked OR distRun.no_magic)
+    AND ((warpRun.magicked > 0) OR distRun.no_magic)
     AND (warpRun.state = 'full' OR (distRun.clean AND warpRun.state = 'cleaned'))
Index: trunk/ippTools/share/warptool_change_run_state.sql
===================================================================
--- trunk/ippTools/share/warptool_change_run_state.sql	(revision 26557)
+++ trunk/ippTools/share/warptool_change_run_state.sql	(revision 26567)
@@ -4,5 +4,9 @@
 -- the chipProcessedImfile sub query
 UPDATE warpRun
-    SET state = '%s'
+JOIN fakeRun USING(fake_id)
+JOIN camRun USING(cam_id)
+JOIN chipRun USING(chip_id)
+    SET warpRun.state = '%s'
+    -- set magicked  hook %s
     WHERE
     warpRun.warp_id = %lld
@@ -12,4 +16,4 @@
         WHERE
             warpSkyfile.warp_id = warpRun.warp_id
-            AND data_state != '%s'
+            AND warpSkyfile.data_state != '%s'
         ) = 0
Index: trunk/ippTools/share/warptool_change_skyfile_data_state.sql
===================================================================
--- trunk/ippTools/share/warptool_change_skyfile_data_state.sql	(revision 26557)
+++ trunk/ippTools/share/warptool_change_skyfile_data_state.sql	(revision 26567)
@@ -1,8 +1,13 @@
 -- handle changes in warpSkyfile.data_state.
--- Used for the modes tocleanedskyfile and topurgedskyfile
--- args are new data_state, warp_id, skycell_id and current expected state for warpRun
+-- Used for the modes tofullskyfile, tocleanedskyfile and topurgedskyfile
+-- args are new data_state, string for magic hook, warp_id, skycell_id and current expected state for warpRun
 UPDATE warpSkyfile
+JOIN warpRun USING(warp_id)
+JOIN fakeRun USING(fake_id)
+JOIN camRun USING(cam_id)
+JOIN chipRun USING(chip_id)
     SET 
     data_state = '%s'
+    -- set magicked hook %s
 WHERE
     warp_id = %lld
Index: trunk/ippTools/share/warptool_finish_run.sql
===================================================================
--- trunk/ippTools/share/warptool_finish_run.sql	(revision 26557)
+++ trunk/ippTools/share/warptool_finish_run.sql	(revision 26567)
@@ -1,5 +1,5 @@
 UPDATE warpRun
     SET state = 'full',
-    magicked = %d
+    magicked = %lld
 WHERE warp_id = %lld
 
Index: trunk/ippTools/share/warptool_finished_run_select.sql
===================================================================
--- trunk/ippTools/share/warptool_finished_run_select.sql	(revision 26557)
+++ trunk/ippTools/share/warptool_finished_run_select.sql	(revision 26567)
@@ -8,5 +8,5 @@
        warpSkyCellMap.warp_id as foo,
        warpSkyfile.warp_id as bar,
-       SUM(!warpSkyfile.magicked) = 0 as magicked
+       warpSkyfile.magicked as magicked
    FROM warpRun
    JOIN warpSkyCellMap
Index: trunk/ippTools/share/warptool_towarped.sql
===================================================================
--- trunk/ippTools/share/warptool_towarped.sql	(revision 26557)
+++ trunk/ippTools/share/warptool_towarped.sql	(revision 26567)
@@ -40,4 +40,6 @@
         AND warpSkyfile.tess_id IS NULL)
     OR (warpRun.state = 'update'
+        AND chipRun.magicked >= 0
+        AND warpSkyfile.fault = 0
         AND warpSkyfile.data_state = 'cleaned')
     )
