IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 27354 for trunk


Ignore:
Timestamp:
Mar 19, 2010, 8:31:40 AM (16 years ago)
Author:
bills
Message:

Cache data returned by camtool -processedexp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm

    r27237 r27354  
    1616                    locate_images
    1717                    resolve_project
     18                    getCamRunByCamID
    1819                    );
    1920our %EXPORT_TAGS = (standard => [@EXPORT_OK]);
     
    2627use PS::IPP::Config qw( :standard );
    2728use Carp;
     29
     30# caches of camProcessedExp objects.
     31# Key is $exp_id
     32my %camRunByExpIDCache;
     33# Key is $cam_id
     34my %camRunByCamIDCache;
    2835
    2936### my @images = locate_images($image_db, $req_type, $img_type, $id, $component,
     
    665672    my $runs;
    666673    foreach my $camRun (@$camruns) {
     674        my $cam_id = $camRun->{cam_id};
     675
     676        updateCamRunCache($camRun);
     677
    667678        next if $camRun->{quality};
    668679        next if $camRun->{fault};
     
    809820    my $verbose = shift;
    810821
     822    my $mdcParser;
     823
    811824    my $exp_id = $image->{exp_id};
    812825    if (($exp_id eq $last_exp_id) and $lastAstromFile) {
     
    825838    }
    826839
    827     my $command = "$camtool -dbname $image_db -processedexp -exp_id $exp_id";
    828     # run the tool and parse the output
    829     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    830                 run(command => $command, verbose => $verbose);
    831     unless ($success) {
    832         print STDERR @$stderr_buf;
    833         return undef;
    834     }
    835 
    836     my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    837 
    838     my $output = join "", @$stdout_buf;
    839     if (!$output) {
    840         print STDERR "no output returned from $command\n" if $verbose;
    841         return undef;
    842     }
    843     my $camruns = parse_md_fast($mdcParser, $output);
    844     if (!$camruns) {
    845         return undef;
    846     }
    847 
    848     # If there are multiple cam runs for this exposure, take the last completed one
    849     # on the assumption that it has the best astrometry.
    850     my $camdata;
    851     while ($camdata = pop @$camruns) {
    852         last if (($camdata->{quality} eq 0) and ($camdata->{fault} eq 0));
    853     }
    854     if (!$camdata) {
    855         # no cam runs for this exposure id therefore best astrometry is whatever is in the header
    856         return undef;
    857     }
    858     my $camRoot = $camdata->{path_base};
     840    my $camRun = getCamRunByExpID($exp_id);
     841    if (!$camRun) {
     842        my $command = "$camtool -dbname $image_db -processedexp -exp_id $exp_id";
     843        # run the tool and parse the output
     844        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     845                    run(command => $command, verbose => $verbose);
     846        unless ($success) {
     847            print STDERR @$stderr_buf;
     848            return undef;
     849        }
     850
     851        $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     852
     853        my $output = join "", @$stdout_buf;
     854        if (!$output) {
     855            print STDERR "no output returned from $command\n" if $verbose;
     856            return undef;
     857        }
     858        my $camruns = parse_md_fast($mdcParser, $output);
     859        if (!$camruns) {
     860            return undef;
     861        }
     862
     863        # If there are multiple cam runs for this exposure, take the last completed one with good quality
     864        # on the assumption that it has the best astrometry.
     865        while ($camRun = pop @$camruns) {
     866            last if (($camRun->{quality} eq 0) and ($camRun->{fault} eq 0));
     867        }
     868        # XXX: this looks like a bug at least if ASTROM.SOURCE eq PSASTRO.OUTPUT
     869        if (!$camRun) {
     870            # no cam runs for this exposure id therefore best astrometry is whatever is in the header
     871            return undef;
     872        }
     873        updateCamRunCache($camRun);
     874    }
     875    my $camRoot = $camRun->{path_base};
    859876    my $camera = $image->{camera};
    860877    my $astromSource = $astromSources{$camera};
    861878    if (!$astromSource) {
    862        my $command = "$ppConfigDump -camera $camera -dump-recipe PSWARP -";
    863         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    864             run(command => $command, verbose => $verbose);
    865         unless ($success) {
    866             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    867             die("Unable to perform ppConfigDump: $error_code");
    868         }
    869         my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    870             die("Unable to parse metadata config doc");
    871         $astromSource = metadataLookupStr($metadata, 'ASTROM.SOURCE');
     879        if ($camera eq "GPC1") {
     880            # CHEATER !
     881            $astromSource = "PSASTRO.OUTPUT";
     882        } else {
     883            my $command = "$ppConfigDump -camera $camera -dump-recipe PSWARP -";
     884            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     885                run(command => $command, verbose => $verbose);
     886            unless ($success) {
     887                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     888                die("Unable to perform ppConfigDump: $error_code");
     889            }
     890            $mdcParser = PS::IPP::Metadata::Config->new if !$mdcParser; # Parser for metadata config files
     891            my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     892                die("Unable to parse metadata config doc");
     893            $astromSource = metadataLookupStr($metadata, 'ASTROM.SOURCE');
     894        }
    872895        $astromSources{$camera} = $astromSource;
    873896    }
    874897
     898    # XXX: Is this code correct if ASTROM.SOURCE ne "PSASTRO.OUTPUT"
    875899    my $astromFile = $ipprc->filename($astromSource, $camRoot);
    876900    if ($astromFile) {
     
    9841008    return $last_project;
    9851009}
     1010
     1011sub updateCamRunCache {
     1012    my $camRun = shift;
     1013    die "updateCamRunCache: camRun is nil" if !$camRun;
     1014
     1015    my $exp_id = $camRun->{exp_id};
     1016    die "updateCamRunCache: exp_id is nil" if !$exp_id;
     1017
     1018    my $cam_id = $camRun->{cam_id};
     1019    die "updateCamRunCache: cam_id is nil" if !$cam_id;
     1020
     1021    $camRunByCamIDCache{$cam_id} = $camRun;
     1022
     1023    # if this camRun is newer than previous update the cache.
     1024    # This assumes that the newest has the "best" astrometry
     1025    my $previous = $camRunByExpIDCache{$exp_id};
     1026    if ($previous) {
     1027        my $previous_cam_id = $previous->{cam_id};
     1028        return if $cam_id < $previous_cam_id;
     1029    }
     1030
     1031    $camRunByExpIDCache{$exp_id} = $camRun;
     1032}
     1033
     1034sub getCamRunByExpID {
     1035    my $exp_id = shift;
     1036    die "getCamRun: exp_id is nil" if !$exp_id;
     1037
     1038    return $camRunByExpIDCache{$exp_id};
     1039}
     1040sub getCamRunByCamID {
     1041    my $cam_id = shift;
     1042    die "getCamRun: cam_id is nil" if !$cam_id;
     1043
     1044    return $camRunByCamIDCache{$cam_id};
     1045}
    98610461;
Note: See TracChangeset for help on using the changeset viewer.