Index: trunk/ippScripts/scripts/magic_destreak.pl
===================================================================
--- trunk/ippScripts/scripts/magic_destreak.pl	(revision 26378)
+++ trunk/ippScripts/scripts/magic_destreak.pl	(revision 26447)
@@ -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 $ppStatsFromMetadata = can_run('ppStatsFromMetadata') or (warn "Can't find ppStatsFromMetadata" and $missing_tools = 1);
 if ($missing_tools) {
     warn("Can't find required tools.");
@@ -38,5 +39,5 @@
 
 # Parse the command-line arguments
-my ($magic_ds_id, $camera, $streaks, $inv_streaks, $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);
 my ($outroot, $recoveryroot);
 my ($replace, $release);
@@ -48,4 +49,5 @@
            'streaks=s'      => \$streaks,    # file containing the list of streaks
            'inv_streaks=s'  => \$inv_streaks,# file containing the list of streaks from the inverse diff
+           'exp_id=s'       => \$exp_id,     # exp_id, chip_id, warp_id, or diff_id
            'stage=s'        => \$stage,      # raw, chip, warp, or diff
            'stage_id=s'     => \$stage_id,   # exp_id, chip_id, warp_id, or diff_id
@@ -74,4 +76,5 @@
     defined $stage and
     defined $stage_id and
+    defined $exp_id and
     defined $component and
     defined $uri and
@@ -145,4 +148,6 @@
     }
 }
+
+my $statsFile = "$outroot/$exp_id.mds.$magic_ds_id.$stage_id.$component.stats";
 
 my $backup_path_base;
@@ -166,5 +171,5 @@
         if (! -e $recoveryroot ) {
             my $code = system "mkdir -p $recoveryroot";
-            &my_die("cannot create output directory $outroot", $magic_ds_id, $component,
+            &my_die("cannot create output directory $recoveryroot", $magic_ds_id, $component,
                     $code >> 8) if $code;
         }
@@ -260,4 +265,5 @@
         my $command = "$streaksremove -stage $stage -tmproot $tmproot -streaks $streaks -image $image";
 
+        $command .= " -stats $statsFile";
         $command .= " -class_id $class_id" if defined $class_id;
         $command .= " -recovery $recoveryroot" if defined $recoveryroot;
@@ -288,5 +294,9 @@
         $sources = $ipprc->filename("PPSUB.INVERSE.SOURCES", $path_base);
 
+        # Note: we create a stats file for the inverse procesing but we don't look at the results
+        my $invStatsFile = "$outroot/$exp_id.mds.$magic_ds_id.$stage_id.$component.inv.stats";
+
         my $command = "$streaksremove -stage $stage -tmproot $tmproot -streaks $streaks -image $image";
+        $command .= " -stats $invStatsFile";
 
         $command .= " -recovery $recoveryroot" if defined $recoveryroot;
@@ -371,5 +381,23 @@
 }
 
-# if recovery and/or backup files were expected make sure they exist
+file_check($statsFile);
+my $statsFlags;
+{
+    my $resolvedStatsFile = $ipprc->file_resolve($statsFile);
+    my $command = "$ppStatsFromMetadata $resolvedStatsFile - STREAKSREMOVE";
+
+    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 ppStatsFromMetadata: $error_code", $magic_ds_id, $component, $error_code);
+    }
+    foreach my $line (@$stdout_buf) {
+        $statsFlags .= " $line";
+    }
+    chomp $statsFlags;
+}
+
+# XXX: if recovery and/or backup files were expected make sure they exist
 
 # Input result into database
@@ -381,4 +409,5 @@
     $command   .= " -backup_path_base $backup_path_base" if $backup_path_base;
     $command   .= " -recovery_path_base $recovery_path_base" if $recovery_path_base;
+    $command   .= " $statsFlags" if $statsFlags;
     $command   .= " -dbname $dbname" if defined $dbname;
 
