Index: trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm
===================================================================
--- trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm	(revision 27990)
+++ trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm	(revision 27991)
@@ -369,5 +369,5 @@
         $images = selectComponents($ipprc, $imagedb, $req_type, $stage, $rowList, $images, $verbose);
     } else {
-        # put each of the rows into all of the the images
+        # put index for each of the rows into all of the the images
         setRowRefs($rowList, $images);
     }
@@ -398,26 +398,27 @@
             $ipprc->define_camera($camera);
         }
+        # ok it's a keeper
         my $out = $image;
 
         # if uri is nil this will get overridded below
         # (we do this here for raw stage)
-        $out->{image}  = $image->{uri};
+        $out->{image}  = $out->{uri};
 
         if ($set_class_id) {
-            $class_id = $image->{class_id};
+            $class_id = $out->{class_id};
             $out->{component} = $class_id;
         } else {
-            $out->{component} = $image->{skycell_id};
+            $out->{component} = $out->{skycell_id};
         }
         my $stage_id;
         if ($stage eq "raw") {
-            $stage_id = $image->{exp_id};
+            $stage_id = $out->{exp_id};
         } elsif ($stage eq "chip") {
-            $stage_id = $image->{chip_id};
+            $stage_id = $out->{chip_id};
         } elsif ($stage eq "warp") {
-            $stage_id = $image->{warp_id};
+            $stage_id = $out->{warp_id};
         } elsif ($stage eq "diff") {
-            $stage_id = $image->{diff_id};
-            if ($inverse && $image->{bothways}) {
+            $stage_id = $out->{diff_id};
+            if ($inverse && $out->{bothways}) {
                 $image_name  = "PPSUB.INVERSE";
                 $mask_name   = "PPSUB.INVERSE.MASK";
@@ -426,5 +427,5 @@
             }
         } elsif ($stage eq "stack") {
-            $stage_id = $image->{stack_id};
+            $stage_id = $out->{stack_id};
         }
         $out->{stage_id} = $stage_id;
@@ -450,7 +451,7 @@
             $out->{mask}   = $ipprc->filename($mask_name,   $mask_base, $class_id) if $mask_name;
             $out->{weight} = $ipprc->filename($weight_name, $base, $class_id) if $weight_name;
-            $out->{cmf}    = $ipprc->filename($cmf_name, $base, $class_id) if $cmf_name;
-            $out->{psf}    = $ipprc->filename($psf_name, $base, $class_id) if $psf_name;
-            $out->{backmdl}= $ipprc->filename($backmdl_name, $base, $class_id) if $backmdl_name;
+            $out->{cmf}    = $ipprc->filename($cmf_name,    $base, $class_id) if $cmf_name;
+            $out->{psf}    = $ipprc->filename($psf_name,    $base, $class_id) if $psf_name;
+            $out->{backmdl}= $ipprc->filename($backmdl_name,$base, $class_id) if $backmdl_name;
         }
 
@@ -775,5 +776,5 @@
             chip_id   => $camRun->{chip_id},
             cam_id    => $camRun->{cam_id},
-            astrom    => $astrom_resolved,
+            astrom    => $astrom_resolved,  # XXX: is astrom used?
             class_id  => $class_id,
             component => $class_id
@@ -855,10 +856,10 @@
 # cache of results of ppConfigDump
 my %astromSources;
-# my $last_exp_id = 0;
-my $lastCamRun;
 
 # find the astrometry file for a given exposure
 # return undef if no completed camRun exists
 # XXX Right now this probably only works cameras where the astrometry is done at the camera stage
+# What other possibilities are there for ASTROM.SOURCE besides PSASTRO.OUTPUT?
+
 sub find_astrometry {
     my $ipprc = shift;
@@ -870,15 +871,4 @@
 
     my $exp_id = $image->{exp_id};
-    if (defined $lastCamRun) {
-        if ($lastCamRun->{exp_id} == $exp_id) {
-            # running camtool 60 times is really expensive when the answer is the same every time
-            $image->{astrom} = $lastCamRun->{astrom};
-            $image->{cam_path_base} = $lastCamRun->{path_base};
-            return 1;
-        }
-    }
-    # $last_exp_id = 0;
-    # $lastAstromFile = undef;
-    $lastCamRun = undef;
 
     my $camRun = getCamRunByExpID($exp_id);
@@ -945,9 +935,6 @@
     # XXX: Is this code correct if ASTROM.SOURCE ne "PSASTRO.OUTPUT"
     my $astromFile = $ipprc->filename($astromSource, $camRoot);
-    if ($astromFile) {
-        $lastCamRun = $camRun;
-        $lastCamRun->{astrom} = $astromFile;
-#        $last_exp_id = $exp_id;
-    } else {
+    if (!$astromFile) {
+        print STDERR "failed to find astrometry file from $astromSource $camRoot\n";
         return 0;
     }
