Index: trunk/ippToPsps/scripts/ippToPsps_run.pl
===================================================================
--- trunk/ippToPsps/scripts/ippToPsps_run.pl	(revision 28664)
+++ trunk/ippToPsps/scripts/ippToPsps_run.pl	(revision 28691)
@@ -49,8 +49,9 @@
 my $quit = 0;
 print "\n";
-if (!defined $batchType) {print "* ERROR: need to define a batch type (-b)\n"; $quit=1;}
-if (!defined $output) {print "* ERROR: need to provide an output path (-o)\n"; $quit=1;}
-if (!defined $dvodb) {print "* ERROR: need to provide a DVO Db path (-d)\n"; $quit=1;}
-if (!defined $survey and !defined $singleExpId) {print "* ERROR: need to provide a survey type (-s) or an exposure ID (-e)\n"; $quit=1;}
+if (!defined $batchType) {print "* REQUIRED: need to define a batch type: -b <init|det|diff|stack>\n"; $quit=1;}
+if (!defined $output) {print "* REQUIRED: need to provide an output path: -o <path>\n"; $quit=1;}
+if (!defined $dvodb) {print "* REQUIRED: need to provide a DVO Db path: -d <path>\n"; $quit=1;}
+if (!defined $survey and !defined $singleExpId) {print "* REQUIRED: need to provide a survey type (-s <ThreePi|STS|SAS|etc>) or an exposure ID (-e <expID>)\n"; $quit=1;}
+if (!defined $datastoreProduct) {print "* OPTIONAL: datastore producth: -p <product>\n";}
 print "\n\n";
 
@@ -289,5 +290,4 @@
 
     my $query = $db->prepare(<<SQL);
-
     UPDATE batches 
         SET processed = $processed, on_datastore = $published, total_detections = $totalDetections 
@@ -296,5 +296,5 @@
 SQL
 
-    $query->execute; # TODO check response of these
+    $query->execute; # TODO check response of this
 }
 
@@ -380,4 +380,7 @@
     elsif ($batchType =~ /diff/) {
         $success = produceDiffs($gpc1Db, $expId, $expName, $surveyType, $batchDir, $resultsFilePath);
+    }
+    elsif ($batchType =~ /test/) {
+        $success = produceDetections($gpc1Db, $expId, $expName, $surveyType, $batchDir, $resultsFilePath);
     }
 
@@ -622,41 +625,35 @@
     my ($gpc1Db, $expId, $expName, $surveyType, $outputPath, $resultsFilePath) = @_;
 
-    # query to retrieve nebulous key of camera smf file for this exposure
-    my $query = 
-        "SELECT camProcessedExp.path_base ".
-        "FROM warpRun ".
-        "JOIN fakeRun USING(fake_id) ".
-        "JOIN camRun USING(cam_id) ".
-        "JOIN camProcessedExp USING(cam_id) ".
-        "JOIN chipRun USING(chip_id) ".
-        "JOIN rawExp USING (exp_id) ".
-        "WHERE rawExp.exp_id = $expId AND camRun.magicked ".
-        "ORDER BY camRun.cam_id DESC LIMIT 1";  # make sure we get most recently processed
-
-    if ($verbose) { print"* $query\n";}
-
-
-    # execute query and check results
-    my $results = $gpc1Db->selectall_arrayref( $query );
-    my $size = @$results;
-    if ($size < 1) {print "* No smf files found for this exposure\n"; return 0;}
-
-    # loop round db results TODO should only be one result
+    # DESC and LIMIT 1 is to make sure we get most recently processed
+    my $query = $gpc1Db->prepare(<<SQL);
+    SELECT 
+        camProcessedExp.path_base
+        FROM warpRun
+        JOIN fakeRun USING(fake_id)
+        JOIN camRun USING(cam_id)
+        JOIN camProcessedExp USING(cam_id)
+        JOIN chipRun USING(chip_id)
+        JOIN rawExp USING (exp_id)
+        WHERE rawExp.exp_id = $expId AND camRun.magicked
+        ORDER BY camRun.cam_id DESC LIMIT 1
+SQL
+
+    $query->execute;
+    my $nebPath = $query->fetchrow_array();
+    if (!$nebPath) { print "* No smf files found for this exposure\n"; return 0; }
+
     my $success = 0;
-    for my $row (@$results) {
-
-        # get real filename from neb 'key'
-        my ($nebPath) = @$row;
-        my $fpaObjects = $ipprc->filename("PSASTRO.OUTPUT",$nebPath) or return 0;
-        my $realFile = $ipprc->file_resolve($fpaObjects) or return 0;
-
-        # now write the path to this file out to temp file
-        my ($tempFile, $tempName) = tempfile( "/tmp/ippToPsps_inputFileList.XXXX", UNLINK => !$save_temps);
-        print $tempFile $realFile . "\n";
-        close $tempFile;
-
-        $success = runProgram($tempName, $outputPath, $expId, $expName, $surveyType, $batchType, $resultsFilePath);
-        return $success;
-    }
+
+    # get real filename from neb 'key'
+    my $fpaObjects = $ipprc->filename("PSASTRO.OUTPUT",$nebPath) or return 0;
+    my $realFile = $ipprc->file_resolve($fpaObjects) or return 0;
+
+    # now write the path to this file out to temp file
+    my ($tempFile, $tempName) = tempfile( "/tmp/ippToPsps_inputFileList.XXXX", UNLINK => !$save_temps);
+    print $tempFile $realFile . "\n";
+    close $tempFile;
+
+    $success = runProgram($tempName, $outputPath, $expId, $expName, $surveyType, $batchType, $resultsFilePath);
+    return $success;
 }
 
