Index: trunk/ippTools/src/disttool.c
===================================================================
--- trunk/ippTools/src/disttool.c	(revision 23566)
+++ trunk/ippTools/src/disttool.c	(revision 23661)
@@ -92,8 +92,12 @@
     PS_ASSERT_PTR_NON_NULL(config, false);
 
+    // required
     PXOPT_LOOKUP_STR(stage, config->args, "-stage", true, false);
     PXOPT_LOOKUP_S64(stage_id, config->args, "-stage_id",  true, false);
     PXOPT_LOOKUP_STR(outroot, config->args, "-outroot", true, false);
+    // optional
+    PXOPT_LOOKUP_S64(target_id, config->args, "-target_id",  false, false);
     PXOPT_LOOKUP_BOOL(clean, config->args, "-clean", false);
+    PXOPT_LOOKUP_BOOL(no_magic, config->args, "-no_magic", false);
     PXOPT_LOOKUP_STR(set_label, config->args, "-set_label", false, false);
 
@@ -101,12 +105,21 @@
     // XXX: all of the following concerns will be managed properly by definebyquery
 
-    // TODO: check that stage_id actually exists for stage
+    // TODO: should we check that stage_id actually exists for stage
     // in magicdstool we queue off of a magic_id so the stage_id, exp_id, and cam_id get looked up 
     // when the run is queued
-    // Should we also check here that the run is full or cleaned and that all of the images
-    // are magicked. We need to do that at run time as well since the run and magic state can
-    // change between the time that it is queued.
-
-    if (!distRunInsert(config->dbh, 0, stage, stage_id, set_label, outroot, clean, "new", NULL, 0)) {
+
+    if (!distRunInsert(config->dbh,
+            0,          // dist_id
+            target_id,
+            stage,
+            stage_id,
+            set_label,
+            outroot,
+            clean,
+            no_magic,
+            "new",
+            NULL,       // time_stamp
+            0           // fault
+            )) {
         psError(PS_ERR_UNKNOWN, false, "database error");
         return false;
@@ -296,5 +309,4 @@
     PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
-    PXOPT_LOOKUP_BOOL(need_magic, config->args, "-need_magic", false);
 
     // look for "inputs" that need to processed
@@ -319,5 +331,9 @@
     }
 
-    psString    chip_magic = "";
+    // the query has where hooks for each stage.
+    // right now we aren't using them.
+    // XXX: I think that I want to change the query from a union of selects on the various
+    // stages to separate queries. As it is pending data at the later stages of the pipline
+    // will get blocked by pending earlier stages
     psString    raw_where = "";
     psString    chip_where = "";
@@ -328,17 +344,6 @@
     psString    stack_where = "";
 
-    if (need_magic) {
-        chip_magic = psStringCopy("\nAND chipRun.magicked");
-        raw_where  = psStringCopy("\nAND rawExp.magicked");
-        chip_where = psStringCopy("\nAND (distRun.clean OR chipRun.magicked)");
-        // chipRun must be magicked to allow release camera level masks
-        camera_where = psStringCopy("\nAND (distRun.clean OR chipRun.magicked)");
-        warp_where = psStringCopy("\nAND (distRun.clean OR warpRun.magicked)");
-        diff_where = psStringCopy("\nAND (distRun.clean OR diffRun.magicked)");
-    }
-
     if (!p_psDBRunQueryF(config->dbh,
             query,
-            chip_magic,
             raw_where,
             chip_where,
