Index: branches/eam_branches/ipp-20130207/ippTools/share/Makefile.am
===================================================================
--- branches/eam_branches/ipp-20130207/ippTools/share/Makefile.am	(revision 35125)
+++ branches/eam_branches/ipp-20130207/ippTools/share/Makefile.am	(revision 35236)
@@ -155,4 +155,5 @@
 	difftool_completed_runs.sql \
 	difftool_coalesce_run.sql \
+	difftool_definewarpstack.sql \
 	difftool_definewarpstack_part1.sql \
 	difftool_definewarpstack_part2.sql \
@@ -463,6 +464,14 @@
 	sctool_list.sql \
 	releasetool_listsurvey.sql \
+	releasetool_tocalibexp.sql \
 	releasetool_listrelease.sql \
 	releasetool_listrelexp.sql \
-	releasetool_definerelexp.sql
+	releasetool_definerelexp.sql \
+	releasetool_definerelstack.sql \
+	releasetool_definerelstack_with_skycal.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
 
Index: branches/eam_branches/ipp-20130207/ippTools/share/bgtool_chip.sql
===================================================================
--- branches/eam_branches/ipp-20130207/ippTools/share/bgtool_chip.sql	(revision 35125)
+++ branches/eam_branches/ipp-20130207/ippTools/share/bgtool_chip.sql	(revision 35236)
@@ -5,4 +5,6 @@
     chipBackgroundRun.label,
     chipBackgroundRun.data_group,
+    chipBackgroundRun.chip_id,
+    chipBackgroundRun.cam_id,
     rawExp.exp_id,
     rawExp.exp_name,
@@ -12,6 +14,5 @@
     rawExp.ra,
     rawExp.decl,
-    rawExp.exp_time,
-    chipRun.chip_id
+    rawExp.exp_time
 FROM chipBackgroundRun
 JOIN chipBackgroundImfile USING(chip_bg_id)
Index: branches/eam_branches/ipp-20130207/ippTools/share/bgtool_chipinputs.sql
===================================================================
--- branches/eam_branches/ipp-20130207/ippTools/share/bgtool_chipinputs.sql	(revision 35125)
+++ branches/eam_branches/ipp-20130207/ippTools/share/bgtool_chipinputs.sql	(revision 35236)
@@ -1,7 +1,9 @@
 SELECT
-    chipProcessedImfile.*
+    chipProcessedImfile.*,
+    camProcessedExp.path_base AS cam_path_base
 FROM chipBackgroundRun
 JOIN chipRun USING(chip_id)
 JOIN chipProcessedImfile USING(chip_id)
+LEFT JOIN camProcessedExp ON chipBackgroundRun.cam_id = camProcessedExp.cam_id
 WHERE chipRun.state = 'full'
     AND chipProcessedImfile.fault = 0
Index: branches/eam_branches/ipp-20130207/ippTools/share/bgtool_definechip.sql
===================================================================
--- branches/eam_branches/ipp-20130207/ippTools/share/bgtool_definechip.sql	(revision 35125)
+++ branches/eam_branches/ipp-20130207/ippTools/share/bgtool_definechip.sql	(revision 35236)
@@ -1,6 +1,12 @@
 SELECT
-    chipRun.*
+    chipRun.*,
+    camRun.cam_id,
+    chip_bg_id,
+    CURRENT_TIMESTAMP AS registered
 FROM chipRun
 JOIN rawExp USING(exp_id)
-LEFT JOIN chipBackgroundRun USING(chip_id)
-WHERE chipRun.state = 'full'
+JOIN chipRun as altChipRun USING(exp_id)
+JOIN camRun ON altChipRun.chip_id = camRun.chip_id
+JOIN camProcessedExp USING(cam_id)
+LEFT JOIN chipBackgroundRun ON chipBackgroundRun.chip_id = chipRun.chip_id -- labelHook %s
+WHERE chipRun.state = 'full' AND camRun.state ='full' AND camProcessedExp.quality = 0
Index: branches/eam_branches/ipp-20130207/ippTools/share/bgtool_definewarp.sql
===================================================================
--- branches/eam_branches/ipp-20130207/ippTools/share/bgtool_definewarp.sql	(revision 35125)
+++ branches/eam_branches/ipp-20130207/ippTools/share/bgtool_definewarp.sql	(revision 35236)
@@ -1,12 +1,19 @@
 SELECT
-    warpRun.*,
-    chipBackgroundRun.chip_bg_id
+    warpRun.warp_id,
+    chipBackgroundRun.*
+    -- the following items are selected for aid in debugging
+    ,
+    warpsChipRun.chip_id as warpschip_id,
+    chipRun.chip_id AS thischip_id,
+    warpBackgroundRun.warp_bg_id
 FROM warpRun
 JOIN fakeRun USING(fake_id)
 JOIN camRun USING(cam_id)
-JOIN chipRun USING(chip_id)
-JOIN chipBackgroundRun USING(chip_id)
+JOIN chipRun as warpsChipRun ON camRun.chip_id = warpsChipRun.chip_id
 JOIN rawExp USING(exp_id)
-LEFT JOIN warpBackgroundRun USING(chip_bg_id)
+JOIN chipRun USING(exp_id)
+JOIN chipBackgroundRun ON chipRun.chip_id = chipBackgroundRun.chip_id 
+    AND (chipBackgroundRun.cam_id = camRun.cam_id OR chipBackgroundRun.cam_id = 0)
+LEFT JOIN warpBackgroundRun ON chipBackgroundRun.chip_bg_id = warpBackgroundRun.warp_bg_id -- label hook %s
 WHERE chipBackgroundRun.state = 'full'
-    AND warpRun.state IN ('full', 'cleaned', 'goto_cleaned') -- only need it to have been completed
+    AND warpRun.state IN ('full', 'cleaned', 'goto_cleaned') -- need warp to have completed so warpSkyCellMap is populated
Index: branches/eam_branches/ipp-20130207/ippTools/share/bgtool_tochip.sql
===================================================================
--- branches/eam_branches/ipp-20130207/ippTools/share/bgtool_tochip.sql	(revision 35125)
+++ branches/eam_branches/ipp-20130207/ippTools/share/bgtool_tochip.sql	(revision 35236)
@@ -16,3 +16,3 @@
     AND (Label.active OR Label.active IS NULL)
 -- WHERE hook %s
-ORDER BY priority DESC, chip_bg_id
+ORDER BY priority DESC, chip_bg_id, class_id
Index: branches/eam_branches/ipp-20130207/ippTools/share/bgtool_towarp.sql
===================================================================
--- branches/eam_branches/ipp-20130207/ippTools/share/bgtool_towarp.sql	(revision 35125)
+++ branches/eam_branches/ipp-20130207/ippTools/share/bgtool_towarp.sql	(revision 35236)
@@ -24,3 +24,3 @@
     AND (Label.active OR Label.active IS NULL)
 -- WHERE hook %s
-ORDER BY priority DESC, chip_bg_id
+ORDER BY priority DESC, warp_bg_id, skycell_id
Index: branches/eam_branches/ipp-20130207/ippTools/share/bgtool_warp.sql
===================================================================
--- branches/eam_branches/ipp-20130207/ippTools/share/bgtool_warp.sql	(revision 35125)
+++ branches/eam_branches/ipp-20130207/ippTools/share/bgtool_warp.sql	(revision 35236)
@@ -2,6 +2,10 @@
     warpBackgroundSkyfile.*,
     warpBackgroundRun.state,
+    warpBackgroundRun.warp_id,
+    camRun.cam_id,
+    warpBackgroundRun.chip_bg_id,
     warpBackgroundRun.workdir,
     warpBackgroundRun.label,
+    warpRun.label as warp_label,
     rawExp.exp_id,
     rawExp.exp_name,
Index: branches/eam_branches/ipp-20130207/ippTools/share/bgtool_warpinputs.sql
===================================================================
--- branches/eam_branches/ipp-20130207/ippTools/share/bgtool_warpinputs.sql	(revision 35125)
+++ branches/eam_branches/ipp-20130207/ippTools/share/bgtool_warpinputs.sql	(revision 35236)
@@ -11,5 +11,5 @@
 JOIN chipBackgroundImfile USING(chip_bg_id, class_id)
 JOIN fakeRun USING(fake_id)
-JOIN camProcessedExp USING(cam_id)
+JOIN camProcessedExp ON camProcessedExp.cam_id = fakeRun.cam_id
 WHERE warpRun.state IN ('full', 'cleaned', 'goto_cleaned') -- only need it to have been completed
     AND warpSkyfile.fault = 0
Index: branches/eam_branches/ipp-20130207/ippTools/share/difftool_definewarpstack.sql
===================================================================
--- branches/eam_branches/ipp-20130207/ippTools/share/difftool_definewarpstack.sql	(revision 35125)
+++ branches/eam_branches/ipp-20130207/ippTools/share/difftool_definewarpstack.sql	(revision 35236)
@@ -1,58 +1,42 @@
--- Get list of warps that can be diffed, with any associated diff,
--- and the best stack to use as a template
--- Warps without an existing diff can be identified by a NULL diff_id
+-- Get list of warp-stack pairs that can be diffed
+-- and check results against existing diffs
 SELECT
-    warpsToDiff.warp_id,
-    warpsToDiff.skycell_id,
-    warpsToDiff.tess_id,
-    warpsToDiff.filter,
-    warpsToDiff.good_frac,
-    warpsToDiff.diff_id,
-    current_stack_id,
-    best_stack_id,
-    exp_id
-FROM (
-    -- Get list of warps that can be diffed, with any associated diff
-    SELECT
-        warpSkyfile.warp_id,
-        warpSkyfile.skycell_id,
-        warpSkyfile.tess_id,
-        warpSkyfile.good_frac,
-        warpRun.label,
-        filter,
-        warpRun.label as warp_label,
-        diffInputs.diff_id,
-        diffInputs.stack2 AS current_stack_id,
-        rawExp.exp_id
-    FROM warpSkyfile
-    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)
-    -- Check if it has an associated diff
-    LEFT JOIN diffInputSkyfile AS diffInputs
-        ON diffInputs.warp1 = warpSkyfile.warp_id
-        AND diffInputs.skycell_id = warpSkyfile.skycell_id
-        AND diffInputs.stack2 IS NOT NULL
-    WHERE
-        warpSkyfile.fault = 0
-        AND warpSkyfile.quality = 0
-    -- warpsToDiff WHERE hook %s
-    ) AS warpsToDiff
--- Get best stack as a function of skycell_id, filter
-JOIN (
-    SELECT
-        MAX(stack_id) AS best_stack_id, -- most recent stack, by virtue of auto-increment
-        skycell_id,
-        filter
-    FROM stackRun
-    JOIN stackSumSkyfile USING(stack_id)
-    WHERE stackRun.state = 'full'
-        AND stackSumSkyfile.fault = 0
-        AND stackSumSkyfile.quality = 0
-    -- stacksForDiff WHERE hook %s
-    GROUP BY
-        skycell_id,
-        filter
-    ) AS stacksForDiff USING(skycell_id, filter)
+   exp_id,
+   warp_id,
+   rawExp.filter,
+   warpRun.label AS warpLabel,
+   warpRun.data_group AS warpDataGroup,
+   warpRun.tess_id,
+   warpSkyfile.skycell_id,
+   MAX(stack_id) AS stack_id,
+   stackRun.label AS stackLabel,
+   stackRun.data_group AS stackDataGroup,
+   diff_id,
+   diffRun.label AS diffLabel
+FROM warpRun
+     JOIN fakeRun USING(fake_id)
+     JOIN camRun USING(cam_id)
+     JOIN chipRun USING(chip_id)
+     JOIN rawExp USING(exp_id)
+     JOIN warpSkyfile USING(warp_id)
+     JOIN stackRun ON 
+       (stackRun.skycell_id = warpSkyfile.skycell_id AND
+        stackRun.filter     = rawExp.filter AND
+	stackRun.tess_id    = warpRun.tess_id)
+     JOIN stackSumSkyfile USING(stack_id)
+     LEFT JOIN diffInputSkyfile ON 
+       (warp_id = diffInputSkyfile.warp1 AND
+        stack_id = diffInputSkyfile.stack2 AND
+	diffInputSkyfile.skycell_id = stackRun.skycell_id AND
+	diffInputSkyfile.tess_id = stackRun.tess_id)
+     LEFT JOIN diffRun USING(diff_id)
+WHERE 
+     warpRun.state = 'full'
+     AND stackRun.state = 'full'
+     AND warpSkyfile.fault = 0
+     AND warpSkyfile.quality = 0
+     AND stackSumSkyfile.fault = 0
+     AND stackSumSkyfile.quality = 0
+     AND exp_id IS NOT NULL
+-- %s
+GROUP BY exp_id,warp_id,skycell_id
Index: branches/eam_branches/ipp-20130207/ippTools/share/pxadmin_create_tables.sql
===================================================================
--- branches/eam_branches/ipp-20130207/ippTools/share/pxadmin_create_tables.sql	(revision 35125)
+++ branches/eam_branches/ipp-20130207/ippTools/share/pxadmin_create_tables.sql	(revision 35236)
@@ -521,4 +521,5 @@
     deteff_uq FLOAT,
     quality SMALLINT NOT NULL DEFAULT 0,
+    background_model SMALLINT,
     PRIMARY KEY(cam_id),
     KEY(fault),
@@ -1791,4 +1792,5 @@
     chip_bg_id BIGINT AUTO_INCREMENT, -- unique identifier
     chip_id BIGINT NOT NULL,          -- link to chipRun
+    cam_id BIGINT DEFAULT 0,          -- optional link to camRun
     state VARCHAR(64) NOT NULL,       -- state of run (new, full, etc.)
     workdir VARCHAR(255) NOT NULL,    -- working directory
@@ -1843,5 +1845,5 @@
     data_group VARCHAR(64),           -- group for data
     dist_group VARCHAR(64),           -- group for distribution
-    reduction VARCHAR(64),    -- reduction class (for altering recipe)
+    reduction VARCHAR(64),            -- reduction class (for altering recipe)
     note VARCHAR(255),        -- note
     registered TIMESTAMP DEFAULT CURRENT_TIMESTAMP, -- time run was registered
@@ -2122,4 +2124,6 @@
       zpt_obs FLOAT,
       zpt_stdev FLOAT,
+      fwhm_major  FLOAT,
+      fwhm_minor  FLOAT,
       quality SMALLINT NOT NULL,
       hostname VARCHAR(64) NOT NULL,
@@ -2149,22 +2153,21 @@
 
 CREATE TABLE survey (
-    surveyID    INT(8),
+    surveyID    INT,
     surveyName  VARCHAR(16) NOT NULL,
     description VARCHAR(255),
     PRIMARY KEY(surveyID),
-    UNIQUE  KEY(name)
+    UNIQUE  KEY(surveyName)
 ) ENGINE=InnoDB CHARSET=latin1;
 
-
 CREATE TABLE ippRelease (
-    rel_id      INT(8) AUTO_INCREMENT,
-    surveyID    INT(8),
-    releaseName VARCHAR(64),
-    relase_state VARCHAR(16),   -- active, pending, archive, drop 
-    dataRelease INT(8),         -- PSPS dataRelease
-    priority    INT(8),
+    rel_id      INT AUTO_INCREMENT,
+    surveyID    INT,
+    release_name VARCHAR(64),
+    release_state VARCHAR(16),   -- active, pending, archive, drop 
+    dataRelease INT,         -- PSPS dataRelease
+    priority    INT,
     PRIMARY KEY(rel_id),
-    KEY(releaseName),
-    KEY(state),
+    KEY(release_name),
+    KEY(release_state),
     KEY(priority),
     FOREIGN KEY(surveyID) REFERENCES survey(surveyID)
@@ -2173,14 +2176,16 @@
 CREATE TABLE relExp (
     relexp_id   BIGINT AUTO_INCREMENT,
-    rel_id      INT(8),
+    rel_id      INT,
     exp_id      BIGINT,
     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
     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
     path_base   VARCHAR(255),   -- path_base of any supporting files for this
                                 -- release of this exposure.
+    fault SMALLINT NOT NULL,
     registered  DATETIME,       -- insertion time for this row
     time_stamp  DATETIME,       -- time of last update for this row
@@ -2188,4 +2193,5 @@
     FOREIGN KEY(rel_id) REFERENCES ippRelease(rel_id),
     KEY (state),
+    KEY (fault),
     FOREIGN KEY(exp_id) REFERENCES rawExp(exp_id),
     FOREIGN KEY(chip_id) REFERENCES chipRun(chip_id),
@@ -2195,9 +2201,11 @@
 CREATE TABLE relStack (
     relstack_id BIGINT AUTO_INCREMENT,
-    rel_id      INT(8),
+    rel_id      INT,
+    stack_id    BIGINT,         -- id of the stackRun
     skycal_id   BIGINT,         -- id of the sky calibration run that supplied the calibration
-                                -- for this release. We get back to stack from here
-    skycell_id  varchar(64),
-    tess_id     varchar(64),
+                                -- for this release of this skycell.
+    skycell_id  VARCHAR(64),
+    tess_id     VARCHAR(64),
+    filter      VARCHAR(16),
     state       VARCHAR(16),    -- released, pending, archive, drop  
     flags       INT UNSIGNED,
@@ -2205,13 +2213,51 @@
     zpt_obs     FLOAT,          -- calibrated zero point for this release of this skycell
     zpt_stdev   FLOAT,
-    fwhm_major  FLOAT,          -- seeing as measured by staticsky
+    mjd_obs     INT UNSIGNED,   -- for nightly stacks the mjd_obs, zero for deep and reference
     path_base   VARCHAR(255),   -- path_base of any supporting files,
+    fault SMALLINT NOT NULL,
     registered  DATETIME,
     time_stamp  DATETIME,
     PRIMARY KEY (relstack_id),
     KEY (tess_id, skycell_id),
-    KEY (rel_id, tess_id, skycell_id),
+    KEY (rel_id, tess_id, skycell_id, filter, mjd_obs),
+    KEY (stack_type),
+    KEY (mjd_obs),
+    KEY (state),
+    KEY (fault),
     FOREIGN KEY(rel_id) REFERENCES ippRelease(rel_id),
-    FOREIGN KEY(skycal_id) REFERENCES skycalRun(skycal_id)
+    FOREIGN KEY(stack_id) REFERENCES stackRun(stack_id)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
+
+CREATE TABLE relGroup (
+    group_id    INT AUTO_INCREMENT,
+    rel_id      INT,
+    group_type  VARCHAR(16),
+    lap_id      BIGINT,
+    group_name  VARCHAR(16),
+    state       VARCHAR(16),    -- new full
+    label       VARCHAR(64),
+    exp_list_path   VARCHAR(255),
+    fault SMALLINT NOT NULL,
+    registered  DATETIME,
+    PRIMARY KEY (group_id),
+    KEY (rel_id, group_name),
+    KEY (group_type),
+    KEY (lap_id),
+    KEY (group_name),
+    KEY (state),
+    KEY (label),
+    KEY (fault),
+    FOREIGN KEY(rel_id) REFERENCES ippRelease(rel_id)
+) ENGINE=innodb DEFAULT CHARSET=latin1;
+
+CREATE TABLE lapGroup  (
+    seq_id  BIGINT,
+    projection_cell VARCHAR(64),
+    state   VARCHAR(16),
+    fault   SMALLINT,
+    PRIMARY KEY(seq_id, projection_cell),
+    KEY(state),
+    KEY(fault),
+    FOREIGN KEY(seq_id) REFERENCES lapSequence(seq_id)
 ) ENGINE=innodb DEFAULT CHARSET=latin1;
 
Index: branches/eam_branches/ipp-20130207/ippTools/share/pxadmin_drop_tables.sql
===================================================================
--- branches/eam_branches/ipp-20130207/ippTools/share/pxadmin_drop_tables.sql	(revision 35125)
+++ branches/eam_branches/ipp-20130207/ippTools/share/pxadmin_drop_tables.sql	(revision 35236)
@@ -109,7 +109,10 @@
 DROP TABLE IF EXISTS skycalResult;
 DROP TABLE IF EXISTS skycell;
+DROP TABLE IF EXISTS relStack;
 DROP TABLE IF EXISTS relExp;
+DROP TABLE IF EXISTS relGroup;
 DROP TABLE IF EXISTS ippRelease;
 DROP TABLE IF EXISTS survey;
+DROP TABLE IF EXISTS lapGroup;
 
 SET FOREIGN_KEY_CHECKS=1
Index: branches/eam_branches/ipp-20130207/ippTools/share/releasetool_definerelexp.sql
===================================================================
--- branches/eam_branches/ipp-20130207/ippTools/share/releasetool_definerelexp.sql	(revision 35125)
+++ branches/eam_branches/ipp-20130207/ippTools/share/releasetool_definerelexp.sql	(revision 35236)
@@ -1,5 +1,5 @@
 SELECT
     ippRelease.rel_id,
-    ippRelease.releaseName,
+    ippRelease.release_name,
     rawExp.exp_name,
     rawExp.filter,
Index: branches/eam_branches/ipp-20130207/ippTools/share/releasetool_definerelgroup_select_data_group.sql
===================================================================
--- branches/eam_branches/ipp-20130207/ippTools/share/releasetool_definerelgroup_select_data_group.sql	(revision 35236)
+++ branches/eam_branches/ipp-20130207/ippTools/share/releasetool_definerelgroup_select_data_group.sql	(revision 35236)
@@ -0,0 +1,9 @@
+SELECT
+    ippRelease.rel_id,
+    count(exp_id) AS num_exposures
+FROM ippRelease
+    LEFT JOIN relExp using(rel_id)
+    LEFT JOIN camRun using(cam_id)
+    WHERE relExp.group_id = 0
+    AND relExp.state != 'drop'
+
Index: branches/eam_branches/ipp-20130207/ippTools/share/releasetool_definerelgroup_select_exp_data_group.sql
===================================================================
--- branches/eam_branches/ipp-20130207/ippTools/share/releasetool_definerelgroup_select_exp_data_group.sql	(revision 35236)
+++ branches/eam_branches/ipp-20130207/ippTools/share/releasetool_definerelgroup_select_exp_data_group.sql	(revision 35236)
@@ -0,0 +1,6 @@
+SELECT relExp.relexp_id
+FROM relExp
+    JOIN camRun USING(cam_id)
+WHERE 
+    relExp.group_id = 0
+    AND relExp.state != 'drop'
Index: branches/eam_branches/ipp-20130207/ippTools/share/releasetool_definerelgroup_select_exp_lap.sql
===================================================================
--- branches/eam_branches/ipp-20130207/ippTools/share/releasetool_definerelgroup_select_exp_lap.sql	(revision 35236)
+++ branches/eam_branches/ipp-20130207/ippTools/share/releasetool_definerelgroup_select_exp_lap.sql	(revision 35236)
@@ -0,0 +1,4 @@
+SELECT relExp.relexp_id
+FROM relGroup JOIN lapRun USING(lap_id)
+    JOIN relExp using(rel_id, exp_id)
+WHERE relExp.group_id = 0
Index: branches/eam_branches/ipp-20130207/ippTools/share/releasetool_definerelgroup_select_lap.sql
===================================================================
--- branches/eam_branches/ipp-20130207/ippTools/share/releasetool_definerelgroup_select_lap.sql	(revision 35236)
+++ branches/eam_branches/ipp-20130207/ippTools/share/releasetool_definerelgroup_select_lap.sql	(revision 35236)
@@ -0,0 +1,11 @@
+SELECT 
+    lapRun.seq_id,
+    lapRun.lap_id,
+    ippRelease.rel_id
+FROM lapRun
+    JOIN ippRelease
+    LEFT JOIN relGroup USING(lap_id)
+WHERE (lapRun.state = 'done' or lapRun.state = 'full')
+    AND relGroup.group_id IS NULL
+-- AND lapRun.seq_id = xxx
+
Index: branches/eam_branches/ipp-20130207/ippTools/share/releasetool_definerelstack.sql
===================================================================
--- branches/eam_branches/ipp-20130207/ippTools/share/releasetool_definerelstack.sql	(revision 35236)
+++ branches/eam_branches/ipp-20130207/ippTools/share/releasetool_definerelstack.sql	(revision 35236)
@@ -0,0 +1,16 @@
+SELECT
+    ippRelease.rel_id,
+    stackRun.stack_id,
+    0 as skycal_id,
+    stackRun.skycell_id,
+    stackRun.tess_id,
+    stackRun.filter,
+    0 AS mjd_obs,
+    0 AS zpt_obs,
+    0 AS zpt_stdev
+
+FROM ippRelease
+JOIN stackRun
+LEFT JOIN relStack AS previousRelStack USING(rel_id, tess_id, skycell_id, filter)
+
+WHERE previousRelStack.relstack_id IS NULL
Index: branches/eam_branches/ipp-20130207/ippTools/share/releasetool_definerelstack_with_skycal.sql
===================================================================
--- branches/eam_branches/ipp-20130207/ippTools/share/releasetool_definerelstack_with_skycal.sql	(revision 35236)
+++ branches/eam_branches/ipp-20130207/ippTools/share/releasetool_definerelstack_with_skycal.sql	(revision 35236)
@@ -0,0 +1,19 @@
+SELECT
+    ippRelease.rel_id,
+    stackRun.stack_id,
+    IFNULL(skycalRun.skycal_id, 0) as skycal_id,
+    stackRun.skycell_id,
+    stackRun.tess_id,
+    stackRun.filter,
+    stackSumSkyfile.mjd_obs,
+    skycalResult.zpt_obs,
+    skycalResult.zpt_stdev
+
+FROM ippRelease
+JOIN stackRun
+JOIN stackSumSkyfile USING(stack_id)
+LEFT JOIN relStack AS previousRelStack USING(rel_id, tess_id, skycell_id, filter)
+JOIN skycalRun ON skycalRun.stack_id = stackRun.stack_id
+JOIN skycalResult ON skycalRun.skycal_id = skycalResult.skycal_id
+
+WHERE previousRelStack.relstack_id IS NULL
Index: branches/eam_branches/ipp-20130207/ippTools/share/releasetool_listrelexp.sql
===================================================================
--- branches/eam_branches/ipp-20130207/ippTools/share/releasetool_listrelexp.sql	(revision 35125)
+++ branches/eam_branches/ipp-20130207/ippTools/share/releasetool_listrelexp.sql	(revision 35236)
@@ -2,5 +2,6 @@
     relexp_id,
     relExp.state,
-    ippRelease.releaseName,
+    relExp.fault,
+    ippRelease.release_name,
     ippRelease.release_state,
     ippRelease.rel_id,
@@ -21,4 +22,5 @@
     camProcessedExp.path_base as cam_path_base,
     camProcessedExp.fwhm_major,
+    camProcessedExp.fwhm_minor,
     warpRun.warp_id,
     warpRun.state as warp_state,
Index: branches/eam_branches/ipp-20130207/ippTools/share/releasetool_pendingrelgroup.sql
===================================================================
--- branches/eam_branches/ipp-20130207/ippTools/share/releasetool_pendingrelgroup.sql	(revision 35236)
+++ branches/eam_branches/ipp-20130207/ippTools/share/releasetool_pendingrelgroup.sql	(revision 35236)
@@ -0,0 +1,4 @@
+SELECT relGroup.*
+FROM relGroup
+    JOIN ippRelease USING(rel_id)
+WHERE relGroup.state = 'new'
Index: branches/eam_branches/ipp-20130207/ippTools/share/releasetool_tocalibexp.sql
===================================================================
--- branches/eam_branches/ipp-20130207/ippTools/share/releasetool_tocalibexp.sql	(revision 35236)
+++ branches/eam_branches/ipp-20130207/ippTools/share/releasetool_tocalibexp.sql	(revision 35236)
@@ -0,0 +1,5 @@
+SELECT relExp.*,
+ippRelease.release_name,
+ippRelease.release_state
+FROM relExp JOIN ippRelease USING(rel_id)
+WHERE relExp.state = 'goto_calib' AND relExp.fault = 0
Index: branches/eam_branches/ipp-20130207/ippTools/share/reltool_pendinggroup.sql
===================================================================
--- branches/eam_branches/ipp-20130207/ippTools/share/reltool_pendinggroup.sql	(revision 35236)
+++ branches/eam_branches/ipp-20130207/ippTools/share/reltool_pendinggroup.sql	(revision 35236)
@@ -0,0 +1,8 @@
+-- relGroups to process
+SELECT relGroup.*,
+    ippRelease.release_id,
+    ippRelease.release_name
+FROM relGroup 
+    JOIN ippRelease USING(rel_id)
+WHERE relGroup.state ='new'
+    AND relGroup.fault = 0
Index: branches/eam_branches/ipp-20130207/ippTools/share/warptool_scmap.sql
===================================================================
--- branches/eam_branches/ipp-20130207/ippTools/share/warptool_scmap.sql	(revision 35125)
+++ branches/eam_branches/ipp-20130207/ippTools/share/warptool_scmap.sql	(revision 35236)
@@ -5,4 +5,5 @@
     camProcessedExp.path_base as cam_path_base,
     camProcessedExp.fault as cam_fault,
+    camProcessedExp.background_model AS cam_background_model,
     chipProcessedImfile.chip_id,
     chipRun.state,
