- Timestamp:
- Feb 10, 2010, 4:16:03 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/20091201/ippScripts/scripts/diff_skycell.pl
r26753 r26873 35 35 } 36 36 37 my ($diff_id, $dbname, $threads, $outroot, $reduction, $inverse, $ verbose, $no_update, $no_op, $redirect);37 my ($diff_id, $dbname, $threads, $outroot, $reduction, $inverse, $run_state, $verbose, $no_update, $no_op, $redirect); 38 38 my ($skycell_id, $diff_skyfile_id); 39 39 GetOptions( … … 43 43 'dbname|d=s' => \$dbname, # Database name 44 44 'threads=s' => \$threads, # Number of threads to use 45 'run-state=s' => \$run_state, # state for run: 'new' or 'update' 45 46 'outroot=s' => \$outroot, # Output root name 46 47 'inverse' => \$inverse, # Make inverse subtraction? … … 54 55 pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV; 55 56 pod2usage( 56 -msg => "Required options: --diff_id --skycell_id --outroot -- diff_skyfile_id",57 -msg => "Required options: --diff_id --skycell_id --outroot --run-state --diff_skyfile_id", 57 58 -exitval => 3, 58 59 ) unless defined $diff_id 59 60 and defined $skycell_id 60 61 and defined $diff_skyfile_id 62 and defined $run_state 61 63 and defined $outroot; 62 64 … … 66 68 # my $logDest = $ipprc->filename("LOG.EXP", $outroot); 67 69 my $logDest = "$outroot.log"; 70 $logDest .= ".update" if $run_state eq "update"; 68 71 $ipprc->redirect_output($logDest) or my_die( "Unable to redirect output", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR ) if $redirect; 69 72 … … 155 158 # The output file will be considered magicked if the input has been magicked and the 156 159 # template is either a stack or a warp that has been magicked. 157 # note that difftool -inputskyfile outputs the magicked boolean as an int not T or F 158 # because the output is constructed from a union of two selects 159 my $magicked = $inputMagic && $templateMagic; 160 my $magicked = $inputMagic && $templateMagic ? $inputMagic : 0; 160 161 161 162 # Recipes to use based on reduction class … … 216 217 my $traceDest = $ipprc->filename("TRACE.EXP", $outroot); 217 218 219 if ($run_state eq 'update') { 220 $traceDest .= '.update'; 221 $outputStats .= '.update'; 222 } 223 218 224 my ($inverseName, $inverseMask, $inverseVariance, $inverseSources); 219 225 if ($inverse) { … … 227 233 228 234 # Perform subtraction 229 unless ($no_op){235 { 230 236 my $command = "$ppSub $outroot"; 231 237 $command .= " -inimage $input"; … … 239 245 $command .= " -stats $outputStats"; 240 246 $command .= " -threads $threads" if defined $threads; 247 if ($run_state eq "new") { 248 $command .= " -dumpconfig $configuration"; 249 } else { 250 my $configurationReal = $ipprc->file_resolve($configuration) or &my_die("Couldn't resolve configuration file: $configuration", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR); 251 $command .= " -ipprc $configurationReal"; 252 } 241 253 $command .= " -recipe PPSUB $recipe_ppSub"; 242 254 $command .= " -recipe PSPHOT $recipe_psphot"; … … 245 257 $command .= " -F PSPHOT.OUTPUT PSPHOT.OUT.CMF.MEF"; 246 258 $command .= " -F PSPHOT.BACKMDL PSPHOT.BACKMDL.MEF"; 247 $command .= " -photometry"; 259 if ($run_state eq "new") { 260 $command .= " -photometry"; 261 } 248 262 $command .= " -inverse" if $inverse; 249 263 $command .= " -tracedest $traceDest -log $logDest"; 250 $command .= " -dumpconfig $configuration";251 264 $command .= " -dbname $dbname" if defined $dbname; 252 265 $command .= " -image_id $diff_skyfile_id" if defined $diff_skyfile_id; 253 266 $command .= " -source_id $source_id" if defined $source_id; 254 267 255 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 256 run(command => $command, verbose => $verbose); 257 unless ($success) { 258 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 259 &my_die("Unable to perform ppSub: $error_code", $diff_id, $skycell_id, $error_code); 260 } 261 262 my $outputStatsReal = $ipprc->file_resolve($outputStats); 263 &my_die("Couldn't find expected output file: $outputStats", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless -f $outputStatsReal; 264 265 # measure chip stats 266 $command = "$ppStatsFromMetadata $outputStatsReal - DIFF_SKYCELL"; 267 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 268 run(command => $command, verbose => $verbose); 269 unless ($success) { 270 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 271 &my_die("Unable to perform ppStatsFromMetadata: $error_code", $diff_id, $skycell_id, $error_code); 272 } 273 foreach my $line (@$stdout_buf) { 274 $cmdflags .= " $line"; 275 } 276 chomp $cmdflags; 277 278 my ($quality) = $cmdflags =~ /-quality (\d+)/; # Quality flag 279 280 if (!$quality) { 281 &my_die("Couldn't find expected output file: $outputName", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputName); 282 &my_die("Couldn't find expected output file: $outputMask", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask); 283 &my_die("Couldn't find expected output file: $outputVariance", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputVariance); 284 &my_die("Couldn't find expected output file: $outputSources", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources); 285 &my_die("Couldn't find expected output file: $jpeg1Name", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($jpeg1Name); 286 &my_die("Couldn't find expected output file: $jpeg2Name", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($jpeg2Name); 287 if ($inverse) { 288 &my_die("Couldn't find expected output file: $inverseName", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseName); 289 &my_die("Couldn't find expected output file: $inverseMask", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseMask); 290 &my_die("Couldn't find expected output file: $inverseVariance", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseVariance); 291 &my_die("Couldn't find expected output file: $inverseSources", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseSources); 292 } 293 } 294 } 295 296 unless ($no_update) { 297 298 # Add the subtraction result 299 { 300 my $command = "$difftool -adddiffskyfile -diff_id $diff_id -skycell_id $skycell_id -path_base $outroot"; 301 $command .= " $cmdflags"; 302 $command .= " -magicked" if $magicked; 303 $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400)); 304 $command .= " -hostname $host" if defined $host; 305 $command .= " -dbname $dbname" if defined $dbname; 306 268 unless ($no_op) { 307 269 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 308 270 run(command => $command, verbose => $verbose); 309 271 unless ($success) { 310 272 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 311 &my_die("Unable to perform difftool -adddiffskyfile: $error_code", $diff_id, $skycell_id, $error_code); 273 &my_die("Unable to perform ppSub: $error_code", $diff_id, $skycell_id, $error_code); 274 } 275 276 my $outputStatsReal = $ipprc->file_resolve($outputStats); 277 &my_die("Couldn't find expected output file: $outputStats", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless -f $outputStatsReal; 278 279 # measure chip stats 280 $command = "$ppStatsFromMetadata $outputStatsReal - DIFF_SKYCELL"; 281 ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 282 run(command => $command, verbose => $verbose); 283 unless ($success) { 284 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 285 &my_die("Unable to perform ppStatsFromMetadata: $error_code", $diff_id, $skycell_id, $error_code); 286 } 287 foreach my $line (@$stdout_buf) { 288 $cmdflags .= " $line"; 289 } 290 chomp $cmdflags; 291 292 my ($quality) = $cmdflags =~ /-quality (\d+)/; # Quality flag 293 294 if (!$quality) { 295 &my_die("Couldn't find expected output file: $outputName", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputName); 296 &my_die("Couldn't find expected output file: $outputMask", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask); 297 &my_die("Couldn't find expected output file: $outputVariance", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputVariance); 298 &my_die("Couldn't find expected output file: $outputSources", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources); 299 &my_die("Couldn't find expected output file: $jpeg1Name", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($jpeg1Name); 300 &my_die("Couldn't find expected output file: $jpeg2Name", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($jpeg2Name); 301 if ($inverse) { 302 &my_die("Couldn't find expected output file: $inverseName", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseName); 303 &my_die("Couldn't find expected output file: $inverseMask", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseMask); 304 &my_die("Couldn't find expected output file: $inverseVariance", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseVariance); 305 &my_die("Couldn't find expected output file: $inverseSources", $diff_id, $skycell_id, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($inverseSources); 306 } 307 } 308 } else { 309 print "Not executing: $command\n"; 310 } 311 } 312 313 unless ($no_update) { 314 315 # Add the subtraction result 316 { 317 my $command = "$difftool -diff_id $diff_id -skycell_id $skycell_id"; 318 $command .= " -magicked $magicked" if $magicked; 319 if ($run_state eq 'new') { 320 $command .= " -adddiffskyfile -path_base $outroot"; 321 $command .= " $cmdflags"; 322 $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400)); 323 $command .= " -hostname $host" if defined $host; 324 } else { 325 $command .= " -tofullskyfile"; 326 } 327 $command .= " -dbname $dbname" if defined $dbname; 328 329 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 330 run(command => $command, verbose => $verbose); 331 unless ($success) { 332 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 333 my $err_message = $run_state eq "update" ? 334 "Unable to perform difftool -adddiffskyfile" : 335 "Unable to perform difftool -tofullskyfile"; 336 &my_die("$err_message: $error_code", $diff_id, $skycell_id, $error_code); 312 337 } 313 338 } … … 326 351 warn($msg); 327 352 if (defined $diff_id and defined $skycell_id and not $no_update) { 328 my $command = "$difftool -adddiffskyfile -diff_id $diff_id -skycell_id $skycell_id -fault $exit_code"; 329 $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400)); 330 $command .= " -hostname $host" if defined $host; 331 $command .= " -path_base $outroot" if defined $outroot; 332 $command .= " -dbname $dbname" if defined $dbname; 353 my $command = "$difftool -diff_id $diff_id -skycell_id $skycell_id -fault $exit_code"; 354 if ($run_state eq 'new') { 355 $command .= " -adddiffskyfile"; 356 $command .= (" -dtime_script " . ((DateTime->now->mjd - $mjd_start) * 86400)); 357 $command .= " -hostname $host" if defined $host; 358 $command .= " -path_base $outroot" if defined $outroot; 359 $command .= " -dbname $dbname" if defined $dbname; 360 } else { 361 $command .= " -updatediffskyfile"; 362 } 333 363 run(command => $command, verbose => $verbose); 334 364 }
Note:
See TracChangeset
for help on using the changeset viewer.
