Changeset 27354
- Timestamp:
- Mar 19, 2010, 8:31:40 AM (16 years ago)
- File:
-
- 1 edited
-
trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm
r27237 r27354 16 16 locate_images 17 17 resolve_project 18 getCamRunByCamID 18 19 ); 19 20 our %EXPORT_TAGS = (standard => [@EXPORT_OK]); … … 26 27 use PS::IPP::Config qw( :standard ); 27 28 use Carp; 29 30 # caches of camProcessedExp objects. 31 # Key is $exp_id 32 my %camRunByExpIDCache; 33 # Key is $cam_id 34 my %camRunByCamIDCache; 28 35 29 36 ### my @images = locate_images($image_db, $req_type, $img_type, $id, $component, … … 665 672 my $runs; 666 673 foreach my $camRun (@$camruns) { 674 my $cam_id = $camRun->{cam_id}; 675 676 updateCamRunCache($camRun); 677 667 678 next if $camRun->{quality}; 668 679 next if $camRun->{fault}; … … 809 820 my $verbose = shift; 810 821 822 my $mdcParser; 823 811 824 my $exp_id = $image->{exp_id}; 812 825 if (($exp_id eq $last_exp_id) and $lastAstromFile) { … … 825 838 } 826 839 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}; 859 876 my $camera = $image->{camera}; 860 877 my $astromSource = $astromSources{$camera}; 861 878 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 } 872 895 $astromSources{$camera} = $astromSource; 873 896 } 874 897 898 # XXX: Is this code correct if ASTROM.SOURCE ne "PSASTRO.OUTPUT" 875 899 my $astromFile = $ipprc->filename($astromSource, $camRoot); 876 900 if ($astromFile) { … … 984 1008 return $last_project; 985 1009 } 1010 1011 sub 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 1034 sub getCamRunByExpID { 1035 my $exp_id = shift; 1036 die "getCamRun: exp_id is nil" if !$exp_id; 1037 1038 return $camRunByExpIDCache{$exp_id}; 1039 } 1040 sub getCamRunByCamID { 1041 my $cam_id = shift; 1042 die "getCamRun: cam_id is nil" if !$cam_id; 1043 1044 return $camRunByCamIDCache{$cam_id}; 1045 } 986 1046 1;
Note:
See TracChangeset
for help on using the changeset viewer.
