Index: trunk/ippTools/src/disttool.c
===================================================================
--- trunk/ippTools/src/disttool.c	(revision 23545)
+++ trunk/ippTools/src/disttool.c	(revision 23566)
@@ -296,4 +296,5 @@
     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
@@ -318,5 +319,33 @@
     }
 
-    if (!p_psDBRunQuery(config->dbh, query)) {
+    psString    chip_magic = "";
+    psString    raw_where = "";
+    psString    chip_where = "";
+    psString    camera_where = "";
+    psString    fake_where = "";
+    psString    warp_where = "";
+    psString    diff_where = "";
+    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,
+            camera_where,
+            fake_where,
+            warp_where,
+            diff_where,
+            stack_where)) {
         psError(PS_ERR_UNKNOWN, false, "database error");
         psFree(query);
Index: trunk/ippTools/src/disttoolConfig.c
===================================================================
--- trunk/ippTools/src/disttoolConfig.c	(revision 23545)
+++ trunk/ippTools/src/disttoolConfig.c	(revision 23566)
@@ -75,4 +75,5 @@
     psMetadataAddS64(pendingcomponentArgs, PS_LIST_TAIL, "-dist_id", 0, "define dist_id", 0); 
     psMetadataAddStr(pendingcomponentArgs, PS_LIST_TAIL, "-stage",    0, "limit results to runs for stage", NULL);
+    psMetadataAddBool(pendingcomponentArgs, PS_LIST_TAIL, "-need_magic", 0, "magic is needed", false);
     psMetadataAddStr(pendingcomponentArgs, PS_LIST_TAIL, "-label",    0, "limit results to label", NULL);
     psMetadataAddU64(pendingcomponentArgs, PS_LIST_TAIL, "-limit",  0,  "limit result set to N items", 0);
