- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
tools/ipp_apply_burntool.pl (modified) (9 diffs, 1 prop)
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/tools/ipp_apply_burntool.pl
-
Property svn:executable
set to
*
r24859 r27840 1 1 #!/usr/bin/env perl 2 2 # this program is used to run 'burntool' on images for a single chip 3 # for all exposures for a given time period. 4 # USAGE: ipp_apply_burntool.pl --dbname gpc1 --class_id XY00 --dateobs_begin YYYY/MM/DD --dateobs_end YYYY/MM/DD 3 # for all exposures for a given time period. 4 # USAGE: ipp_apply_burntool.pl --dbname gpc1 --class_id XY00 --dateobs_begin YYYY/MM/DD --dateobs_end YYYY/MM/DD 5 5 6 6 # XXX todo: 7 7 # - add filters to processedimfile 8 # 8 # 9 9 10 10 use warnings; … … 12 12 use Carp; 13 13 14 use IPC::Cmd 0.36 qw( can_run );15 use IPC::Run 0.36 qw( run );14 use IPC::Cmd 0.36 qw( can_run run ); 15 #use IPC::Run 0.36 qw( run ); 16 16 use PS::IPP::Metadata::List qw( parse_md_list ); 17 17 use PS::IPP::Config 1.01 qw( :standard ); … … 20 20 use Pod::Usage qw( pod2usage ); 21 21 22 my ( $class_id, $dateobs_begin, $dateobs_end, $ skip_burned, $rerun_from_first, $dbname, $logfile, $verbose, $save_temps);22 my ( $class_id, $dateobs_begin, $dateobs_end, $convert, $camera, $dbname, $logfile, $verbose, $save_temps); 23 23 GetOptions( 24 24 'class_id=s' => \$class_id, # chip identifier 25 25 'dateobs_begin=s' => \$dateobs_begin, # exposure date/time range start 26 26 'dateobs_end=s' => \$dateobs_end, # exposure date/time range stop 27 'camera=s' => \$camera, # Camera 27 28 'dbname|d=s' => \$dbname, # Database name 28 29 'logfile=s' => \$logfile, 29 'skip_burned' => \$skip_burned, # Print to stdout30 'rerun_from_first' => \$rerun_from_first, # Print to stdout31 30 'verbose' => \$verbose, # Print to stdout 32 31 'save-temps' => \$save_temps, # Save temporary files? 32 33 33 ) or pod2usage( 2 ); 34 34 … … 43 43 defined $dbname; 44 44 45 if ($skip_burned and $rerun_from_first) { &my_die("-rerun_from_first and -skip_burned are incompatible"); } 45 unless (defined $camera) { 46 $camera = "GPC1"; 47 # warn("No camera defined. Defaulting to $camera and warning."); 48 } 46 49 47 50 my $missing_tools; … … 49 52 my $funpack = can_run('funpack') or (warn "Can't find funpack" and $missing_tools = 1); 50 53 my $burntool = can_run('burntool') or (warn "Can't find burntool" and $missing_tools = 1); 51 my $fpack = can_run('fpack') or (warn "Can't find fpack" and $missing_tools = 1); 54 my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1); 55 my $nebXattr = can_run('neb-xattr') or (warn "Can't find neb-xattr" and $missing_tools = 1); 56 #my $fpack = can_run('fpack') or (warn "Can't find fpack" and $missing_tools = 1); 52 57 if ($missing_tools) { 53 58 warn("Can't find required tools."); … … 57 62 my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files 58 63 64 # IPP configuration (including nebulous) 65 my $ipprc = PS::IPP::Config->new( $camera ) or my_die("Unable to set up"); 66 67 $ipprc->redirect_output($logfile) if $logfile; 68 69 # Determine the value of a "good" burntool run. 70 my $config_cmd = "$ppConfigDump -camera $camera -dump-camera - | grep BURNTOOL | uniq"; 71 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 72 run ( command => $config_cmd, verbose => $verbose); 73 unless ($success) { 74 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 75 &my_die("Unable to perform ppConfigDump: $error_code", 0, 0, $class_id, $PS_EXIT_SYS_ERROR); 76 } 77 78 my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or 79 &my_die("Unable to parse metadata config doc", 0, 0, $class_id, $PS_EXIT_SYS_ERROR); 80 81 my $burntoolStateGood = 999; 82 foreach my $cfg (@$recipeData) { 83 if ($cfg->{name} eq 'BURNTOOL.STATE.GOOD') { 84 $burntoolStateGood = $cfg->{value}; 85 } 86 } 87 if ($burntoolStateGood == 999) { 88 &my_die("Failed to determine BURNTOOL.STATE.GOOD", $burntoolStateGood, $class_id, 0, $PS_EXIT_SYS_ERROR); 89 } 90 my $outState = -1 * abs($burntoolStateGood); 91 92 print ">>$burntoolStateGood<<\n"; 93 94 # Define list of images to examine. 59 95 my $command = "$regtool -processedimfile"; 60 96 $command .= " -class_id $class_id"; … … 64 100 $command .= " -dbname $dbname" if defined $dbname; 65 101 66 my @command = split /\s+/, $command; 67 my ( $stdin, $stdout, $stderr ); # Buffers for running program 68 print "Running [$command]...\n" if $verbose; 69 if (not run(\@command, \$stdin, \$stdout, \$stderr)) { 70 &my_die("Unable to perform regtool -processedimfile"); 71 } 72 print $stdout . "\n" if $verbose; 73 74 my @files; 75 my @whole = split /\n/, $stdout; 76 my @single = (); 77 while ( scalar @whole > 0 ) { 78 my $value = shift @whole; 79 push @single, $value; 80 if ($value =~ /^\s*END\s*$/) { 81 push @single, "\n"; 82 83 my $list = parse_md_list( $mdcParser->parse( join( "\n", @single ) ) ); 84 &my_die("Unable to parse output from regtool") unless defined $list; 85 push @files, @$list; 86 @single = (); 87 } 88 } 89 90 # IPP configuration (including nebulous) 91 my $ipprc = PS::IPP::Config->new() or my_die("Unable to set up"); 92 93 $ipprc->redirect_output($logfile) if $logfile; 94 95 my $Nfiles = @files; 96 print "files: $Nfiles\n"; 102 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 103 run ( command => $command, verbose => $verbose); 104 unless ($success) { 105 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 106 &my_die("Unable to perform regtool: $error_code", $class_id, $dateobs_begin, $dateobs_end, $PS_EXIT_SYS_ERROR); 107 } 108 109 my $metadata = $mdcParser->parse(join "", @$stdout_buf) or 110 &my_die("Unable to parse metadata", $class_id, $dateobs_begin, $dateobs_end, $PS_EXIT_SYS_ERROR); 111 112 my $files = parse_md_list($metadata) or 113 &my_die("Unable to parse metadata list", $class_id, $dateobs_begin, $dateobs_end, $PS_EXIT_SYS_ERROR); 97 114 98 115 my $REALRUN = 1; 99 my $RAWTABLES = 1; 100 # XXX if we want to avoid using the raw tables in this script, we need to delay deletion of the tempfile until the next pass. 101 102 # first pass: mark the db entries to catch failures 103 # these will not be identified as burned by chip processing (user_1 > 0.5) 104 if (! $skip_burned) { 105 foreach my $file (@files) { 106 107 # rerun_from_first treats the first image as already burned (if it is already burned) 108 # the artifact table from the first file is used for the rest of the sequence. 109 if ($rerun_from_first) { 110 $skip_burned = 1; 111 $rerun_from_first = 0; 112 next; 113 } 114 my $exp_id = $file->{exp_id}; 115 116 my $status; 117 $status = vsystem ("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -user_1 0.1", 1); 118 if ($status) { 119 &my_die("failed to update imfile"); 120 } 121 $file->{user_1} = 0.1; 122 } 123 } 124 125 my $prevFileOpt = ""; 126 foreach my $file (@files) { 116 117 # Process each file in turn, checking to see if it needs processing, and doing it all in a single pass 118 my $processNext = 0; 119 my $previousTable = ''; 120 121 foreach my $file (@$files) { 127 122 my $exp_id = $file->{exp_id}; 123 my $state = $file->{burntool_state}; 128 124 129 125 my $rawImfile = $file->{uri}; 130 my $rawImfileReal; 131 if ($REALRUN) { 132 $rawImfileReal = $ipprc->file_resolve($rawImfile, 0); 133 } else { 134 ($rawImfileReal) = $rawImfile =~ m|^neb:/(.*)|; 135 } 136 print "rawImfile: $rawImfile -> $rawImfileReal\n"; 137 138 # mangle name, create tmp file (always a UNIX file) 139 my $basename = `basename $rawImfile`; chomp $basename; 140 my $tempfile = new File::Temp ( TEMPLATE => "$basename.XXXX", 141 DIR => '/tmp', 142 UNLINK => !$save_temps); 143 my $tmpImfileReal = $tempfile->filename; 144 # print "tmpImfile: $tmpImfile -> $tmpImfileReal\n"; 145 146 # destination for the burntool-applied image file (may be a NEB file) 147 my $outImfile = $rawImfile; 148 $outImfile =~ s/fits$/burn.fits/; 149 my $outImfileReal = $ipprc->file_resolve($outImfile, 1); 150 # print "outImfile: $outImfile -> $outImfileReal\n"; 151 152 # burntool now can write the artifacts to the fits file. 153 # destination for the burntool artifacts. use this if RAWTABLES is set. 154 my $artImfile; 155 my $artImfileReal; 156 if ($RAWTABLES) { 157 $artImfile = $rawImfile; 158 $artImfile =~ s/fits$/burn.tbl/; 159 $artImfileReal = $ipprc->file_resolve($artImfile, 1); 160 # print "artImfile: $artImfile -> $artImfileReal\n"; 161 } 162 163 print "$rawImfile : $skip_burned, $file->{user_1}\n"; 164 165 if (! ($skip_burned and ($file->{user_1} > 0.5))) { 166 print "running on: $rawImfile\n"; 167 # uncompress the image (do we need to check if it is compressed?) 168 my $status = vsystem ("$funpack -S $rawImfileReal > $tmpImfileReal", $REALRUN); 169 if ($status) { 170 &my_die("failed on funpack"); 171 } 172 173 if ($RAWTABLES) { 174 $status = vsystem ("$burntool $tmpImfileReal out=$artImfileReal $prevFileOpt", $REALRUN); 175 } else { 176 $status = vsystem ("$burntool $tmpImfileReal $prevFileOpt", $REALRUN); 177 } 178 if ($status) { 179 &my_die("failed on burntool"); 180 } 181 182 # compress the image (do we need to check if it is compressed?) 183 $status = vsystem ("$fpack -S $tmpImfileReal > $outImfileReal", $REALRUN); 184 if ($status) { 185 &my_die("failed on fpack"); 186 } 187 188 $status = vsystem ("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -user_1 1.0", 1); 126 my $rawImfileReal = $ipprc->file_resolve($rawImfile, 0); 127 128 my $outTable = $file->{uri}; 129 $outTable =~ s/fits$/burn.tbl/; 130 my $outTableReal = $ipprc->file_resolve($outTable, 1); 131 132 my $process = 0; 133 my $previousTableStyle = 0; 134 135 if ($state == 0) { 136 $process = 1; 137 } 138 elsif ($state == -1) { 139 $process = 1; 140 } 141 elsif ($state == -3) { 142 $process = 1; 143 } 144 elsif ($state == -2) { 145 &my_die("Aborting as $rawImfile has modified pixel data!"); 146 } 147 elsif ($state == $burntoolStateGood) { 148 $process = 0; 149 $previousTableStyle = 1; 150 } 151 elsif ($state == -1 * $burntoolStateGood) { 152 $process = 0; 153 # $previousTable = "in=$outTableReal"; 154 $previousTableStyle = -1; 155 } 156 else { 157 $process = 1; 158 } 159 if ($REALRUN == 0) { 160 print "##Pretending to process as instructed!\n"; 161 $process = 1; 162 } 163 if (($process == 1)||($processNext == 1)) { 164 $processNext = 1; 165 # Set state to processing 166 my $status = vsystem ("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state -1", $REALRUN); 189 167 if ($status) { 190 168 &my_die("failed to update imfile"); 191 169 } 170 $file->{burntool_state} = -1; 171 172 my $tempfile = new File::Temp ( TEMPLATE => "$file->{exp_name}.XXXX", 173 DIR => '/tmp/', 174 UNLINK => !$save_temps, 175 SUFFIX => '.fits'); 176 my $tempPixels = $tempfile->filename; 177 178 # Run burntool 179 $status = vsystem ("$funpack -S $rawImfileReal > $tempPixels", $REALRUN); 180 if ($status) { 181 &my_die("failed on funpack",$exp_id,$class_id); 182 } 183 if ($previousTable ne '') { 184 $status = vsystem ("$burntool $tempPixels $previousTable out=$outTableReal tableonly=t persist=t", $REALRUN); 185 } 186 else { 187 $status = vsystem ("$burntool $tempPixels out=$outTableReal tableonly=t persist=t", $REALRUN); 188 } 189 if ($status) { 190 &my_die("failed on burntool",$exp_id,$class_id); 191 } 192 &my_die("Unable to find output file: $outTableReal", $exp_id, $class_id) unless $ipprc->file_exists($outTableReal); 193 194 $status = vsystem ("$nebXattr --write $outTable user.copies:2", $REALRUN); 195 if ($status) { 196 &my_die("failed to neb-xattr imfile", $outTable); 197 } 198 $status = vsystem ("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state $outState", $REALRUN); 199 if ($status) { 200 &my_die("failed to update imfile"); 201 } 202 203 $previousTableStyle = -1; 204 192 205 print "\n"; 193 206 } 194 # save the artifact file for the next image 195 if ($RAWTABLES) { 196 $prevFileOpt = "in=$artImfileReal"; 197 } else { 198 $prevFileOpt = "infits=$artImfileReal"; 199 } 207 208 if ($previousTableStyle == 1) { 209 $previousTable = "infits=$rawImfileReal"; 210 } 211 elsif ($previousTableStyle == -1) { 212 $previousTable = "in=$outTableReal"; 213 } 214 else { 215 die "previousTableStyle undefined!\n"; 216 } 217 200 218 } 201 219 … … 207 225 208 226 print "$command\n"; 209 227 210 228 my $status = 0; 211 229 if ($realrun) { 212 $status = system ($command);230 $status = system ($command); 213 231 } 214 232 … … 218 236 sub my_die { 219 237 my $message = shift; 220 238 if ($#_ != -1) { 239 my $exp_id = shift; 240 my $class_id = shift; 241 vsystem("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state -3",1); 242 } 221 243 printf STDERR "$message\n"; 222 244 exit 1; -
Property svn:executable
set to
Note:
See TracChangeset
for help on using the changeset viewer.
