Index: trunk/ippScripts/scripts/magic_destreak.pl
===================================================================
--- trunk/ippScripts/scripts/magic_destreak.pl	(revision 27300)
+++ trunk/ippScripts/scripts/magic_destreak.pl	(revision 27301)
@@ -32,4 +32,5 @@
 my $camtool = can_run('camtool') or (warn "Can't find camtool" and $missing_tools = 1);
 my $censorObjects = can_run('censorObjects') or (warn "Can't find censorObjects" and $missing_tools = 1);
+my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
 my $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
 if ($missing_tools) {
@@ -39,5 +40,5 @@
 
 # Parse the command-line arguments
-my ($magic_ds_id, $camera, $streaks, $inv_streaks, $exp_id, $stage, $stage_id, $component, $uri, $path_base, $cam_path_base);
+my ($magic_ds_id, $camera, $streaks, $inv_streaks, $exp_id, $stage, $stage_id, $component, $uri, $path_base, $cam_path_base, $cam_reduction);
 my ($outroot, $recoveryroot);
 my ($replace, $release);
@@ -56,4 +57,5 @@
            'path_base=s'    => \$path_base,  # path_base of the input
            'cam_path_base=s'=> \$cam_path_base,  # path_base from camera stage (for chip and raw)
+           'cam_reduction=s'=> \$cam_reduction,  # reduction class from camera stage (for chip and raw)
            'outroot=s'      => \$outroot,     # "directory" for temporary images (may be nebulous)
            'recoveryroot=s' => \$recoveryroot,# "directory" for saving the images of excised pixels
@@ -84,4 +86,6 @@
 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
 $ipprc->redirect_output($logfile) or my_die( "Unable to redirect output", $magic_ds_id, $component, $PS_EXIT_SYS_ERROR ) if $logfile;
+my $recipe_psastro = $ipprc->reduction($cam_reduction, 'PSASTRO'); # Recipe to use
+&my_die("Unrecognised PSASTRO recipe", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR) unless defined $recipe_psastro;
 
 my ($skycell_args, $class_id, $skycell_id);
@@ -97,5 +101,5 @@
 } elsif ($stage ne "camera") {
     &my_die("Invalid value for stage: $stage", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
-}    
+}
 $inv_streaks = undef if defined($inv_streaks) and ($inv_streaks eq "NULL");
 
@@ -114,6 +118,6 @@
     if ($stage eq 'camera') {
         my $nebulousServer = metadataLookupStr( $ipprc->{_siteConfig}, 'NEB_SERVER' );
-        &my_die("cannot find NEB_SERVER in site configuration", 
-                                        $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR) 
+        &my_die("cannot find NEB_SERVER in site configuration",
+                                        $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR)
             if !$ nebulousServer;
 
@@ -233,16 +237,37 @@
         $mask   = $ipprc->filename("PSASTRO.OUTPUT.MASK", $cam_path_base, $class_id) if $release ;
     } elsif ($stage eq "chip") {
+
+        # Check to see if we're using dynamic masks
+        my $dynamicMasks;               # Use dynamic masks?
+        {
+            # Get the PSASTRO recipe
+            my $command = "$ppConfigDump -camera $camera -recipe PSASTRO $recipe_psastro -dump-recipe PSASTRO -";
+            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+                run(command => $command, verbose => $verbose);
+            unless ($success) {
+                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+                &my_die("Unable to perform ppConfigDump: $error_code", $magic_ds_id, $component,
+                        $PS_EXIT_CONFIG_ERROR);
+            }
+            my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or
+                &my_die("Unable to parse metadata config doc", $magic_ds_id, $component,
+                        $PS_EXIT_CONFIG_ERROR);
+
+            $dynamicMasks = metadataLookupBool($recipeData, 'REFSTAR_MASK');
+        }
+
         # we use the mask output from the camera stage for input and replace
         # the output of the chip stage with that mask as well.
         $image  = $ipprc->filename("PPIMAGE.CHIP", $path_base, $class_id);
-        $mask   = $ipprc->filename("PSASTRO.OUTPUT.MASK", $cam_path_base, $class_id);
-        $ch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $path_base, $class_id);
         $weight = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $path_base, $class_id);
         $astrom = $ipprc->filename("PSASTRO.OUTPUT", $cam_path_base);
-        if (!$ipprc->file_exists($mask)) {
-            carp("camera mask file $mask for $component not found. Continuing using mask from chip stage.");
-            $mask = $ch_mask;
-            $ch_mask = undef;
-        }
+
+        if ($dynamicMasks) {
+            $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $cam_path_base, $class_id);
+            $ch_mask = $ipprc->filename("PPIMAGE.CHIP.MASK", $path_base, $class_id);
+        } else {
+            $mask = $ipprc->filename("PPIMAGE.CHIP.MASK", $path_base, $class_id);
+        }
+
         # XXX: should we censor the sources as well? For now we're leaving them out of the distribution bundles
         # because they confuse people
@@ -262,5 +287,5 @@
 
         if ($inv_streaks) {
-            # create a temporary file containing the contents of the 
+            # create a temporary file containing the contents of the
             # two streaks files
             ($allstreaks_fh, $allstreaks_name) = tempfile ("/tmp/all.streaks.XXXX",
@@ -357,5 +382,5 @@
         my $quality = $file->{quality};
         if (!$quality) {
-            my $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $path_base, $class_id); 
+            my $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $path_base, $class_id);
             if (! $ipprc->file_exists($mask)) {
                 # camera mask doesn't exist for this chip. Fall back to the chip mask
@@ -379,5 +404,5 @@
                 &my_die("Unable to perform censorObjects: $error_code", $magic_ds_id, $component, $error_code);
             }
-            my $output = $ipprc->filename("CENSOR.OUTPUT", $backup_path_base); 
+            my $output = $ipprc->filename("CENSOR.OUTPUT", $backup_path_base);
             &my_die("expected output file $output not found ", $magic_ds_id, $component, $PS_EXIT_DATA_ERROR)
                 unless $ipprc->file_exists($output);
@@ -481,5 +506,5 @@
     }
 
-    close $fout 
+    close $fout
         or my_die("failed to close combined streaks file", $magic_ds_id,
                      $component, $PS_EXIT_UNKNOWN_ERROR);
Index: trunk/ippScripts/scripts/magic_destreak_cleanup.pl
===================================================================
--- trunk/ippScripts/scripts/magic_destreak_cleanup.pl	(revision 27300)
+++ trunk/ippScripts/scripts/magic_destreak_cleanup.pl	(revision 27301)
@@ -30,4 +30,5 @@
 my $missing_tools;
 my $magicdstool   = can_run('magicdstool') or (warn "Can't find magicdstool" and $missing_tools = 1);
+my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
 if ($missing_tools) {
     warn("Can't find required tools.");
@@ -36,5 +37,5 @@
 
 # Parse the command-line arguments
-my ($magic_ds_id, $camera, $force);
+my ($magic_ds_id, $camera);
 my ($dbname, $save_temps, $verbose, $no_update, $no_op, $logfile);
 
@@ -42,5 +43,4 @@
            'magic_ds_id=s'  => \$magic_ds_id,# Magic destreak run identifier
            'camera=s'       => \$camera,     # camera for evaluating file rules
-           'force'          => \$force,      # force deletion
            'save-temps'     => \$save_temps, # Save temporary files?
            'dbname=s'       => \$dbname,     # Database name
@@ -87,10 +87,8 @@
 my $dbh = DBI->connect($dsn, $dbuser, $dbpassword) or die "Cannot connect to mysql server\n";
 
-my $q1 = "SELECT magicDSRun.*, camera, camProcessedExp.path_base AS cam_path_base, magicRun.inverse"
-         . " FROM magicDSRun JOIN magicRun USING(magic_id) JOIN rawExp USING(exp_id) LEFT JOIN camProcessedExp USING(cam_id)"
+my $q1 = "SELECT magicDSRun.*, camera, camProcessedExp.path_base AS cam_path_base, camRun.reduction AS cam_reduction, magicRun.inverse"
+         . " FROM magicDSRun JOIN magicRun USING(magic_id) JOIN rawExp USING(exp_id) LEFT JOIN camProcessedExp USING(cam_id) LEFT JOIN camRun USING(cam_id)"
          . " WHERE magic_ds_id = $magic_ds_id";
 my $q2 = "SELECT * from magicDSFile where magic_ds_id = $magic_ds_id";
-
-# my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
 
 my $stmt1 = $dbh->prepare($q1);
@@ -104,10 +102,13 @@
 my $stage_id = $run->{stage_id};
 my $cam_path_base = $run->{cam_path_base};
+my $cam_reduction = $run->{cam_reduction};
 my $inverse = $run->{inverse};
-my $replace = $run->{re_place};
 
 
 &my_die("unexpected run state found: $state", $magic_ds_id, $PS_EXIT_CONFIG_ERROR) if $state ne "goto_cleaned";
-&my_die("clean not allowed for raw stage, use goto_restore", $magic_ds_id, $PS_EXIT_CONFIG_ERROR) if ($stage eq "raw"); # XXX: add this once we implement and $replace;
+&my_die("clean not allowed for raw stage, use goto_restore", $magic_ds_id, $PS_EXIT_CONFIG_ERROR) if $stage eq "raw";
+
+my $recipe_psastro = $ipprc->reduction($cam_reduction, 'PSASTRO'); # Recipe to use
+&my_die("Unrecognised PSASTRO recipe", $magic_ds_id, $PS_EXIT_CONFIG_ERROR) unless defined $recipe_psastro;
 
 
@@ -126,29 +127,49 @@
 
         if ($stage eq "chip") {
-            # we use the mask output from the camera stage for input and replace
-            # the output of the chip stage with that mask as well.
-            my $cammask   = $cam_path_base ? $ipprc->filename("PSASTRO.OUTPUT.MASK", $cam_path_base, $component) : undef;
+            # Check to see if we're using dynamic masks
+            my $dynamicMasks;               # Use dynamic masks?
+            {
+                # Get the PSASTRO recipe
+                my $command = "$ppConfigDump -camera $camera -recipe PSASTRO $recipe_psastro -dump-recipe PSASTRO -";
+                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+                    run(command => $command, verbose => $verbose);
+                unless ($success) {
+                    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+                    &my_die("Unable to perform ppConfigDump: $error_code", $magic_ds_id, $component,
+                            $PS_EXIT_CONFIG_ERROR);
+                }
+                my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
+                my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or
+                    &my_die("Unable to parse metadata config doc", $magic_ds_id, $component,
+                            $PS_EXIT_CONFIG_ERROR);
+
+                $dynamicMasks = metadataLookupBool($recipeData, 'REFSTAR_MASK');
+            }
 
             if ($backup_path_base) {
                 $bimage  = $ipprc->filename("PPIMAGE.CHIP", $backup_path_base, $component);
-                $bch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $backup_path_base, $component);
+
+                if ($dynamicMasks) {
+                    my $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $cam_path_base, $component);
+                    # This is kludgey but correct
+                    $bmask = dirname($backup_path_base) . "/SR_" . basename($mask);
+                    $bch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $backup_path_base, $component);
+                } else {
+                    $bmask = $ipprc->filename("PPIMAGE.CHIP.MASK", $backup_path_base, $component);
+                }
                 $bweight = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $backup_path_base, $component);
-                # This is kludgey but correct
-                
-                my $prefix;
-                if ($backup_path_base =~ /\.SR/) {
-                    $prefix = "";
+            }
+            if ($recovery_path_base) {
+                $rimage  = $ipprc->filename("PPIMAGE.CHIP", $recovery_path_base, $component);
+
+                if ($dynamicMasks) {
+                    my $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $cam_path_base, $component);
+                    # This is kludgey but correct
+                    $rmask = dirname($recovery_path_base) . "/" . basename($mask);
+                    $rch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $recovery_path_base, $component);
                 } else {
-                    $prefix = "SR_";
-                }
-
-                $bmask   = dirname($backup_path_base) . "/" . $prefix . basename($cammask) if $cammask;
-            }
-            if ($recovery_path_base) {
-                $rimage  = $ipprc->filename("PPIMAGE.CHIP", $recovery_path_base, $component);
-                $rch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $recovery_path_base, $component);
+                    $rmask = $ipprc->filename("PPIMAGE.CHIP.MASK", $recovery_path_base, $component);
+                }
                 $rweight = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $recovery_path_base, $component);
-                # This is kludgey but correct
-                $rmask   = dirname($recovery_path_base) . "/" . basename($cammask) if $cammask;;
             }
         } elsif ($stage eq "camera") {
@@ -162,5 +183,5 @@
                 $bweight = $ipprc->filename("PSWARP.OUTPUT.VARIANCE", $backup_path_base);
                 $bsources = $ipprc->filename("PSWARP.OUTPUT.SOURCES", $backup_path_base);
-            } 
+            }
             if ($recovery_path_base) {
                 $rimage  = $ipprc->filename("PSWARP.OUTPUT", $recovery_path_base);
@@ -168,5 +189,5 @@
                 $rweight = $ipprc->filename("PSWARP.OUTPUT.VARIANCE", $recovery_path_base);
                 $rsources = $ipprc->filename("PSWARP.OUTPUT.SOURCES", $recovery_path_base);
-            } 
+            }
         } elsif ($stage eq "diff") {
             my $name = "PPSUB.OUTPUT";
@@ -228,6 +249,6 @@
                 if (!$no_update) {
                     print STDERR "deleting $file\n" if $verbose;
-                    $ipprc->file_delete($file, $force) or my_die("Failed to delete $file", $magic_ds_id, $PS_EXIT_UNKNOWN_ERROR);
-                } else {
+                    $ipprc->file_delete($file, 1) or my_die("Failed to delete $file", $magic_ds_id, $PS_EXIT_UNKNOWN_ERROR);
+                    } else {
                     print STDERR "skipping delete $file\n";
                 }
Index: trunk/ippScripts/scripts/magic_destreak_revert.pl
===================================================================
--- trunk/ippScripts/scripts/magic_destreak_revert.pl	(revision 27300)
+++ trunk/ippScripts/scripts/magic_destreak_revert.pl	(revision 27301)
@@ -30,4 +30,5 @@
 my $magicdstool   = can_run('magicdstool') or (warn "Can't find magicdstool" and $missing_tools = 1);
 my $isdestreaked = can_run('isdestreaked') or (warn "Can't find isdestreaked" and $missing_tools = 1);
+my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
 if ($missing_tools) {
     warn("Can't find required tools.");
@@ -36,5 +37,5 @@
 
 # Parse the command-line arguments
-my ($magic_ds_id, $camera, $streaks, $stage, $stage_id, $component, $uri, $path_base, $bothways, $cam_path_base);
+my ($magic_ds_id, $camera, $streaks, $stage, $stage_id, $component, $uri, $path_base, $bothways, $cam_path_base, $cam_reduction);
 my ($outroot, $recoveryroot, $replace, $release, $bytes, $md5sum);
 my ($dbname, $save_temps, $verbose, $no_update, $no_op, $logfile);
@@ -48,4 +49,5 @@
            'path_base=s'    => \$path_base,  # path_base of the input
            'cam_path_base=s'=> \$cam_path_base,  # path_base of the associated camera run
+           'cam_reduction=s'=> \$cam_reduction,  # reduction class of the associated camera run
            'outroot=s'      => \$outroot,     # "directory" for temporary images (may be nebulous)
            'recoveryroot=s' => \$recoveryroot,# "directory" for saving the images of excised pixels
@@ -78,4 +80,6 @@
 
 $ipprc->redirect_output($logfile) or my_die( "Unable to redirect output", $magic_ds_id, $component, $PS_EXIT_SYS_ERROR ) if $logfile;
+my $recipe_psastro = $ipprc->reduction($cam_reduction, 'PSASTRO'); # Recipe to use
+&my_die("Unrecognised PSASTRO recipe", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR) unless defined $recipe_psastro;
 
 my $nebulousServer = metadataLookupStr( $ipprc->{_siteConfig}, 'NEB_SERVER' );
@@ -112,5 +116,5 @@
 }
 
-&my_die("replace not allowed for non-nebulous files", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR) 
+&my_die("replace not allowed for non-nebulous files", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR)
     if ($replace eq "T") and !$nebulousInput;
 
@@ -156,10 +160,34 @@
     $bimage = $backup_path_base . ".fits";
 } elsif ($stage eq "chip") {
+    # Check to see if we're using dynamic masks
+    my $dynamicMasks;               # Use dynamic masks?
+    {
+        # Get the PSASTRO recipe
+        my $command = "$ppConfigDump -camera $camera -recipe PSASTRO $recipe_psastro -dump-recipe PSASTRO -";
+        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+            run(command => $command, verbose => $verbose);
+        unless ($success) {
+            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+            &my_die("Unable to perform ppConfigDump: $error_code", $magic_ds_id, $component,
+                    $PS_EXIT_CONFIG_ERROR);
+        }
+        my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or
+            &my_die("Unable to parse metadata config doc", $magic_ds_id, $component,
+                    $PS_EXIT_CONFIG_ERROR);
+
+        $dynamicMasks = metadataLookupBool($recipeData, 'REFSTAR_MASK');
+    }
+
     # we use the mask output from the camera stage for input and replace
     # the output of the chip stage with that mask as well.
     $image  = $ipprc->filename("PPIMAGE.CHIP", $path_base, $class_id);
-    $mask   = $ipprc->filename("PSASTRO.OUTPUT.MASK", $cam_path_base, $class_id);
-    $ch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $path_base, $class_id);
     $weight = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $path_base, $class_id);
+
+    if ($dynamicMasks) {
+        $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $cam_path_base, $class_id);
+        $ch_mask = $ipprc->filename("PPIMAGE.CHIP.MASK", $path_base, $class_id);
+    } else {
+        $mask = $ipprc->filename("PPIMAGE.CHIP.MASK", $path_base, $class_id);
+    }
 
     $bimage  = $ipprc->filename("PPIMAGE.CHIP", $backup_path_base, $class_id);
@@ -261,5 +289,5 @@
             &my_die("failed to restore chip mask file", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
         }
-    } 
+    }
 
 
Index: trunk/ippTasks/destreak.pro
===================================================================
--- trunk/ippTasks/destreak.pro	(revision 27300)
+++ trunk/ippTasks/destreak.pro	(revision 27301)
@@ -208,4 +208,5 @@
     book getword magicToDS $pageName path_base -var PATH_BASE
     book getword magicToDS $pageName cam_path_base -var CAM_PATH_BASE
+    book getword magicToDS $pageName cam_reduction -var CAM_REDUCTION
     book getword magicToDS $pageName outroot -var OUTROOT
     book getword magicToDS $pageName recoveryroot -var RECROOT
@@ -225,5 +226,5 @@
     # TODO: do not add recoveryroot or replace if they are null or zero
 
-    $run = magic_destreak.pl --magic_ds_id $MAGIC_DS_ID --camera $CAMERA --exp_id $EXP_ID --streaks $STREAKS --inv_streaks $INV_STREAKS --stage $STAGE --stage_id $STAGE_ID --component $COMPONENT --uri $URI --path_base $PATH_BASE --cam_path_base $CAM_PATH_BASE --outroot $OUTROOT --logfile $logfile --recoveryroot $RECROOT --replace $REPLACE
+    $run = magic_destreak.pl --magic_ds_id $MAGIC_DS_ID --camera $CAMERA --exp_id $EXP_ID --streaks $STREAKS --inv_streaks $INV_STREAKS --stage $STAGE --stage_id $STAGE_ID --component $COMPONENT --uri $URI --path_base $PATH_BASE --cam_path_base $CAM_PATH_BASE --cam_reduction $CAM_REDUCTION --outroot $OUTROOT --logfile $logfile --recoveryroot $RECROOT --replace $REPLACE
 
     add_standard_args run
@@ -401,4 +402,5 @@
     book getword magicDSToRevert $pageName path_base -var PATH_BASE
     book getword magicDSToRevert $pageName cam_path_base -var CAM_PATH_BASE
+    book getword magicDSToRevert $pageName cam_reduction -var CAM_REDUCTION
     book getword magicDSToRevert $pageName outroot -var OUTROOT
     book getword magciDSToRevert $pageName bytes -var BYTES
@@ -419,5 +421,5 @@
     end
 
-    $run = magic_destreak_revert.pl --magic_ds_id $MAGIC_DS_ID --camera $CAMERA --stage $STAGE --stage_id $STAGE_ID --component $COMPONENT --path_base $PATH_BASE --cam_path_base $CAM_PATH_BASE --outroot $OUTROOT --logfile $logfile --replace $REPLACE --bothways $BOTHWAYS
+    $run = magic_destreak_revert.pl --magic_ds_id $MAGIC_DS_ID --camera $CAMERA --stage $STAGE --stage_id $STAGE_ID --component $COMPONENT --path_base $PATH_BASE --cam_path_base $CAM_PATH_BASE --cam_reduction $CAM_REDUCTION --outroot $OUTROOT --logfile $logfile --replace $REPLACE --bothways $BOTHWAYS
 
     add_standard_args run
Index: trunk/ippTools/share/magicdstool_todestreak_camera.sql
===================================================================
--- trunk/ippTools/share/magicdstool_todestreak_camera.sql	(revision 27300)
+++ trunk/ippTools/share/magicdstool_todestreak_camera.sql	(revision 27301)
@@ -5,13 +5,14 @@
     magicDSRun.label,
     camera,
-    magicMask.uri as streaks_uri,
+    magicMask.uri AS streaks_uri,
     CAST(NULL AS CHAR(255)) AS inv_streaks_uri,
     stage,
     stage_id,
-    'exposure' as component,
+    'exposure' AS component,
     CAST(NULL AS CHAR(255)) AS uri,
     camProcessedExp.path_base,
     magicRun.inverse,
-    camProcessedExp.path_base as cam_path_base,
+    camProcessedExp.path_base AS cam_path_base,
+    camRun.reduction AS cam_reduction,
     outroot,
     recoveryroot,
Index: trunk/ippTools/share/magicdstool_todestreak_chip.sql
===================================================================
--- trunk/ippTools/share/magicdstool_todestreak_chip.sql	(revision 27300)
+++ trunk/ippTools/share/magicdstool_todestreak_chip.sql	(revision 27301)
@@ -5,13 +5,14 @@
     magicDSRun.label,
     camera,
-    magicMask.uri as streaks_uri,
+    magicMask.uri AS streaks_uri,
     CAST(NULL AS CHAR(255)) AS inv_streaks_uri,
     stage,
     stage_id,
-    class_id as component,
+    class_id AS component,
     chipProcessedImfile.uri,
     chipProcessedImfile.path_base,
     magicRun.inverse,
-    camProcessedExp.path_base as cam_path_base,
+    camProcessedExp.path_base AS cam_path_base,
+    camRun.reduction AS cam_reduction,
     outroot,
     recoveryroot,
@@ -21,4 +22,5 @@
 JOIN magicMask USING (magic_id)
 JOIN magicRun USING(magic_id)
+JOIN camRun USING(cam_id)
 JOIN camProcessedExp USING(cam_id)
 JOIN chipRun ON chip_id = stage_id
Index: trunk/ippTools/share/magicdstool_todestreak_diff.sql
===================================================================
--- trunk/ippTools/share/magicdstool_todestreak_diff.sql	(revision 27300)
+++ trunk/ippTools/share/magicdstool_todestreak_diff.sql	(revision 27301)
@@ -6,13 +6,14 @@
     magicDSRun.label,
     rawExp.camera,
-    magicMask.uri as streaks_uri,
+    magicMask.uri AS streaks_uri,
     CAST(NULL AS CHAR(255)) AS inv_streaks_uri,
     stage,
-    magicRun.diff_id as stage_id,
-    diffSkyfile.skycell_id as component,
+    magicRun.diff_id AS stage_id,
+    diffSkyfile.skycell_id AS component,
     CAST(NULL AS CHAR(255)) AS uri,
     diffSkyfile.path_base,
     magicRun.inverse,
-    CAST(NULL AS CHAR(255)) as cam_path_base,
+    CAST(NULL AS CHAR(255)) AS cam_path_base,
+    CAST(NULL AS CHAR(255)) AS cam_reduction,
     outroot,
     recoveryroot,
Index: trunk/ippTools/share/magicdstool_todestreak_raw.sql
===================================================================
--- trunk/ippTools/share/magicdstool_todestreak_raw.sql	(revision 27300)
+++ trunk/ippTools/share/magicdstool_todestreak_raw.sql	(revision 27301)
@@ -14,4 +14,5 @@
     magicRun.inverse,
     camProcessedExp.path_base as cam_path_base,
+    camRun.reduction AS cam_reduction,
     outroot,
     recoveryroot,
@@ -21,4 +22,5 @@
 JOIN magicMask USING (magic_id)
 JOIN magicRun USING (magic_id)
+JOIN camRun USING(cam_id)
 JOIN camProcessedExp USING(cam_id)
 JOIN rawImfile ON magicRun.exp_id = rawImfile.exp_id
Index: trunk/ippTools/share/magicdstool_todestreak_warp.sql
===================================================================
--- trunk/ippTools/share/magicdstool_todestreak_warp.sql	(revision 27300)
+++ trunk/ippTools/share/magicdstool_todestreak_warp.sql	(revision 27301)
@@ -14,4 +14,5 @@
     magicRun.inverse,
     CAST(NULL AS CHAR(255)) as cam_path_base,
+    CAST(NULL AS CHAR(255)) as cam_reduction,
     outroot,
     recoveryroot,
