Index: trunk/ippTools/src/disttool.c
===================================================================
--- trunk/ippTools/src/disttool.c	(revision 28516)
+++ trunk/ippTools/src/disttool.c	(revision 28536)
@@ -210,4 +210,20 @@
             psStringAppend(&query, " AND (chipRun.dist_group = '%s')", dist_group);
         }
+    } else if (!strcmp(stage, "chip_bg")) {
+        magicRunType = "chipBackgroundRun";
+        runJoinStr = "chipBackgroundRun.chip_bg_id";
+        query = pxDataGet("disttool_definebyquery_chip_bg.sql");
+        if (!query) {
+            psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
+            psFree(where);
+            return false;
+        }
+
+        if (label) {
+            psStringAppend(&query, " AND (chipBackgroundRun.label = '%s')", label);
+        }
+        if (dist_group) {
+            psStringAppend(&query, " AND (chipBackgroundRun.dist_group = '%s')", dist_group);
+        }
     } else if (!strcmp(stage, "camera")) {
         magicRunType = "camRun";    // This is used below to set the magicked business
@@ -258,4 +274,21 @@
         if (dist_group) {
             psStringAppend(&query, " AND (warpRun.dist_group = '%s')", dist_group);
+        }
+
+    } else if (!strcmp(stage, "warp_bg")) {
+        magicRunType = "warpBackgroundRun";
+        runJoinStr = "warpBackgroundRun.warp_bg_id";
+        query = pxDataGet("disttool_definebyquery_warp_bg.sql");
+        if (!query) {
+            psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
+            psFree(where);
+            return false;
+        }
+
+        if (label) {
+            psStringAppend(&query, " AND (warpBackgroundRun.label = '%s')", label);
+        }
+        if (dist_group) {
+            psStringAppend(&query, " AND (warpBackgroundRun.dist_group = '%s')", dist_group);
         }
 
Index: trunk/ippTools/src/magicdstool.c
===================================================================
--- trunk/ippTools/src/magicdstool.c	(revision 28516)
+++ trunk/ippTools/src/magicdstool.c	(revision 28536)
@@ -122,6 +122,8 @@
     PXOPT_COPY_S64(config->args, where, "-exp_id",  "exp_id", "==");
     PXOPT_COPY_S64(config->args, where, "-chip_id", "chip_id", "==");
+    PXOPT_COPY_S64(config->args, where, "-chip_bg_id", "chip_bg_id", "==");
     PXOPT_COPY_S64(config->args, where, "-cam_id",  "cam_id", "==");
     PXOPT_COPY_S64(config->args, where, "-warp_id", "warp_id", "==");
+    PXOPT_COPY_S64(config->args, where, "-warp_bg_id", "warp_bg_id", "==");
     PXOPT_COPY_S64(config->args, where, "-diff_id", "diff_id", "==");
     PXOPT_COPY_S64(config->args, where, "-magic_id","magicRun.magic_id", "==");
@@ -140,4 +142,7 @@
         query = pxDataGet("magicdstool_definebyquery_chip.sql");
         break;
+    case IPP_STAGE_CHIP_BG:
+        query = pxDataGet("magicdstool_definebyquery_chip_bg.sql");
+        break;
     case IPP_STAGE_CAMERA:
         query = pxDataGet("magicdstool_definebyquery_camera.sql");
@@ -145,4 +150,7 @@
     case IPP_STAGE_WARP:
         query = pxDataGet("magicdstool_definebyquery_warp.sql");
+        break;
+    case IPP_STAGE_WARP_BG:
+        query = pxDataGet("magicdstool_definebyquery_warp_bg.sql");
         break;
     case IPP_STAGE_DIFF:
@@ -720,4 +728,7 @@
         query = "UPDATE chipProcessedImfile SET magicked = %" PRId64 " where chip_id = %" PRId64 " AND class_id = '%s'";
         break;
+    case IPP_STAGE_CHIP_BG:
+        query = "UPDATE chipBackgroundImfile SET magicked = %" PRId64 " where chip_bg_id = %" PRId64 " AND class_id = '%s'";
+        break;
     case IPP_STAGE_CAMERA:
         // no there is no magicked column in camProcessedExp so we have nothing to do
@@ -727,4 +738,7 @@
         query = "UPDATE warpSkyfile SET magicked = %" PRId64 " where warp_id = %" PRId64 " AND skycell_id = '%s'";
         break;
+    case IPP_STAGE_WARP_BG:
+        query = "UPDATE warpBackgroundSkyfile SET magicked = %" PRId64 " where warp_bg_id = %" PRId64 " AND skycell_id = '%s'";
+        break;
     case IPP_STAGE_DIFF:
         query = "UPDATE diffSkyfile SET magicked = %" PRId64 " where diff_id = %" PRId64 " AND skycell_id = '%s'";
@@ -794,4 +808,7 @@
         query = "UPDATE chipRun SET magicked = %" PRId64 " where chip_id = %" PRId64;
         break;
+    case IPP_STAGE_CHIP_BG:
+        query = "UPDATE chipBackgroundRun SET magicked = %" PRId64 " where chip_bg_id = %" PRId64;
+        break;
     case IPP_STAGE_CAMERA:
         query = "UPDATE camRun SET magicked = %" PRId64 " where cam_id = %" PRId64;
@@ -799,4 +816,7 @@
     case IPP_STAGE_WARP:
         query = "UPDATE warpRun SET magicked = %" PRId64 " where warp_id = %" PRId64;
+        break;
+    case IPP_STAGE_WARP_BG:
+        query = "UPDATE warpBackgroundRun SET magicked = %" PRId64 " where warp_bg_id = %" PRId64;
         break;
     case IPP_STAGE_DIFF:
Index: trunk/ippTools/src/magicdstoolConfig.c
===================================================================
--- trunk/ippTools/src/magicdstoolConfig.c	(revision 28516)
+++ trunk/ippTools/src/magicdstoolConfig.c	(revision 28536)
@@ -60,6 +60,8 @@
     psMetadataAddS64(definebyqueryArgs, PS_LIST_TAIL, "-exp_id",   0, "search by exp_id", 0);
     psMetadataAddS64(definebyqueryArgs, PS_LIST_TAIL, "-chip_id",  0, "search by chip_id", 0);
+    psMetadataAddS64(definebyqueryArgs, PS_LIST_TAIL, "-chip_bg_id",  0, "search by chip_bg_id", 0);
     psMetadataAddS64(definebyqueryArgs, PS_LIST_TAIL, "-cam_id",  0, "search by cam_id", 0);
     psMetadataAddS64(definebyqueryArgs, PS_LIST_TAIL, "-warp_id",  0, "search by warp_id", 0);
+    psMetadataAddS64(definebyqueryArgs, PS_LIST_TAIL, "-warp_bg_id",  0, "search by warp_bg_id", 0);
     psMetadataAddS64(definebyqueryArgs, PS_LIST_TAIL, "-diff_id",  0, "search by diff_id", 0);
     psMetadataAddS64(definebyqueryArgs, PS_LIST_TAIL, "-magic_id", 0, "search by magic_id", 0);
