Index: trunk/ippScripts/scripts/detrend_reject_exp.pl
===================================================================
--- trunk/ippScripts/scripts/detrend_reject_exp.pl	(revision 11829)
+++ trunk/ippScripts/scripts/detrend_reject_exp.pl	(revision 11837)
@@ -32,5 +32,5 @@
 use Pod::Usage qw( pod2usage );
 
-my ($det_id, $iter, $det_type, $camera, $filter, $workdir, $dbname, $no_update);
+my ($det_id, $iter, $det_type, $camera, $filter, $workdir, $dbname, $no_update, $no_op);
 GetOptions(
 	   'det_id|d=s'        => \$det_id,
@@ -41,5 +41,6 @@
 	   'workdir|w=s'       => \$workdir, # Working directory for output files
 	   'dbname|d=s'        => \$dbname, # Database name
-	   'no-update'         => \$no_update
+	   'no-update'         => \$no_update,
+	   'no-op'             => \$no_op,
 ) or pod2usage( 2 );
 
@@ -133,5 +134,5 @@
     $command = "$dettool -updateresidexp -det_id $det_id -iteration $iter -exp_tag $expTag"; # Command to run
     $command .= " -dbname $dbname" if defined $dbname;
-
+    
     $reject = 0;		# Reject this exposure?
 
@@ -143,4 +144,14 @@
     }
 
+    # Cop-out if we're not doing any operations
+    if ($no_op) {
+	# Make sure something gets rejected (just once!), just so that
+	# we can trace the full range of the workflow
+	if ($i == 0 and $iter == 0) {
+	    $reject = 1;
+	}
+	goto UPDATE;
+    }
+    
     if ($reject_mean and defined $meanStats->standard_deviation() ) {
 	my $dMean = abs($means[$i] - $meanStats->mean()) ;
@@ -201,5 +212,5 @@
     }
 }
-    
+
 # Decide if the current is sufficient to use as a master, and if we can stop iterating
 my $master = 1;			# This is good enough for a master
@@ -220,41 +231,48 @@
 print "Stop: $stop\n";
 
-# Put the result into the database
+# Put results into the database
 unless ($no_update) {
-    my $varianceStats = Statistics::Descriptive::Sparse->new(); # Statistics calculator
-    $varianceStats->add_data(@variances);
-
-    my $command = "$dettool -adddetrunsummary -det_id $det_id -iteration $iter" .
-	" -bg " . $meanStats->mean() . " -bg_stdev " . sqrt($varianceStats->mean()) .
-	" -bg_mean_stdev " . $meanStats->standard_deviation();
-    $command .= " -accept" if $master;
-    $command .= " -dbname $dbname" if defined $dbname;
-
-    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run(command => $command, verbose => 1);
-    unless ($success) {
-	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	warn("Unable to perform dettool -adddetrunsummary: $error_code");
-	exit($error_code);
-    }
-}
-
-# Re-run processing if required
-unless ($no_update) {
-    my $command = "$dettool -updatedetrun -det_id $det_id";
-    if ($stop) {
-	$command .= ' -state stop';
-    } else {
-	$command .= ' -again';
-    }
-    
-    $command .= " -dbname $dbname" if defined $dbname;
-    
-    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
-	run(command => $command, verbose => 1);
-    unless ($success) {
-	$error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
-	warn("Unable to perform dettool -updatedetrun: $error_code");
-	exit($error_code);
+
+    {
+	# Add the summary
+	my $varianceStats = Statistics::Descriptive::Sparse->new(); # Statistics calculator
+	$varianceStats->add_data(@variances);
+	
+	my $bg = ($meanStats->mean() or 'NAN');
+	my $bg_stdev = (sqrt( $varianceStats->mean() ) or 'NAN');
+	my $bg_mean_stdev = ($meanStats->standard_deviation() or 'NAN');
+	
+	my $command = "$dettool -adddetrunsummary -det_id $det_id -iteration $iter";
+	$command .= " -bg $bg -bg_stdev $bg_stdev -bg_mean_stdev $bg_mean_stdev";
+	$command .= " -accept" if $master;
+	$command .= " -dbname $dbname" if defined $dbname;
+	
+	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+	    run(command => $command, verbose => 1);
+	unless ($success) {
+	    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+	    warn("Unable to perform dettool -adddetrunsummary: $error_code");
+	    exit($error_code);
+	}
+    }
+
+    # Re-run processing if required
+    {
+	my $command = "$dettool -updatedetrun -det_id $det_id";
+	if ($stop) {
+	    $command .= ' -state stop';
+	} else {
+	    $command .= ' -again';
+	}
+	
+	$command .= " -dbname $dbname" if defined $dbname;
+	
+	my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+	    run(command => $command, verbose => 1);
+	unless ($success) {
+	    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
+	    warn("Unable to perform dettool -updatedetrun: $error_code");
+	    exit($error_code);
+	}
     }
 }
