Index: /trunk/ippTools/src/warptool.c
===================================================================
--- /trunk/ippTools/src/warptool.c	(revision 11980)
+++ /trunk/ippTools/src/warptool.c	(revision 11981)
@@ -46,4 +46,5 @@
 static bool setp4RunState(pxConfig *config, const char *p4_id, const char *state);
 static bool isValidMode(pxConfig *config, const char *mode);
+bool p4CompletedRuns(pxConfig *config);
 
 # define MODECASE(caseName, func) \
@@ -611,5 +612,5 @@
     psMetadataItem *item = NULL;
     psMetadataIterator *iter = psMetadataIteratorAlloc(skycells, 0, NULL);
-    if ((item = psMetadataGetAndIncrement(iter))) {
+    while ((item = psMetadataGetAndIncrement(iter))) {
         if (item->type != PS_DATA_METADATA) {
             psError(PS_ERR_UNKNOWN, false, "mapfile: %s is in the wrong format", mapfile);
@@ -761,5 +762,5 @@
         "   USING(p4_id)\n"
         " LEFT JOIN p4Scfile\n"
-        "   USING(p4_id, skycell_id, tess_id, exp_tag, p3_version)\n"
+        "   USING(p4_id, skycell_id, tess_id)\n"
         " WHERE\n"
         "   p4Run.state = 'run'\n" 
@@ -767,6 +768,4 @@
         "   AND p4Scfile.skycell_id IS NULL\n"
         "   AND p4Scfile.tess_id IS NULL\n"
-        "   AND p4Scfile.exp_tag IS NULL\n"
-        "   AND p4Scfile.p3_version IS NULL\n"
     );
 
@@ -871,14 +870,4 @@
     }
 
-    psString exp_tag = psMetadataLookupStr(&status, config->args, "-exp_tag");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_tag");
-        return false;
-    }
-    if (!exp_tag) {
-        psError(PS_ERR_UNKNOWN, true, "-exp_tag is required");
-        return false;
-    }
-
     psString uri = psMetadataLookupStr(&status, config->args, "-uri");
     if (!status) {
@@ -891,11 +880,4 @@
     }
 
-    // defaults to 0
-    psS32 p3_version = psMetadataLookupS32(&status, config->args, "-p3_version");
-    if (!status) {
-        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -p3_version");
-        return false;
-    }
-
     // optional
     psF64 bg = psMetadataLookupF64(&status, config->args, "-bg");
@@ -911,4 +893,10 @@
     }
 
+    // we don't want to insert the last scfile in a run but then not mark the
+    // run as 'stop'
+    if (!psDBTransaction(config->dbh)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
 
     // XXX need to validate that this coresponds to an p4InputImfile
@@ -917,6 +905,4 @@
             skycell_id,
             tess_id,
-            exp_tag,
-            p3_version,
             uri,
             bg,
@@ -927,7 +913,60 @@
     }
 
-    return true;
-}
-
+    if (!p4CompletedRuns(config)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+
+    // point of no return
+    if (!psDBCommit(config->dbh)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        return false;
+    }
+
+    return true;
+}
+
+bool p4CompletedRuns(pxConfig *config)
+{
+    PS_ASSERT_PTR_NON_NULL(config, false);
+
+    // find
+    psString query = psStringCopy( 
+        "UPDATE p4Run\n"
+        "   SET p4Run.state = 'stop'\n"
+        " WHERE\n"
+        "   p4Run.p4_id =\n"
+        "   (SELECT DISTINCT\n"
+        "       p4_id\n"
+        "   FROM\n"
+        "       (SELECT DISTINCT\n"
+        "           p4Run.p4_id,\n"
+        "           p4SkyCellMap.p4_id as foo,\n"
+        "           p4Scfile.p4_id as bar\n"
+        "       FROM p4Run\n"
+        "       JOIN p4SkyCellMap\n"
+        "           USING(p4_id)\n"
+        "       LEFT JOIN p4Scfile\n"
+        "           USING(p4_id, skycell_id, tess_id)\n"
+        "       WHERE\n"
+        "           p4Run.state = 'run'\n" 
+        "       GROUP BY\n"
+        "           p4Run.p4_id\n"  
+        "       HAVING\n"
+        "       COUNT(p4SkyCellMap.p4_id) = COUNT(p4Scfile.p4_id)\n"
+        "       ) as Foo\n"
+        "   )\n"
+    );
+
+    if (!p_psDBRunQuery(config->dbh, query)) {
+        psError(PS_ERR_UNKNOWN, false, "database error");
+        psFree(query);
+        return false;
+    }
+
+    psFree(query);
+
+    return true;
+}
 
 static bool warpedMode(pxConfig *config)
Index: /trunk/ippTools/src/warptoolConfig.c
===================================================================
--- /trunk/ippTools/src/warptoolConfig.c	(revision 11980)
+++ /trunk/ippTools/src/warptoolConfig.c	(revision 11981)
@@ -151,8 +151,4 @@
     psMetadataAddStr(addwarpedArgs, PS_LIST_TAIL, "-tess_id",  0,
             "define tessellation ID (required)", NULL);
-    psMetadataAddStr(addwarpedArgs, PS_LIST_TAIL, "-exp_tag", 0,
-            "define exposure tag (required)", NULL);
-    psMetadataAddS32(addwarpedArgs, PS_LIST_TAIL, "-p3_version", 0,
-            "define phase 3 version of exposure tag (required)", 0);
     psMetadataAddStr(addwarpedArgs, PS_LIST_TAIL, "-uri", 0,
             "define URI of file (required)", 0);
