Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/Makefile.am
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/Makefile.am	(revision 35859)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/Makefile.am	(revision 36680)
@@ -105,4 +105,5 @@
 	detselect_search.sql \
 	detselect_select.sql \
+	detselect_show.sql \
 	dettool_addprocessedexp.sql \
 	dettool_childlessrun.sql \
@@ -189,8 +190,10 @@
 	disttool_definebyquery_diff.sql \
 	disttool_definebyquery_fake.sql \
+	disttool_definebyquery_ff.sql \
 	disttool_definebyquery_raw.sql \
 	disttool_definebyquery_raw_no_magic.sql \
 	disttool_definebyquery_sky.sql \
 	disttool_definebyquery_sky_singlefilter.sql \
+	disttool_definebyquery_skycal.sql \
 	disttool_definebyquery_stack.sql \
 	disttool_definebyquery_warp.sql \
@@ -205,6 +208,8 @@
 	disttool_pending_diff.sql \
 	disttool_pending_fake.sql \
+	disttool_pending_ff.sql \
 	disttool_pending_raw.sql \
 	disttool_pending_sky.sql \
+	disttool_pending_skycal.sql \
 	disttool_pending_stack.sql \
 	disttool_pending_warp.sql \
@@ -398,4 +403,6 @@
 	stacktool_tosummary.sql \
 	stacktool_addsummary.sql \
+	stacktool_revertsummary.sql \
+	stacktool_summary.sql \
 	staticskytool_definebyquery_select.sql \
 	staticskytool_definebyquery_select_by_dg.sql \
@@ -408,4 +415,6 @@
 	staticskytool_export_input.sql \
 	staticskytool_export_result.sql \
+	staticskytool_export_skycalrun.sql \
+	staticskytool_export_skycalresult.sql \
 	staticskytool_inputs.sql \
 	staticskytool_todo.sql \
@@ -476,8 +485,26 @@
 	releasetool_definerelstack_with_skycal.sql \
 	releasetool_listrelstack.sql \
+	releasetool_summary.sql \
 	releasetool_definerelgroup_select_lap.sql \
 	releasetool_definerelgroup_select_data_group.sql \
 	releasetool_definerelgroup_select_exp_data_group.sql \
 	releasetool_definerelgroup_select_exp_lap.sql \
-	releasetool_pendingrelgroup.sql
-
+	releasetool_stacksummary.sql \
+	releasetool_pendingrelgroup.sql \
+	fftool_definebyquery.sql \
+	fftool_definebyquery_select_warps.sql \
+	fftool_result.sql \
+	fftool_revert.sql \
+	fftool_revertsummary.sql \
+	fftool_summary.sql \
+	fftool_todo.sql \
+	fftool_toadvance.sql \
+	fftool_export_run.sql \
+	fftool_export_input.sql \
+	fftool_export_result.sql \
+	fftool_export_summary.sql \
+	remotetool_definebyquery_chip.sql \
+	remotetool_definebyquery_cam.sql \
+	remotetool_definebyquery_warp.sql \
+	remotetool_definebyquery_stack.sql \
+	remotetool_updatepoll.sql
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/camtool_pendingexp.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/camtool_pendingexp.sql	(revision 35859)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/camtool_pendingexp.sql	(revision 36680)
@@ -23,5 +23,6 @@
 WHERE
     chipRun.state = 'full'
-    AND ((camRun.state = 'new' AND camProcessedExp.cam_id IS NULL) OR camRun.state = 'update')
+    AND ((camRun.state = 'new' AND camProcessedExp.cam_id IS NULL) OR
+         (camRun.state = 'update' and camProcessedExp.fault = 0 and camProcessedExp.quality = 0))
     AND camMask.label IS NULL
     AND (Label.active OR Label.active IS NULL)
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/chiptool_pendingcleanuprun.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/chiptool_pendingcleanuprun.sql	(revision 35859)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/chiptool_pendingcleanuprun.sql	(revision 36680)
@@ -4,8 +4,11 @@
     rawExp.exp_tag,
     chipRun.state,
-    chipRun.workdir
+    chipRun.workdir,
+    chipRun.label,
+    IFNULL(Label.priority, 10000) AS priority
 FROM chipRun
 JOIN rawExp 
 USING (exp_id)
+LEFT JOIN Label ON chipRun.label = Label.label
 WHERE
     (chipRun.state = 'goto_cleaned' OR chipRun.state = 'goto_scrubbed' OR chipRun.state = 'goto_purged')
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/detselect_show.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/detselect_show.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/detselect_show.sql	(revision 36680)
@@ -0,0 +1,35 @@
+-- this query needs to use the same fields in both of the tables in
+-- the union statement, but we need to report the
+-- detRunSummary.iteration in the first case, and this is missing in
+-- the second case.
+
+SELECT DISTINCT
+    det_id,
+    good_iteration as iteration,
+    filelevel,
+    det_type,
+    mode,
+    registered,
+    filter,
+    time_begin,
+    time_end
+FROM
+    (SELECT DISTINCT
+	detRun.*,
+	detRunSummary.iteration as good_iteration
+    FROM detRun
+    JOIN detRunSummary
+        USING(det_id)
+    WHERE
+       detRun.mode  = 'master'
+       AND detRunSummary.accept = 1
+    UNION
+    SELECT DISTINCT
+	detRun.*,
+	detRun.iteration as good_iteration
+    FROM detRun
+    WHERE
+       (detRun.mode  = 'register' OR detRun.mode = 'correction')
+    ) as Foo
+WHERE
+    (state = 'stop')
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_SSdiff.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_SSdiff.sql	(revision 35859)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_SSdiff.sql	(revision 36680)
@@ -22,5 +22,3 @@
       AND distTarget.state = 'enabled'
       AND rcInterest.state = 'enabled'
-      AND distRun.dist_id IS NULL
-
       AND ((diffRun.state = 'full') OR (distTarget.clean AND diffRun.state = 'cleaned'))
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_camera.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_camera.sql	(revision 35859)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_camera.sql	(revision 36680)
@@ -21,4 +21,3 @@
 WHERE distTarget.state = 'enabled'
     AND rcInterest.state = 'enabled'
-    AND distRun.dist_id IS NULL      -- no existing distRun 
     AND ((camRun.state = 'full') OR (distTarget.clean AND camRun.state = 'cleaned'))
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_chip.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_chip.sql	(revision 35859)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_chip.sql	(revision 36680)
@@ -20,4 +20,3 @@
 WHERE distTarget.state = 'enabled'
     AND rcInterest.state = 'enabled'
-    AND distRun.dist_id IS NULL      -- no existing distRun 
     AND ((chipRun.state = 'full') OR (distTarget.clean AND chipRun.state = 'cleaned'))
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_chip_bg.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_chip_bg.sql	(revision 35859)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_chip_bg.sql	(revision 36680)
@@ -23,4 +23,3 @@
 WHERE distTarget.state = 'enabled'
     AND rcInterest.state = 'enabled'
-    AND distRun.dist_id IS NULL      -- no existing distRun
     AND ((chipBackgroundRun.state = 'full') OR (distTarget.clean AND chipBackgroundRun.state = 'cleaned'))
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_diff.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_diff.sql	(revision 35859)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_diff.sql	(revision 36680)
@@ -25,5 +25,4 @@
 WHERE  distTarget.state = 'enabled'
     AND rcInterest.state = 'enabled'
-    AND distRun.dist_id IS NULL
     AND ((diffRun.state = 'full') OR (distTarget.clean AND diffRun.state = 'cleaned'))
 
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_fake.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_fake.sql	(revision 35859)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_fake.sql	(revision 36680)
@@ -20,4 +20,3 @@
 WHERE  distTarget.state = 'enabled'
     AND rcInterest.state = 'enabled'
-    AND distRun.dist_id IS NULL
     AND ((fakeRun.state = 'full') OR (distTarget.clean AND fakeRun.state = 'cleaned'))
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_ff.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_ff.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_ff.sql	(revision 36680)
@@ -0,0 +1,26 @@
+SELECT DISTINCT
+    'ff' as stage,
+    fullForceRun.ff_id AS stage_id,
+    CAST(0 AS SIGNED) AS magicked,
+    -- run tag in the form 'ff.$skycell_id.$ff_id'
+    CONCAT_WS('.', 'ff', stackRun.skycell_id, convert(fullForceRun.ff_id, CHAR)) as run_tag,
+    fullForceRun.label,
+    fullForceRun.data_group,
+    distTarget.dist_group,
+    distTarget.target_id,
+    distTarget.clean
+FROM fullForceRun
+JOIN skycalRun USING(skycal_id)
+JOIN stackRun using(stack_id)
+JOIN distTarget ON distTarget.stage = 'ff'
+    AND fullForceRun.dist_group = distTarget.dist_group
+JOIN rcInterest USING(target_id)
+LEFT JOIN distRun ON (distRun.stage_id = ff_id)
+    AND distRun.target_id = distTarget.target_id
+    -- JOIN hook %s
+WHERE  distTarget.state = 'enabled'
+    AND rcInterest.state = 'enabled'
+    AND fullForceRun.state = 'full'
+    AND stackRun.filter = distTarget.filter
+    -- we shouldn't need to check fault. If faulted it shouldn't be full
+    -- AND (skycalResult.fault = 0 AND skycalResult.quality = 0)
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_raw.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_raw.sql	(revision 35859)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_raw.sql	(revision 36680)
@@ -16,6 +16,5 @@
 JOIN rcInterest USING(target_id)
 LEFT JOIN distRun ON distRun.stage_id = exp_id AND distRun.target_id = distTarget.target_id
-WHERE distRun.dist_id IS NULL           -- no existing distRun for this exposure
-    AND distTarget.state = 'enabled'    -- target and intrest are enabled
+WHERE distTarget.state = 'enabled'    -- target and intrest are enabled
     AND rcInterest.state = 'enabled'
     AND magicDSRun.state = 'full'       -- destreaked files are available
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_sky.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_sky.sql	(revision 35859)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_sky.sql	(revision 36680)
@@ -3,5 +3,5 @@
     staticskyRun.sky_id AS stage_id,
     CAST(0 AS SIGNED) AS magicked,
-    -- run tag in the form 'sky.$skycell_id.$stack_id'
+    -- run tag in the form 'sky.$skycell_id.$sky_id'
     CONCAT_WS('.', 'sky', stackRun.skycell_id, convert(staticskyRun.sky_id, CHAR)) as run_tag,
     staticskyRun.label,
@@ -23,5 +23,4 @@
     AND rcInterest.state = 'enabled'
     AND distTarget.filter = 'multi'
-    AND distRun.dist_id IS NULL
     AND ((staticskyRun.state = 'full') OR (distTarget.clean AND staticskyRun.state = 'cleaned'))
     -- we shouldn't need to check fault. If faulted it shouldn't be full
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_sky_singlefilter.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_sky_singlefilter.sql	(revision 35859)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_sky_singlefilter.sql	(revision 36680)
@@ -22,5 +22,4 @@
 WHERE  distTarget.state = 'enabled'
     AND rcInterest.state = 'enabled'
-    AND distRun.dist_id IS NULL
     AND ((staticskyRun.state = 'full') OR (distTarget.clean AND staticskyRun.state = 'cleaned'))
     AND stackRun.filter = distTarget.filter
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_skycal.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_skycal.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_skycal.sql	(revision 36680)
@@ -0,0 +1,26 @@
+SELECT DISTINCT
+    'skycal' as stage,
+    skycalRun.skycal_id AS stage_id,
+    CAST(0 AS SIGNED) AS magicked,
+    -- run tag in the form 'skycal.$skycell_id.$skycal_id'
+    CONCAT_WS('.', 'skycal', stackRun.skycell_id, convert(skycalRun.skycal_id, CHAR)) as run_tag,
+    skycalRun.label,
+    skycalRun.data_group,
+    distTarget.dist_group,
+    distTarget.target_id,
+    distTarget.clean
+FROM skycalRun
+JOIN skycalResult USING(skycal_id)
+JOIN stackRun using(stack_id)
+JOIN distTarget ON distTarget.stage = 'skycal'
+    AND skycalRun.dist_group = distTarget.dist_group
+JOIN rcInterest USING(target_id)
+LEFT JOIN distRun ON (distRun.stage_id = skycal_id)
+    AND distRun.target_id = distTarget.target_id
+    -- JOIN hook %s
+WHERE  distTarget.state = 'enabled'
+    AND rcInterest.state = 'enabled'
+    AND ((skycalRun.state = 'full') OR (distTarget.clean AND skycalRun.state = 'cleaned'))
+    AND stackRun.filter = distTarget.filter
+    -- we shouldn't need to check fault. If faulted it shouldn't be full
+    AND (skycalResult.fault = 0 AND skycalResult.quality = 0)
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_stack.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_stack.sql	(revision 35859)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_stack.sql	(revision 36680)
@@ -21,5 +21,4 @@
 WHERE  distTarget.state = 'enabled'
     AND rcInterest.state = 'enabled'
-    AND distRun.dist_id IS NULL
     AND ((stackRun.state = 'full') OR (distTarget.clean AND stackRun.state = 'cleaned'))
     -- we shouldn't need to check fault. If faulted it shouldn't be full
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_warp.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_warp.sql	(revision 35859)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_warp.sql	(revision 36680)
@@ -22,5 +22,4 @@
 WHERE  distTarget.state = 'enabled'
     AND rcInterest.state = 'enabled'
-    AND distRun.dist_id IS NULL
     AND ((warpRun.state = 'full') OR (distTarget.clean AND warpRun.state = 'cleaned'))
 
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_warp_bg.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_warp_bg.sql	(revision 35859)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_definebyquery_warp_bg.sql	(revision 36680)
@@ -24,5 +24,4 @@
 WHERE  distTarget.state = 'enabled'
     AND rcInterest.state = 'enabled'
-    AND distRun.dist_id IS NULL
     AND ((warpBackgroundRun.state = 'full') OR (distTarget.clean AND warpBackgroundRun.state = 'cleaned'))
 
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_pending_ff.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_pending_ff.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_pending_ff.sql	(revision 36680)
@@ -0,0 +1,86 @@
+-- look for fullForceResult components and a summary components
+SELECT * FROM
+(
+SELECT
+    distRun.dist_id,
+    distRun.label,
+    distTarget.dist_group,
+    stage,
+    stage_id,
+    CONCAT_WS('.', warp_id, stackRun.skycell_id) AS component,
+    exp_type,
+    clean,
+    rawExp.camera,
+    CONCAT_WS('.', outroot, CONVERT(distRun.dist_id, CHAR)) as outdir,
+    fullForceResult.path_base,
+    CAST(NULL AS CHAR(255)) as chip_path_base,
+    fullForceRun.state,
+    'full' AS data_state,
+    fullForceResult.quality,
+    distRun.no_magic,
+    warpRun.magicked,
+    IFNULL(Label.priority, 10000) AS priority
+FROM distRun
+JOIN distTarget USING(target_id, stage, clean)
+JOIN fullForceRun ON stage_id = ff_id
+JOIN skycalRun USING(skycal_id)
+JOIN stackRun USING(stack_id)
+JOIN fullForceResult USING(ff_id)
+JOIN warpRun USING(warp_id)
+JOIN fakeRun USING(fake_id)
+JOIN camRun USING(cam_id)
+JOIN chipRun ON camRun.chip_id = chipRun.chip_id
+JOIN rawExp using(exp_id)
+LEFT JOIN distComponent 
+    ON distRun.dist_id = distComponent.dist_id 
+    AND CONCAT_WS('.', warp_id, stackRun.skycell_id) = distComponent.component
+LEFT JOIN Label ON distRun.label = Label.label
+WHERE
+    distRun.state = 'new'
+    AND distRun.stage = 'ff'
+    AND distComponent.dist_id IS NULL
+    AND (Label.active OR Label.active IS NULL)
+UNION
+SELECT DISTINCT
+    distRun.dist_id,
+    distRun.label,
+    distTarget.dist_group,
+    stage,
+    stage_id,
+    'summary' AS component,
+    exp_type,
+    clean,
+    rawExp.camera,
+    CONCAT_WS('.', outroot, CONVERT(distRun.dist_id, CHAR)) as outdir,
+    fullForceSummary.path_base,
+    CAST(NULL AS CHAR(255)) as chip_path_base,
+    fullForceRun.state,
+    'full' AS data_state,
+    fullForceSummary.quality,
+    distRun.no_magic,
+    0 AS magicked,
+    IFNULL(Label.priority, 10000) AS priority
+FROM distRun
+JOIN distTarget USING(target_id, stage, clean)
+JOIN fullForceRun ON stage_id = ff_id
+JOIN fullForceSummary USING(ff_id)
+JOIN skycalRun USING(skycal_id)
+JOIN stackRun USING(stack_id)
+JOIN stackInputSkyfile USING(stack_id)
+JOIN warpRun USING(warp_id)
+JOIN fakeRun USING(fake_id)
+JOIN camRun USING(cam_id)
+JOIN chipRun ON camRun.chip_id = chipRun.chip_id
+JOIN rawExp using(exp_id)
+LEFT JOIN distComponent 
+    ON distRun.dist_id = distComponent.dist_id 
+    AND 'summary' = distComponent.component
+LEFT JOIN Label ON distRun.label = Label.label
+WHERE
+    distRun.state = 'new'
+    AND distRun.stage = 'ff'
+    AND distComponent.dist_id IS NULL
+    AND (Label.active OR Label.active IS NULL)
+) as distRun
+-- where arguments are appended here
+WHERE 1
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_pending_skycal.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_pending_skycal.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_pending_skycal.sql	(revision 36680)
@@ -0,0 +1,52 @@
+SELECT DISTINCT
+    distRun.dist_id,
+    distRun.label,
+    distTarget.dist_group,
+    stage,
+    stage_id,
+    stackRun.skycell_id AS component,
+    exp_type,
+    clean,
+    rawExp.camera,
+    CONCAT_WS('.', outroot, CONVERT(distRun.dist_id, CHAR)) as outdir,
+    skycalResult.path_base,
+    CAST(NULL AS CHAR(255)) as chip_path_base,
+    skycalRun.state,
+    skycalRun.state AS data_state,
+    skycalResult.quality,
+    1 AS no_magic,
+    0 AS magicked,
+    IFNULL(Label.priority, 10000) AS priority
+FROM distRun
+JOIN distTarget USING(target_id, stage, clean)
+JOIN skycalRun
+    ON stage_id = skycal_id
+JOIN skycalResult
+    USING(skycal_id)
+JOIN stackRun USING(stack_id)
+JOIN stackInputSkyfile USING(stack_id)
+JOIN warpSkyfile
+    ON  stackInputSkyfile.warp_id = warpSkyfile.warp_id
+    AND stackRun.skycell_id       = warpSkyfile.skycell_id
+    AND stackRun.tess_id          = warpSkyfile.tess_id
+JOIN warpRun
+    ON warpRun.warp_id = warpSkyfile.warp_id
+JOIN fakeRun
+    USING(fake_id)
+JOIN camRun
+    USING(cam_id)
+JOIN chipRun
+    USING(chip_id)
+JOIN rawExp 
+     USING (exp_id)
+LEFT JOIN distComponent 
+    ON distRun.dist_id = distComponent.dist_id 
+    AND stackRun.skycell_id = distComponent.component
+LEFT JOIN Label ON distRun.label = Label.label
+WHERE
+    distRun.state = 'new'
+    AND distRun.stage = 'skycal'
+    AND distComponent.dist_id IS NULL
+    AND (skycalRun.state = 'full' OR (distRun.clean AND skycalRun.state = 'cleaned'))
+    AND (skycalResult.fault = 0 AND skycalResult.quality = 0)
+    AND (Label.active OR Label.active IS NULL)
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_toadvance.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_toadvance.sql	(revision 35859)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/disttool_toadvance.sql	(revision 36680)
@@ -262,4 +262,25 @@
         AND distComponent.fault = 0
 UNION
+-- skycal stage
+-- NOTE this assumes that there is only one component per skycalRun
+-- (one skycell)
+SELECT
+    distRun.dist_id,
+    stage,
+    stage_id,
+    outroot,
+    label,
+    clean
+    FROM distRun
+    JOIN skycalResult on stage_id = skycal_id
+    LEFT JOIN distComponent
+        ON distRun.dist_id = distComponent.dist_id
+    WHERE
+        distRun.state = 'new'
+        AND distRun.fault = 0
+        AND distRun.stage = 'skycal'
+        AND distComponent.component IS NOT NULL
+        AND distComponent.fault = 0
+UNION
 -- SSdiff stage
 SELECT
@@ -287,3 +308,33 @@
         COUNT(diffSkyfile.skycell_id) = COUNT(distComponent.component)
         AND SUM(distComponent.fault) = 0
+UNION
+-- ff stage
+SELECT
+    distRun.dist_id,
+    stage,
+    stage_id,
+    outroot,
+    distRun.label,
+    clean
+    -- ,COUNT(warp_id)
+    -- ,COUNT(ff_id)
+    FROM distRun
+    JOIN fullForceRun ON stage_id = ff_id
+    JOIN fullForceResult USING(ff_id)
+    JOIN skycalRun USING(skycal_id)
+    JOIN stackRun USING(stack_id)
+    LEFT JOIN distComponent
+        ON distRun.dist_id = distComponent.dist_id
+        AND distComponent.component = CONCAT_WS('.', warp_id, stackRun.skycell_id) 
+    WHERE
+        distRun.state = 'new'
+        AND distRun.fault = 0
+        AND distRun.stage = 'ff'
+    GROUP BY
+        distRun.dist_id,
+        ff_id
+    HAVING
+        -- number of dist components is the number of warps plus 1 (for the summary component)
+        COUNT(fullForceResult.ff_id) = COUNT(distComponent.component)
+        AND SUM(distComponent.fault) = 0
 ) as Foo
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_definebyquery.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_definebyquery.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_definebyquery.sql	(revision 36680)
@@ -0,0 +1,14 @@
+SELECT
+    skycalRun.skycal_id,
+    skycalResult.path_base,
+    skycalRun.data_group,
+    stackRun.tess_id,
+    stackRun.skycell_id,
+    stackRun.filter
+FROM skycalRun
+    JOIN skycalResult USING(skycal_id)
+    JOIN stackRun USING(stack_id)
+    JOIN skycell USING(tess_id, skycell_id)
+    -- join hook %s
+WHERE 
+    skycalRun.state = 'full' AND skycalResult.quality = 0
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_definebyquery_select_warps.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_definebyquery_select_warps.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_definebyquery_select_warps.sql	(revision 36680)
@@ -0,0 +1,9 @@
+SELECT warp_id
+FROM warpRun join warpSkyfile using(warp_id, tess_id)
+    JOIN fakeRun using(fake_id)
+    JOIN camRun USING(cam_id)
+    JOIN chipRun USING(chip_id)
+    JOIN rawExp USING(exp_id)
+    JOIN skycell ON skycell.tess_id = warpSkyfile.tess_id AND skycell.skycell_id = warpSkyfile.skycell_id
+WHERE warpRun.tess_id = '%s' AND warpSkyfile.skycell_id = '%s' AND rawExp.filter = '%s'
+    AND warpRun.state = 'full' AND warpSkyfile.quality = 0 and warpSkyfile.fault = 0
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_export_input.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_export_input.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_export_input.sql	(revision 36680)
@@ -0,0 +1,3 @@
+SELECT
+    fullForceInput.*
+FROM fullForceInput
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_export_result.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_export_result.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_export_result.sql	(revision 36680)
@@ -0,0 +1,3 @@
+SELECT
+    fullForceResult.*
+FROM fullForceResult
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_export_run.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_export_run.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_export_run.sql	(revision 36680)
@@ -0,0 +1,3 @@
+SELECT
+    fullForceRun.*
+FROM fullForceRun
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_export_summary.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_export_summary.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_export_summary.sql	(revision 36680)
@@ -0,0 +1,3 @@
+SELECT
+    fullForceSummary.*
+FROM fullForceSummary
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_result.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_result.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_result.sql	(revision 36680)
@@ -0,0 +1,23 @@
+SELECT
+    fullForceResult.*,
+    fullForceRun.state,
+    fullForceRun.label,
+    fullForceRun.data_group,
+    fullForceRun.skycal_id,
+    fullForceRun.workdir,
+    fullForceRun.sources_path_base,
+    CONCAT_WS('.', warp_id, skycell_id) AS dist_component,
+    stackRun.tess_id,
+    stackRun.skycell_id,
+    stackRun.filter,
+    rawExp.camera
+FROM fullForceRun
+    JOIN fullForceResult USING(ff_id)
+    JOIN skycalRun using(skycal_id)
+    JOIN stackRun using(stack_id)
+    JOIN warpRun using(warp_id, tess_id)
+    JOIN warpSkyfile USING(warp_id, tess_id, skycell_id)
+    JOIN fakeRun using(fake_id)
+    JOIN camRun using(cam_id)
+    JOIN chipRun using(chip_id)
+    JOIN rawExp using(exp_id)
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_revert.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_revert.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_revert.sql	(revision 36680)
@@ -0,0 +1,7 @@
+DELETE FROM fullForceResult
+USING fullForceResult, fullForceRun, skycalRun, stackRun, skycell
+WHERE fullForceRun.ff_id = fullForceResult.ff_id
+    AND fullForceResult.fault != 0
+    AND fullForceRun.skycal_id = skycalRun.skycal_id
+    AND skycalRun.stack_id = stackRun.stack_id
+    AND stackRun.tess_id = skycell.tess_id AND stackRun.skycell_id =  skycell.skycell_id
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_revertsummary.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_revertsummary.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_revertsummary.sql	(revision 36680)
@@ -0,0 +1,7 @@
+DELETE FROM fullForceSummary
+USING fullForceSummary, fullForceRun, skycalRun, stackRun, skycell
+WHERE fullForceRun.ff_id = fullForceSummary.ff_id
+    AND fullForceSummary.fault != 0
+    AND fullForceRun.skycal_id = skycalRun.skycal_id
+    AND skycalRun.stack_id = stackRun.stack_id
+    AND stackRun.tess_id = skycell.tess_id AND stackRun.skycell_id =  skycell.skycell_id
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_summary.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_summary.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_summary.sql	(revision 36680)
@@ -0,0 +1,24 @@
+SELECT DISTINCT
+    fullForceSummary.*,
+    fullForceRun.state,
+    fullForceRun.label,
+    fullForceRun.data_group,
+    fullForceRun.skycal_id,
+    fullForceRun.workdir,
+    fullForceRun.sources_path_base,
+    'summary' AS dist_component,
+    stackRun.tess_id,
+    stackRun.skycell_id,
+    stackRun.filter,
+    rawExp.camera
+FROM fullForceRun
+    JOIN fullForceSummary USING(ff_id)
+    JOIN fullForceInput USING(ff_id)
+    JOIN skycalRun using(skycal_id)
+    JOIN stackRun using(stack_id)
+    JOIN warpRun using(warp_id, tess_id)
+    JOIN warpSkyfile USING(warp_id, tess_id, skycell_id)
+    JOIN fakeRun using(fake_id)
+    JOIN camRun using(cam_id)
+    JOIN chipRun using(chip_id)
+    JOIN rawExp using(exp_id)
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_summaryinputs.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_summaryinputs.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_summaryinputs.sql	(revision 36680)
@@ -0,0 +1,4 @@
+SELECT
+    fullForceResult.*
+FROM fullForceRun 
+    JOIN fullForceResult USING(ff_id)
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_toadvance.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_toadvance.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_toadvance.sql	(revision 36680)
@@ -0,0 +1,22 @@
+SELECT
+    fullForceRun.*,
+    stackRun.tess_id,
+    stackRun.skycell_id,
+    stackRun.filter,
+    rawExp.camera
+FROM fullForceRun
+    JOIN fullForceInput USING(ff_id)
+    JOIN skycalRun USING(skycal_id)
+    JOIN stackRun USING(stack_id)
+    JOIN warpRun USING(warp_id, tess_id)
+    JOIN fakeRun USING(fake_id)
+    JOIN camRun USING(cam_id)
+    JOIN chipRun USING(chip_id)
+    JOIN rawExp USING(exp_id)
+    LEFT JOIN fullForceResult USING(ff_id, warp_id)
+    LEFT JOIN fullForceSummary USING(ff_id)
+WHERE fullForceRun.state = 'new' AND fullForceSummary.ff_id IS NULL
+    -- WHERE hook %s
+    GROUP BY ff_id
+    HAVING COUNT(fullForceInput.warp_id) = COUNT(fullForceResult.warp_id)
+        AND SUM(fullForceResult.fault) = 0
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_todo.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_todo.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/fftool_todo.sql	(revision 36680)
@@ -0,0 +1,22 @@
+SELECT
+    fullForceRun.*,
+    fullForceInput.warp_id,
+    stackRun.tess_id,
+    stackRun.skycell_id,
+    stackRun.filter,
+    rawExp.camera,
+    warpSkyfile.path_base AS warp_path_base
+FROM fullForceRun
+    JOIN fullForceInput USING(ff_id)
+    JOIN skycalRun USING(skycal_id)
+    JOIN stackRun USING(stack_id)
+    JOIN warpRun USING(warp_id, tess_id)
+    JOIN warpSkyfile USING(warp_id, tess_id, skycell_id)
+    JOIN fakeRun USING(fake_id)
+    JOIN camRun USING(cam_id)
+    JOIN chipRun USING(chip_id)
+    JOIN rawExp USING(exp_id)
+    LEFT JOIN fullForceResult USING(ff_id, warp_id)
+WHERE fullForceRun.state = 'new'
+    AND fullForceResult.ff_id IS NULL
+    AND warpSkyfile.data_state = 'full'
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/pstamptool_pendingdependent.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/pstamptool_pendingdependent.sql	(revision 35859)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/pstamptool_pendingdependent.sql	(revision 36680)
@@ -1,4 +1,5 @@
 SELECT DISTINCT
     pstampDependent.*,
+    pstampRequest.label,
     concat( pstampDependent.outdir, '/checkdep.', dep_id, '.log') as logfile,
     IFNULL(Label.priority, 10000) AS priority
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/pxadmin_create_tables.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/pxadmin_create_tables.sql	(revision 35859)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/pxadmin_create_tables.sql	(revision 36680)
@@ -2172,4 +2172,6 @@
     dataRelease INT,         -- PSPS dataRelease
     priority    INT,
+    dvodb       VARCHAR(255),
+    ubercal_file VARCHAR(255),
     PRIMARY KEY(rel_id),
     UNIQUE KEY(surveyID, release_name),
@@ -2186,9 +2188,11 @@
     chip_id     BIGINT,         -- links to the runs that supplied the data
     cam_id      BIGINT,         -- for this release
-    group_id    INT,         -- id of relGroup that this exposure is contained in
+    group_id    INT,            -- id of relGroup that this exposure is contained in
     state       VARCHAR(16),    -- released, pending, archive, drop  
-    flags       INT UNSIGNED,  -- flags for relphot, relastro, ??
+    flags       INT UNSIGNED,   -- flags for relphot, relastro, ??
     zpt_obs     FLOAT,          -- calibrated zero point for this release of
     zpt_stdev   FLOAT,          -- this exposure
+    mcal        FLOAT,          -- this exposure
+    ubercal_dist INT,           -- ubercal distance (from dvo calibration)
     path_base   VARCHAR(255),   -- path_base of any supporting files for this
                                 -- release of this exposure.
@@ -2303,4 +2307,85 @@
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
 
+CREATE TABLE fullForceRun (
+    ff_id           BIGINT NOT NULL AUTO_INCREMENT,
+    skycal_id       BIGINT,
+    sources_path_base VARCHAR(255),
+    state           VARCHAR(64),
+    workdir         VARCHAR(255),
+    label           VARCHAR(64),
+    data_group      VARCHAR(64),
+    dist_group      VARCHAR(64),
+    note            VARCHAR(255),
+    reduction       VARCHAR(64),
+    registered TIMESTAMP DEFAULT CURRENT_TIMESTAMP, -- time run was registered
+    PRIMARY KEY(ff_id),
+    KEY(state),
+    KEY(label),
+    KEY(data_group),
+    KEY(skycal_id),
+    FOREIGN KEY(skycal_id) REFERENCES skycalRun(skycal_id)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
+
+CREATE TABLE fullForceInput (
+    ff_id           BIGINT,
+    warp_id         BIGINT,
+    PRIMARY KEY(ff_id, warp_id),
+    FOREIGN KEY(ff_id) REFERENCES fullForceRun(ff_id),
+    FOREIGN KEY(warp_id) REFERENCES warpRun(warp_id)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
+
+CREATE TABLE fullForceResult (
+    ff_id           BIGINT,
+    warp_id         BIGINT,
+    path_base       VARCHAR(255) NOT NULL,
+    dtime_script    FLOAT,
+    quality         SMALLINT NOT NULL,
+    hostname        VARCHAR(64) NOT NULL,
+    software_ver    VARCHAR(16),
+    fault           SMALLINT NOT NULL,
+    PRIMARY KEY(ff_id, warp_id),
+    KEY(fault),
+    KEY(quality),
+    FOREIGN KEY(ff_id) REFERENCES fullForceRun(ff_id),
+    FOREIGN KEY(warp_id) REFERENCES warpRun(warp_id)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
+
+CREATE TABLE fullForceSummary (
+    ff_id           BIGINT,
+    path_base       VARCHAR(255) NOT NULL,
+    dtime_script    FLOAT,
+    quality         SMALLINT NOT NULL,
+    hostname        VARCHAR(64) NOT NULL,
+    software_ver    VARCHAR(16),
+    fault           SMALLINT NOT NULL,
+    PRIMARY KEY(ff_id),
+    KEY(fault),
+    KEY(quality),
+    FOREIGN KEY(ff_id) REFERENCES fullForceRun(ff_id)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
+
+CREATE TABLE remoteRun (
+    remote_id BIGINT NOT NULL AUTO_INCREMENT,
+    state     VARCHAR(64) NOT NULL,
+    stage     VARCHAR(64) NOT NULL,
+    label     VARCHAR(64) NOT NULL,
+    path_base VARCHAR(255) NOT NULL,
+    job_id    BIGINT,
+    last_poll TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
+    fault     SMALLINT NOT NULL,
+    PRIMARY KEY (remote_id),
+    KEY (state),
+    KEY (stage),
+    KEY (label),
+    KEY (job_id)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
+
+CREATE TABLE remoteComponent (
+    remote_id BIGINT,
+    stage_id  BIGINT,
+    KEY (stage_id),
+    FOREIGN KEY (remote_id) REFERENCES remoteRun(remote_id)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
+
 -- These comment lines are here to avoid an empty query error.
 -- Another way to avoid that problem is to omit the semicolon above but I think that is untidy.
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/pxadmin_drop_tables.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/pxadmin_drop_tables.sql	(revision 35859)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/pxadmin_drop_tables.sql	(revision 36680)
@@ -118,6 +118,11 @@
 DROP TABLE IF EXISTS mergedvodbProcessed;
 DROP TABLE IF EXISTS mergedvodbRun;
+DROP TABLE IF EXISTS dqstatsContent;
 DROP TABLE IF EXISTS dqstatsRun;
-DROP TABLE IF EXISTS dqstatsContent;
+DROP TABLE IF EXISTS fullForceRun;
+DROP TABLE IF EXISTS fullForceInput;
+DROP TABLE IF EXISTS fullForceResult;
+DROP TABLE IF EXISTS fullForceSummary;
+
 
 SET FOREIGN_KEY_CHECKS=1
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/releasetool_listrelexp.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/releasetool_listrelexp.sql	(revision 35859)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/releasetool_listrelexp.sql	(revision 36680)
@@ -7,4 +7,6 @@
     ippRelease.rel_id,
     ippRelease.priority,
+    ippRelease.dvodb,
+    ippRelease.ubercal_file,
     survey.surveyName,
     rawExp.exp_name,
@@ -12,4 +14,6 @@
     relExp.zpt_obs,
     relExp.zpt_stdev,
+    relExp.mcal,
+    relExp.ubercal_dist,
     relExp.path_base,
     relExp.registered,
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/releasetool_listrelstack.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/releasetool_listrelstack.sql	(revision 35859)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/releasetool_listrelstack.sql	(revision 36680)
@@ -10,4 +10,6 @@
     skycalResult.path_base AS skycal_path_base,
     skycalRun.data_group AS skycal_data_group,
+    staticskyResult.sky_id AS sky_id,
+    staticskyResult.path_base AS staticsky_path_base,
     'GPC1' AS camera
 FROM relStack
@@ -18,2 +20,3 @@
 LEFT JOIN skycalRun USING(skycal_id)
 LEFT JOIN skycalResult USING(skycal_id)
+LEFT JOIN staticskyResult USING(sky_id)
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/releasetool_stacksummary.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/releasetool_stacksummary.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/releasetool_stacksummary.sql	(revision 36680)
@@ -0,0 +1,19 @@
+SELECT DISTINCT sass_id,
+       stackAssociation.tess_id,
+       stackAssociation.projection_cell,
+       stackAssociation.filter,
+       stackSummary.path_base,
+       stackAssociation.data_group,
+       survey.surveyName,
+       ippRelease.release_name,
+       ippRelease.rel_id
+
+FROM relStack 
+    JOIN ippRelease USING(rel_id)
+    JOIN survey USING(surveyID)
+    JOIN stackAssociationMap USING(stack_id) 
+    JOIN stackAssociation USING(sass_id, filter)
+    JOIN stackSummary using(sass_id, projection_cell)
+
+-- WHERE rel_id = 37 and skycell_id like 'skycell.0635.045' and filter = 'r.00000'\G
+-- WHERE rel_id = 37 and projection_cell = 'skycell.0635' and filter = 'r.00000'\G
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/releasetool_summary.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/releasetool_summary.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/releasetool_summary.sql	(revision 36680)
@@ -0,0 +1,23 @@
+SELECT DISTINCT 
+       release_name,
+       surveyName,
+       sass_id,
+       stackAssociation.tess_id,
+       stackAssociation.projection_cell,
+       stackAssociation.filter,
+       stackSummary.path_base,
+       stackAssociation.data_group,
+       rawExp.camera
+FROM relStack 
+    JOIN ippRelease USING(rel_id)
+    JOIN survey USING(surveyID)
+    JOIN stackRun USING(stack_id, filter, tess_id, skycell_id)
+    JOIN stackAssociationMap USING(stack_id) 
+    JOIN stackAssociation USING(sass_id, filter)
+    JOIN stackSummary using(sass_id, projection_cell)
+    JOIN stackInputSkyfile using(stack_id)
+    JOIN warpRun USING(warp_id)
+    JOIN fakeRun USING(fake_id)
+    JOIN camRun USING(cam_id)
+    JOIN chipRun USING(chip_id)
+    JOIN rawExp USING(exp_id)
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/remotetool_definebyquery_cam.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/remotetool_definebyquery_cam.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/remotetool_definebyquery_cam.sql	(revision 36680)
@@ -0,0 +1,12 @@
+SELECT 
+       cam_id AS stage_id
+FROM camRun 
+       LEFT JOIN remoteComponent ON (remoteComponent.stage_id = camRun.cam_id) 
+       LEFT JOIN remoteRun ON (
+       	    remoteComponent.remote_id = remoteRun.remote_id AND 
+	    remoteRun.label = camRun.label
+	    )
+WHERE
+camRun.state = 'new' AND
+remoteRun.stage = 'camera' AND
+remote_id IS NULL
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/remotetool_definebyquery_chip.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/remotetool_definebyquery_chip.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/remotetool_definebyquery_chip.sql	(revision 36680)
@@ -0,0 +1,16 @@
+SELECT 
+       chip_id AS stage_id
+FROM chipRun 
+       LEFT JOIN remoteComponent ON (remoteComponent.stage_id = chipRun.chip_id) 
+       LEFT JOIN remoteRun ON (
+       	    remoteComponent.remote_id = remoteRun.remote_id AND 
+	    remoteRun.label = chipRun.label
+	    )
+WHERE
+chipRun.state = 'new' AND
+(remoteRun.stage = 'chip' OR remoteRun.stage IS NULL) AND
+remoteComponent.remote_id IS NULL
+
+
+
+       
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/remotetool_definebyquery_stack.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/remotetool_definebyquery_stack.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/remotetool_definebyquery_stack.sql	(revision 36680)
@@ -0,0 +1,12 @@
+SELECT 
+       stack_id AS stage_id
+FROM stackRun 
+       LEFT JOIN remoteComponent ON (remoteComponent.stage_id = stackRun.stack_id) 
+       LEFT JOIN remoteRun ON (
+       	    remoteComponent.remote_id = remoteRun.remote_id AND 
+	    remoteRun.label = stackRun.label
+	    )
+WHERE
+stackRun.state = 'new' AND
+remoteRun.stage = 'stack' AND
+remote_id IS NULL
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/remotetool_definebyquery_warp.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/remotetool_definebyquery_warp.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/remotetool_definebyquery_warp.sql	(revision 36680)
@@ -0,0 +1,12 @@
+SELECT 
+       warp_id AS stage_id
+FROM warpRun 
+       LEFT JOIN remoteComponent ON (remoteComponent.stage_id = warpRun.warp_id) 
+       LEFT JOIN remoteRun ON (
+       	    remoteComponent.remote_id = remoteRun.remote_id AND 
+	    remoteRun.label = warpRun.label
+	    )
+WHERE
+warpRun.state = 'new' AND
+remoteRun.stage = 'warp' AND
+remote_id IS NULL
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/remotetool_updatepoll.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/remotetool_updatepoll.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/remotetool_updatepoll.sql	(revision 36680)
@@ -0,0 +1,3 @@
+UPDATE remoteRun SET last_poll = CURRENT_TIMESTAMP 
+WHERE
+%s
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/stacktool_addsummary.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/stacktool_addsummary.sql	(revision 35859)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/stacktool_addsummary.sql	(revision 36680)
@@ -1,4 +1,4 @@
 INSERT INTO stackSummary (sass_id,projection_cell,path_base) VALUES (
-       %lld,   -- warp_id
+       %lld,   -- sass_id
        '%s',   -- projection_cell
        '%s'    -- path_base
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/stacktool_revertsummary.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/stacktool_revertsummary.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/stacktool_revertsummary.sql	(revision 36680)
@@ -0,0 +1,3 @@
+DELETE FROM stackSummary 
+       WHERE 
+       sass_id = %lld
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/stacktool_summary.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/stacktool_summary.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/stacktool_summary.sql	(revision 36680)
@@ -0,0 +1,17 @@
+SELECT DISTINCT sass_id,
+       stackAssociation.tess_id,
+       stackAssociation.projection_cell,
+       stackAssociation.filter,
+       stackSummary.path_base,
+       stackAssociation.data_group,
+       rawExp.camera
+FROM stackRun 
+    JOIN stackAssociationMap USING(stack_id) 
+    JOIN stackAssociation USING(sass_id, filter)
+    JOIN stackSummary using(sass_id, projection_cell)
+    JOIN stackInputSkyfile using(stack_id)
+    JOIN warpRun USING(warp_id)
+    JOIN fakeRun USING(fake_id)
+    JOIN camRun USING(cam_id)
+    JOIN chipRun USING(chip_id)
+    JOIN rawExp USING(exp_id)
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/staticskytool_export_skycalresult.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/staticskytool_export_skycalresult.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/staticskytool_export_skycalresult.sql	(revision 36680)
@@ -0,0 +1,1 @@
+SELECT * from skycalResult
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/staticskytool_export_skycalrun.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/staticskytool_export_skycalrun.sql	(revision 36680)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/staticskytool_export_skycalrun.sql	(revision 36680)
@@ -0,0 +1,1 @@
+SELECT * from skycalRun
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/staticskytool_skycalresult.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/staticskytool_skycalresult.sql	(revision 35859)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/staticskytool_skycalresult.sql	(revision 36680)
@@ -2,8 +2,10 @@
     skycalResult.*,
     skycalRun.stack_id,
+    skycalRun.workdir,
     stackRun.filter,
     skycalRun.state,
     skycalRun.label,
     skycalRun.data_group,
+    skycalRun.dist_group,
     skycalRun.sky_id,
     skycell.*
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/warptool_scmap.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/warptool_scmap.sql	(revision 35859)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/warptool_scmap.sql	(revision 36680)
@@ -8,4 +8,5 @@
     chipProcessedImfile.chip_id,
     chipRun.state,
+    chipRun.data_group as chip_data_group,
     chipProcessedImfile.data_state,
     chipProcessedImfile.fault AS chip_fault,
Index: branches/eam_branches/ps2-tc3-20130727/ippTools/share/warptool_warped.sql
===================================================================
--- branches/eam_branches/ps2-tc3-20130727/ippTools/share/warptool_warped.sql	(revision 35859)
+++ branches/eam_branches/ps2-tc3-20130727/ippTools/share/warptool_warped.sql	(revision 36680)
@@ -4,4 +4,5 @@
     warpRun.workdir,
     warpRun.label,
+    warpRun.data_group,
     warpImfile.warp_skyfile_id,
     rawExp.exp_id,
@@ -13,4 +14,5 @@
     rawExp.decl,
     rawExp.exp_time,
+    camRun.cam_id,
     magicDSRun.state AS dsRun_state,
     IFNULL(magicDSRun.magic_ds_id, 0) AS magic_ds_id
