Index: trunk/ippToPsps/perl/ippToPsps_run.pl
===================================================================
--- trunk/ippToPsps/perl/ippToPsps_run.pl	(revision 28842)
+++ trunk/ippToPsps/perl/ippToPsps_run.pl	(revision 28849)
@@ -18,6 +18,7 @@
 my $camera = 'GPC1';
 my $batchType = undef;
-my $survey = undef;
-my $dvodb = undef;
+my $dvoPath = undef;
+my $dvoDb = undef;
+my $fullDvoPath = undef;
 my $verbose = undef;
 my $save_temps = undef; 
@@ -34,6 +35,6 @@
         'output|o=s' => \$output,
         'batch|b=s' => \$batchType,
-        'dvodb|d=s' => \$dvodb,
-        'survey|s=s' => \$survey,
+        'dvopath=s' => \$dvoPath,
+        'dvodb|d=s' => \$dvoDb,
         'expid|e=s' => \$singleExpId,
         'product|p=s' => \$datastoreProduct,
@@ -49,29 +50,56 @@
 print "* \n";
 if (@ARGV) {
-    print "* UNKNKOWN: option                          @ARGV\n"; $quit=1;}
+    $quit=1;
+    print "* UNKNKOWN: option                          @ARGV\n";
+}
 if (!defined $output) {
-    print "* REQUIRED: need to provide an output path  -o <path>\n"; $quit=1;}
+    $quit=1;
+    print "* REQUIRED: need to provide an output path  -o <path>\n";
+}
 if (!defined $batchType) {
-    print "* REQUIRED: need to define a batch type     -b <init|det|diff|stack>\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|M31|MD01|MD02|etc> ***OR***\n";
-    print "*           an exposure ID                  -e <expID>\n"; $quit=1;}
+    $quit=1;
+    print "* REQUIRED: need to define a batch type     -b <init|det|diff|stack>\n";
+}
+if (!defined $dvoDb) {
+    $quit=1;
+    print "* REQUIRED: need to provide a DVO Db name   -d <name>\n";
+}
+if (!defined $dvoPath) {
+    $dvoPath="/data/ipp037.0/gpc1/catdirs";
+    print "* OPTIONAL: path to DVO Db                  -dvopath <path>      default = '$dvoPath'\n";
+}
+if (!defined $singleExpId) {
+
+    print "* OPTIONAL: an single exposure ID           -e <expID>           default = none\n";
+}
 if (!defined $datastoreProduct) {
-    print "* OPTIONAL: datastore product               -p <product>\n";}
+
+    print "* OPTIONAL: datastore product               -p <product>         default = none (i.e. data will not be published)\n";
+}
 if (!defined $verbose) {
-    print "* OPTIONAL: run in verbose mode             -v\n"; $verbose = 0;}
+    $verbose = 0;
+    print "* OPTIONAL: run in verbose mode             -v                   default = $verbose\n";
+}
 if (!defined $save_temps) {
-    print "* OPTIONAL: keep temp files                 -t\n"; $save_temps = 0;}
+    $save_temps = 0;
+    print "* OPTIONAL: keep temp files                 -t                   default = $save_temps\n";
+}
 if (!defined $no_update) {
-    print "* OPTIONAL: don't update database           -u\n"; $no_update = 0;}
+    $no_update = 0;
+    print "* OPTIONAL: don't update database           -u                   default = $no_update\n";
+}
 if (!defined $force) {
-    print "* OPTIONAL: force if already processed      -f\n"; $force = 0;}
+    $force = 0;
+    print "* OPTIONAL: force if already processed      -f                   default = $force\n";
+}
 if (!defined $dontTarNZip) {
-    print "* OPTIONAL: don't tar and zip output        -z\n"; $dontTarNZip = 0;}
-    print "*\n*******************************************************************************\n";
+    $dontTarNZip = 0;
+    print "* OPTIONAL: don't tar and zip output        -z                   default = $dontTarNZip\n";
+}
+print "*\n*******************************************************************************\n";
 
 if ($quit) { exit; }
+
+$fullDvoPath = $dvoPath . "/" . $dvoDb;
 
 my $gpc1Db = new ippToPsps::Gpc1Db("gpc1", "ippdb01", "ippuser", "ippuser", $verbose, $save_temps);
@@ -85,5 +113,7 @@
 if ($batchType eq "init") {$initBatch = 1;}
 else {$initBatch = 0;}
-process();
+
+if (!process()) {print "* Finished unsuccessfully\n";}
+else {print "* Finished successfully\n";}
 
 #######################################################################################
@@ -114,16 +144,22 @@
     my ($resultsFile, $resultsFilePath) = tempfile( "/tmp/ippToPsps_results.XXXX", UNLINK => !$save_temps);
     my $lastExpId = $ippToPspsDb->getLastExpId();
-    my $rows = undef;
+    my $exposures;
 
     my $query;
     if ($initBatch) {
-   
-        my @row = (0, 'NULL', 'ThreePi');
-        @{$rows} = (\@row);
-    }
-    elsif ($singleExpId) {$rows = $gpc1Db->getSingleExposureInfo($singleExpId);}
-    else {$rows = $gpc1Db->getExposureListFromSurvey($survey);}
-
-# TODO check if there are no exposures and give a warning
+
+        my @exposure = (0, 'NULL', 'ThreePi');
+        @{$exposures} = (\@exposure);
+    }
+    # get single exposure
+    elsif ($singleExpId) {
+       
+        if (!$gpc1Db->getSingleExposureFromDvoDb($dvoDb, $singleExpId, \$exposures)) {return 0;}
+    }
+    # get all exposures in this DVO Db
+    else {
+        
+        if (!$gpc1Db->getExposureListFromDvoDb($dvoDb, \$exposures)) {return 0;}
+    }
 
     my $batchId = 0;
@@ -132,17 +168,12 @@
 
     #my $batchId = -1;
-    my $row;
-    foreach $row ( @{$rows} ) {
-        my ($expId, $expName, $distGroup) = @{$row};
-    #        print "JHGHGHGHGH2 $expId, $expName, $distGroup\n";
-
-    # loop round exposures
-    #while (my @row = $query->fetchrow_array()) {
-     #   my ($expId, $expName, $distGroup) = @row;
+    my $exposure;
+    foreach $exposure ( @{$exposures} ) {
+        my ($expId, $expName, $distGroup) = @{$exposure};
 
         if (!$initBatch && $ippToPspsDb->isExposureAlreadyProcessed($expId)) {
-                
-                if ($force) {print "* Forcing....\n";} 
-                else {next};
+
+            if ($force) {print "* Forcing....\n";} 
+            else {next};
         }
 
@@ -457,5 +488,5 @@
     my ($expId, $expName, $surveyType, $outputPath, $resultsFilePath) = @_;
 
-    my $nebPath = $gpc1Db->getCameraStageSmf($expId);
+    my $nebPath = $gpc1Db->getCameraStageSmfForThisDvoDb($dvoDb, $expId);
     if (!$nebPath) { return 0; }
 
@@ -527,7 +558,7 @@
     $command .= " -input $input";
     $command .= " -output $output";
-    $command .= " -D CATDIR $dvodb";
+    $command .= " -D CATDIR $fullDvoPath";
     $command .= " -config ../config"; # TODO
-    $command .= " -expid $expid";
+        $command .= " -expid $expid";
     $command .= " -expname $expName";
     $command .= " -survey $surveyType";
