IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 19, 2010, 6:50:13 PM (16 years ago)
Author:
eugene
Message:

updates from trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20100621/ippToPsps/perl/ippToPsps_run.pl

    r28794 r28980  
    66use PS::IPP::Config 1.01 qw( :standard );
    77use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
    8 use Pod::Usage qw( pod2usage );
    98use IPC::Cmd 0.36 qw( can_run run );
    109use File::Temp qw(tempfile);
    1110use XML::LibXML;
     11use File::Basename;
    1212
    1313# local classes
    1414use ippToPsps::Gpc1Db;
    1515use ippToPsps::IppToPspsDb;
     16use ippToPsps::Datastore;
    1617
    1718# globals
    1819my $camera = 'GPC1';
    1920my $batchType = undef;
    20 my $survey = undef;
    21 my $dvodb = undef;
     21my $dvoLocation = undef;
     22my $dvoDb = undef;
     23my $fullDvoPath = undef;
    2224my $verbose = undef;
    2325my $save_temps = undef;
    24 my $no_update = undef;
    2526my $output = undef;
    2627my $singleExpId = undef;
     
    3435        'output|o=s' => \$output,
    3536        'batch|b=s' => \$batchType,
    36         'dvodb|d=s' => \$dvodb,
    37         'survey|s=s' => \$survey,
     37        'dvo|d=s' => \$fullDvoPath,
    3838        'expid|e=s' => \$singleExpId,
    3939        'product|p=s' => \$datastoreProduct,
    4040        'verbose|v' => \$verbose,
    4141        'save_temps|t' => \$save_temps,
    42         'no-update|u' => \$no_update,
    4342        'force|f' => \$force,
    4443        'tarnzip|z' => \$dontTarNZip,
     
    4948print "* \n";
    5049if (@ARGV) {
    51     print "* UNKNKOWN: option:                         @ARGV\n"; $quit=1;}
     50    $quit=1;
     51    print "* UNKNKOWN: option                          @ARGV\n";
     52}
    5253if (!defined $output) {
    53     print "* REQUIRED: need to provide an output path: -o <path>\n"; $quit=1;}
     54    $quit=1;
     55    print "* REQUIRED: need to provide an output path  -o <path>\n";
     56}
    5457if (!defined $batchType) {
    55     print "* REQUIRED: need to define a batch type:    -b <init|det|diff|stack>\n"; $quit=1;}
    56 if (!defined $dvodb) {
    57     print "* REQUIRED: need to provide a DVO Db path:  -d <path>\n"; $quit=1;}
    58 if (!defined $survey and !defined $singleExpId) {
    59     print "* REQUIRED: need to provide a survey type:  -s <ThreePi|STS|SAS|M31|MD01|MD02|etc> ***OR***\n";
    60     print "*           an exposure ID                  -e <expID>\n"; $quit=1;}
     58    $quit=1;
     59    print "* REQUIRED: need to define a batch type     -b <init|det|diff|stack>\n";
     60}
     61if (!defined $fullDvoPath) {
     62    $quit=1;
     63    print "* REQUIRED: need to provide a DVO Db        -d <pathToDVO>\n";
     64}
     65if (!defined $singleExpId) {
     66
     67    print "* OPTIONAL: a single exposure ID            -e <expID>           (default = none)\n";
     68}
    6169if (!defined $datastoreProduct) {
    62     print "* OPTIONAL: datastore product:              -p <product>\n";}
     70
     71    print "* OPTIONAL: datastore product               -p <product>         (default = none, i.e. data will not be published)\n";
     72}
    6373if (!defined $verbose) {
    64     print "* OPTIONAL: run in verbose mode:            -v\n"; $verbose = 0;}
     74    $verbose = 0;
     75    print "* OPTIONAL: run in verbose mode             -v                   (default = $verbose)\n";
     76}
    6577if (!defined $save_temps) {
    66     print "* OPTIONAL: keep temp files:                -t\n"; $save_temps = 0;}
    67 if (!defined $no_update) {
    68     print "* OPTIONAL: don't update database:          -u\n"; $no_update = 0;}
     78    $save_temps = 0;
     79    print "* OPTIONAL: keep temp files                 -t                   (default = $save_temps)\n";
     80}
    6981if (!defined $force) {
    70     print "* OPTIONAL: force if already processed :    -f\n"; $force = 0;}
     82    $force = 0;
     83    print "* OPTIONAL: force if already processed      -f                   (default = $force)\n";
     84}
    7185if (!defined $dontTarNZip) {
    72     print "* OPTIONAL: don't tar and zip output :      -z\n"; $dontTarNZip = 0;}
    73     print "*\n*******************************************************************************\n";
     86    $dontTarNZip = 0;
     87    print "* OPTIONAL: don't tar and zip output        -z                   (default = $dontTarNZip)\n";
     88}
     89print "*\n*******************************************************************************\n";
    7490
    7591if ($quit) { exit; }
     92
     93# determine PSPS batch 'type'
     94my $pspsBatchType;
     95if ($batchType eq 'init') {$pspsBatchType = "IN";}
     96elsif ($batchType eq 'det') {$pspsBatchType = "P2";}
     97elsif ($batchType eq 'stack') {$pspsBatchType = "ST";}
     98elsif ($batchType eq 'diff') {$pspsBatchType = "OB";}
     99else {$pspsBatchType = "UNKNOWN";}
     100
     101# spilt full DVO path into Db and path
     102$fullDvoPath =~ s/\/$//; # strip off trailing '\'
     103($dvoDb, $dvoLocation) = fileparse($fullDvoPath);
    76104
    77105my $gpc1Db = new ippToPsps::Gpc1Db("gpc1", "ippdb01", "ippuser", "ippuser", $verbose, $save_temps);
    78106my $ippToPspsDb = new ippToPsps::IppToPspsDb("ippToPsps", "ippdb01", "ipp", "ipp", $verbose, $save_temps);
     107my $datastore = undef;
     108if ($datastoreProduct) {$datastore = new ippToPsps::Datastore($datastoreProduct, $verbose, $save_temps);}
    79109
    80110# check we can run programs and get camera config
    81111my $ippToPsps = can_run('ippToPsps') or (warn "Can't find 'ippToPsps' program" and exit($PS_EXIT_CONFIG_ERROR));
    82 my $dsreg = can_run('dsreg') or (warn "Can't find 'dsreg' program" and exit($PS_EXIT_CONFIG_ERROR));
    83112my $ipprc = PS::IPP::Config->new($camera) or (warn "Can't get camera configuration" and exit($PS_EXIT_CONFIG_ERROR));
    84113
    85114if ($batchType eq "init") {$initBatch = 1;}
    86115else {$initBatch = 0;}
    87 process();
     116
     117if (!process()) {print "* Finished unsuccessfully\n";}
     118else {print "* Finished successfully\n";}
    88119
    89120#######################################################################################
     
    114145    my ($resultsFile, $resultsFilePath) = tempfile( "/tmp/ippToPsps_results.XXXX", UNLINK => !$save_temps);
    115146    my $lastExpId = $ippToPspsDb->getLastExpId();
    116     my $rows = undef;
     147    my $exposures;
    117148
    118149    my $query;
    119150    if ($initBatch) {
    120    
    121         my @row = (0, 'NULL', 'ThreePi');
    122         @{$rows} = (\@row);
    123     }
    124     elsif ($singleExpId) { $rows = $gpc1Db->getExposureListFromExpId($singleExpId); }
    125     else { $rows = $gpc1Db->getExposureListFromSurvey($survey); }
    126 
    127 # TODO check if there are no exposures and give a warning
     151
     152        my @exposure = (0, 'NULL', 'ThreePi');
     153        @{$exposures} = (\@exposure);
     154    }
     155    # get single exposure
     156    elsif ($singleExpId) {
     157       
     158        if (!$gpc1Db->getSingleExposureFromDvoDb($dvoDb, $singleExpId, \$exposures)) {return 0;}
     159    }
     160    # get all exposures in this DVO Db
     161    else {
     162       
     163        if (!$gpc1Db->getExposureListFromDvoDb($dvoDb, \$exposures)) {return 0;}
     164    }
    128165
    129166    my $batchId = 0;
     
    132169
    133170    #my $batchId = -1;
    134     my $row;
    135     foreach $row ( @{$rows} ) {
    136         my ($expId, $expName, $distGroup) = @{$row};
    137     #        print "JHGHGHGHGH2 $expId, $expName, $distGroup\n";
    138 
    139     # loop round exposures
    140     #while (my @row = $query->fetchrow_array()) {
    141      #   my ($expId, $expName, $distGroup) = @row;
     171    my $exposure;
     172    foreach $exposure ( @{$exposures} ) {
     173        my ($expId, $expName, $distGroup) = @{$exposure};
    142174
    143175        if (!$initBatch && $ippToPspsDb->isExposureAlreadyProcessed($expId)) {
    144                
    145                 if ($force) {print "* Forcing....\n";}
    146                 else {next};
     176
     177            if ($force) {print "* Forcing....\n";}
     178            else {next};
    147179        }
    148180
     
    150182        if (!$surveyType) {next;}
    151183
    152         $batchId = $ippToPspsDb->getNewBatchId($expId, $surveyType, $batchType);
     184        $batchId = $ippToPspsDb->createNewBatch($expId, $distGroup, $pspsBatchType, $dvoDb, (defined $datastore) ? $datastoreProduct : "NONE");
    153185
    154186        # TODO quit here if no sensible batch ID
     
    156188        # generate batch path from batch IDs
    157189        my $batch = sprintf("B%08d", $batchId);
    158         my $batchDir = sprintf("$output/$batch");
     190        my $dvoDir = "$output/$dvoDb";
     191        my $batchDir = "$dvoDir/$batch";
     192
     193        # make directories
     194        unless(-d $dvoDir) {mkdir($dvoDir, 0777);}
    159195        mkdir($batchDir, 0777);
     196
    160197        $published = 0;
    161198
     
    171208            if (writeBatchManifest($batchDir, $batch, $batchType, $surveyType, $filename, $minObjId, $maxObjId)) {
    172209
     210                # tar n' zip
    173211                if (!$dontTarNZip) {
    174                     my $tarball = tarAndZipBatch($output, $batch);
    175                     if ($tarball && $datastoreProduct && publishToDatastore($batch, $output, $tarball)) {$published = 1;}
     212                    my $tarball = tarAndZipBatch($dvoDir, $batch);
     213
     214                    # and publish
     215                    if ($tarball && defined $datastore ) {
     216                       
     217                        $published = $datastore->register($batch, $dvoDir, $tarball, "IPP_PSPS", "tgz");
     218                    }
    176219                }
    177220            }
    178221
    179             $ippToPspsDb->updateDb($batchId, $expId, 1, $published, $totalDetections);
     222            $ippToPspsDb->updateBatch($batchId, $expId, 1, $published, $totalDetections, $minObjId, $maxObjId);
    180223        }
    181224
     
    330373    my $timeStamp = sprintf "%4d-%02d-%02d %02d:%02d:%02d", $year+1900,$mon+1,$mday,$hour,$min,$sec;
    331374
    332     # determine batch 'type'
    333     my $type;
    334     if ($batchType eq 'init') {$type = "IN";}
    335     elsif ($batchType eq 'det') {$type = "P2";}
    336     elsif ($batchType eq 'stack') {$type = "ST";}
    337     elsif ($batchType eq 'diff') {$type = "OB";}
    338     else {$type = "UNKNOWN";}
    339 
    340375    # create XML file
    341376    my $writer = new XML::Writer(OUTPUT => $output, DATA_MODE => 1, DATA_INDENT=>2);
     
    372407                $writer->startTag('manifest',
    373408                        "name" => "$batch",
    374                         "type" => $type,
     409                        "type" => $pspsBatchType,
    375410                        "survey" => $pspsSurvey,
    376411                        "timestamp" => "$timeStamp",
     
    382417                $writer->startTag('manifest',
    383418                        "name" => "$batch",
    384                         "type" => $type,
     419                        "type" => $pspsBatchType,
    385420                        "timestamp" => "$timeStamp");
    386421            }
     
    404439
    405440#######################################################################################
    406 #
    407 # register new job with the datastore
    408 #
    409 ########################################################################################
    410 sub publishToDatastore {
    411     my ($batch, $path, $tarball) = @_;
    412 
    413     my ($tempFile, $tempName) = tempfile( "/tmp/ippToPsps_dsregList.XXXX", UNLINK => !$save_temps);
    414 
    415     print $tempFile $tarball . '|||tgz' . "\n";
    416 
    417     # build dsreg command command
    418     my $command  = "$dsreg";
    419     $command .= " --add $batch";
    420     $command .= " --copy";
    421     $command .= " --datapath $path";
    422     $command .= " --type IPP_PSPS";
    423     $command .= " --product $datastoreProduct";
    424     $command .= " --list $tempName";
    425 
    426     # run command
    427     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    428         run(command => $command, verbose => $verbose);
    429 
    430     if (!$success) { print "* Unable to publish $tarball to datastore\n" and return 0 };
    431 
    432     print "* Successfully published $tarball to datastore\n";
    433 
    434     close($tempFile);
    435 
    436     return 1;
    437 }
    438 
    439 #######################################################################################
    440441#
    441442# runs ippToPsps to produce init batch
     
    457458    my ($expId, $expName, $surveyType, $outputPath, $resultsFilePath) = @_;
    458459
    459     my $nebPath = $gpc1Db->getCameraStageSmf($expId);
     460    my $nebPath = $gpc1Db->getCameraStageSmfForThisDvoDb($dvoDb, $expId);
    460461    if (!$nebPath) { return 0; }
    461462
     
    527528    $command .= " -input $input";
    528529    $command .= " -output $output";
    529     $command .= " -D CATDIR $dvodb";
     530    $command .= " -D CATDIR $fullDvoPath";
    530531    $command .= " -config ../config"; # TODO
    531     $command .= " -expid $expid";
     532        $command .= " -expid $expid";
    532533    $command .= " -expname $expName";
    533534    $command .= " -survey $surveyType";
Note: See TracChangeset for help on using the changeset viewer.