Index: /trunk/ippTools/src/dettool.c
===================================================================
--- /trunk/ippTools/src/dettool.c	(revision 7238)
+++ /trunk/ippTools/src/dettool.c	(revision 7239)
@@ -426,13 +426,109 @@
     // I.e., when all of the same class_id for the input exposures have been
     // processed.  This should be done after detStackedImfiles are masked so we
-    // don't have to doen this check unless we have to.
+    // don't have to do this check unless we have to.
     if (psMetadataLookupBool(&status, config->args, "-chip")) {
+        // get a count of raw imfiles per class_id
         psArray *rawImfiles = searchInputImfiles(config, det_id);
-
-
-
-
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -det_id");
-        return false;
+        if (!rawImfiles) {
+            psError(PS_ERR_UNKNOWN, false, "no rawImfile row founds");
+            return false;
+        }
+
+        psHash *raw_counts = psHashAlloc(psArrayLength(rawImfiles));
+        for (long i = 0; i < psArrayLength(rawImfiles); i++) {
+            // check to see if the key already exists
+            psU32 *count = psHashLookup(
+                raw_counts,
+                ((rawImfileRow *)rawImfiles->data[i])->class_id
+            );
+            if (count) {
+                ++(*count);
+            } else {
+                psU32 *count = psAlloc(sizeof(psU32));
+                *count = 1;
+                psHashAdd(raw_counts,
+                    ((rawImfileRow *)rawImfiles->data[i])->class_id, count
+                );
+                psFree(count);
+            }
+        }
+#if 0
+        {
+            printf("raw counts:\n");
+            psList *keys  = psHashKeyList(raw_counts);
+            psListIterator *iter = psListIteratorAlloc(keys, 0, false);
+            char *key = NULL;
+            while ((key = psListGetAndIncrement(iter))) {
+                psU32 *count = psHashLookup(raw_counts, key);
+                printf("%s: %d\n", key, *count);
+            }
+            psFree(iter);
+            psFree(keys);
+        }
+#endif
+
+        // get a count of processed imfiles per class_id
+        psHash *processed_counts = psHashAlloc(psArrayLength(processedImfiles));
+        for (long i = 0; i < psArrayLength(processedImfiles); i++) {
+            // check to see if the key already exists
+            psU32 *count = psHashLookup(
+                processed_counts,
+                ((detProcessedImfileRow *)processedImfiles->data[i])->class_id
+            );
+            if (count) {
+                ++(*count);
+            } else {
+                psU32 *count = psAlloc(sizeof(psU32));
+                *count = 1;
+                psHashAdd(processed_counts,
+            ((detProcessedImfileRow *)processedImfiles->data[i])->class_id,
+                count
+                );
+                psFree(count);
+            }
+        }
+#if 0
+        {
+            printf("processed counts:\n");
+            psList *keys  = psHashKeyList(processed_counts);
+            psListIterator *iter = psListIteratorAlloc(keys, 0, false);
+            char *key = NULL;
+            while ((key = psListGetAndIncrement(iter))) {
+                psU32 *count = psHashLookup(processed_counts, key);
+                printf("%s: %d\n", key, *count);
+            }
+            psFree(iter);
+            psFree(keys);
+        }
+#endif
+
+        // compare the two class_id counts for any mismatched counts
+        psList *keys  = psHashKeyList(processed_counts);
+        psListIterator *iter = psListIteratorAlloc(keys, 0, false);
+        char *key = NULL;
+        while ((key = psListGetAndIncrement(iter))) {
+            psU32 *pcount = psHashLookup(processed_counts, key);
+            psU32 *rcount = psHashLookup(raw_counts, key);
+            if (*pcount != *rcount) {
+                psError(PS_ERR_UNKNOWN, false,
+                    "class_id %s - processed: %u raw: %u ",
+                    key, *pcount, *rcount 
+                );
+                // iterate through processedImfiles and remove *ALL* enteries
+                // with the mismatched class_id
+                for (long i = 0; i < psArrayLength(processedImfiles); i++) {
+                    if (((detProcessedImfileRow *)processedImfiles->data[i])->class_id) {
+                        psArrayRemove(processedImfiles, processedImfiles->data[i]);
+                        --i;
+                    }
+                }
+
+            }
+        }
+        psFree(iter);
+        psFree(keys);
+
+        psFree(raw_counts);
+        psFree(processed_counts);
     }
 
