Index: trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm
===================================================================
--- trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm	(revision 25794)
+++ trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm	(revision 26143)
@@ -84,9 +84,14 @@
 
         my $image = $results->[0];
-        if (($img_type eq "raw") or ($img_type eq "chip")) {
-            $req_type = "byexp";
-            $id = $image->{exp_name};
+        if ($img_type eq "raw") {
+            $req_type = "byid";
+            $id = $image->{exp_id};
             return undef if !$id;
-            # fall through and lookup byexp
+            # fall through and lookup byid
+        } elsif ($img_type eq "chip") {
+            $req_type = "byid";
+            $id = $image->{chip_id};
+            return undef if !$id;
+            # fall through and lookup byid
         } elsif ($img_type eq "warp") {
             $req_type = "byid";
@@ -171,5 +176,7 @@
     }
 
+    # note $magic_arg may be cleared below depending on $req_type
     my $magic_arg = $need_magic ? " -destreaked" : "";
+
     my $component_args;
     if ($img_type eq "raw") {
@@ -229,7 +236,13 @@
         $command .= " $id_opt $id";
         $command .= $component_args if $component_args;
+        # don't include -destreaked if lookup is byid. Let pstampparse check so that the error code gives
+        # the reason as 'not destreaked'
+        $magic_arg = "";
     } elsif ($req_type eq "byexp") {
         $command .= " -exp_name $id";
         $command .= $component_args if $component_args;
+        # don't include -destreaked if lookup is byexp. Let pstampparse check so that the error code gives
+        # the reason as 'not destreaked'
+        $magic_arg = "";
     } elsif ($req_type eq "byskycell") {
         die "tess_id and component are required for byskycell" if !$tess_id or ! $skycell_id;
@@ -402,5 +415,5 @@
         }
 
-        my ($warp_id, $exp_id, $exp_name);
+        my ($warp_id, $exp_id, $exp_name, $chip_id, $cam_id);
         if ($inverse and !$image->{bothways}) {
             print STDERR "Inverse images requested for diffRun that is not bothways. Ignoring.\n";
@@ -411,8 +424,12 @@
             $exp_id = $image->{exp_id_2};
             $exp_name = $image->{exp_name_2};
+            $chip_id = $image->{chip_id_2};
+            $cam_id = $image->{cam_id_2};
         } else {
             $warp_id =  $image->{warp1};
             $exp_id = $image->{exp_id_1};
             $exp_name = $image->{exp_name_1};
+            $chip_id = $image->{chip_id_1};
+            $cam_id = $image->{cam_id_1};
         }
         # XXX difftool currently returns max long long for null
@@ -422,4 +439,6 @@
             $image->{exp_id} = $exp_id;
             $image->{exp_name} = $exp_name;
+            $image->{chip_id} = $chip_id;
+            $image->{cam_id} = $cam_id;
         } else {
             print STDERR "unexpected result warp_id not defined\n";
