Index: trunk/ippTools/src/chiptool.c
===================================================================
--- trunk/ippTools/src/chiptool.c	(revision 17186)
+++ trunk/ippTools/src/chiptool.c	(revision 17188)
@@ -355,6 +355,29 @@
     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
 
-    // XXX does this need to be constrained so that it won't return any results
-    // if a match chipPendingExp hasn't been registered?
+    psMetadata *where = psMetadataAlloc();
+    PXOPT_LOOKUP_STR(chip_id, config->args, "-chip_id", false, false);
+    // convert chip_id into a psS64
+    if (chip_id) {
+        if (!psMetadataAddS64(where, PS_LIST_TAIL, "chipRun.chip_id", 0, "==", (psS64)atoll(chip_id))) {
+            psError(PS_ERR_UNKNOWN, false, "failed to add item chip_id");
+            psFree(where);
+            return false;
+        }
+    }
+
+    PXOPT_LOOKUP_STR(exp_id, config->args, "-exp_id", false, false);
+    // convert exp_id into a psS64
+    if (exp_id) {
+        if (!psMetadataAddS64(where, PS_LIST_TAIL, "rawExp.exp_id", 0, "==", (psS64)atoll(exp_id))) {
+            psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id");
+            psFree(where);
+            return false;
+        }
+    }
+
+    PXOPT_COPY_STR(config->args, where, "-class_id", "rawImfile.class_id", "==");
+    PXOPT_COPY_STR(config->args, where, "-inst", "rawExp.telescope", "==");
+    PXOPT_COPY_STR(config->args, where, "-filter", "rawExp.filter", "==");
+
     psString query = pxDataGet("chiptool_pendingimfile.sql");
     if (!query) {
@@ -363,9 +386,10 @@
     }
 
-    if (config->where) {
-        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "chipInputImfile");
+    if (where && psListLength(where->list)) {
+        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
         psStringAppend(&query, " AND %s", whereClause);
         psFree(whereClause);
     }
+    psFree(where);
 
     // treat limit == 0 as "no limit"
@@ -529,6 +553,29 @@
     PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false);
 
-    // XXX does this need to be constrained so that it won't return any results
-    // if a match chipPendingExp hasn't been registered?
+    psMetadata *where = psMetadataAlloc();
+    PXOPT_LOOKUP_STR(chip_id, config->args, "-chip_id", false, false);
+    // convert chip_id into a psS64
+    if (chip_id) {
+        if (!psMetadataAddS64(where, PS_LIST_TAIL, "chipRun.chip_id", 0, "==", (psS64)atoll(chip_id))) {
+            psError(PS_ERR_UNKNOWN, false, "failed to add item chip_id");
+            psFree(where);
+            return false;
+        }
+    }
+
+    PXOPT_LOOKUP_STR(exp_id, config->args, "-exp_id", false, false);
+    // convert exp_id into a psS64
+    if (exp_id) {
+        if (!psMetadataAddS64(where, PS_LIST_TAIL, "rawExp.exp_id", 0, "==", (psS64)atoll(exp_id))) {
+            psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id");
+            psFree(where);
+            return false;
+        }
+    }
+
+    PXOPT_COPY_STR(config->args, where, "-class_id", "rawImfile.class_id", "==");
+    PXOPT_COPY_STR(config->args, where, "-inst", "rawExp.telescope", "==");
+    PXOPT_COPY_STR(config->args, where, "-filter", "rawExp.filter", "==");
+
     psString query = pxDataGet("chiptool_processedimfile.sql");
     if (!query) {
@@ -537,9 +584,10 @@
     }
 
-    if (config->where) {
-        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "chipProcessedImfile");
+    if (where && psListLength(where->list)) {
+        psString whereClause = psDBGenerateWhereConditionSQL(where, "chipProcessedImfile");
         psStringAppend(&query, " AND %s", whereClause);
         psFree(whereClause);
     }
+    psFree(where);
 
     if (faulted) {
