Index: branches/eam_branches/ipp-ops-20130712/ippTools/share/Makefile.am
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/Makefile.am	(revision 37064)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/Makefile.am	(revision 37068)
@@ -105,4 +105,5 @@
 	detselect_search.sql \
 	detselect_select.sql \
+	detselect_show.sql \
 	dettool_addprocessedexp.sql \
 	dettool_childlessrun.sql \
@@ -189,4 +190,5 @@
 	disttool_definebyquery_diff.sql \
 	disttool_definebyquery_fake.sql \
+	disttool_definebyquery_ff.sql \
 	disttool_definebyquery_raw.sql \
 	disttool_definebyquery_raw_no_magic.sql \
@@ -206,4 +208,5 @@
 	disttool_pending_diff.sql \
 	disttool_pending_fake.sql \
+	disttool_pending_ff.sql \
 	disttool_pending_raw.sql \
 	disttool_pending_sky.sql \
@@ -400,4 +403,5 @@
 	stacktool_tosummary.sql \
 	stacktool_addsummary.sql \
+	stacktool_revertsummary.sql \
 	stacktool_summary.sql \
 	staticskytool_definebyquery_select.sql \
@@ -487,4 +491,21 @@
 	releasetool_definerelgroup_select_exp_lap.sql \
 	releasetool_stacksummary.sql \
-	releasetool_pendingrelgroup.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_dropcomponent.sql \
+	remotetool_updatepoll.sql
Index: branches/eam_branches/ipp-ops-20130712/ippTools/share/camtool_find_processedexp.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/camtool_find_processedexp.sql	(revision 37064)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/camtool_find_processedexp.sql	(revision 37068)
@@ -1,4 +1,5 @@
 SELECT
     camProcessedExp.*,
+    HEX(IFNULL(camProcessedExp.astrom_chips, 0)) AS good_astrom_chips,
     camRun.workdir,
     camRun.label,
Index: branches/eam_branches/ipp-ops-20130712/ippTools/share/detselect_show.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/detselect_show.sql	(revision 37068)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/detselect_show.sql	(revision 37068)
@@ -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/ipp-ops-20130712/ippTools/share/disttool_definebyquery_SSdiff.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_SSdiff.sql	(revision 37064)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_SSdiff.sql	(revision 37068)
@@ -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/ipp-ops-20130712/ippTools/share/disttool_definebyquery_camera.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_camera.sql	(revision 37064)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_camera.sql	(revision 37068)
@@ -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/ipp-ops-20130712/ippTools/share/disttool_definebyquery_chip.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_chip.sql	(revision 37064)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_chip.sql	(revision 37068)
@@ -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/ipp-ops-20130712/ippTools/share/disttool_definebyquery_chip_bg.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_chip_bg.sql	(revision 37064)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_chip_bg.sql	(revision 37068)
@@ -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/ipp-ops-20130712/ippTools/share/disttool_definebyquery_diff.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_diff.sql	(revision 37064)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_diff.sql	(revision 37068)
@@ -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/ipp-ops-20130712/ippTools/share/disttool_definebyquery_fake.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_fake.sql	(revision 37064)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_fake.sql	(revision 37068)
@@ -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/ipp-ops-20130712/ippTools/share/disttool_definebyquery_ff.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_ff.sql	(revision 37068)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_ff.sql	(revision 37068)
@@ -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/ipp-ops-20130712/ippTools/share/disttool_definebyquery_raw.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_raw.sql	(revision 37064)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_raw.sql	(revision 37068)
@@ -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/ipp-ops-20130712/ippTools/share/disttool_definebyquery_sky.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_sky.sql	(revision 37064)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_sky.sql	(revision 37068)
@@ -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/ipp-ops-20130712/ippTools/share/disttool_definebyquery_sky_singlefilter.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_sky_singlefilter.sql	(revision 37064)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_sky_singlefilter.sql	(revision 37068)
@@ -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/ipp-ops-20130712/ippTools/share/disttool_definebyquery_skycal.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_skycal.sql	(revision 37064)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_skycal.sql	(revision 37068)
@@ -1,3 +1,3 @@
-SELECT
+SELECT DISTINCT
     'skycal' as stage,
     skycalRun.skycal_id AS stage_id,
@@ -21,5 +21,4 @@
 WHERE  distTarget.state = 'enabled'
     AND rcInterest.state = 'enabled'
-    AND distRun.dist_id IS NULL
     AND ((skycalRun.state = 'full') OR (distTarget.clean AND skycalRun.state = 'cleaned'))
     AND stackRun.filter = distTarget.filter
Index: branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_stack.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_stack.sql	(revision 37064)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_stack.sql	(revision 37068)
@@ -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/ipp-ops-20130712/ippTools/share/disttool_definebyquery_warp.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_warp.sql	(revision 37064)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_warp.sql	(revision 37068)
@@ -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/ipp-ops-20130712/ippTools/share/disttool_definebyquery_warp_bg.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_warp_bg.sql	(revision 37064)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_definebyquery_warp_bg.sql	(revision 37068)
@@ -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/ipp-ops-20130712/ippTools/share/disttool_pending_ff.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_pending_ff.sql	(revision 37068)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_pending_ff.sql	(revision 37068)
@@ -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/ipp-ops-20130712/ippTools/share/disttool_toadvance.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_toadvance.sql	(revision 37064)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/disttool_toadvance.sql	(revision 37068)
@@ -308,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/ipp-ops-20130712/ippTools/share/fftool_definebyquery.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_definebyquery.sql	(revision 37068)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_definebyquery.sql	(revision 37068)
@@ -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/ipp-ops-20130712/ippTools/share/fftool_definebyquery_select_warps.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_definebyquery_select_warps.sql	(revision 37068)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_definebyquery_select_warps.sql	(revision 37068)
@@ -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/ipp-ops-20130712/ippTools/share/fftool_export_input.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_export_input.sql	(revision 37068)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_export_input.sql	(revision 37068)
@@ -0,0 +1,3 @@
+SELECT
+    fullForceInput.*
+FROM fullForceInput
Index: branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_export_result.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_export_result.sql	(revision 37068)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_export_result.sql	(revision 37068)
@@ -0,0 +1,3 @@
+SELECT
+    fullForceResult.*
+FROM fullForceResult
Index: branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_export_run.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_export_run.sql	(revision 37068)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_export_run.sql	(revision 37068)
@@ -0,0 +1,3 @@
+SELECT
+    fullForceRun.*
+FROM fullForceRun
Index: branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_export_summary.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_export_summary.sql	(revision 37068)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_export_summary.sql	(revision 37068)
@@ -0,0 +1,3 @@
+SELECT
+    fullForceSummary.*
+FROM fullForceSummary
Index: branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_result.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_result.sql	(revision 37068)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_result.sql	(revision 37068)
@@ -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/ipp-ops-20130712/ippTools/share/fftool_revert.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_revert.sql	(revision 37068)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_revert.sql	(revision 37068)
@@ -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/ipp-ops-20130712/ippTools/share/fftool_revertsummary.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_revertsummary.sql	(revision 37068)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_revertsummary.sql	(revision 37068)
@@ -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/ipp-ops-20130712/ippTools/share/fftool_summary.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_summary.sql	(revision 37068)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_summary.sql	(revision 37068)
@@ -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/ipp-ops-20130712/ippTools/share/fftool_summaryinputs.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_summaryinputs.sql	(revision 37068)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_summaryinputs.sql	(revision 37068)
@@ -0,0 +1,4 @@
+SELECT
+    fullForceResult.*
+FROM fullForceRun 
+    JOIN fullForceResult USING(ff_id)
Index: branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_toadvance.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_toadvance.sql	(revision 37068)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_toadvance.sql	(revision 37068)
@@ -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/ipp-ops-20130712/ippTools/share/fftool_todo.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_todo.sql	(revision 37068)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/fftool_todo.sql	(revision 37068)
@@ -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/ipp-ops-20130712/ippTools/share/pxadmin_create_tables.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/pxadmin_create_tables.sql	(revision 37064)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/pxadmin_create_tables.sql	(revision 37068)
@@ -523,4 +523,5 @@
     quality SMALLINT NOT NULL DEFAULT 0,
     background_model SMALLINT,
+    astrom_chips BIGINT,
     PRIMARY KEY(cam_id),
     KEY(fault),
@@ -2307,4 +2308,84 @@
 ) 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.
Index: branches/eam_branches/ipp-ops-20130712/ippTools/share/pxadmin_drop_tables.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/pxadmin_drop_tables.sql	(revision 37064)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/pxadmin_drop_tables.sql	(revision 37068)
@@ -120,4 +120,9 @@
 DROP TABLE IF EXISTS dqstatsContent;
 DROP TABLE IF EXISTS dqstatsRun;
+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/ipp-ops-20130712/ippTools/share/remotetool_definebyquery_cam.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/remotetool_definebyquery_cam.sql	(revision 37068)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/remotetool_definebyquery_cam.sql	(revision 37068)
@@ -0,0 +1,21 @@
+SELECT stage_id FROM
+
+( SELECT cam_id AS stage_id
+    FROM camRun
+WHERE
+camRun.state = 'new'
+-- where hook %s
+GROUP BY cam_id
+) AS W
+
+LEFT JOIN
+
+(SELECT remote_id,remoteRun.stage,remoteRun.label,remoteComponent.stage_id,remoteRun.state 
+   FROM remoteRun 
+   JOIN remoteComponent USING (remote_id)
+WHERE
+remoteRun.stage = 'camera'
+-- where hook %s
+) AS R
+USING (stage_id)
+WHERE R.remote_id IS NULL
Index: branches/eam_branches/ipp-ops-20130712/ippTools/share/remotetool_definebyquery_chip.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/remotetool_definebyquery_chip.sql	(revision 37068)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/remotetool_definebyquery_chip.sql	(revision 37068)
@@ -0,0 +1,26 @@
+SELECT stage_id FROM
+
+( SELECT chip_id AS stage_id
+    FROM chipRun
+WHERE
+chipRun.state = 'new'
+-- where hook %s
+GROUP BY chip_id
+) AS W
+
+LEFT JOIN
+
+(SELECT remote_id,remoteRun.stage,remoteRun.label,remoteComponent.stage_id,remoteRun.state 
+   FROM remoteRun 
+   JOIN remoteComponent USING (remote_id)
+WHERE
+remoteRun.stage = 'chip'
+-- where hook %s
+) AS R
+USING (stage_id)
+WHERE R.remote_id IS NULL
+
+
+
+
+       
Index: branches/eam_branches/ipp-ops-20130712/ippTools/share/remotetool_definebyquery_stack.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/remotetool_definebyquery_stack.sql	(revision 37068)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/remotetool_definebyquery_stack.sql	(revision 37068)
@@ -0,0 +1,21 @@
+SELECT stage_id FROM
+
+( SELECT stack_id AS stage_id
+    FROM stackRun
+WHERE
+stackRun.state = 'new'
+-- where hook %s
+GROUP BY stack_id
+) AS W
+
+LEFT JOIN
+
+(SELECT remote_id,remoteRun.stage,remoteRun.label,remoteComponent.stage_id,remoteRun.state 
+   FROM remoteRun 
+   JOIN remoteComponent USING (remote_id)
+WHERE
+remoteRun.stage = 'stack'
+-- where hook %s
+) AS R
+USING (stage_id)
+WHERE R.remote_id IS NULL
Index: branches/eam_branches/ipp-ops-20130712/ippTools/share/remotetool_definebyquery_warp.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/remotetool_definebyquery_warp.sql	(revision 37068)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/remotetool_definebyquery_warp.sql	(revision 37068)
@@ -0,0 +1,24 @@
+SELECT stage_id FROM
+
+( SELECT warp_id AS stage_id, count(warpSkyCellMap.skycell_id) AS N
+    FROM warpRun
+    LEFT JOIN warpSkyCellMap USING(warp_id)
+WHERE
+warpRun.state = 'new'
+-- where hook %s
+GROUP BY warp_id
+HAVING N != 0
+) AS W
+
+LEFT JOIN
+
+(SELECT remote_id,remoteRun.stage,remoteRun.label,remoteComponent.stage_id,remoteRun.state 
+   FROM remoteRun 
+   JOIN remoteComponent USING (remote_id)
+WHERE
+remoteRun.stage = 'warp'
+-- where hook %s
+) AS R
+USING (stage_id)
+WHERE R.remote_id IS NULL
+
Index: branches/eam_branches/ipp-ops-20130712/ippTools/share/remotetool_dropcomponent.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/remotetool_dropcomponent.sql	(revision 37068)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/remotetool_dropcomponent.sql	(revision 37068)
@@ -0,0 +1,4 @@
+DELETE FROM remoteComponent
+WHERE 
+remote_id = %ld AND
+stage_id  = %ld
Index: branches/eam_branches/ipp-ops-20130712/ippTools/share/remotetool_updatepoll.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/remotetool_updatepoll.sql	(revision 37068)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/remotetool_updatepoll.sql	(revision 37068)
@@ -0,0 +1,3 @@
+UPDATE remoteRun SET last_poll = CURRENT_TIMESTAMP 
+WHERE
+%s
Index: branches/eam_branches/ipp-ops-20130712/ippTools/share/stacktool_addsummary.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/stacktool_addsummary.sql	(revision 37064)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/stacktool_addsummary.sql	(revision 37068)
@@ -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/ipp-ops-20130712/ippTools/share/stacktool_revertsummary.sql
===================================================================
--- branches/eam_branches/ipp-ops-20130712/ippTools/share/stacktool_revertsummary.sql	(revision 37068)
+++ branches/eam_branches/ipp-ops-20130712/ippTools/share/stacktool_revertsummary.sql	(revision 37068)
@@ -0,0 +1,3 @@
+DELETE FROM stackSummary 
+       WHERE 
+       sass_id = %lld
