Index: branches/czw_branch/20101203/ippTools/share/Makefile.am
===================================================================
--- branches/czw_branch/20101203/ippTools/share/Makefile.am	(revision 30118)
+++ branches/czw_branch/20101203/ippTools/share/Makefile.am	(revision 30586)
@@ -246,4 +246,6 @@
 	magictool_exposure.sql \
 	magictool_setfull.sql \
+	magictool_setgotocleaned.sql \
+	magictool_tocleanup.sql \
 	magicdstool_clearstatefaults.sql \
 	magicdstool_change_file_data_state.sql \
@@ -333,4 +335,5 @@
 	regtool_updatebyqueryimfile.sql \
 	regtool_pendingburntoolimfile.sql \
+	regtool_checkstatus.sql \
 	stacktool_associationdefine_select.sql \
 	stacktool_definebyquery_insert.sql \
Index: branches/czw_branch/20101203/ippTools/share/disttool_pending_SSdiff.sql
===================================================================
--- branches/czw_branch/20101203/ippTools/share/disttool_pending_SSdiff.sql	(revision 30118)
+++ branches/czw_branch/20101203/ippTools/share/disttool_pending_SSdiff.sql	(revision 30586)
@@ -17,5 +17,6 @@
     diffSkyfile.quality,
     distRun.no_magic,
-    0 AS magicked
+    0 AS magicked,
+    IFNULL(Label.priority, 10000) AS priority
 FROM distRun
 JOIN distTarget USING(target_id, stage, clean)
@@ -42,4 +43,5 @@
     ON distRun.dist_id = distComponent.dist_id 
     AND diffSkyfile.skycell_id = distComponent.component
+LEFT JOIN Label ON distRun.label = Label.label
 WHERE
     distRun.state = 'new'
@@ -48,2 +50,3 @@
     AND ((diffRun.magicked > 0) OR distRun.no_magic)
     AND (diffRun.state = 'full' OR (distRun.clean AND diffRun.state = 'cleaned'))
+    AND (Label.active OR Label.active IS NULL)
Index: branches/czw_branch/20101203/ippTools/share/disttool_pending_camera.sql
===================================================================
--- branches/czw_branch/20101203/ippTools/share/disttool_pending_camera.sql	(revision 30118)
+++ branches/czw_branch/20101203/ippTools/share/disttool_pending_camera.sql	(revision 30586)
@@ -15,5 +15,6 @@
     camProcessedExp.quality,
     distRun.no_magic,
-    chipRun.magicked
+    chipRun.magicked,
+    IFNULL(Label.priority, 10000) AS priority
 FROM distRun
 JOIN distTarget USING(target_id, stage, clean)
@@ -21,13 +22,14 @@
 JOIN camProcessedExp USING(cam_id)
 JOIN chipRun USING(chip_id)
--- JOIN chipProcessedImfile USING(exp_id, chip_id)
 JOIN rawExp using(exp_id)
 LEFT JOIN distComponent 
     ON distRun.dist_id = distComponent.dist_id 
---    AND chipProcessedImfile.class_id = distComponent.component
+LEFT JOIN Label
+    ON distRun.label = Label.label
 WHERE
     distRun.state = 'new'
     AND distRun.stage = 'camera'
     AND distComponent.dist_id IS NULL
-    AND (((clean OR (chipRun.magicked > 0)) AND (camRun.magicked > 0)) OR distRun.no_magic)
+    AND (((clean OR (chipRun.magicked != 0)) AND (camRun.magicked > 0)) OR distRun.no_magic)
     AND (camRun.state = 'full' OR (distRun.clean AND camRun.state = 'cleaned'))
+    AND (Label.active OR Label.active IS NULL)
Index: branches/czw_branch/20101203/ippTools/share/disttool_pending_chip.sql
===================================================================
--- branches/czw_branch/20101203/ippTools/share/disttool_pending_chip.sql	(revision 30118)
+++ branches/czw_branch/20101203/ippTools/share/disttool_pending_chip.sql	(revision 30586)
@@ -15,5 +15,6 @@
     chipProcessedImfile.quality,
     distRun.no_magic,
-    chipProcessedImfile.magicked
+    chipProcessedImfile.magicked,
+    IFNULL(Label.priority, 10000) AS priority
 FROM distRun
 JOIN distTarget USING(target_id, stage, clean)
@@ -24,4 +25,6 @@
     ON distRun.dist_id = distComponent.dist_id 
     AND chipProcessedImfile.class_id = distComponent.component
+LEFT JOIN Label
+    ON distRun.label = Label.label
 WHERE
     distRun.state = 'new'
@@ -30,2 +33,3 @@
     AND ((chipRun.magicked > 0) OR distRun.no_magic)
     AND (chipRun.state = 'full' OR (distRun.clean AND chipRun.state = 'cleaned'))
+    AND (Label.active OR Label.active IS NULL)
Index: branches/czw_branch/20101203/ippTools/share/disttool_pending_chip_bg.sql
===================================================================
--- branches/czw_branch/20101203/ippTools/share/disttool_pending_chip_bg.sql	(revision 30118)
+++ branches/czw_branch/20101203/ippTools/share/disttool_pending_chip_bg.sql	(revision 30586)
@@ -15,5 +15,6 @@
     0 AS quality,
     distRun.no_magic,
-    chipBackgroundImfile.magicked
+    chipBackgroundImfile.magicked,
+    IFNULL(Label.priority, 10000) AS priority
 FROM distRun
 JOIN distTarget USING(target_id, stage, clean)
@@ -25,4 +26,5 @@
     ON distRun.dist_id = distComponent.dist_id 
     AND chipBackgroundImfile.class_id = distComponent.component
+LEFT JOIN Label ON distRun.label = Label.label
 WHERE
     distRun.state = 'new'
@@ -31,2 +33,3 @@
     AND ((chipBackgroundRun.magicked > 0) OR distRun.no_magic)
     AND (chipBackgroundRun.state = 'full')
+    AND (Label.active OR Label.active IS NULL)
Index: branches/czw_branch/20101203/ippTools/share/disttool_pending_diff.sql
===================================================================
--- branches/czw_branch/20101203/ippTools/share/disttool_pending_diff.sql	(revision 30118)
+++ branches/czw_branch/20101203/ippTools/share/disttool_pending_diff.sql	(revision 30586)
@@ -17,5 +17,6 @@
     diffSkyfile.quality,
     distRun.no_magic,
-    diffSkyfile.magicked
+    diffSkyfile.magicked,
+    IFNULL(Label.priority, 10000) AS priority
 FROM distRun
 JOIN distTarget USING(target_id, stage, clean)
@@ -32,4 +33,5 @@
     ON distRun.dist_id = distComponent.dist_id 
     AND diffSkyfile.skycell_id = distComponent.component
+LEFT JOIN Label ON distRun.label = Label.label
 WHERE
     distRun.state = 'new'
@@ -38,2 +40,3 @@
     AND ((diffRun.magicked > 0) OR distRun.no_magic)
     AND (diffRun.state = 'full' OR (distRun.clean AND diffRun.state = 'cleaned'))
+    AND (Label.active OR Label.active IS NULL)
Index: branches/czw_branch/20101203/ippTools/share/disttool_pending_fake.sql
===================================================================
--- branches/czw_branch/20101203/ippTools/share/disttool_pending_fake.sql	(revision 30118)
+++ branches/czw_branch/20101203/ippTools/share/disttool_pending_fake.sql	(revision 30586)
@@ -15,5 +15,6 @@
     0 as quality,
     distRun.no_magic,
-    0 as magicked
+    0 as magicked,
+    IFNULL(Label.priority, 10000) AS priority
 FROM distRun
 JOIN distTarget USING(target_id, stage, clean)
@@ -26,6 +27,8 @@
     ON distRun.dist_id = distComponent.dist_id 
     AND fakeProcessedImfile.class_id = distComponent.component
+LEFT JOIN Label ON distRun.label = Label.label
 WHERE
     distRun.state = 'new'
     AND distRun.stage = 'fake'
     AND distComponent.dist_id IS NULL
+    AND (Label.active OR Label.active IS NULL)
Index: branches/czw_branch/20101203/ippTools/share/disttool_pending_raw.sql
===================================================================
--- branches/czw_branch/20101203/ippTools/share/disttool_pending_raw.sql	(revision 30118)
+++ branches/czw_branch/20101203/ippTools/share/disttool_pending_raw.sql	(revision 30586)
@@ -17,5 +17,6 @@
     0 as quality,
     distRun.no_magic,
-    rawImfile.magicked
+    rawImfile.magicked,
+    IFNULL(Label.priority, 10000) AS priority
 FROM distRun
 JOIN distTarget USING(target_id, stage, clean)
@@ -28,4 +29,5 @@
     ON distRun.dist_id = distComponent.dist_id 
     AND rawImfile.class_id = distComponent.component
+LEFT JOIN Label ON distRun.label = Label.label
 WHERE
     distRun.state = 'new'
@@ -34,4 +36,5 @@
     AND distComponent.dist_id IS NULL
     AND (rawExp.magicked OR distRun.no_magic)
+    AND (Label.active OR Label.active IS NULL)
 UNION
     -- raw stage alternate inputs
@@ -54,5 +57,6 @@
     0 as quality,
     distRun.no_magic,
-    rawImfile.magicked
+    rawImfile.magicked,
+    IFNULL(Label.priority, 10000) AS priority
 FROM distRun
 JOIN distTarget USING(target_id, stage, clean)
@@ -68,4 +72,5 @@
     ON distRun.dist_id = distComponent.dist_id 
     AND rawImfile.class_id = distComponent.component
+LEFT JOIN Label ON distRun.label = Label.label
 WHERE
     distRun.state = 'new'
@@ -74,4 +79,5 @@
     AND chipProcessedImfile.data_state = 'full'
     AND chipProcessedImfile.magicked > 0
+    AND (Label.active OR Label.active IS NULL)
 UNION
     -- raw stage clean (dbinfo only)
@@ -93,5 +99,6 @@
     0 as quality,
     distRun.no_magic,
-    rawExp.magicked
+    rawExp.magicked,
+    IFNULL(Label.priority, 10000) AS priority
 FROM distRun
 JOIN distTarget USING(target_id, stage, clean)
@@ -99,4 +106,5 @@
 LEFT JOIN distComponent 
     ON distRun.dist_id = distComponent.dist_id 
+LEFT JOIN Label ON distRun.label = Label.label
 WHERE
     distRun.state = 'new'
@@ -104,2 +112,3 @@
     AND distRun.clean
     AND distComponent.dist_id IS NULL
+    AND (Label.active OR Label.active IS NULL)
Index: branches/czw_branch/20101203/ippTools/share/disttool_pending_sky.sql
===================================================================
--- branches/czw_branch/20101203/ippTools/share/disttool_pending_sky.sql	(revision 30118)
+++ branches/czw_branch/20101203/ippTools/share/disttool_pending_sky.sql	(revision 30586)
@@ -15,5 +15,6 @@
     staticskyResult.quality,
     1 AS no_magic,
-    0 AS magicked
+    0 AS magicked,
+    IFNULL(Label.priority, 10000) AS priority
 FROM distRun
 JOIN distTarget USING(target_id, stage, clean)
@@ -43,4 +44,5 @@
     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'
@@ -49,2 +51,3 @@
     AND (staticskyRun.state = 'full' OR (distRun.clean AND staticskyRun.state = 'cleaned'))
     AND (staticskyResult.fault = 0 AND staticskyResult.quality = 0)
+    AND (Label.active OR Label.active IS NULL)
Index: branches/czw_branch/20101203/ippTools/share/disttool_pending_stack.sql
===================================================================
--- branches/czw_branch/20101203/ippTools/share/disttool_pending_stack.sql	(revision 30118)
+++ branches/czw_branch/20101203/ippTools/share/disttool_pending_stack.sql	(revision 30586)
@@ -17,5 +17,6 @@
     stackSumSkyfile.quality,
     1 AS no_magic,
-    0 AS magicked
+    0 AS magicked,
+    IFNULL(Label.priority, 10000) AS priority
 FROM distRun
 JOIN distTarget USING(target_id, stage, clean)
@@ -43,4 +44,5 @@
     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'
@@ -49,2 +51,3 @@
     AND (stackRun.state = 'full' OR (distRun.clean AND stackRun.state = 'cleaned'))
     AND (stackSumSkyfile.fault = 0 AND stackSumSkyfile.quality = 0)
+    AND (Label.active OR Label.active IS NULL)
Index: branches/czw_branch/20101203/ippTools/share/disttool_pending_warp.sql
===================================================================
--- branches/czw_branch/20101203/ippTools/share/disttool_pending_warp.sql	(revision 30118)
+++ branches/czw_branch/20101203/ippTools/share/disttool_pending_warp.sql	(revision 30586)
@@ -15,5 +15,6 @@
     warpSkyfile.quality,
     distRun.no_magic,
-    warpSkyfile.magicked
+    warpSkyfile.magicked,
+    IFNULL(Label.priority, 10000) AS priority
 FROM distRun
 JOIN distTarget USING(target_id, stage, clean)
@@ -27,4 +28,5 @@
     ON distRun.dist_id = distComponent.dist_id 
     AND warpSkyfile.skycell_id = distComponent.component
+LEFT JOIN Label ON distRun.label = Label.label
 WHERE
     distRun.state = 'new'
@@ -33,2 +35,3 @@
     AND ((warpRun.magicked > 0) OR distRun.no_magic)
     AND (warpRun.state = 'full' OR (distRun.clean AND warpRun.state = 'cleaned'))
+    AND (Label.active OR Label.active IS NULL)
Index: branches/czw_branch/20101203/ippTools/share/disttool_pending_warp_bg.sql
===================================================================
--- branches/czw_branch/20101203/ippTools/share/disttool_pending_warp_bg.sql	(revision 30118)
+++ branches/czw_branch/20101203/ippTools/share/disttool_pending_warp_bg.sql	(revision 30586)
@@ -15,5 +15,6 @@
     0 as quality,
     distRun.no_magic,
-    warpBackgroundSkyfile.magicked
+    warpBackgroundSkyfile.magicked,
+    IFNULL(Label.priority, 10000) AS priority
 FROM distRun
 JOIN distTarget USING(target_id, stage, clean)
@@ -28,4 +29,5 @@
     ON distRun.dist_id = distComponent.dist_id 
     AND warpBackgroundSkyfile.skycell_id = distComponent.component
+LEFT JOIN Label ON distRun.label = Label.label
 WHERE
     distRun.state = 'new'
@@ -34,2 +36,3 @@
     AND ((warpBackgroundRun.magicked > 0) OR distRun.no_magic)
     AND (warpBackgroundRun.state = 'full')
+    AND (Label.active OR Label.active IS NULL)
Index: branches/czw_branch/20101203/ippTools/share/disttool_revertrun.sql
===================================================================
--- branches/czw_branch/20101203/ippTools/share/disttool_revertrun.sql	(revision 30118)
+++ branches/czw_branch/20101203/ippTools/share/disttool_revertrun.sql	(revision 30586)
@@ -1,4 +1,4 @@
 UPDATE distRun
 SET distRun.fault = 0
-WHERE distRun.state = 'new'
+WHERE (distRun.state = 'new' OR distRun.state = 'goto_cleaned')
     AND distRun.fault != 0
Index: branches/czw_branch/20101203/ippTools/share/magicdstool_todestreak_camera.sql
===================================================================
--- branches/czw_branch/20101203/ippTools/share/magicdstool_todestreak_camera.sql	(revision 30118)
+++ branches/czw_branch/20101203/ippTools/share/magicdstool_todestreak_camera.sql	(revision 30586)
@@ -38,6 +38,6 @@
     AND magicDSRun.stage = 'camera'
     AND camRun.state = 'full'
-    AND chipRun.state = 'full'
-    AND chipRun.magicked
+    AND ((chipRun.state = 'full' AND chipRun.magicked > 0) 
+         OR (chipRun.state = 'cleaned' AND chipRun.magicked < 0)) 
     AND camProcessedExp.fault = 0
     AND camProcessedExp.quality = 0
Index: branches/czw_branch/20101203/ippTools/share/magicdstool_torevert_diff.sql
===================================================================
--- branches/czw_branch/20101203/ippTools/share/magicdstool_torevert_diff.sql	(revision 30118)
+++ branches/czw_branch/20101203/ippTools/share/magicdstool_torevert_diff.sql	(revision 30586)
@@ -10,4 +10,6 @@
     outroot,
     diffSkyfile.path_base,
+    magicDSFile.backup_path_base,
+    magicDSFile.recovery_path_base,
     "NULL" AS cam_path_base,
     CAST(diffRun.bothways AS SIGNED) AS bothways,
Index: branches/czw_branch/20101203/ippTools/share/magictool_setgotocleaned.sql
===================================================================
--- branches/czw_branch/20101203/ippTools/share/magictool_setgotocleaned.sql	(revision 30586)
+++ branches/czw_branch/20101203/ippTools/share/magictool_setgotocleaned.sql	(revision 30586)
@@ -0,0 +1,4 @@
+UPDATE magicRun 
+    SET workdir_state = 'goto_cleaned'
+WHERE workdir_state = 'dirty'
+
Index: branches/czw_branch/20101203/ippTools/share/magictool_tocleanup.sql
===================================================================
--- branches/czw_branch/20101203/ippTools/share/magictool_tocleanup.sql	(revision 30586)
+++ branches/czw_branch/20101203/ippTools/share/magictool_tocleanup.sql	(revision 30586)
@@ -0,0 +1,10 @@
+SELECT magic_id,
+    magicRun.exp_id,
+    rawExp.camera,
+    magicRun.workdir,
+    IFNULL(priority, 10000) as priority
+FROM magicRun 
+    JOIN rawExp USING(exp_id)
+    LEFT JOIN Label ON magicRun.label = Label.label
+WHERE magicRun.workdir_state = 'goto_cleaned'
+    AND (Label.active OR Label.active IS NULL)
Index: branches/czw_branch/20101203/ippTools/share/pstamptool_pendingreq.sql
===================================================================
--- branches/czw_branch/20101203/ippTools/share/pstamptool_pendingreq.sql	(revision 30118)
+++ branches/czw_branch/20101203/ippTools/share/pstamptool_pendingreq.sql	(revision 30586)
@@ -3,4 +3,5 @@
     pstampRequest.*,
     pstampDataStore.outProduct AS ds_outProduct,
+    IFNULL(pstampDataStore.need_magic, 1) AS need_magic,
     IFNULL(Label.priority, 10000) AS priority
 FROM pstampRequest
Index: branches/czw_branch/20101203/ippTools/share/pubtool_pending.sql
===================================================================
--- branches/czw_branch/20101203/ippTools/share/pubtool_pending.sql	(revision 30118)
+++ branches/czw_branch/20101203/ippTools/share/pubtool_pending.sql	(revision 30586)
@@ -10,4 +10,5 @@
         publishClient.workdir,
 	publishClient.output_format,
+        publishClient.magicked AS need_magic,
         diffRun.diff_id AS stage_id,
         rawExp.camera,
@@ -37,4 +38,5 @@
         publishClient.workdir,
 	publishClient.output_format,
+        publishClient.magicked AS need_magic,
         camRun.cam_id AS stage_id,
         rawExp.camera,
@@ -59,4 +61,5 @@
         publishClient.workdir,
 	publishClient.output_format,
+        publishClient.magicked AS need_magic,
         diffPhotRun.diff_phot_id AS stage_id,
         rawExp.camera,
Index: branches/czw_branch/20101203/ippTools/share/pxadmin_create_tables.sql
===================================================================
--- branches/czw_branch/20101203/ippTools/share/pxadmin_create_tables.sql	(revision 30118)
+++ branches/czw_branch/20101203/ippTools/share/pxadmin_create_tables.sql	(revision 30586)
@@ -1391,4 +1391,5 @@
         uri VARCHAR(255),
         pollInterval INTEGER DEFAULT 60,
+        need_magic TINYINT,
         PRIMARY KEY(ds_id),
         KEY(ds_id)
Index: branches/czw_branch/20101203/ippTools/share/regtool_checkburntoolimfile.sql
===================================================================
--- branches/czw_branch/20101203/ippTools/share/regtool_checkburntoolimfile.sql	(revision 30118)
+++ branches/czw_branch/20101203/ippTools/share/regtool_checkburntoolimfile.sql	(revision 30586)
@@ -1,4 +1,4 @@
 SELECT DISTINCT
-       exp_name,
+       summitExp.exp_name,
        rawImfile.uri,
        summitExp.dateobs AS registered,
@@ -11,21 +11,24 @@
        newExp.exp_id,
        summitExp.exp_type,
-       rawExp.dateobs,
-       rawExp.obs_mode AS obs_mode,
-       rawExp.object AS object,
+       rawImfile.dateobs,
+       rawImfile.obs_mode AS obs_mode,
+       rawImfile.object AS object,
        rawImfile.burntool_state AS burntool_state,
        rawImfile.class_id,
+       summitImfile.class_id AS summit_class_id,
        (pzDownloadExp.state = 'stop') AS is_downloaded,
        (rawImfile.burntool_state IS NOT NULL) AS is_registered
        FROM
-            summitExp
-            LEFT JOIN pzDownloadExp USING(exp_name)
-            LEFT JOIN newExp ON exp_name = tmp_exp_name
-            LEFT JOIN rawExp USING(exp_id, exp_name)
-            LEFT JOIN rawImfile USING(exp_name)
+       summitExp
+       JOIN summitImfile USING(exp_name)
+       LEFT JOIN pzDownloadExp USING(exp_name)
+       LEFT JOIN newExp ON summitExp.exp_name = tmp_exp_name
+       LEFT JOIN newImfile ON (summitImfile.class_id = newImfile.tmp_class_id AND newExp.exp_id = newImfile.exp_id)
+       LEFT JOIN rawExp ON rawExp.exp_id = newExp.exp_id
+       LEFT JOIN rawImfile ON (rawImfile.exp_id = newExp.exp_id AND rawImfile.tmp_class_id = newImfile.tmp_class_id)
        WHERE
-             summitExp.dateobs >= '@DATE@T00:00:00'
-	     AND summitExp.dateobs <= '@DATE@T23:59:59'
-	     AND (rawImfile.class_id = '@CLASS_ID@' OR rawImfile.class_id IS NULL)
-	     AND (exp_name <= '@EXP_NAME@')                                                                     
+             summitExp.dateobs >= '@DATEOBS_BEGIN@'
+	     AND summitExp.dateobs <= '@DATEOBS_END@'
+	     AND summitImfile.class_id = '@CLASS_ID@'
+	     AND (summitExp.exp_name <= '@EXP_NAME@')                                                                     
 ORDER BY summitExp.dateobs
Index: branches/czw_branch/20101203/ippTools/share/regtool_checkstatus.sql
===================================================================
--- branches/czw_branch/20101203/ippTools/share/regtool_checkstatus.sql	(revision 30586)
+++ branches/czw_branch/20101203/ippTools/share/regtool_checkstatus.sql	(revision 30586)
@@ -0,0 +1,29 @@
+SELECT DISTINCT        
+        summitExp.exp_name,
+        rawImfile.uri,
+        summitExp.dateobs AS registered,
+        summitExp.imfiles,
+        summitExp.fault AS summit_fault,
+        pzDownloadExp.state AS download_state,
+        newExp.state AS newExp_state,
+        rawExp.state AS rawExp_state,
+        rawImfile.data_state AS imfile_state,
+        newExp.exp_id,
+        summitExp.exp_type,
+        rawExp.dateobs,
+        rawExp.obs_mode AS obs_mode,
+        rawExp.object AS object,
+        rawImfile.burntool_state AS burntool_state,
+        rawImfile.class_id,
+        summitImfile.class_id AS summit_class_id,
+        (pzDownloadExp.state = 'stop') AS is_downloaded,
+        (rawImfile.burntool_state IS NOT NULL) AS is_registered
+        FROM        summitExp
+        JOIN summitImfile USING(exp_name)
+        LEFT JOIN pzDownloadExp USING(exp_name)
+        LEFT JOIN newExp ON summitExp.exp_name = tmp_exp_name
+        LEFT JOIN newImfile ON (summitImfile.class_id = newImfile.tmp_class_id AND newExp.exp_id = newImfile.exp_id)
+        LEFT JOIN rawExp ON rawExp.exp_id = newExp.exp_id
+        LEFT JOIN rawImfile ON (rawImfile.exp_id = rawExp.exp_id AND rawImfile.tmp_class_id = newImfile.tmp_class_id)
+        WHERE
+	 summitImfile.class_id = '@CLASS_ID@'
Index: branches/czw_branch/20101203/ippTools/share/regtool_pendingburntoolimfile.sql
===================================================================
--- branches/czw_branch/20101203/ippTools/share/regtool_pendingburntoolimfile.sql	(revision 30118)
+++ branches/czw_branch/20101203/ippTools/share/regtool_pendingburntoolimfile.sql	(revision 30586)
@@ -12,20 +12,22 @@
        newImfile.tmp_class_id,
        summitExp.exp_type,
-       rawExp.dateobs,
-       rawExp.obs_mode AS obs_mode,
-       rawExp.object AS object,
+       rawImfile.dateobs,
+       rawImfile.obs_mode AS obs_mode,
+       rawImfile.object AS object,
        rawImfile.burntool_state AS burntool_state,
        rawImfile.class_id,
+       summitImfile.class_id AS summit_class_id,
        (pzDownloadExp.state = 'stop') AS is_downloaded,
        (rawImfile.burntool_state IS NOT NULL) AS is_registered
        FROM
-            summitExp
-            LEFT JOIN pzDownloadExp USING(exp_name)
-            LEFT JOIN newExp ON exp_name = tmp_exp_name
-	    LEFT JOIN newImfile USING(exp_id)
-            LEFT JOIN rawExp USING(exp_id, exp_name)
-            LEFT JOIN rawImfile ON (rawImfile.exp_name = newExp.tmp_exp_name AND rawImfile.tmp_class_id = newImfile.tmp_class_id)
+       summitExp
+       JOIN summitImfile USING(exp_name)
+       LEFT JOIN pzDownloadExp USING(exp_name)
+       LEFT JOIN newExp ON summitExp.exp_name = tmp_exp_name
+       LEFT JOIN newImfile ON (summitImfile.class_id = newImfile.tmp_class_id AND newExp.exp_id = newImfile.exp_id)
+       LEFT JOIN rawExp ON rawExp.exp_id = newExp.exp_id
+       LEFT JOIN rawImfile ON (rawImfile.exp_id = newExp.exp_id AND rawImfile.tmp_class_id = newImfile.tmp_class_id)
        WHERE
-             summitExp.dateobs >= '@DATE@T00:00:00'
-	     AND summitExp.dateobs <= '@DATE@T23:59:59'
-ORDER BY newImfile.tmp_class_id,summitExp.dateobs
+             summitExp.dateobs >= '@DATEOBS_BEGIN@'
+             AND summitExp.dateobs <= '@DATEOBS_END@'
+ORDER BY summitImfile.class_id,summitExp.dateobs
Index: branches/czw_branch/20101203/ippTools/share/regtool_pendingexp.sql
===================================================================
--- branches/czw_branch/20101203/ippTools/share/regtool_pendingexp.sql	(revision 30118)
+++ branches/czw_branch/20101203/ippTools/share/regtool_pendingexp.sql	(revision 30586)
@@ -48,4 +48,5 @@
           GROUP BY newExp.exp_id
           HAVING SUM(rawImfile.fault) = 0
+	  LIMIT 256
          ) AS RAWEXPOSURES
 	 USING (exp_id)
