IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 18, 2010, 12:49:05 PM (16 years ago)
Author:
eugene
Message:

merging changes from trunk into branches/pap

Location:
branches/pap
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/pap

  • branches/pap/ippToPsps/scripts/ippToPsps_run.pl

    r27699 r28003  
    1212
    1313# globals
    14 my ($verbose, $save_temps, $no_op, $no_update, $camera, $product, $output, $dvodb, $label, $singleExpId, $no_publish);
     14my ($verbose, $save_temps, $no_op, $no_update, $camera, $batchType, $output, $dvodb, $datastoreProduct, $label, $singleExpId, $no_publish);
    1515
    1616# TODO temporary until we use database to store current jobid
     
    2626$output = undef;
    2727$singleExpId = undef;
     28$datastoreProduct = "PSPS_test";
    2829
    2930# get user args
    3031GetOptions(
    3132        'output|o=s' => \$output,
    32         'product|p=s' => \$product,
     33        'batch|b=s' => \$batchType,
    3334        'dvodb|d=s' => \$dvodb,
    3435        'label|l=s' => \$label,
    3536        'expid|e=s' => \$singleExpId,
     37        'product|p=s' => \$datastoreProduct,
    3638        'no_publish' => \$no_publish,
    3739        'verbose|v' => \$verbose,
     
    4648pod2usage(
    4749        -msg => "\n   Required options:\n\n".
    48         "--product <init|det|diff|stack>\n".
     50        "--batch <init|det|diff|stack>\n".
    4951        "--output <path>\n".
    50         "--label <label> | --expid <expid>\n" .
    51         "--dvodb <path>\n\n",
     52        "--label <label> or --expid <expid>\n" .
     53        "--dvodb <path>\n".
     54        "\n   Optional:\n\n".
     55        "--product <datastoreProduct>\n".
     56        "--no_publish - won't publish to datastore\n".
     57        "--save_temps - will save temporary files\n".
     58        "--no-op - ?\n".
     59        "--no-update - will not update database\n",
    5260        -exitval => 3
    5361        ) unless
    54 defined $product and
     62defined $batchType and
    5563defined $output and
    5664defined $dvodb and
     
    6876
    6977close $resultsFile;
     78
     79#######################################################################################
     80#
     81# Generates a PSPS-suitable survey 'type' from the IPP distribution group
     82#
     83#######################################################################################
     84sub getSurveyTypeFromDistGroup {
     85    my ($distGroup) = @_;
     86
     87    if ($distGroup eq "MD01") {return $distGroup;}
     88    if ($distGroup eq "MD02") {return $distGroup;}
     89    if ($distGroup eq "MD03") {return $distGroup;}
     90    if ($distGroup eq "MD04") {return $distGroup;}
     91    if ($distGroup eq "MD05") {return $distGroup;}
     92    if ($distGroup eq "MD06") {return $distGroup;}
     93    if ($distGroup eq "MD07") {return $distGroup;}
     94    if ($distGroup eq "MD08") {return $distGroup;}
     95    if ($distGroup eq "MD09") {return $distGroup;}
     96    if ($distGroup eq "MD10") {return $distGroup;}
     97    if ($distGroup eq "M31") {return $distGroup;}
     98    if ($distGroup eq "sts") {return "STS";}
     99    if ($distGroup eq "SweetSpot") {return "SS";}
     100    if ($distGroup eq "3PI") {return $distGroup;}
     101    if ($distGroup eq "ThreePi") {return "3PI";}
     102    if ($distGroup eq "SAS") {return "3PI";}
     103
     104    print "* Do not understand distribution group: '$distGroup'\n";
     105    return undef;
     106}
    70107
    71108#######################################################################################
     
    91128
    92129        # query to retrieve all exposures with the provided label
    93         $query =
    94             "SELECT DISTINCT rawExp.exp_id ".
    95             "FROM camRun, chipRun, rawExp ".
    96             "WHERE camRun.chip_id = chipRun.chip_id ".
    97             "AND chipRun.exp_id = rawExp.exp_id ".
    98             "AND camRun.label like '%$label%' ".
    99             #    "AND rawExp.decl >= '-0.157079633' AND rawExp.decl <= '0.157079633' ". # TODO Jim's decl range
    100             "ORDER BY rawExp.exp_id ASC";
     130        $query = $db->prepare(<<SQL);
     131
     132        SELECT DISTINCT rawExp.exp_id, camRun.dist_group
     133            FROM camRun, chipRun, rawExp
     134            WHERE camRun.chip_id = chipRun.chip_id
     135            AND chipRun.exp_id = rawExp.exp_id
     136            AND camRun.label LIKE '%$label%'
     137            ORDER BY rawExp.exp_id ASC
     138SQL
     139            #AND rawExp.exp_id > 136561
     140            #AND camRun.dist_group LIKE 'sas'
     141            #AND rawExp.decl >= '-0.157079633' AND rawExp.decl <= '0.157079633' Jims Dec range
    101142    }
    102143    else {
    103144
    104         $query = "SELECT DISTINCT exp_id FROM rawExp WHERE rawExp.exp_id = $singleExpId"
    105 
    106     }
    107 
    108     if ($verbose) { print"$query\n";}
     145        $query = $db->prepare(<<SQL);
     146
     147        SELECT DISTINCT rawExp.exp_id, dist_group FROM rawExp, chipRun WHERE chipRun.exp_id = rawExp.exp_id AND rawExp.exp_id = $singleExpId
     148SQL
     149    }
    109150
    110151    my $batchId = 0;
     
    114155    my $jobId = getJobId();
    115156    $jobId++;
    116     if ($jobId < 0) { print "Cannot find sensible jobId ($jobId)\n";
     157    if ($jobId < 0) { print "* Cannot find sensible jobId ($jobId)\n";
    117158        return 0;
    118159    }
    119160
    120     print "------------------------------------------------------------------------------------------\n\n";
     161    print "*******************************************************************************\n*\n";
    121162
    122163    my $anyBatches = 0;
    123164
     165
     166    $query->execute;
     167
    124168    # loop round exposures
    125     my $expResults = $db->selectall_arrayref( $query );
    126 
    127     for my $expRow (@$expResults) {
    128 
    129         my ($expId) = @$expRow;
    130 
    131         print "      *** Exposure ID = $expId ***\n";
     169    while (my @row = $query->fetchrow_array()) {
     170        my ($expId, $distGroup) = @row;
     171
     172        print "* Exposure ID = $expId with dist group = '$distGroup'\n";
     173
     174        my $surveyType = getSurveyTypeFromDistGroup($distGroup);
     175
     176        if (!$surveyType) {next;}
     177        print "* Using survey type of $surveyType\n";
    132178
    133179        # generate batch and job paths from job and batch IDs
     
    137183        my $batchOutputPath = sprintf("$jobOutputPath/%s", $batchDir);
    138184
    139         print "Preparing job '$job'...\n";
     185        print "* Preparing exposure $expId as job '$job'...\n";
    140186
    141187        # make directories
    142188        mkdir($jobOutputPath, 0777);
    143189        mkdir($batchOutputPath, 0777);
     190        setJobId($jobId);
    144191
    145192        # run IppToPsps program
    146         if (runIppToPsps($db, $expId, $batchOutputPath, $product)) {
     193        if (runIppToPsps($db, $expId, $batchOutputPath, $batchType)) {
    147194
    148195            # write batch manifest and tar and zip up
    149             if (writeBatchManifest($batchOutputPath, $batchDir, $product)) {
     196            if (writeBatchManifest($batchOutputPath, $batchDir, $batchType)) {
    150197
    151198                if (tarAndZipDirectory($jobOutputPath, $batchDir)) {
     
    161208            elsif ($anyBatches) {
    162209
    163                 if (writeJobManifest($output, $job)) {
     210                if (writeJobManifest($output, $job, $surveyType)) {
    164211
    165212                    if (!$no_publish && !publishToDatastore($output, $job)) {
     
    168215                }
    169216
    170                 setJobId($jobId);
    171217                $jobId++;
    172218                $batchId = 0;
     
    175221            else {
    176222
    177                 print "No batches to publish\n"
     223                print "* No batches to publish\n"
    178224            }
    179225        }
    180226
    181         if ($product eq "init" ) {print "Wrote initialisation batch\n"; last;}
    182 
    183 
    184         print "------------------------------------------------------------------------------------------\n\n";
    185     }
     227        if ($batchType eq "init" ) {print "* Wrote initialisation batch\n"; last;}
     228
     229
     230        print "*\n*******************************************************************************\n\n";
     231    }
     232
     233    $db->disconnect();
    186234
    187235    return 1;
     
    204252    close (MYFILE);
    205253
    206     if ($verbose) { print "Current jobId = $jobId\n"; }
     254    if ($verbose) { print "* Current jobId = $jobId\n"; }
    207255
    208256    return $jobId;
     
    221269    close (MYFILE);
    222270
    223     if ($verbose) { print "New jobId = $jobId\n"; }
     271    if ($verbose) { print "* New jobId = $jobId\n"; }
    224272}
    225273
     
    230278#######################################################################################
    231279sub runIppToPsps {
    232     my ($db, $expId, $batchOutputPath, $product) = @_;
     280    my ($db, $expId, $batchOutputPath, $batchType) = @_;
    233281
    234282    my $success = 0;
    235283
    236284    # before anything else, we can publish the init batch
    237     if ($product =~ /init/) {
     285    if ($batchType =~ /init/) {
    238286        $success = produceInit($batchOutputPath);
    239287    }
    240     elsif ($product =~ /det/) {
     288    elsif ($batchType =~ /det/) {
    241289        $success = produceDetections($db, $expId, $batchOutputPath);
    242290    }
    243     elsif ($product =~ /diff/) {
     291    elsif ($batchType =~ /diff/) {
    244292        $success = produceDiffs($db, $expId, $batchOutputPath);
    245293    }
     
    265313        run(command => $command, verbose => $verbose);
    266314
    267     if (!$success) { print "Unable to tar up dir: $batch\n" and return 0 };
     315    if (!$success) { print "* Unable to tar up dir: $batch\n" and return 0 };
    268316
    269317    # zip
     
    272320        run(command => $command, verbose => $verbose);
    273321
    274     if (!$success) { print "Unable to gzip: $batchTar\n" and return 0 };
     322    if (!$success) { print "* Unable to gzip: $batchTar\n" and return 0 };
    275323
    276324    $command = "rm $batchTar";
     
    278326        run(command => $command, verbose => $verbose);
    279327
    280     if (!$success) { print "Unable to remove: $batchTar\n" };
     328    if (!$success) { print "* Unable to remove: $batchTar\n" };
    281329
    282330    $command = "rm -r $batchDir";
     
    284332        run(command => $command, verbose => $verbose);
    285333
    286     if (!$success) { print "Unable to remove: $batch\n"};
     334    if (!$success) { print "* Unable to remove: $batch\n"};
    287335
    288336    return 1;
     
    296344sub writeBatchManifest {
    297345
    298     my ($path,$batch,$product) = @_;
     346    my ($path,$batch,$batchType) = @_;
    299347
    300348    use XML::Writer;
     
    311359    # determine batch 'type'
    312360    my $type;
    313     if($product eq 'init') {$type = "IN";}
    314     elsif($product eq 'det') {$type = "P2";}
    315     elsif ($product eq 'stack') {$type = "ST";}
    316     elsif ($product eq 'diff') {$type = "OB";}
     361    if($batchType eq 'init') {$type = "IN";}
     362    elsif($batchType eq 'det') {$type = "P2";}
     363    elsif ($batchType eq 'stack') {$type = "ST";}
     364    elsif ($batchType eq 'diff') {$type = "OB";}
    317365    else {$type = "UNKNOWN";}
    318366
     
    325373    my $maxObjId;
    326374    my $filename;
    327     if($product eq 'det') {
     375    if($batchType eq 'det') {
    328376
    329377        while (<MYFILE>) {
     
    343391
    344392    # open directory to hunt for FITS files
    345     opendir(DIR, $path) or print "Cannot open '$path' to write batch manifest\n" and return 0;
     393    opendir(DIR, $path) or print "* Cannot open '$path' to write batch manifest\n" and return 0;
    346394    my @thefiles= readdir(DIR);
    347395    closedir(DIR);
     
    353401        if ($f =~ /\.FITS/) {
    354402
    355             if ($foundFits) { print "More than one FITS file found for this batch\n"; return 0;}
     403            if ($foundFits) { print "* More than one FITS file found for this batch\n"; return 0;}
    356404
    357405            # get md5sum of file
     
    362410
    363411            # write manifest element TODO untidy
    364             if($product eq 'det' && $filename eq $f) {
     412            if($batchType eq 'det' && $filename eq $f) {
    365413
    366414                $writer->startTag('manifest',
     
    389437            #$writer->startTag('md5'); $writer->characters("$md5sum"); $writer->endTag();
    390438
    391             #if($product eq 'det' && $filename eq $f) {
     439            #if($batchType eq 'det' && $filename eq $f) {
    392440
    393441                #    $writer->startTag('minObjId'); $writer->characters("$minObjId"); $writer->endTag();
     
    404452
    405453
    406     if (!$foundFits) { print "Could not find any FITS files for this batch\n"; return 0;}
     454    if (!$foundFits) { print "* Could not find any FITS files for this batch\n"; return 0;}
    407455    return 1;
    408456}
     
    414462#######################################################################################
    415463sub writeJobManifest {
    416     my ($path, $job) = @_;
     464    my ($path, $job, $surveyType) = @_;
    417465
    418466    use XML::Writer;
     
    433481    $writer->startTag('manifest',
    434482            "name" => "$job",
    435             "type" => "3PI", # TODO survey ID
     483            "type" => $surveyType,
    436484            "timestamp" => "$timeStamp");
    437485
     
    439487
    440488    # open directory to hunt for FITS files
    441     opendir(DIR, $jobPath) or print "Cannot open '$path' to write job manifest\n" and return 0;
     489    opendir(DIR, $jobPath) or print "* Cannot open '$path' to write job manifest\n" and return 0;
    442490    my @thefiles= readdir(DIR);
    443491    closedir(DIR);
     
    472520    $writer->end();
    473521
    474     if (!$foundBatch) { print "Could not find any batches for this job\n"; return 0;}
     522    if (!$foundBatch) { print "* Could not find any batches for this job\n"; return 0;}
    475523    return 1;
    476524}
     
    489537
    490538    # loop through all batch files in this job directory
    491     opendir(DIR, $fullJobPath) or print "Cannot open '$fullJobPath' in order to publish to datastore\n" and return 0;
     539    opendir(DIR, $fullJobPath) or print "* Cannot open '$fullJobPath' in order to publish to datastore\n" and return 0;
    492540    my @thefiles= readdir(DIR);
    493541    closedir(DIR);
     
    512560    $command .= " --datapath $fullJobPath";
    513561    $command .= " --type IPP_PSPS";
    514     $command .= " --product PSPS_test";
     562    $command .= " --product $datastoreProduct";
    515563    $command .= " --list $tempName";
    516564
     
    519567        run(command => $command, verbose => $verbose);
    520568
    521     if (!$success) { print "Unable to publish $job to datastore\n" and return 0 };
    522 
    523     print "Successfully published $job to datastore\n";
     569    if (!$success) { print "* Unable to publish $job to datastore\n" and return 0 };
     570
     571    print "* Successfully published $job to datastore\n";
    524572
    525573    close($tempFile);
     
    536584    my ($outputPath) = @_;
    537585
    538     my $success = runProgram( "NULL", $outputPath, 0, $product);
     586    my $success = runProgram( "NULL", $outputPath, 0, $batchType);
    539587    return $success;
    540588}
     
    558606        "WHERE rawExp.exp_id = $expId AND camRun.magicked";
    559607
    560     if ($verbose) { print"$query\n";}
     608    if ($verbose) { print"* $query\n";}
    561609
    562610
     
    564612    my $results = $db->selectall_arrayref( $query );
    565613    my $size = @$results;
    566     if ($size < 1) {print "No smf files found for this exposure\n"; return 0;}
     614    if ($size < 1) {print "* No smf files found for this exposure\n"; return 0;}
    567615
    568616    # loop round db results TODO should only be one result
     
    580628        close $tempFile;
    581629
    582         $success = runProgram($tempName, $outputPath, $expId, $product);
     630        $success = runProgram($tempName, $outputPath, $expId, $batchType);
    583631        return $success;
    584632    }
     
    604652        "WHERE rawExp.exp_id = $expId AND camRun.magicked";
    605653
    606     if ($verbose) { print"$query\n";}
     654    if ($verbose) { print"* $query\n";}
    607655
    608656    # execute query and check results
    609657    my $results = $db->selectall_arrayref( $query );
    610658    my $size = @$results;
    611     if ($size < 1) {print "No cmf files found for this exposure\n"; return 0;}
     659    if ($size < 1) {print "* No cmf files found for this exposure\n"; return 0;}
    612660
    613661    my ($tempFile, $tempName) = tempfile( "inputFileList.XXXX", UNLINK => !$save_temps);
     
    629677    }
    630678
    631     my $ret = runProgram($tempName, $outputPath, $expId, $product);
     679    my $ret = runProgram($tempName, $outputPath, $expId, $batchType);
    632680
    633681    close $tempFile;
     
    642690#######################################################################################
    643691sub runProgram {
    644     my ($input, $output, $expid, $product) = @_;
     692    my ($input, $output, $expid, $batchType) = @_;
    645693
    646694    # build command
     
    651699    $command .= " -config config"; # TODO
    652700    $command .= " -expid $expid";
    653     $command .= " -product $product";
     701    $command .= " -batch $batchType";
    654702    $command .= " -results $resultsFileName";
    655703
Note: See TracChangeset for help on using the changeset viewer.