- Timestamp:
- May 3, 2010, 8:41:49 AM (16 years ago)
- Location:
- branches/tap_branches
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippScripts/scripts/magic_destreak_revert.pl (modified) (15 diffs, 1 prop)
Legend:
- Unmodified
- Added
- Removed
-
branches/tap_branches
- Property svn:mergeinfo changed
-
branches/tap_branches/ippScripts/scripts/magic_destreak_revert.pl
- Property svn:mergeinfo deleted
r25890 r27838 8 8 use Sys::Hostname; 9 9 my $host = hostname(); 10 my $date = `date`; 10 11 print "\n\n"; 11 print "Starting script $0 on $host \n\n";12 print "Starting script $0 on $host at $date\n\n"; 12 13 13 14 use vars qw( $VERSION ); … … 30 31 my $magicdstool = can_run('magicdstool') or (warn "Can't find magicdstool" and $missing_tools = 1); 31 32 my $isdestreaked = can_run('isdestreaked') or (warn "Can't find isdestreaked" and $missing_tools = 1); 33 my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1); 32 34 if ($missing_tools) { 33 35 warn("Can't find required tools."); … … 36 38 37 39 # Parse the command-line arguments 38 my ($magic_ds_id, $camera, $streaks, $stage, $stage_id, $component, $uri, $path_base, $ inverse, $cam_path_base);40 my ($magic_ds_id, $camera, $streaks, $stage, $stage_id, $component, $uri, $path_base, $bothways, $cam_path_base, $cam_reduction); 39 41 my ($outroot, $recoveryroot, $replace, $release, $bytes, $md5sum); 40 42 my ($dbname, $save_temps, $verbose, $no_update, $no_op, $logfile); … … 48 50 'path_base=s' => \$path_base, # path_base of the input 49 51 'cam_path_base=s'=> \$cam_path_base, # path_base of the associated camera run 52 'cam_reduction=s'=> \$cam_reduction, # reduction class of the associated camera run 50 53 'outroot=s' => \$outroot, # "directory" for temporary images (may be nebulous) 51 54 'recoveryroot=s' => \$recoveryroot,# "directory" for saving the images of excised pixels 52 55 'replace=s' => \$replace, # replace the input images with the results. 56 'bothways=s' => \$bothways, # run has inverse files (bothways diff) 53 57 'save-temps' => \$save_temps, # Save temporary files? 54 58 'dbname=s' => \$dbname, # Database name … … 78 82 $ipprc->redirect_output($logfile) or my_die( "Unable to redirect output", $magic_ds_id, $component, $PS_EXIT_SYS_ERROR ) if $logfile; 79 83 84 $cam_reduction = 'DEFAULT' if !defined $cam_reduction or ($cam_reduction eq "NULL"); 85 my $recipe_psastro = $ipprc->reduction($cam_reduction, 'PSASTRO'); # Recipe to use 86 &my_die("Unrecognised PSASTRO recipe", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR) unless defined $recipe_psastro; 87 80 88 my $nebulousServer = metadataLookupStr( $ipprc->{_siteConfig}, 'NEB_SERVER' ); 81 89 &my_die("cannot find NEB_SERVER in site configuration", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR) if !$nebulousServer; … … 111 119 } 112 120 113 &my_die("replace not allowed for non-nebulous files", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR) 121 &my_die("replace not allowed for non-nebulous files", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR) 114 122 if ($replace eq "T") and !$nebulousInput; 115 123 … … 155 163 $bimage = $backup_path_base . ".fits"; 156 164 } elsif ($stage eq "chip") { 165 # Check to see if we're using dynamic masks 166 my $dynamicMasks; # Use dynamic masks? 167 { 168 # Get the PSASTRO recipe 169 my $command = "$ppConfigDump -camera $camera -recipe PSASTRO $recipe_psastro -dump-recipe PSASTRO -"; 170 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 171 run(command => $command, verbose => $verbose); 172 unless ($success) { 173 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR); 174 &my_die("Unable to perform ppConfigDump: $error_code", $magic_ds_id, $component, 175 $PS_EXIT_CONFIG_ERROR); 176 } 177 my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or 178 &my_die("Unable to parse metadata config doc", $magic_ds_id, $component, 179 $PS_EXIT_CONFIG_ERROR); 180 181 $dynamicMasks = metadataLookupBool($recipeData, 'REFSTAR_MASK'); 182 } 183 157 184 # we use the mask output from the camera stage for input and replace 158 185 # the output of the chip stage with that mask as well. 159 186 $image = $ipprc->filename("PPIMAGE.CHIP", $path_base, $class_id); 160 $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $cam_path_base, $class_id);161 $ch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $path_base, $class_id);162 187 $weight = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $path_base, $class_id); 188 189 if ($dynamicMasks) { 190 $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $cam_path_base, $class_id); 191 $ch_mask = $ipprc->filename("PPIMAGE.CHIP.MASK", $path_base, $class_id); 192 } else { 193 $mask = $ipprc->filename("PPIMAGE.CHIP.MASK", $path_base, $class_id); 194 } 163 195 164 196 $bimage = $ipprc->filename("PPIMAGE.CHIP", $backup_path_base, $class_id); … … 193 225 revert_files($replace, $image, $mask, $weight, $sources, $astrom, $bimage, $bmask, $bweight, $bsources, $bastrom); 194 226 195 if ($stage eq "diff" and $ inverse) {227 if ($stage eq "diff" and $bothways) { 196 228 my $name = "PPSUB.INVERSE"; 197 229 $image = $ipprc->filename($name, $path_base); … … 252 284 if ($mask) { 253 285 if (!revert_file($mask, $bmask)) { 254 if ($stage eq 'chip') { 255 # don't fail if the mask file (from the camera stage) fails to revert. 256 # It probably doesn't exist 257 # XXX: Handle this properly 258 print STDERR "failure to revert mask file, ignored\n"; 259 } else { 260 &my_die("failed to restore mask file", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR); 261 } 286 &my_die("failed to restore mask file", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR); 262 287 } 263 288 } … … 267 292 &my_die("failed to restore chip mask file", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR); 268 293 } 269 } 294 } 270 295 271 296 … … 294 319 run(command => $command, verbose => $verbose); 295 320 321 if (!defined $error_code) { 322 print STDERR "run( $command ) returned undef error_code!!!!!\n"; 323 return $PS_EXIT_UNKNOWN_ERROR; 324 } 296 325 return $error_code >> 8; 297 326 } … … 301 330 my $original = shift; 302 331 my $backup = shift; 332 my $force = 1; # force deletion of backup files in nebulous 303 333 304 334 my $o_path = $ipprc->file_resolve($original); … … 326 356 327 357 if ($backup_is_not_destreaked) { 358 if ($original_is_not_destreaked) { 359 # this is unexpected result. throw an error so this can be checked manually 360 print STDERR "both files appear to not be destreaked\n"; 361 print STDERR "original: $original\n"; 362 print STDERR "backup: $backup\n"; 363 my $o_basename = basename($o_path); 364 my $b_basename = basename($b_path); 365 if (($o_basename =~ /SR_/) and !($b_basename =~ /SR_/)) { 366 print " basenames are as expected it is safe to revert\n"; 367 } else { 368 return 0; 369 } 370 } 328 371 # XXX TODO if stage is raw, check that backup has the correct size and md5sum 329 372 373 if ($verbose) { 374 print "ready to swap $backup\n"; 375 print " to $original\n"; 376 } 330 377 # Do we need to make this test? After the swap we're going to delete the file anyways 331 print "ready to swap $backup to $original\n" if $verbose;332 378 333 379 if (! $nebulous->swap($backup, $original)) { 334 print "failed to swap $backup to $original\n"; 380 print "failed to swap $backup\n"; 381 print " to $original\n"; 335 382 return 0; 336 383 } 337 384 338 if ($b_path and -e $b_path) {385 if ($b_path) { 339 386 print "ready to delete backup\n" if $verbose; 340 if (! $ipprc->file_delete($backup )) {387 if (! $ipprc->file_delete($backup, $force)) { 341 388 print "failed to delete $backup\n"; 342 389 return 0; … … 347 394 print "original uri: $original is not a destreaked file no need to swap backup_result: $backup_result\n"; 348 395 # delete the 'backup' (destreaked target) file if it exists 349 if ($b_path and -e $b_path) {350 if (! $ipprc->file_delete($backup )) {396 if ($b_path) { 397 if (! $ipprc->file_delete($backup, $force)) { 351 398 print "failed to delete $backup\n"; 352 399 return 0; … … 389 436 $exit_code = $PS_EXIT_PROG_ERROR unless defined $exit_code; 390 437 391 # we wouldn't be here unless an entry already exists in the database 392 # my $command = "$magicdstool -adddestreakedfile"; 393 # $command .= " -magic_ds_id $magic_ds_id"; 394 # $command .= " -component $component"; 395 # $command .= " -fault $exit_code"; 396 # $command .= " -dbname $dbname" if defined $dbname; 397 398 # # Add the processed file to the database 399 # unless ($no_update) { 400 # my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 401 # run(command => $command, verbose => $verbose); 402 # unless ($success) { 403 # carp("failed to update database for $magic_ds_id $component"); 404 # } 405 # } else { 406 # print "Skipping command: $command\n"; 407 # } 408 409 carp($msg); 438 # fault the whole run if one of the components fails to revert 439 my $command = "$magicdstool -updaterun"; 440 $command .= " -magic_ds_id $magic_ds_id"; 441 $command .= " -set_state failed_revert"; 442 $command .= " -dbname $dbname" if defined $dbname; 443 444 # Add the processed file to the database 445 unless ($no_update) { 446 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 447 run(command => $command, verbose => $verbose); 448 unless ($success) { 449 carp("failed to update database for $magic_ds_id $component"); 450 } 451 } else { 452 print "Skipping command: $command\n"; 453 } 454 410 455 exit $exit_code; 411 456 }
Note:
See TracChangeset
for help on using the changeset viewer.
