Index: trunk/ippTools/share/bgtool_definewarp.sql
===================================================================
--- trunk/ippTools/share/bgtool_definewarp.sql	(revision 28551)
+++ trunk/ippTools/share/bgtool_definewarp.sql	(revision 35154)
@@ -1,12 +1,19 @@
 SELECT
-    warpRun.*,
-    chipBackgroundRun.chip_bg_id
+    warpRun.warp_id,
+    chipBackgroundRun.*
+    -- the following items are selected for aid in debugging
+    ,
+    warpsChipRun.chip_id as warpschip_id,
+    chipRun.chip_id AS thischip_id,
+    warpBackgroundRun.warp_bg_id
 FROM warpRun
 JOIN fakeRun USING(fake_id)
 JOIN camRun USING(cam_id)
-JOIN chipRun USING(chip_id)
-JOIN chipBackgroundRun USING(chip_id)
+JOIN chipRun as warpsChipRun ON camRun.chip_id = warpsChipRun.chip_id
 JOIN rawExp USING(exp_id)
-LEFT JOIN warpBackgroundRun USING(chip_bg_id)
+JOIN chipRun USING(exp_id)
+JOIN chipBackgroundRun ON chipRun.chip_id = chipBackgroundRun.chip_id 
+    AND (chipBackgroundRun.cam_id = camRun.cam_id OR chipBackgroundRun.cam_id = 0)
+LEFT JOIN warpBackgroundRun ON chipBackgroundRun.chip_bg_id = warpBackgroundRun.warp_bg_id -- label hook %s
 WHERE chipBackgroundRun.state = 'full'
-    AND warpRun.state IN ('full', 'cleaned', 'goto_cleaned') -- only need it to have been completed
+    AND warpRun.state IN ('full', 'cleaned', 'goto_cleaned') -- need warp to have completed so warpSkyCellMap is populated
