Index: trunk/ippScripts/scripts/chip_imfile.pl
===================================================================
--- trunk/ippScripts/scripts/chip_imfile.pl	(revision 35770)
+++ trunk/ippScripts/scripts/chip_imfile.pl	(revision 35789)
@@ -45,5 +45,5 @@
 # Parse the command-line arguments
 my ( $exp_id, $chip_id, $class_id, $chip_imfile_id, $uri, $camera, $outroot, $dbname, $run_state, $reduction, $threads, $verbose,
-     $no_update, $save_temps, $no_op, $redirect, $magicked, $deburned );
+     $no_update, $save_temps, $no_op, $redirect, $magicked, $deburned, $update_mode );
 
 GetOptions(
@@ -58,4 +58,5 @@
     'reduction=s'       => \$reduction, # Reduction class
     'run-state=s'       => \$run_state, # current state of the run (new, update)
+    'update-mode=s'     => \$update_mode, # update_mode if non-zero do not use configdump
     'magicked=s'        => \$magicked,  # magicked state of input file
     'deburned=s'        => \$deburned,  # does deburned image exist?
@@ -147,6 +148,12 @@
 my $outputBin2;
 my $dump_config = 1;
-my $do_stats = 1;
+
+# Note: We currently always do_stats because we need the quality flags
+# If run_state eq 'update' using the same file name wipes out the stats from the original processing which
+# is arguably a bug.  Since they are already in the database in that case this probably isn't a big
+# deal
+my $do_stats = 1;   
 $outputStats   = prepare_output("PPIMAGE.STATS",         $outroot, $class_id, 1);
+
 my $do_binned_images = 1;
 
@@ -155,22 +162,28 @@
     $configuration = prepare_output("PPIMAGE.CONFIG",        $outroot, $class_id, 1);
 } else {
-    $configuration = $ipprc->filename('PPIMAGE.CONFIG', $outroot, $class_id) 
+    # If update_mode is non-zero we are going to update with current recipes. 
+    # In this case dump the new configuration.
+    if ($update_mode) {
+        $configuration = prepare_output("PPIMAGE.CONFIG",        $outroot, $class_id, 1);
+    } else {
+        $configuration = $ipprc->filename('PPIMAGE.CONFIG', $outroot, $class_id) 
             or &my_die("Missing entry from camera config: PPIMAGE.CONFIG", $exp_id, $chip_id, $class_id, $PS_EXIT_CONFIG_ERROR);
-    if ($ipprc->file_exists($configuration)) {
-        $dump_config = 0;
-    } else {
-        print STDERR "WARNING: Config dump file $configuration is missing. Using current recipes and file rules.\n";
-
-        # XXX: should we create a new config dump file?
-        # I vote yes but only if we can distingusing between temporarily unavailable and GONE.
-        my $gone = 0;
-        if (storage_object_exists($configuration, \$gone)) {
-            if ($gone) {
-                $configuration = prepare_output('PPIMAGE.CONFIG', $outroot, $class_id, 1);
-                # if we dump the config we need to insure that the config dump represents
-                # the full processing
-            } else {
-                # file is temporarily not available. Don't dump config.
-                $dump_config = 0;
+        if ($ipprc->file_exists($configuration)) {
+            $dump_config = 0;
+        } else {
+            print STDERR "WARNING: Config dump file $configuration is missing. Using current recipes and file rules.\n";
+
+            # XXX: should we create a new config dump file?
+            # I vote yes but only if we can distingusing between temporarily unavailable and GONE.
+            my $gone = 0;
+            if (storage_object_exists($configuration, \$gone)) {
+                if ($gone) {
+                    $configuration = prepare_output('PPIMAGE.CONFIG', $outroot, $class_id, 1);
+                    # if we dump the config we need to insure that the config dump represents
+                    # the full processing
+                } else {
+                    # file is temporarily not available. Don't dump config.
+                    $dump_config = 0;
+                }
             }
         }
@@ -185,6 +198,6 @@
         or &my_die("failed to delete existing destreak backup weight file", $exp_id, $chip_id, $class_id, $PS_EXIT_UNKNOWN_ERROR);
 
-    # don't do binned images when updating unless we are starting from scratch.
-    $do_binned_images = 0 unless $dump_config;
+    # don't do binned images when updating
+    $do_binned_images = 0;
 }
 if ($do_binned_images) {
@@ -219,5 +232,5 @@
     my $do_photom = metadataLookupBool($recipeData, 'PHOTOM');
     if ($do_photom and ($run_state eq 'update')) {
-        # If previous photometry outputs are ok skip running photometry
+        # If previous psf file is ok skip photometry
         if ($dump_config || rerun_photometry($outroot, $class_id)) {
             carp "Will rerun photometry\n";
@@ -562,4 +575,7 @@
     $command .= " -class_id $class_id";
     $command .= " -dbname $dbname" if defined $dbname;
+    # XXX: if we had a quality problem on this re-run we are not saving that fact in the DB...
+    # to change this we need to modify chiptool -tofullimfile to supprot -set_quality and then add
+    #$command .= " -set_quality $quality" if $quality;
 }
 
@@ -600,5 +616,5 @@
 
     my $update_sources_if_gone = 0; # set this to regenerate sources if gone. 
-                                    # We no longer do this as of 2012-12
+                                    # We no longer do this as of 2012-12 since cleanup deletes them
     my $make_sources = 0;
     my $sources_available = 0;
@@ -635,5 +651,5 @@
         if (storage_object_exists($outputPsf, \$gone)) {
             # object exists, but no instances are available. If they are permanently gone
-            # rename the storage object
+            # remake it
             if ($gone) {
                 carp "WARNING: PSF storage object exists but all instances are permanently gone";
@@ -641,4 +657,5 @@
             }
         } else {
+            # object completely missing remake it
             $make_psf = 1;
         }
