Index: trunk/ippToPsps/perl/checkOdmStatus.pl
===================================================================
--- trunk/ippToPsps/perl/checkOdmStatus.pl	(revision 29186)
+++ trunk/ippToPsps/perl/checkOdmStatus.pl	(revision 29187)
@@ -10,5 +10,5 @@
 use ippToPsps::IppToPspsDb;
 use ippToPsps::Datastore;
-use ippToPsps::BatchManager;
+use ippToPsps::Batch;
 
 my $singleBatch = undef;
@@ -19,4 +19,5 @@
 my $product = undef;
 my $filePath = undef;
+my $removeUnprocessed = undef;
 
 
@@ -27,4 +28,5 @@
         'product|p=s' => \$product,
         'location|l=s' => \$filePath,
+        'remove|r' => \$removeUnprocessed,
         'verbose|v' => \$verbose,
         'save_temps|s' => \$save_temps
@@ -32,27 +34,31 @@
 
 if (!defined $product) {
-    print "* OPTIONAL: a datastore product name        -p <name>\n";
+    print "* OPTIONAL: a datastore product name            -p <name>\n";
 }
 if (!defined $singleBatch) {
-    print "* OPTIONAL: a single batch                  -b <batchNum>        (default = none)\n";
+    print "* OPTIONAL: a single batch                      -b <batchNum>        (default = none)\n";
 }
 if (!defined $fromTime) {
     $fromTime = "2010-01-01";
-    print "* OPTIONAL: from time                       -f <dateTime>        (default = $fromTime)\n";
+    print "* OPTIONAL: from time                           -f <dateTime>        (default = $fromTime)\n";
 }
 if (!defined $toTime) {
     $toTime = "2099-12-31";
-    print "* OPTIONAL: to time                         -t <dateTime>        (default = $toTime)\n";
+    print "* OPTIONAL: to time                             -t <dateTime>        (default = $toTime)\n";
 }
 if (!defined $filePath) {
     print "* OPTIONAL: location for files to be deleted    -l <path>\n";
 }
+if (!defined $removeUnprocessed) {
+    $removeUnprocessed = 0;
+    print "* OPTIONAL: remove unprocessed files            -r                   (default = $removeUnprocessed)\n";
+}
 if (!defined $verbose) {
     $verbose = 0;
-    print "* OPTIONAL: run in verbose mode             -v                   (default = $verbose)\n";
+    print "* OPTIONAL: run in verbose mode                 -v                   (default = $verbose)\n";
 }
 if (!defined $save_temps) {
     $save_temps = 0;
-    print "* OPTIONAL: keep temp files                 -t                   (default = $save_temps)\n";
+    print "* OPTIONAL: keep temp files                     -t                   (default = $save_temps)\n";
 }
 
@@ -60,5 +66,4 @@
 my $datastore = new ippToPsps::Datastore($product, 0, 0);
 my $ippToPspsDb = new ippToPsps::IppToPspsDb("ippToPsps", "ippdb01", "ipp", "ipp", $verbose, $save_temps);
-my $batchManager = new ippToPsps::BatchManager($ippToPspsDb, $filePath, $verbose, $save_temps);
 my $odmUrl = "http://web01.psps.ifa.hawaii.edu/a01/OdmWebService/OdmWebService.asmx/GetBatchStatus";
 my $ua = LWP::UserAgent->new;
@@ -96,16 +101,27 @@
     my $numDeleted = 0;
     foreach $batch ( @{$batches} ) {
-        my ($timestamp, $expId, $batchId, $surveyType, $deleted, $dvoDb, $processed, $onDatastore, $loadedToOdm, $mergeWorthy, $merged) =  @{$batch};
-
-        if (!$processed) {next;}
+        my ($timestamp, $type, $expId, $batchId, $surveyType, $deleted, $dvoDb, $processed, $onDatastore, $loadedToOdm, $mergeWorthy, $merged) =  @{$batch};
+
+        if (!$onDatastore) {next;}
+
+        my $batch = ippToPsps::Batch->existing($batchId, $ippToPspsDb, $filePath, $verbose, $save_temps);
+
+        if (!$processed) {
+
+            if ($removeUnprocessed && defined $filePath) {
+
+                if ($batch->deleteDir()) {$numDeleted++;}
+            }
+            next;
+        }
 
         $numBatchesToCheck++;
 
-        my $batchName = $batchManager->getBatchName($batchId);
 
         # if not merged then update by polling ODM for status
         if (!$merged) {
 
-            if (checkODM($batchName, \$loadedToOdm, \$mergeWorthy, \$merged)) {$numChecked++;}
+            if (checkODM($batch->getName(), \$loadedToOdm, \$mergeWorthy, \$merged)) {$numChecked++;}
+            else {next;}
         }
 
@@ -113,5 +129,5 @@
         if (defined $product && !$deleted && $loadedToOdm && $mergeWorthy) {
 
-            $deleted = $datastore->remove($batchName);
+            $deleted = $datastore->remove($batch->getName());
             if ($deleted) {
                 $ippToPspsDb->setBatchAsDeleted($batchId, $expId);
@@ -122,5 +138,5 @@
         if (defined $filePath && $merged && $deleted) {
 
-            if($batchManager->deleteBatch($batchId)) {$numDeleted++;}
+            if($batch->deleteFile($batchId)) {$numDeleted++;}
         }
 
@@ -129,5 +145,5 @@
         printf( "| %18s  | %11s  | %10d   |    %6s      |    %6s     | %6s  |  %5s   |\n", 
                 $timestamp, 
-                $batchName, 
+                $batch->getName(), 
                 $expId, 
                 $loadedToOdm ? "yes" : "no", 
Index: trunk/ippToPsps/perl/ippToPsps/Batch.pm
===================================================================
--- trunk/ippToPsps/perl/ippToPsps/Batch.pm	(revision 29187)
+++ trunk/ippToPsps/perl/ippToPsps/Batch.pm	(revision 29187)
@@ -0,0 +1,512 @@
+#!/usr/bin/perl -w
+
+package ippToPsps::Batch;
+
+use warnings;
+use strict;
+use XML::LibXML;
+use PS::IPP::Config 1.01 qw( :standard );
+use IPC::Cmd 0.36 qw( can_run run );
+use File::Basename;
+use File::Temp qw(tempfile);
+
+
+###########################################################################
+#
+# Constructor
+#
+###########################################################################
+sub existing {
+
+    my $class = shift;
+    my $self = {
+        _batchId => shift,
+        _ippToPspsDb => shift,
+        _baseDir => shift,
+        _verbose => shift,
+        _save_temps => shift,
+    };
+
+    my $batches;
+    $self->{_ippToPspsDb}->getBatch($self->{_batchId}, \$batches);
+    my $batch;
+    foreach $batch ( @{$batches} ) {
+        my ($timestamp, 
+                $type,
+                $expId, 
+                $batchId, 
+                $surveyType, 
+                $deleted,
+                $dvoDb, 
+                $processed, 
+                $onDatastore,
+                $loadedToOdm,
+                $mergeWorthy, 
+                $merged) = @{$batch};
+
+        $self->{_timestamp} = $timestamp; 
+        $self->{_type} = $type; 
+        $self->{_expId} = $expId; 
+        $self->{_batchId} = $batchId; 
+        $self->{_surveyType} = $surveyType; 
+        $self->{_deleted} = $deleted; 
+        $self->{_dvoDb} = $dvoDb; 
+        $self->{_processed} = $processed; 
+        $self->{_onDatastore} = $onDatastore; 
+        $self->{_loadedToOdm} = $loadedToOdm; 
+        $self->{_mergeWorthy} = $mergeWorthy; 
+        $self->{_merged} = $merged;
+    }
+
+    bless $self, $class;
+
+    $self->{_parentDir} = $self->{_dvoDb};
+
+    $self->init();
+    return $self;
+}
+
+###########################################################################
+#
+# Constructor
+#
+# This is the superclass of all different types of Batches, eg
+# - detections (DetectionBatch)
+# - init (InitBatch)
+# - etc
+#
+###########################################################################
+sub create {
+
+    my $class = shift;
+    my $self = {
+        _type => shift,        # batch type, IN,P2,ST...
+        _camera => shift,
+        _gpc1Db => shift,
+        _ippToPspsDb => shift,
+        _baseDir => shift,        # output path
+        _datastore => shift,
+        _expId => shift,
+        _expName => shift,
+        _dvoDb => shift,
+        _dvoPath => shift,
+        _distGroup => shift,
+        _dontTarball => shift,
+        _verbose => shift,
+        _save_temps => shift,
+    };
+
+    bless $self, $class;
+
+    # break up the DVO Db path, if provided
+    if (defined $self->{_dvoPath} && defined $self->{_dvoDb}) {
+
+        $self->{_parentDir} = $self->{_dvoDb};
+    }
+    else {
+
+        $self->{_parentDir} = ".";
+        $self->{_dvoDb} = "NULL";
+    }
+
+# create a new batch entry in the database
+    $self->{_batchId} = $self->{_ippToPspsDb}->createNewBatch(
+            $self->{_expId}, 
+            $self->{_distGroup}, 
+            $self->{_type}, 
+            $self->{_dvoDb}, 
+            (defined $self->{_datastore}) ? $self->{_datastore}->getProduct() : "NONE"
+            );
+
+# use IPP dist_group to get PSPS survey type
+    $self->{_surveyType} = $self->getSurveyTypeFromDistGroup();
+
+# can we run ippToPsps?
+    $self->{_ippToPsps} = can_run('ippToPsps') or
+        (warn "Can't find 'ippToPsps' program" and exit($PS_EXIT_CONFIG_ERROR));
+
+# get ipp config stuff
+    $self->{_ipprc} = PS::IPP::Config->new($self->{_camera}) or
+        (warn "Can't get camera configuration" and exit($PS_EXIT_CONFIG_ERROR));
+
+# set up batch output paths
+    $self->init();
+
+# make directories
+    unless(-d $self->{_typeDir}) {mkdir($self->{_typeDir}, 0777);}
+    unless(-d $self->{_subDir}) {mkdir($self->{_subDir}, 0777);}
+    mkdir($self->{_batchDir}, 0777);
+
+    $self->process();
+
+    return $self;
+}
+
+########################################################################################
+# 
+# Sets names and paths
+# 
+########################################################################################
+sub init {
+    my ($self) = @_;
+
+    $self->{_name} =  sprintf("B%08d", $self->{_batchId});
+    $self->{_filename} = "$self->{_name}.tar.gz"; 
+    $self->{_typeDir} = "$self->{_baseDir}/$self->{_type}";
+    $self->{_subDir} = "$self->{_typeDir}/$self->{_parentDir}";
+    $self->{_batchDir} = "$self->{_subDir}/$self->{_name}";
+    $self->{_tarball} = "$self->{_subDir}/$self->{_filename}";
+
+    #print "name     $self->{_name}\n";
+    #print "filename $self->{_filename}\n";
+    #print "subDir   $self->{_subDir}\n";
+    #print "batchDir $self->{_batchDir}\n";
+    #print "tarball  $self->{_tarball}\n";
+
+}
+
+#######################################################################################
+# 
+# Generates a PSPS-suitable survey 'type' from the IPP distribution group
+#
+#######################################################################################
+sub getSurveyTypeFromDistGroup {
+    my ($self) = @_;
+
+    if ($self->{_distGroup} =~ m/^MD([0-1][0-9])$/i) {return "MD$1";}
+    if ($self->{_distGroup} =~ m/^M31$/i) {return "M31";}
+    if ($self->{_distGroup} =~ m/^sts$/i) {return "STS1";}
+    if ($self->{_distGroup} =~ m/^SweetSpot$/i) {return "SSS";}
+    if ($self->{_distGroup} =~ m/^(3PI)|(ThreePi)|(SAS)$/i) {return "3PI";}
+
+    print "* Unknown distribution group: '$self->{_distGroup}'\n";
+    return undef;
+}
+
+#######################################################################################
+#
+# runs the ippToPsps program
+#
+#######################################################################################
+sub runProgram {
+    my ($self, $input, $resultsFilePath) = @_;
+
+    # build command
+    my $command = "$self->{_ippToPsps}";
+    $command .= " -input $input";
+    $command .= " -output $self->{_batchDir}";
+    if (defined $self->{_dvoPath} ) {$command .= " -D CATDIR $self->{_dvoPath}";}
+    $command .= " -config ../config"; # TODO
+    $command .= " -expid $self->{_expId}";
+    $command .= " -expname $self->{_expName}";
+    $command .= " -survey $self->{_surveyType}";
+    $command .= " -batch $self->{_type}";
+    $command .= " -results $resultsFilePath";
+
+    print "*\n*******************************************************************************\n\n";
+
+    # run command
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf )
+        = run(command => $command, verbose => $self->{_verbose});
+
+    print "\n*******************************************************************************\n\n";
+
+    return $success;
+}
+
+
+########################################################################################
+# 
+# Returns batch ID
+# 
+########################################################################################
+sub getId {
+    my ($self) = @_;
+    return $self->{_batchId};
+}
+
+########################################################################################
+# 
+# Returns batch name
+# 
+########################################################################################
+sub getName {
+    my ($self) = @_;
+    return $self->{_name};
+}
+
+########################################################################################
+# 
+# Returns name of tarred and zipped batch file
+# 
+########################################################################################
+sub getFileName {
+    my ($self) = @_;
+    return $self->{_filename};
+}
+
+########################################################################################
+# 
+# Returns full path of type dir
+# 
+########################################################################################
+sub getTypeDir {
+    my ($self) = @_;
+    return $self->{_typeDir};
+}
+
+########################################################################################
+# 
+# Returns full path of sub dir
+# 
+########################################################################################
+sub getSubDir {
+    my ($self) = @_;
+    return $self->{_subDir};
+}
+
+########################################################################################
+# 
+# Returns full path of batch dir
+# 
+########################################################################################
+sub getBatchDir {
+    my ($self) = @_;
+    return $self->{_batchDir};
+}
+
+########################################################################################
+# 
+# Returns file name of tarball 
+# 
+########################################################################################
+sub getFilename {
+    my ($self) = @_;
+    return $self->{_filename};
+}
+
+########################################################################################
+# 
+# Returns full path of tarball 
+# 
+########################################################################################
+sub getTarball {
+    my ($self) = @_;
+    return $self->{_tarball};
+}
+
+########################################################################################
+# 
+# Deletes a batch tar.gz file
+# 
+########################################################################################
+sub deleteFile {
+    my ($self) = @_;
+
+    if (! -e $self->{_tarball}) {return 0;}
+
+    my $command = "rm " . $self->{_tarball};
+    my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf) =
+        run(command => $command, verbose => $self->{_verbose});
+    if (!$success) {
+        print "* Unable to run: $command\n";
+        return 0;
+    }
+
+    return 1;
+}
+
+########################################################################################
+# 
+# Deletes batch dir 
+# 
+########################################################################################
+sub deleteDir {
+    my ($self) = @_;
+
+    if (! -e $self->{_batchDir}) {return 0;}
+    my $command = "rm -r " . $self->{_batchDir};
+
+    my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf) =
+        run(command => $command, verbose => $self->{_verbose});
+    if (!$success) {
+        print "* Unable to run: $command\n";
+        return 0;
+    }
+
+    return 1;
+}
+
+#######################################################################################
+#
+# Writes the manifest file
+#
+#######################################################################################
+sub writeManifest {
+    my ($self, $filename, $minObjId, $maxObjId) = @_;
+
+    use XML::Writer;
+    use Digest::MD5::File qw( file_md5_hex );
+
+    # sort out paths
+    my $outputPath = "$self->{_batchDir}/BatchManifest.xml";
+    my $output = new IO::File(">$outputPath");
+
+    # create a timestamp
+    my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
+    my $timeStamp = sprintf "%4d-%02d-%02d %02d:%02d:%02d", $year+1900,$mon+1,$mday,$hour,$min,$sec;
+
+    # create XML file
+    my $writer = new XML::Writer(OUTPUT => $output, DATA_MODE => 1, DATA_INDENT=>2);
+    $writer->xmlDecl('UTF-8');
+
+    # get md5sum of file
+    my $md5sum  = file_md5_hex("$self->{_batchDir}/$filename");
+
+    # get size of file in bytes
+    my $filesize = -s "$self->{_batchDir}/$filename";
+
+    # write manifest element TODO needs to be in subclass
+    if($self->{_type} eq 'P2') {
+
+        my $pspsSurvey = undef;
+        if ($self->{_surveyType} =~ m/^MD[0-1][0-9]$/i) {$pspsSurvey = "MDF";}
+        else {$pspsSurvey = $self->{_surveyType};}
+
+        $writer->startTag('manifest',
+                "name" => "$self->{_name}",
+                "type" => "$self->{_type}",
+                "survey" => $pspsSurvey,
+                "timestamp" => "$timeStamp",
+                "minObjId" => $minObjId,
+                "maxObjId" => $maxObjId);
+    }
+    else {
+
+        print "'$self->{_name}' '$self->{_type}' '$timeStamp'\n";
+
+        $writer->startTag('manifest',
+                "name" => "$self->{_name}",
+                "type" => "$self->{_type}",
+                "timestamp" => "$timeStamp");
+    }
+    # write the tag for this batch
+    $writer->startTag("file",
+            "name" => $filename,
+            "bytes" => $filesize,
+            "md5" => $md5sum);
+
+    $writer->endTag();
+    $writer->endTag();
+    $writer->end();
+
+    return 1;
+}
+
+#######################################################################################
+#
+# tar 'n zip a batch TODO handle errors
+#
+#######################################################################################
+sub createTarball {
+    my ($self) = @_;
+
+    my $tar = $self->{_name}.".tar";
+    my $tarball = "$tar.gz";
+    my $batchTar = "$self->{_batchDir}/$tar";
+
+    # tar
+    my $command = "tar -cvf $batchTar -C $self->{_subDir} $self->{_name}";
+    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => $self->{_verbose});
+    if (!$success) { print "* Unable to tar up contents of dir: ". $self->{_batchDir}. "\n" and return 0; }
+
+    # zip
+    $command = "gzip -c $batchTar  > $self->{_tarball}";
+    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => $self->{_verbose});
+    if (!$success) { print "* Unable to gzip: $batchTar\n" and return 0; }
+
+    # remove tar file
+    $command = "rm $batchTar";
+    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => $self->{_verbose});
+    if (!$success) { print "* Unable to remove: $batchTar\n" };
+
+    # remove batch dir
+    $command = "rm -r $self->{_batchDir}";
+    ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
+        run(command => $command, verbose => $self->{_verbose});
+    if (!$success) { print "* Unable to remove: $self->{_name}\n"};
+
+    return 1;
+}
+
+#######################################################################################
+#
+# Abstract method to be inherited by subclasses
+#
+#######################################################################################
+sub process {
+    my ($self) = @_;
+
+    print "* Preparing batch '$self->{_name}' for '$self->{_type}'\n";
+
+    # create temporary input file for file list
+    my ($resultsFile, $resultsFilePath) = tempfile( "/tmp/ippToPsps_results.XXXX", UNLINK => !$self->{_save_temps});
+# TODO create input file here
+    # get list of input files
+    my $inputFile = $self->createInputFileList();
+
+    # run IppToPsps program TODO should not need
+    my $success = $self->runProgram($inputFile, $resultsFilePath);
+    unlink $inputFile;
+
+    if ($success) {
+
+        # TODO type-specific processing
+        $self->parseResults($resultsFilePath);
+
+        # tar n' zip
+        if (!$self->{_dontTarball} && $self->createTarball()) {
+
+            # and publish
+            if (defined $self->{_datastore} &&
+                    $self->{_datastore}->register($self->{_name}, $self->{_subDir}, $self->{_filename}, "IPP_PSPS", "tgz")) {
+                $self->{_ippToPspsDb}->setPublished($self->{_batchId}, $self->{_expId}, 1);
+            }
+        }
+    }
+
+    close $resultsFile;
+    unlink $resultsFile;
+
+    return $success;
+}
+
+#######################################################################################
+# 
+# Abstract method to be inherited by subclasses
+# Creates an input file list for ippToPsps 
+#
+#######################################################################################
+sub createInputFileList {
+    my ($self) = @_;
+    my $thisFunction = (caller(0))[3];
+    print "* ERROR: '$thisFunction' not implemented\n";
+}
+
+#######################################################################################
+#
+# Abstract method to be inherited by subclasses
+# Deals with the results
+#
+#######################################################################################
+sub parseResults {
+    my ($self) = @_;
+
+    my $thisFunction = (caller(0))[3];
+    print "* ERROR: '$thisFunction' not implemented\n";
+}
+
+1;
Index: trunk/ippToPsps/perl/ippToPsps/BatchManager.pm
===================================================================
--- trunk/ippToPsps/perl/ippToPsps/BatchManager.pm	(revision 29186)
+++ 	(revision )
@@ -1,95 +1,0 @@
-#!/usr/bin/perl -w
-
-package ippToPsps::BatchManager;
-
-use warnings;
-use strict;
-
-use IPC::Cmd 0.36 qw( can_run run );
-
-###########################################################################
-#
-# Constructor
-#
-###########################################################################
-sub new {
-
-    my $class = shift;
-    my $self = {
-        _ippToPspsDb => shift,
-        _path => shift,
-        _verbose => shift,
-        _save_temps => shift,
-    };
-
-    bless $self, $class;
-    return $self;
-}
-
-########################################################################################
-# 
-# Returns batch name from batch_id
-# 
-########################################################################################
-sub getBatchName {
-    my ($self, $batchId) = @_;
-
-    return sprintf("B%08d", $batchId);
-}
-
-########################################################################################
-# 
-# Returns name of tarred and zipped batch file
-# 
-########################################################################################
-sub getBatchFileName {
-    my ($self, $batchId) = @_;
-
-    my $batchName = $self->getBatchName($batchId);
-    return "$batchName.tar.gz";
-}
-
-########################################################################################
-# 
-# Returns full path of batch 
-# 
-########################################################################################
-sub getFullBatchPath {
-    my ($self, $batchId) = @_;
-
-    my $batches;
-    my $numOfBatches = $self->{_ippToPspsDb}->getBatch($batchId, \$batches);
-    if ($numOfBatches < 1) {return "unknown";}
-
-    my $batch;
-    my ($timestamp, $expId, $batchIdi, $surveyType, $deleted, $dvoDb, $processed, $onDatastore, $loadedToOdm, $mergeWorthy, $merged);
-    foreach $batch ( @{$batches} ) {
-        ($timestamp, $expId, $batchIdi, $surveyType, $deleted, $dvoDb, $processed, $onDatastore, $loadedToOdm, $mergeWorthy, $merged) =  @{$batch};
-
-
-    }
-
-    my $batchFile = $self->getBatchFileName($batchId);
-    return "$self->{_path}/$dvoDb/$batchFile";
-}
-
-########################################################################################
-# 
-# Deletes a batch 
-# 
-########################################################################################
-sub deleteBatch {
-    my ($self, $batchId) = @_;
-
-    my $command = "rm " . $self->getFullBatchPath($batchId);
-    my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf) =
-        run(command => $command, verbose => $self->{_verbose});
-    if (!$success) {
-        print "* Unable to run: $command\n";
-        return 0;
-    }
-
-    return 1;
-}
-
-1;
Index: trunk/ippToPsps/perl/ippToPsps/DetectionBatch.pm
===================================================================
--- trunk/ippToPsps/perl/ippToPsps/DetectionBatch.pm	(revision 29187)
+++ trunk/ippToPsps/perl/ippToPsps/DetectionBatch.pm	(revision 29187)
@@ -0,0 +1,94 @@
+#!/usr/bin/perl -w
+
+package ippToPsps::DetectionBatch;
+
+use warnings;
+use strict;
+use File::Basename;
+use File::Temp qw(tempfile);
+use XML::LibXML;
+
+use ippToPsps::Batch;
+our @ISA = qw(ippToPsps::Batch);    # inherits from Batch class
+
+###########################################################################
+#
+# Constructor (overrides superclass)
+#
+###########################################################################
+sub new {
+    my ($class) = @_;
+
+    # Call the constructor of the parent class
+    my $self = $class->SUPER::create(
+            "P2",   # type 
+            $_[1],  # camera
+            $_[2],  # gpc1Db
+            $_[3],  # ippToPspsDb
+            $_[4],  # path
+            $_[5],  # datastore
+            $_[6],  # expId
+            $_[7],  # expName
+            $_[8],  # dvoDb
+            $_[9],  # dvoPath
+            $_[10], # distGroup
+            $_[11], # dontTarBall
+            $_[12], # verbose
+            $_[13]  # save_temps
+            );
+
+    bless $self, $class;
+    return $self;
+}
+
+#######################################################################################
+# 
+# Creates an input file list for ippToPsps 
+#
+#######################################################################################
+sub createInputFileList {
+    my ($self) = @_;
+
+    my $nebPath = $self->{_gpc1Db}->getCameraStageSmfForThisDvoDb($self->{_dvoDb}, $self->{_expId});
+    if (!$nebPath) { return 0; }
+
+    # get real filename from neb 'key'
+    my $fpaObjects = $self->{_ipprc}->filename("PSASTRO.OUTPUT",$nebPath) or return 0;
+    my $realFile = $self->{_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 => !$self->{_save_temps});
+    print $tempFile $realFile . "\n";
+    close $tempFile;
+
+    return $tempName;
+}
+
+#######################################################################################
+#
+# Deals with results from processing, writes to Db and writes manifest file
+#
+#######################################################################################
+sub parseResults {
+    my ($self, $resultsFilePath) = @_;
+
+    my($filename, $minObjId, $maxObjId, $totalDetections);
+
+    # read results of FITS creation from XML file
+    my $parser = XML::LibXML->new;
+    my $doc = $parser->parse_file($resultsFilePath);
+    $filename = $doc->findvalue('//filename');
+    $minObjId = $doc->findvalue('//minObjID');
+    $maxObjId = $doc->findvalue('//maxObjID');
+    $totalDetections = $doc->findvalue('//totalDetections');
+
+    # write results to database
+    $self->{_ippToPspsDb}->setAsProcessed($self->{_batchId}, $self->{_expId}, $totalDetections, $minObjId, $maxObjId);
+
+    # write batch manifest
+    if (!$self->writeManifest($filename, $minObjId, $maxObjId)) {return 0;}
+
+    return 1;
+}
+1;
+
Index: trunk/ippToPsps/perl/ippToPsps/IppToPsps.pm
===================================================================
--- trunk/ippToPsps/perl/ippToPsps/IppToPsps.pm	(revision 29186)
+++ 	(revision )
@@ -1,43 +1,0 @@
-#!/usr/bin/perl -w
-
-use warnings;
-use strict;
-use DBI;
-
-package ippToPsps::IppToPsps;
-
-###########################################################################
-#
-# Constructor
-#
-###########################################################################
-sub new {
-
-    my $class = shift;
-    my $self = {
-        _dbName => shift,
-        _dbHost => shift,
-        _dbUser => shift,
-        _dbPass => shift,
-        _verbose => shift,
-    };
-
-    my $dbname = $self->{_dbName};
-    my $dbhost = $self->{_dbHost};
-    my $dbuser = $self->{_dbUser};
-    my $dbpass = $self->{_dbPass};
-
-    use constant DB_SOCKET => '/var/run/mysqld/mysqld.sock';
-
-    $self->{_db} = DBI->connect("DBI:mysql:database=${dbname};host=${dbhost};" .
-            "mysql_socket=" . DB_SOCKET(),
-            ${dbuser},${dbpass},
-            { RaiseError => 1, AutoCommit => 1}
-            );
-
-    if ($self->{_verbose}) {printf("* Connection to " . $dbname . "@" . $dbhost . ": %s\n", $self->{_db} ? "success" : "FAILED ($DBI::errstr)");}
-
-    bless $self, $class;
-    return $self;
-}
-
