IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 3, 2010, 8:50:52 AM (16 years ago)
Author:
eugene
Message:

updates from trunk

Location:
branches/simtest_nebulous_branches
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/simtest_nebulous_branches

  • branches/simtest_nebulous_branches/pstamp/scripts/pstamp_finish.pl

    r25053 r27840  
    88use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
    99use Pod::Usage qw( pod2usage );
     10use Carp;
    1011
    1112use Time::Local;
     
    6263my $pstamp_results = can_run('pstamp_results_file.pl')
    6364                            or (warn "Can't find pstamp_results_file.pl" and $missing_tools = 1);
     65my $pstampdump = can_run('pstampdump') or (warn "Can't find pstampdump" and $missing_tools = 1);
    6466if ($missing_tools) {
    6567    warn("Can't find required tools.");
     
    6769}
    6870
     71if ($product eq "NULL") {
     72    stop_request_and_exit($req_id, $PS_EXIT_PROG_ERROR);
     73}
    6974
    7075my $outputDataStoreRoot = metadataLookupStr($ipprc->{_siteConfig}, 'DATA_STORE_ROOT');
     
    7782    my $fileset = $req_name;
    7883
    79 
    80     # Here we invoke the assumption that the output for the request is placed in the
    81     # fileset directory directly
    82 #    my $out_dir = "$outputDataStoreRoot/$product/$fileset";
    83 
    84     # now we are assuming that the output directory is the dirname of the request file
    85     # XXX: put this in the database
    86 
    8784    print STDERR "product: $product  REQ_NAME: $req_name $out_dir\n" if $verbose;
    8885
     
    9390        if (!mkdir $out_dir) {
    9491            print STDERR "cannot create output directory $out_dir";
    95             stop_request($req_id, $PS_EXIT_UNKNOWN_ERROR);
     92            stop_request_and_exit($req_id, $PS_EXIT_UNKNOWN_ERROR);
    9693        }
    9794
     
    10198        # request
    10299        print STDERR "output directory $out_dir exists but is not a directory";
    103         stop_request($req_id, $PS_EXIT_UNKNOWN_ERROR);
     100        stop_request_and_exit($req_id, $PS_EXIT_UNKNOWN_ERROR);
    104101    }
    105102
    106103    if (! -e $req_file ) {
    107104        print STDERR "request file $req_file is missing\n";
    108         stop_request($req_id, $PS_EXIT_CONFIG_ERROR);
     105        stop_request_and_exit($req_id, $PS_EXIT_CONFIG_ERROR);
    109106    }
    110107
     
    116113        # point
    117114        print STDERR "failed to read request_file $req_file" ;
    118         stop_request($req_id, $PS_EXIT_CONFIG_ERROR);
     115        stop_request_and_exit($req_id, $PS_EXIT_CONFIG_ERROR);
    119116    }
    120117
     
    127124    my ($rlf, $reglist_name) = tempfile ("$out_dir/reglist.XXXX", UNLINK => !$save_temps);
    128125    print $rlf "results.fits|||table|\n";
     126    print $rlf "results.mdc|||text|\n";
    129127
    130128    my $err_file = "parse_error.txt";
     
    153151                print STDERR "Request $req_id produced no jobs.\n"
    154152            }
    155             # No Jobs.
    156             # XXXX Ouch. We need results for each rownum (each request specification) in the request file
    157             # including those that produced no jobs.
    158             # for now add an entry for rownum 1 and a phony error code.
    159             # we've included parse_error.txt to the fileset if it exists
    160             #
    161             my $rownum = 0;
    162             my $fault = 42; # get a real error code
    163             print $tdf "$rownum|$fault|0|0|";
    164             print $tdf "0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|\n";
     153            # This should not happen. A fake job should be queued
     154            stop_request_and_exit($req_id, $PS_EXIT_PROG_ERROR);
    165155        } else {
    166156            my $metadata = $mdcParser->parse($output) or die("Unable to parse metdata config doc");
     
    181171        my $exp_id = $job->{exp_id};
    182172
     173
     174        if (($fault eq $PSTAMP_DUP_REQUEST) and ($req_name eq "NULL")) {
     175            # this request had a duplicate request name. We can't put the results
     176            # on the data store since the product name is already used
     177            # maybe we could be more clever about this and choose a fileset name
     178            stop_request_and_exit($req_id, $fault);
     179        }
    183180        my ($row, $req_info, $project) = get_request_info($rows, $rownum);
    184181
     
    187184        if (!$image_db) {
    188185            carp("failed to find imagedb for project: $project");
    189             stop_request($req_id, $PS_EXIT_CONFIG_ERROR);
    190         }
    191 
    192         if ($exp_id ne $last_exp_id) {
     186            if (!$fault) {
     187                stop_request_and_exit($req_id, $PS_EXIT_CONFIG_ERROR);
     188            }
     189        }
     190
     191        my $job_params = get_job_parameters($job);
     192        my $stage = "";
     193        if ($job_params) {
     194            $stage = $job_params->{stage};
     195        }
     196
     197        if ($stage ne 'stack') {
    193198            # get the metadata for the exposure (if any i.e. stack)
    194199            # returns an appropriate string if !$exp_id
    195200            $exp_info = get_exposure_info($image_db, $exp_id);
    196201            $last_exp_id = $exp_id;
    197         }
    198 
    199         if (($job_type eq "stamp") || ($job_type eq "get_image")) {
     202        } else {
     203            my $filter = $job_params->{filter};
     204            $filter = "0" if !$filter;
     205            $exp_info = "0|0|0|$filter|0|0";
     206            $last_exp_id = -1;
     207        }
     208
     209        if (($job_type eq "stamp") || ($job_type eq "get_image") || ($job_type eq "none")) {
    200210            my $jreglist = "$out_dir/reglist$job_id";
    201211            if (open JRL, "<$jreglist") {;
     
    212222
    213223                    # ra_deg and dec_deg are the coordinates of center of the stamp
    214                     # XXX: parse the stamp header to find it
    215                     print $tdf "0.0|0.0|";
     224                    # first assume that the image is compressed and check the first extension.
     225                    # If not found check the PHU. If that doesn't work just set them to zero.
     226                    # XXX do this more cleanly
     227                    my (undef, $ra_deg, $dec_deg) = split " ", `echo $out_dir/$img_name | fields -x 0 RA_DEG DEC_DEG`;
     228                    if (!defined $ra_deg) {
     229                        (undef, $ra_deg, $dec_deg) = split " ", `echo $out_dir/$img_name | fields RA_DEG DEC_DEG`;
     230                    }
     231                    $ra_deg = 0.0 if (!$ra_deg);
     232                    $dec_deg = 0.0 if (!$dec_deg);
     233                    print $tdf "$ra_deg|$dec_deg|";
    216234
    217235                    print $tdf "$exp_info|";
     
    246264            print STDERR "Unable to perform $command error code: $error_code\n";
    247265            $request_fault = $error_code >> 8;
     266        } else {
     267            # dump a textual representation
     268            my $command = "$pstampdump $out_dir/results.fits > $out_dir/results.mdc";
     269            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     270                run(command => $command, verbose => $verbose);
     271            unless ($success) {
     272                print STDERR "Unable to perform $command error code: $error_code\n";
     273                $request_fault = $error_code >> 8;
     274            }
    248275        }
    249276    }
     
    251278        # register the fileset
    252279        my $command = "$dsreg --list $reglist_name --add $fileset --product $product --type PSRESULTS";
    253         $command .= " --link --datapath $out_dir";
     280        $command .= " --link --datapath $out_dir --ps0 $req_id";
    254281        $command .= " --dbname $dbname" if $dbname;
    255282
     
    277304}
    278305
    279 sub stop_request {
     306sub stop_request_and_exit {
    280307    my $req_id = shift;
    281308    my $fault  = shift;
     
    297324    my $rownum = shift;
    298325
     326    if ($rownum eq 0) {
     327        my $dummy_rowinfo = "0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|";
     328        return (undef, $dummy_rowinfo, "none");
     329    }
    299330    my $row = $rows->{$rownum};
     331
    300332
    301333    # these may be set to null during processing
     
    304336    my $tess_id = $row->{TESS_ID};
    305337    $tess_id = "null" if !$tess_id;
     338    my $comment = $row->{COMMENT};
     339    $comment = "null" if !$comment;
     340    my $data_group = $row->{DATA_GROUP};
     341    if (!defined $data_group) {
     342        # XXX: backwards compatibility hook. Remove "soon".
     343        $data_group = $row->{LABEL};
     344    }
     345    $data_group = "null" if !$data_group;
    306346
    307347    # This is ugly, error prone and hard to change.
    308348    # Create a results file module and provide a list of the names (we have the data in the columns)
    309349    my $rowinfo = "$row->{PROJECT}|$row->{JOB_TYPE}|$row->{REQ_TYPE}|$row->{IMG_TYPE}|";
    310     $rowinfo   .= "$row->{ID}|$tess_id|$component|$row->{OPTION_MASK}|$row->{MJD_MIN}|$row->{MJD_MAX}|";
     350    $rowinfo   .= "$row->{ID}|$tess_id|$component|$data_group|$row->{OPTION_MASK}|$row->{MJD_MIN}|$row->{MJD_MAX}|";
    311351    $rowinfo   .= "$row->{REQFILT}|$row->{COORD_MASK}|$row->{CENTER_X}|$row->{CENTER_Y}|";
    312     $rowinfo   .= "$row->{WIDTH}|$row->{HEIGHT}";
     352    $rowinfo   .= "$row->{WIDTH}|$row->{HEIGHT}|";
     353    $rowinfo   .= $comment;
    313354
    314355    return ($row, $rowinfo, $row->{PROJECT});
     356}
     357
     358sub get_job_parameters {
     359    my $job = shift;
     360    if (!$job->{outputBase}) {
     361        print "get_job_parameters: $job->{job_id} has no outputBase\n";
     362        return undef;
     363    }
     364    my $params_file = $job->{outputBase} . '.mdc';
     365    if (! -e $params_file ) {
     366        print "get_job_parameters: $job->{job_id} has no parameters file\n";
     367        return undef;
     368    }
     369    open IN, "<$params_file" or die "unable to open $params_file";
     370    my $data = join "", (<IN>);
     371    close IN;
     372    if (! $data ) {
     373        print "get_job_parameters: parameters file is empty\n";
     374        return undef;
     375    }
     376    my $metadata = $mdcParser->parse($data) or die("Unable to parse metdata config doc");
     377
     378    my $results = parse_md_list($metadata);
     379    if (scalar @$results != 1) {
     380        print STDERR "get_job_params: failed to parse_md_list\n";
     381        return undef;
     382    }
     383    return $results->[0];
    315384}
    316385
     
    319388    my $exp_id = shift;
    320389
    321     if (!$exp_id) {
     390    if (!$exp_id or !$image_db) {
    322391        # no exposure id just return zeros
    323392        # XXX: we could put a value in for filter, but we don't have a good place to find it
     
    363432    my $ra_deg   = $exp->{ra} * RADIANS_TO_DEGREES;
    364433    my $decl_deg = $exp->{decl} * RADIANS_TO_DEGREES;
    365     my $mjd_obs = dateobs_to_mjd($exp->{dateobs}, $exp->{exp_time});
     434    my $mjd_obs = dateobs_to_mjd($exp->{dateobs});
    366435
    367436    my $info = "$mjd_obs|$ra_deg|$decl_deg|$exp->{filter}|$exp->{exp_time}|$exp->{exp_name}";
     
    372441sub dateobs_to_mjd {
    373442    my $dateobs = shift;
    374     my $exp_time = shift;
    375443
    376444    # dateobs is in format: 1970-01-01T00:00:00
     
    382450    my $ticks = timegm($sec, $min, $hr, $day, $mon-1, $year-1900);
    383451
    384     $ticks += $exp_time / 2.0;
    385 
    386452    return 40587.0 + ($ticks/86400.);
    387453}
Note: See TracChangeset for help on using the changeset viewer.