Index: branches/eam_branches/ipp-20110213/ippTools/share/disttool_pending_raw.sql
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/share/disttool_pending_raw.sql	(revision 30628)
+++ branches/eam_branches/ipp-20110213/ippTools/share/disttool_pending_raw.sql	(revision 30675)
@@ -12,5 +12,6 @@
     TRIM(TRAILING '.fits' FROM rawImfile.uri) AS path_base,
     CAST(NULL AS CHAR(255)) AS alt_path_base,
-    chipProcessedImfile.path_base as chip_path_base,
+    -- pass camera stage path base since we want the camera mask file. The script knows what to do
+    camProcessedExp.path_base as chip_path_base,
     CAST(NULL AS CHAR(255)) AS state,
     CAST(NULL AS CHAR(255)) AS data_state,
@@ -26,4 +27,6 @@
 JOIN chipProcessedImfile
     USING(chip_id, class_id)
+JOIN camRun USING(chip_id)
+JOIN camProcessedExp using(cam_id)
 LEFT JOIN distComponent 
     ON distRun.dist_id = distComponent.dist_id 
@@ -36,4 +39,7 @@
     AND distComponent.dist_id IS NULL
     AND (rawExp.magicked OR distRun.no_magic)
+    -- need to have magicked the chip image which makes the camera mask
+    AND chipProcessedImfile.magicked != 0
+    AND camRun.magicked > 0 
     AND (Label.active OR Label.active IS NULL)
 UNION
@@ -52,5 +58,6 @@
     TRIM(TRAILING '.fits' FROM rawImfile.uri) AS path_base,
     magicDSFile.backup_path_base AS alt_path_base,
-    chipProcessedImfile.path_base AS chip_path_base,
+    -- pass camera stage path base since we want the camera mask file. The script knows what to do
+    camProcessedExp.path_base AS chip_path_base,
     CAST('full' AS CHAR(255)) AS state,
     CAST('full' AS CHAR(255)) AS data_state,
@@ -77,6 +84,6 @@
     AND distRun.clean = 0
     AND distComponent.dist_id IS NULL
-    AND chipProcessedImfile.data_state = 'full'
-    AND chipProcessedImfile.magicked > 0
+    AND chipProcessedImfile.magicked != 0
+    AND camRun.magicked > 0 
     AND (Label.active OR Label.active IS NULL)
 UNION
Index: branches/eam_branches/ipp-20110213/ippTools/share/magicdstool_torevert_camera.sql
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/share/magicdstool_torevert_camera.sql	(revision 30628)
+++ branches/eam_branches/ipp-20110213/ippTools/share/magicdstool_torevert_camera.sql	(revision 30675)
@@ -11,4 +11,5 @@
     camProcessedExp.path_base,
     camProcessedExp.path_base AS cam_path_base,
+    recovery_path_base,
     0 AS bothways,
     0 AS bytes,
Index: branches/eam_branches/ipp-20110213/ippTools/share/magicdstool_torevert_chip.sql
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/share/magicdstool_torevert_chip.sql	(revision 30628)
+++ branches/eam_branches/ipp-20110213/ippTools/share/magicdstool_torevert_chip.sql	(revision 30675)
@@ -11,4 +11,5 @@
     chipProcessedImfile.path_base,
     camProcessedExp.path_base AS cam_path_base,
+    recovery_path_base,
     0 AS bothways,
     0 AS bytes,
Index: branches/eam_branches/ipp-20110213/ippTools/share/magicdstool_torevert_diff.sql
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/share/magicdstool_torevert_diff.sql	(revision 30628)
+++ branches/eam_branches/ipp-20110213/ippTools/share/magicdstool_torevert_diff.sql	(revision 30675)
@@ -13,4 +13,5 @@
     magicDSFile.recovery_path_base,
     "NULL" AS cam_path_base,
+    recovery_path_base,
     CAST(diffRun.bothways AS SIGNED) AS bothways,
     0 AS bytes,
Index: branches/eam_branches/ipp-20110213/ippTools/share/magicdstool_torevert_raw.sql
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/share/magicdstool_torevert_raw.sql	(revision 30628)
+++ branches/eam_branches/ipp-20110213/ippTools/share/magicdstool_torevert_raw.sql	(revision 30675)
@@ -11,4 +11,5 @@
     rawImfile.uri AS path_base,
     CAST(NULL AS CHAR(255)) AS cam_path_base, 
+    recovery_path_base,
     0 AS bothways,
     bytes,
Index: branches/eam_branches/ipp-20110213/ippTools/share/magicdstool_torevert_warp.sql
===================================================================
--- branches/eam_branches/ipp-20110213/ippTools/share/magicdstool_torevert_warp.sql	(revision 30628)
+++ branches/eam_branches/ipp-20110213/ippTools/share/magicdstool_torevert_warp.sql	(revision 30675)
@@ -11,4 +11,5 @@
     warpSkyfile.path_base,
     "NULL" AS cam_path_base,
+    recovery_path_base,
     0 AS bothways,
     0 AS bytes,
