Index: trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm
===================================================================
--- trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm	(revision 24921)
+++ trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm	(revision 24968)
@@ -232,13 +232,12 @@
         }
         my $out = $image;
+
         # if uri is nil this will get overridded below
+        # (this is for raw stage)
         $out->{image}  = $image->{uri};
-#        $out->{exp_id} = $image->{exp_id};
-#        $out->{exp_name} = $image->{exp_name};
-#        $out->{state}  = $image->{state}; # state is undef for rawExp, but that's ok
-#        if ($set_class_id) {
-#            $class_id = $image->{class_id};
-#            $out->{class_id} = $class_id;
-#        }
+        if ($set_class_id) {
+            $class_id = $image->{class_id};
+            $out->{component} = $class_id;
+        }
 
         # find the mask and weight images
@@ -248,6 +247,4 @@
             $out->{weight} = $ipprc->filename($weight_name, $base, $class_id) if $weight_name;
         }
-#        $out->{camera} = $camera;
-
         $out->{astrom} = find_astrometry($ipprc, $image_db, $image, $verbose) if $want_astrom;
 
@@ -441,4 +438,9 @@
 }
 
+# cache of results of ppConfigDump
+my %astromSources;
+my $last_exp_id = 0;
+my $lastAstromFile;
+
 # find the astrometry file for a given exposure
 # return undef if no completed camRun exists
@@ -449,4 +451,12 @@
     my $verbose = shift;
 
+    my $exp_id = $image->{exp_id};
+    if (($exp_id eq $last_exp_id) and $lastAstromFile) {
+        # running camtool 60 times is really expensive when the answer is the same
+        return $lastAstromFile;
+    }
+    $last_exp_id = 0;
+    $lastAstromFile = undef;
+
     my $missing_tools;
     my $camtool = can_run("camtool") or (warn "Can't find camtool" and $missing_tools = 1);
@@ -457,5 +467,5 @@
     }
 
-    my $command = "$camtool -dbname $image_db -processedexp -exp_id $image->{exp_id}";
+    my $command = "$camtool -dbname $image_db -processedexp -exp_id $exp_id";
     # run the tool and parse the output
     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
@@ -487,6 +497,6 @@
     my $camRoot = $camdata->{path_base};
     my $camera = $image->{camera};
-    my $astromSource;
-    {
+    my $astromSource = $astromSources{$camera};
+    if (!$astromSource) {
        my $command = "$ppConfigDump -camera $camera -dump-recipe PSWARP -";
         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
@@ -499,7 +509,12 @@
             die("Unable to parse metadata config doc");
         $astromSource = metadataLookupStr($metadata, 'ASTROM.SOURCE');
+        $astromSources{$camera} = $astromSource;
     }
 
     my $astromFile = $ipprc->filename($astromSource, $camRoot);
+    if ($astromFile) {
+        $lastAstromFile = $astromFile;
+        $last_exp_id = $exp_id;
+    }
 
     return $astromFile;
