Index: trunk/ippTools/share/camtool_find_chip_id.sql
===================================================================
--- trunk/ippTools/share/camtool_find_chip_id.sql	(revision 14018)
+++ trunk/ippTools/share/camtool_find_chip_id.sql	(revision 14018)
@@ -0,0 +1,13 @@
+-- this query is used by both camtool -pendingexp & camtool -addprocessedexp it
+-- does a little more work then is necessary for -addprocessed but it seems
+-- "cleaner" to use the same query for both cases 
+SELECT
+    *
+FROM
+    (SELECT DISTINCT
+        chipRun.*
+    FROM chipRun
+    JOIN chipProcessedExp
+        USING(chip_id)
+    WHERE
+        chipRun.state = 'stop') as Foo
Index: trunk/ippTools/share/camtool_find_pendingexp.sql
===================================================================
--- trunk/ippTools/share/camtool_find_pendingexp.sql	(revision 13827)
+++ trunk/ippTools/share/camtool_find_pendingexp.sql	(revision 14018)
@@ -3,5 +3,5 @@
 -- "cleaner" to use the same query for both cases 
 SELECT
-    camPendingExp.*,
+    camRun.*,
     rawExp.exp_tag,
     rawExp.exp_id,
@@ -9,14 +9,18 @@
     rawExp.telescope,
     rawExp.filelevel
-FROM camPendingExp
-JOIN chipProcessedExp
+FROM camRun
+JOIN chipRun
+    USING(chip_id)
+JOIN chipProcessedImfile
     USING(chip_id)
 JOIN rawExp
-    ON chipProcessedExp.exp_tag = rawExp.exp_tag
+    ON chipProcessedImfile.exp_tag = rawExp.exp_tag
 LEFT JOIN camProcessedExp
-    ON camPendingExp.cam_id = camProcessedExp.cam_id
+    ON camRun.cam_id = camProcessedExp.cam_id
 LEFT JOIN camMask
-    ON camPendingExp.label = camMask.label
+    ON camRun.label = camMask.label
 WHERE
-    camProcessedExp.cam_id IS NULL
+    chipRun.state = 'stop'
+    AND camRun.state = 'run'
     AND camMask.label IS NULL
+    AND camProcessedExp.cam_id IS NULL
Index: trunk/ippTools/share/camtool_queue_chip_id.sql
===================================================================
--- trunk/ippTools/share/camtool_queue_chip_id.sql	(revision 13827)
+++ trunk/ippTools/share/camtool_queue_chip_id.sql	(revision 14018)
@@ -1,14 +1,17 @@
 -- camtool only operates on exposures so we can safely queue more then one at a
 -- time without worrying about losing the track of the generated cam_id
-INSERT INTO camPendingExp
+INSERT INTO camRun
     SElECT
         0,              -- cam_id
         chip_id,        -- chip_id
+        '%s',           -- state
         '%s',           -- workdir
+        '%s',           -- workdir_state
         '%s',           -- label
-        '%s',           -- recipe
+        '%s',           -- reduction
         '%s',           -- expgroup
         '%s'            -- dvodb 
-    FROM chipProcessedExp
+    FROM chipRun
     WHERE
-        chipProcessedExp.chip_id = %lld
+        chipRun.state = 'stop'
+        AND chipRun.chip_id = %lld
Index: trunk/ippTools/share/chiptool_completely_processed_exp.sql
===================================================================
--- trunk/ippTools/share/chiptool_completely_processed_exp.sql	(revision 13827)
+++ trunk/ippTools/share/chiptool_completely_processed_exp.sql	(revision 14018)
@@ -1,26 +1,31 @@
--- select * from chipPendingExp
--- where exp_tag is not in chipProcessedExp
--- where exp_tag is not in chipPendingImfile
--- where the number of entries in chipProccessedImfile matches the .imfiles
--- entry in rawExp
+-- the output of this query must match the format of chipRun row
 SELECT DISTINCT
-    chipPendingExp.*,
-    rawExp.imfiles,
-    chipProcessedImfile.class_id
-FROM chipPendingExp
-JOIN rawExp
-    ON chipPendingExp.exp_tag = rawExp.exp_tag
-LEFT JOIN chipProcessedExp
-    ON chipPendingExp.chip_id = chipProcessedExp.chip_id
-LEFT JOIN chipPendingImfile
-    ON chipPendingExp.chip_id = chipPendingImfile.chip_id
-LEFT JOIN chipProcessedImfile
-    ON chipPendingExp.chip_id = chipProcessedImfile.chip_id
-WHERE
-    chipProcessedExp.chip_id IS NULL
-    AND chipPendingImfile.chip_id IS NULL
-    AND chipProcessedImfile.chip_id IS NOT NULL
-    AND chipProcessedImfile.fault = 0
-GROUP BY
-    chipPendingExp.chip_id
-HAVING rawExp.imfiles = COUNT(chipProcessedImfile.class_id)
+    chip_id,
+    state,
+    workdir,
+    workdir_state,
+    label,
+    reduction,
+    expgroup,
+    dvodb
+FROM
+    (SELECT 
+        chipRun.*,
+        rawExp.imfiles,
+        chipProcessedImfile.class_id
+    FROM chipRun
+    JOIN chipInputImfile
+        USING(chip_id)
+    JOIN rawExp
+        ON chipInputImfile.exp_tag = rawExp.exp_tag
+    JOIN chipProcessedImfile
+        ON chipInputImfile.chip_id = chipProcessedImfile.chip_id
+        AND chipInputImfile.exp_tag = chipProcessedImfile.exp_tag
+        AND chipInputImfile.class_id = chipProcessedImfile.class_id
+    WHERE
+        chipRun.state = 'run'
+        AND chipProcessedImfile.fault = 0
+    GROUP BY
+        chipInputImfile.chip_id,
+        chipInputImfile.exp_tag
+    HAVING rawExp.imfiles = COUNT(chipProcessedImfile.class_id)) as Foo
Index: trunk/ippTools/share/chiptool_find_unprocessed_imfile.pl
===================================================================
--- trunk/ippTools/share/chiptool_find_unprocessed_imfile.pl	(revision 13827)
+++ trunk/ippTools/share/chiptool_find_unprocessed_imfile.pl	(revision 14018)
@@ -1,5 +1,5 @@
 SELECT DISTINCT
-   chipPendingImfile.*
-FROM chipPendingImfile
+   chipInputImfile.*
+FROM chipInputImfile
 LEFT JOIN chipProcessedImfile
     USING(chip_id, class_id)
Index: trunk/ippTools/share/chiptool_pendingimfile.sql
===================================================================
--- trunk/ippTools/share/chiptool_pendingimfile.sql	(revision 13827)
+++ trunk/ippTools/share/chiptool_pendingimfile.sql	(revision 14018)
@@ -1,17 +1,29 @@
 SELECT
-    chipPendingExp.*,
-    chipPendingImfile.class_id,
-    chipPendingImfile.uri,
+    chipRun.*,
+    chipInputImfile.exp_tag,
+    chipInputImfile.class_id,
+    rawImfile.uri,
     rawExp.exp_id,
     rawExp.camera,
     rawExp.telescope,
     rawExp.filelevel
-FROM chipPendingImfile
-JOIN chipPendingExp
+FROM chipRun
+JOIN chipInputImfile
     USING(chip_id)
+LEFT JOIN chipProcessedImfile
+    ON chipInputImfile.chip_id = chipProcessedImfile.chip_id
+    AND chipInputImfile.exp_tag = chipProcessedImfile.exp_tag
+    AND chipInputImfile.class_id = chipProcessedImfile.class_id
+JOIN rawImfile
+    ON chipInputImfile.exp_tag = rawImfile.exp_tag
+    AND chipInputImfile.class_id = rawImfile.class_id
 JOIN rawExp
-    ON chipPendingExp.exp_tag = rawExp.exp_tag
+    ON rawImfile.exp_tag = rawExp.exp_tag
 LEFT JOIN chipMask
-    ON chipPendingExp.label = chipMask.label
+    ON chipRun.label = chipMask.label
 WHERE
-    chipMask.label IS NULL
+    chipRun.state = 'run'
+    AND chipProcessedImfile.chip_id IS NULL
+    AND chipProcessedImfile.exp_tag IS NULL
+    AND chipProcessedImfile.class_id IS NULL
+    AND chipMask.label IS NULL
Index: trunk/ippTools/share/chiptool_queuerawexp.sql
===================================================================
--- trunk/ippTools/share/chiptool_queuerawexp.sql	(revision 13827)
+++ 	(revision )
@@ -1,16 +1,0 @@
--- we can only enqueue one exp_tag at a time or the generated chip_id of all
--- put the last one inserted will be lost
-INSERT INTO chipPendingExp
-    SElECT
-        0,              -- chip_id
-        exp_tag,        -- exp_tag
-        0xdeadbeef,     -- guide_id
-        '%s',           -- workdir
-        '%s',           -- label
-        '%s',           -- recipe
-        '%s',           -- expgroup
-        '%s'            -- dvodb 
-   FROM rawExp
-   WHERE
-        rawExp.fault = 0
-        AND rawExp.exp_tag = '%s'
Index: trunk/ippTools/share/chiptool_queuerawimfile.sql
===================================================================
--- trunk/ippTools/share/chiptool_queuerawimfile.sql	(revision 13827)
+++ trunk/ippTools/share/chiptool_queuerawimfile.sql	(revision 14018)
@@ -1,11 +1,13 @@
-INSERT INTO chipPendingImfile
+INSERT INTO chipInputImfile
     SELECT
-        chipPendingExp.chip_id,
-        rawImfile.class_id,
-        rawImfile.uri
-    FROM chipPendingExp
-    JOIN rawImfile
+        LAST_INSERT_ID(),
+        rawImfile.exp_tag,
+        rawImfile.class_id
+    FROM rawImfile
+    JOIN newExp
         USING(exp_tag)
     WHERE
         rawImfile.fault = 0
-        AND chipPendingExp.chip_id = LAST_INSERT_ID()
+        AND newExp.state = 'stop'
+        AND rawImfile.exp_tag = '%s'
+
Index: trunk/ippTools/share/regtool_find_unprocessed_exp.sql
===================================================================
--- trunk/ippTools/share/regtool_find_unprocessed_exp.sql	(revision 13827)
+++ trunk/ippTools/share/regtool_find_unprocessed_exp.sql	(revision 14018)
@@ -1,15 +1,16 @@
-SELECT
-   newExp.*
-FROM newExp
-LEFT JOIN newImfile
-   USING(exp_tag)
-LEFT JOIN rawExp
-   USING(exp_tag)
+SELECT DISTINCT * FROM
+    (SELECT
+       newExp.*
+    FROM newExp
+    JOIN newImfile
+       USING(exp_tag)
+    LEFT JOIN rawExp
+       USING(exp_tag)
+    WHERE
+        newExp.state = 'run'
+        AND rawExp.exp_tag IS NULL
+        AND newExp.imfiles =
+        (SELECT COUNT(exp_tag) FROM rawImfile
+            WHERE rawImfile.exp_tag = newExp.exp_tag)) as Foo
 WHERE
-    newExp.exp_tag IS NOT NULL
-    AND newImfile.exp_tag IS NULL
-    AND rawExp.exp_tag IS NULL
-    AND newExp.imfiles =
-    (SELECT COUNT(exp_tag) FROM rawImfile
-        WHERE rawImfile.exp_tag = newExp.exp_tag)
-    AND newExp.exp_tag = '%s'
+    exp_tag = '%s'
Index: trunk/ippTools/share/regtool_find_unprocessed_imfile.sql
===================================================================
--- trunk/ippTools/share/regtool_find_unprocessed_imfile.sql	(revision 13827)
+++ trunk/ippTools/share/regtool_find_unprocessed_imfile.sql	(revision 14018)
@@ -1,8 +1,11 @@
-SELECT
-    *
-FROM
-    (SELECT newImfile.* FROM newImfile
-        LEFT JOIN newExp USING(exp_tag)
-        LEFT JOIN rawExp USING(exp_tag)
-        WHERE newExp.exp_tag IS NOT NULL
+SELECT DISTINCT * FROM
+    (SELECT
+        newImfile.*
+    FROM newImfile
+    JOIN newExp
+        USING(exp_tag)
+    LEFT JOIN rawExp
+        USING(exp_tag)
+    WHERE
+        newExp.state = 'run'
         AND rawExp.exp_tag IS NULL) as Foo
Index: trunk/ippTools/share/regtool_pendingexp.sql
===================================================================
--- trunk/ippTools/share/regtool_pendingexp.sql	(revision 13827)
+++ trunk/ippTools/share/regtool_pendingexp.sql	(revision 14018)
@@ -2,10 +2,10 @@
     newExp.*
 FROM newExp
-LEFT JOIN newImfile
+JOIN newImfile
     USING(exp_tag)
 LEFT JOIN rawExp
     USING(exp_tag)
 WHERE
-    newImfile.exp_tag IS NULL
+    newExp.state = 'run'
     AND rawExp.exp_tag IS NULL
     AND newExp.imfiles =
