Index: trunk/ippTools/src/disttool.c
===================================================================
--- trunk/ippTools/src/disttool.c	(revision 27235)
+++ trunk/ippTools/src/disttool.c	(revision 27459)
@@ -137,5 +137,5 @@
 
     // optional
-    PXOPT_LOOKUP_S64(magic_ds_id, config->args, "-magic_ds_id",  false, false);
+    PXOPT_LOOKUP_BOOL(use_alternate, config->args, "-use_alternate", false);
     PXOPT_LOOKUP_BOOL(no_magic, config->args, "-no_magic", false);
     PXOPT_LOOKUP_STR(set_label, config->args, "-set_label", false, false);
@@ -145,5 +145,16 @@
     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
 
-    PXOPT_LOOKUP_BOOL(dry_run, config->args, "-dry_run", false);
+    PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
+
+    if (use_alternate) { 
+        if (strcmp(stage, "raw")) {
+            psError(PXTOOLS_ERR_SYS, true, "alternate inputs only supported for raw stage");
+            return false;
+        }
+        if (no_magic) {
+            psError(PXTOOLS_ERR_SYS, true, "no_magic forbidden with alternate inputs");
+            return false;
+        }
+    }
 
     // select arguments
@@ -161,6 +172,11 @@
     psString runJoinStr = NULL;
     if (!strcmp(stage, "raw")) {
-        magicRunType = "rawExp";
-        runJoinStr = "rawExp.exp_id";
+        if (! use_alternate ) {
+            magicRunType = "rawExp";
+            runJoinStr = "rawExp.exp_id";
+        } else {
+            magicRunType = "camRun";
+            runJoinStr = "camRun.exp_id";
+        }
         query = pxDataGet("disttool_definebyquery_raw.sql");
         if (!query) {
@@ -170,10 +186,10 @@
         }
 
-        // for raw stage we select by chipRun.label because raw labels typically aren't set
+        // for raw stage we select by camRun.label and dist_group because rawExp doesn't have those columns
         if (label) {
-            psStringAppend(&query, " AND (chipRun.label = '%s')", label);
+            psStringAppend(&query, " AND (camRun.label = '%s')", label);
         }
         if (dist_group) {
-            psStringAppend(&query, " AND (chipRun.dist_group = '%s')", dist_group);
+            psStringAppend(&query, " AND (camRun.dist_group = '%s')", dist_group);
         }
     } else if (!strcmp(stage, "chip")) {
@@ -301,4 +317,11 @@
     }
 
+    if (!strcmp(stage, "raw")) {
+        if (!no_magic) {
+            psStringAppend(&query, " AND (magicDSRun.re_place = %d)", !use_alternate);
+            psStringAppend(&query, " AND (camRun.state = 'full')");
+        }
+    }
+
     if (psListLength(where->list)) {
         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
@@ -311,7 +334,8 @@
 
     if (!no_magic) {
-        psStringAppend(&query, " AND (%s.magicked)", magicRunType);
-
-        // is selecting by magic_ds_id really interesting?
+        psStringAppend(&query, " AND (%s.magicked > 0)", magicRunType);
+
+#ifdef notdef
+        // XXX: is selecting by magic_ds_id really interesting? I declare no
         if (magic_ds_id) {
             if (!runJoinStr) {
@@ -324,4 +348,5 @@
             psStringAppend(&query, " AND (magicDSRun.state = 'full' AND magicDSRun.re_place AND (magicDSRun.magic_ds_id = %" PRId64 "))", magic_ds_id);
         }
+#endif
     }
 
@@ -352,5 +377,5 @@
 
 
-    if (dry_run) {
+    if (pretend) {
         if (!ippdbPrintMetadatas(stdout, output, "newdistRuns", true)) {
             psError(PS_ERR_UNKNOWN, false, "failed to print array");
@@ -399,4 +424,5 @@
                 clean,
                 no_magic,
+                use_alternate,
                 "new",
                 NULL,    // time_stamp
