Index: trunk/ippScripts/scripts/magic_destreak_revert.pl
===================================================================
--- trunk/ippScripts/scripts/magic_destreak_revert.pl	(revision 27718)
+++ trunk/ippScripts/scripts/magic_destreak_revert.pl	(revision 27946)
@@ -38,5 +38,5 @@
 
 # Parse the command-line arguments
-my ($magic_ds_id, $camera, $streaks, $stage, $stage_id, $component, $uri, $path_base, $bothways, $cam_path_base, $cam_reduction);
+my ($magic_ds_id, $camera, $streaks, $stage, $stage_id, $component, $uri, $path_base, $bothways, $cam_path_base, $cam_reduction, $magicked);
 my ($outroot, $recoveryroot, $replace, $release, $bytes, $md5sum);
 my ($dbname, $save_temps, $verbose, $no_update, $no_op, $logfile);
@@ -55,4 +55,5 @@
            'replace=s'      => \$replace,    # replace the input images with the results.
            'bothways=s'     => \$bothways,   # run has inverse files (bothways diff)
+           'magicked=s'     => \$magicked,   # magicked state of the run
            'save-temps'     => \$save_temps, # Save temporary files?
            'dbname=s'       => \$dbname,     # Database name
@@ -64,5 +65,5 @@
 
 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
-pod2usage( -msg => "Required options: --magic_ds_id --camera --stage --stage_id --component --path_base --outroot",
+pod2usage( -msg => "Required options: --magic_ds_id --camera --stage --stage_id --component --path_base --outroot --magicked",
            -exitval => 3) unless
     defined $magic_ds_id and
@@ -72,4 +73,5 @@
     defined $component and
     defined $path_base and
+    defined $magicked and
     defined $outroot;
 
@@ -77,4 +79,6 @@
 
 &my_die("cam_path_base is required for chip stage", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR) if ($stage eq 'chip' and !$cam_path_base);
+
+
 
 my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
@@ -169,5 +173,6 @@
         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);
+            # note verbose == 0 to keep from polluting log file with lots of usually useless information
+            run(command => $command, verbose => 0);
         unless ($success) {
             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
@@ -182,10 +187,12 @@
     }
 
+    $image  = $ipprc->filename("PPIMAGE.CHIP", $path_base, $class_id);
+    $weight = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $path_base, $class_id);
+
     # 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);
-    $weight = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $path_base, $class_id);
-
-    if ($dynamicMasks) {
+    # Note that when destreaking as part of an update $magicked is non-zero.
+    # In this case we do not touch the camera stage mask so there is no need to revert it
+    if (!$magicked and $dynamicMasks) {
         $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $cam_path_base, $class_id);
         $ch_mask = $ipprc->filename("PPIMAGE.CHIP.MASK", $path_base, $class_id);
@@ -195,5 +202,5 @@
 
     $bimage  = $ipprc->filename("PPIMAGE.CHIP", $backup_path_base, $class_id);
-    # This is kludgey but correct
+    # This is somewhat kludgey but it works whether the mask is camera mask or chip mask
     $bmask   = dirname($backup_path_base) . "/SR_" . basename($mask);
     $bch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $backup_path_base, $class_id);
