Index: trunk/ippTools/src/disttool.c
===================================================================
--- trunk/ippTools/src/disttool.c	(revision 23365)
+++ 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);
