Index: trunk/ippTools/src/dettool.c
===================================================================
--- trunk/ippTools/src/dettool.c	(revision 7243)
+++ trunk/ippTools/src/dettool.c	(revision 7247)
@@ -4,4 +4,5 @@
 
 #include <stdlib.h>
+#include <metadatadb.h>
 
 #include "pxtools.h"
@@ -9,4 +10,5 @@
 
 static bool defineMode(pxConfig *config);
+static bool runsMode(pxConfig *config);
 static bool rawMode(pxConfig *config);
 static bool addprocMode(pxConfig *config);
@@ -31,4 +33,9 @@
         case DETTOOL_MODE_DEFINE:
             if (!defineMode(config)) {
+                goto FAIL;
+            }
+            break;
+        case DETTOOL_MODE_RUNS:
+            if (!runsMode(config)) {
                 goto FAIL;
             }
@@ -163,4 +170,74 @@
     // print the new det_id
     printf("%ld\n", det_id);
+
+    return true;
+}
+
+static bool runsMode(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+//    psArray *runs = detRunSelectRowObjects(config->dbh, config->where, 0);
+    // XXX fix the hard coding of the table name
+    psArray *runs = psDBSelectRows(config->dbh, "detRun", config->where, 0);
+    if (!runs) {
+        psError(PS_ERR_UNKNOWN, false, "no detRun rows found");
+        return false;
+    }
+
+    // print imfile list
+    psMetadata *output = psMetadataAlloc();
+    for (long i = 0; i < psArrayLength(runs); i++) {
+        psMetadata *run = runs->data[i];
+        psMetadata *md = psMetadataAlloc();
+        bool status = false;
+        // we need to change "position" to "det_id"
+        // lookup values
+        psS32 det_id = psMetadataLookupS32(&status, run, "position");
+        if (!status) {
+            psError(PS_ERR_UNKNOWN, false,
+                    "failed to lookup value for position");
+            psFree(output);
+            psFree(md);
+            psFree(runs);
+            return false;
+        }
+        psString det_type = psMetadataLookupStr(&status, run, "det_type");
+        if (!status) {
+            psError(PS_ERR_UNKNOWN, false,
+                    "failed to lookup value for det_type");
+            psFree(output);
+            psFree(md);
+            psFree(runs);
+            return false;
+        }
+        // add values
+        if (!psMetadataAddS32(md, PS_LIST_TAIL, "det_id", PS_META_DUPLICATE_OK,
+                NULL, det_id)) {
+            psError(PS_ERR_UNKNOWN, false, "failed to add item det_id");
+            psFree(output);
+            psFree(md);
+            psFree(runs);
+            return false;
+        }
+        if (!psMetadataAddStr(md, PS_LIST_TAIL, "det_type",
+                    PS_META_DUPLICATE_OK, NULL, det_type)) {
+            psError(PS_ERR_UNKNOWN, false, "failed to add item det_type");
+            psFree(output);
+            psFree(md);
+            psFree(runs);
+            return false;
+        }
+        psMetadataAddMetadata(
+            output, PS_LIST_TAIL, "detRun", PS_META_DUPLICATE_OK, NULL, md
+        );
+    }
+
+    psString str = psMetadataConfigFormat(output); 
+    psFree(output);
+    fprintf(stdout, "%s\n", str);
+    psFree(str);
+
+    psFree(runs);
 
     return true;
