IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 27896


Ignore:
Timestamp:
May 10, 2010, 10:49:44 AM (16 years ago)
Author:
bills
Message:

Get exposure parameters from the params file to avoid calling regtool repeatedly.
use parse_md_fast to parse the simple mdc lists.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pstamp/scripts/pstamp_finish.pl

    r27874 r27896  
    2424use PS::IPP::PStamp::RequestFile qw( :standard );
    2525use PS::IPP::PStamp::Job qw( :standard );
     26
     27my %imagedb_cache;
    2628
    2729my ( $req_id, $req_name, $req_file, $outdir, $product, $dbname, $dbserver, $verbose, $save_temps, $redirect_output);
     
    3436           'req_file=s'     => \$req_file,
    3537           'product=s'      => \$product,
    36            'outdir=s'      => \$outdir,
     38           'outdir=s'       => \$outdir,
    3739           'dbname=s'       => \$dbname,
    3840           'dbserver=s'     => \$dbserver,
     
    4749    if !$req_id or !$req_name or !$req_file or !$product or !$outdir;
    4850
     51die "outdir is NULL\n" if $outdir eq "NULL";
     52
    4953my $ipprc = PS::IPP::Config->new(); # IPP Configuration
    5054if ($redirect_output) {
     55    # XXX: what happens here if the directory does not exist? We check below
    5156    my $logDest = "$outdir/psfinish.$req_id.log";
    5257    $ipprc->redirect_output($logDest);
     
    7075
    7176if ($product eq "NULL") {
     77    # nothing more to do
    7278    stop_request_and_exit($req_id, $PS_EXIT_PROG_ERROR);
    7379}
    74 
    75 my $outputDataStoreRoot = metadataLookupStr($ipprc->{_siteConfig}, 'DATA_STORE_ROOT');
    76 exit ($PS_EXIT_CONFIG_ERROR) unless defined $outputDataStoreRoot; # lookup failure outputs a message
    7780
    7881my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     
    116119    }
    117120
    118     # at this point we need to find out what kind of request type it is and
    119     # split the processing depending on the request type
    120     # the only processing required for a detectabilty query is to build the output fileset.
    121 
    122     # the following is for a postage stamp request
    123 
     121    # start building the list of files to be placed in the output fileset
    124122    my ($rlf, $reglist_name) = tempfile ("$outdir/reglist.XXXX", UNLINK => !$save_temps);
     123
     124    # results file
    125125    print $rlf "results.fits|||table|\n";
     126    # human readable representation of the results file
    126127    print $rlf "results.mdc|||text|\n";
    127128
     
    131132    }
    132133
     134    # The results table definition file
    133135    my ($tdf, $table_def_name) = tempfile ("$outdir/tabledef.XXXX", UNLINK => !$save_temps);
    134 
    135136
    136137    # data for the header
    137138    print $tdf "$req_name|$req_id|\n";
     139
     140    # get the list of jobs generated for this request
    138141    my @jobs;
    139142    {
     
    151154                print STDERR "Request $req_id produced no jobs.\n"
    152155            }
    153             # This should not happen. A fake job should be queued
     156            # This should not happen. A fake job should have been entered
    154157            stop_request_and_exit($req_id, $PS_EXIT_PROG_ERROR);
    155158        } else {
     159if (0) {
    156160            my $metadata = $mdcParser->parse($output) or die("Unable to parse metdata config doc");
    157161
    158162            my $jobs = parse_md_list($metadata);
     163}
     164            my $jobs = parse_md_fast($mdcParser, $output);
    159165
    160166            @jobs = @$jobs;
     
    163169
    164170    my $exp_info;
    165     my $last_exp_id = -1;
    166171    foreach my $job (@jobs) {
    167172        my $job_id = $job->{job_id};
     
    171176        my $exp_id = $job->{exp_id};
    172177
    173 
    174178        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            # this request had a duplicate request name yet the parser didn't give
     180            # it an "ERROR style name.
     181            stop_request_and_exit($req_id, $PS_EXIT_PROG_ERROR);
    179182        }
    180183        my ($row, $req_info, $project) = get_request_info($rows, $rownum);
     
    198201            # get the metadata for the exposure (if any i.e. stack)
    199202            # returns an appropriate string if !$exp_id
    200             $exp_info = get_exposure_info($image_db, $exp_id);
    201             $last_exp_id = $exp_id;
     203            $exp_info = get_exposure_info($job_params, $image_db, $exp_id);
    202204        } else {
    203205            my $filter = $job_params->{filter};
    204206            $filter = "0" if !$filter;
    205207            $exp_info = "0|0|0|$filter|0|0";
    206             $last_exp_id = -1;
    207208        }
    208209
     
    346347    $data_group = "null" if !$data_group;
    347348
    348     # This is ugly, error prone and hard to change.
     349    # XXX: This is ugly, error prone and hard to change.
    349350    # Create a results file module and provide a list of the names (we have the data in the columns)
    350351    my $rowinfo = "$row->{PROJECT}|$row->{JOB_TYPE}|$row->{REQ_TYPE}|$row->{IMG_TYPE}|";
     
    377378    my $metadata = $mdcParser->parse($data) or die("Unable to parse metdata config doc");
    378379
     380    # no need to use parse_md_fast here
    379381    my $results = parse_md_list($metadata);
    380382    if (scalar @$results != 1) {
     
    386388
    387389sub get_exposure_info {
     390    my $job_params = shift;
    388391    my $image_db= shift;
    389392    my $exp_id = shift;
    390393
    391     if (!$exp_id or !$image_db) {
    392         # no exposure id just return zeros
    393         # XXX: we could put a value in for filter, but we don't have a good place to find it
    394 
    395         #"$mjd_obs|$ra_obs|$dec_obs|$filter|$exp_time|$fpa_id";
    396         return "0|0|0|0|0|0";
    397     }
    398 
    399     my $regtool = can_run('regtool') or (warn "Can't find regtool" and $missing_tools = 1);
    400     if ($missing_tools) {
    401         warn("Can't find required tools.");
    402         exit ($PS_EXIT_CONFIG_ERROR);
    403     }
    404 
    405     my $command = "$regtool -processedexp -dbname $image_db -exp_id $exp_id";
    406 
    407     # run the tool and parse the output
    408     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    409                 run(command => $command, verbose => $verbose);
    410     unless ($success) {
    411         # not sure if we should die here
    412         die "cannot get exposure information for $exp_id from image database $image_db";
    413     }
    414     my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    415 
    416     my $output = join "", @$stdout_buf;
    417     if (!$output) {
    418         print STDERR "no output returned from $command\n" if $verbose;
    419         return undef;
    420     }
    421     my $metadata = $mdcParser->parse($output) or die("Unable to parse metdata config doc");
    422 
    423     my $exposures = parse_md_list($metadata);
    424     my $numExp = @$exposures;
    425 
    426     die "unexpected number of exposures $numExp found for exp_id: $exp_id in DB: $image_db" if $numExp != 1;
     394    my ($dateobs, $ra, $decl, $filter, $exp_time, $exp_name);
     395
     396    $dateobs  = $job_params->{dateobs};
     397    $ra       = $job_params->{ra};
     398    $decl     = $job_params->{decl};
     399    $filter   = $job_params->{filter};
     400    $exp_time = $job_params->{exp_time};
     401    $exp_name = $job_params->{exp_name};
     402
     403    unless (defined $dateobs and defined $ra and defined $decl and defined $filter and defined $exp_time and defined $exp_name) {
     404        # job params don't have all of the values that we need (most likely this is a diff stage job)
     405        # go look up the exposure if we have one
     406        if (!$exp_id or !$image_db) {
     407            # no exposure id just return zeros
     408            # XXX: we could put a value in for filter, but we don't have a good place to find it
     409
     410            #"$mjd_obs|$ra_obs|$dec_obs|$filter|$exp_time|$fpa_id";
     411            return "0|0|0|0|0|0";
     412        }
     413
     414        my $exp;
     415        # get cache of exposures for this image_db
     416        my $exp_cache = $imagedb_cache{$image_db};
     417        if (defined $exp_cache) {
     418            $exp = $exp_cache->{$exp_id};
     419        }
     420
     421        unless (defined $exp) {
     422
     423            my $regtool = can_run('regtool') or (warn "Can't find regtool" and $missing_tools = 1);
     424            if ($missing_tools) {
     425                warn("Can't find required tools.");
     426                exit ($PS_EXIT_CONFIG_ERROR);
     427            }
     428
     429            my $command = "$regtool -processedexp -dbname $image_db -exp_id $exp_id";
     430
     431            # run the tool and parse the output
     432            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     433                        run(command => $command, verbose => $verbose);
     434            unless ($success) {
     435                # not sure if we should die here
     436                die "cannot get exposure information for $exp_id from image database $image_db";
     437            }
     438            my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     439
     440            my $output = join "", @$stdout_buf;
     441            if (!$output) {
     442                print STDERR "no output returned from $command\n" if $verbose;
     443                return undef;
     444            }
     445if (0) {
     446            my $metadata = $mdcParser->parse($output) or die("Unable to parse metdata config doc");
     447
     448            my $exposures = parse_md_list($metadata);
     449}
     450            my $exposures = parse_md_fast($mdcParser, $output);
     451            my $numExp = @$exposures;
     452
     453            die "unexpected number of exposures $numExp found for exp_id: $exp_id in DB: $image_db" if $numExp != 1;
     454
     455            $exp = $exposures->[0];
     456
     457            unless (defined $exp_cache) {
     458                my %new_exp_cache;
     459                $exp_cache = \%new_exp_cache;
     460                $imagedb_cache{$image_db} = $exp_cache;
     461            }
     462            $exp_cache->{$exp_id} = $exp;
     463        } else {
     464            print "found $exp_id in cache\n";
     465        }
     466       
     467        #my $info = "$mjd_obs|$ra_obs|$dec_obs|$filter|$exp_time|$fpa_id";
     468        $dateobs  = $exp->{dateobs};
     469        $ra       = $exp->{ra};
     470        $decl     = $exp->{decl};
     471        $filter   = $exp->{filter};
     472        $exp_time = $exp->{exp_time};
     473        $exp_name = $exp->{exp_name};
     474    }
     475
     476    die "failed to find exp_info for $exp_id" unless (defined $dateobs and defined $ra and defined $decl and defined $filter and defined $exp_time and defined $exp_name);
    427477   
    428     my $exp = $exposures->[0];
    429 
    430     #my $info = "$mjd_obs|$ra_obs|$dec_obs|$filter|$exp_time|$fpa_id";
    431 
    432478    use constant RADIANS_TO_DEGREES => 90. / atan2(1, 0);
    433     my $ra_deg   = $exp->{ra} * RADIANS_TO_DEGREES;
    434     my $decl_deg = $exp->{decl} * RADIANS_TO_DEGREES;
    435     my $mjd_obs = dateobs_to_mjd($exp->{dateobs});
    436 
    437     my $info = "$mjd_obs|$ra_deg|$decl_deg|$exp->{filter}|$exp->{exp_time}|$exp->{exp_name}";
     479    my $ra_deg   = $ra * RADIANS_TO_DEGREES;
     480    my $decl_deg = $decl * RADIANS_TO_DEGREES;
     481    my $mjd_obs = dateobs_to_mjd($dateobs);
     482
     483    my $info = "$mjd_obs|$ra_deg|$decl_deg|$filter|$exp_time|$exp_name";
    438484           
    439485    return $info;
Note: See TracChangeset for help on using the changeset viewer.