- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
ippScripts/scripts/magic_destreak_revert.pl (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/ippScripts/scripts/magic_destreak_revert.pl
r25024 r27840 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); … … 191 223 } 192 224 193 revert_files($ image, $mask, $weight, $sources, $astrom, $bimage, $bmask, $bweight, $bsources, $bastrom);194 195 if ($stage eq "diff" ) {225 revert_files($replace, $image, $mask, $weight, $sources, $astrom, $bimage, $bmask, $bweight, $bsources, $bastrom); 226 227 if ($stage eq "diff" and $bothways) { 196 228 my $name = "PPSUB.INVERSE"; 197 229 $image = $ipprc->filename($name, $path_base); … … 203 235 $bweight = $ipprc->filename("$name.VARIANCE", $backup_path_base); 204 236 $bsources = $ipprc->filename("$name.SOURCES", $backup_path_base); 205 revert_files($ image, $mask, $weight, $sources, undef, $bimage, $bmask, $bweight, $bsources, undef);237 revert_files($replace, $image, $mask, $weight, $sources, undef, $bimage, $bmask, $bweight, $bsources, undef); 206 238 } 207 239 208 240 # now revert the row in the database 209 241 { 210 my $command = "$magicdstool -revertdestreakedfile ";242 my $command = "$magicdstool -revertdestreakedfile -i_am_sure"; 211 243 $command .= " -magic_ds_id $magic_ds_id"; 212 244 $command .= " -component $component"; … … 231 263 232 264 sub revert_files { 265 my $replace = shift; 266 return if !$replace; 267 233 268 my $image = shift; 234 269 my $mask = shift; … … 249 284 if ($mask) { 250 285 if (!revert_file($mask, $bmask)) { 251 if ($stage eq 'chip') { 252 # don't fail if the mask file (from the camera stage) fails to revert. 253 # It probably doesn't exist 254 # XXX: Handle this properly 255 print STDERR "failure to revert mask file, ignored\n"; 256 } else { 257 &my_die("failed to restore mask file", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR); 258 } 286 &my_die("failed to restore mask file", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR); 259 287 } 260 288 } … … 264 292 &my_die("failed to restore chip mask file", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR); 265 293 } 266 } 294 } 267 295 268 296 … … 291 319 run(command => $command, verbose => $verbose); 292 320 321 if (!defined $error_code) { 322 print STDERR "run( $command ) returned undef error_code!!!!!\n"; 323 return $PS_EXIT_UNKNOWN_ERROR; 324 } 293 325 return $error_code >> 8; 294 326 } … … 298 330 my $original = shift; 299 331 my $backup = shift; 332 my $force = 1; # force deletion of backup files in nebulous 300 333 301 334 my $o_path = $ipprc->file_resolve($original); … … 323 356 324 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 } 325 371 # XXX TODO if stage is raw, check that backup has the correct size and md5sum 326 372 373 if ($verbose) { 374 print "ready to swap $backup\n"; 375 print " to $original\n"; 376 } 327 377 # Do we need to make this test? After the swap we're going to delete the file anyways 328 print "ready to swap $backup to $original\n" if $verbose;329 378 330 379 if (! $nebulous->swap($backup, $original)) { 331 print "failed to swap $backup to $original\n"; 380 print "failed to swap $backup\n"; 381 print " to $original\n"; 332 382 return 0; 333 383 } 334 384 335 if ($b_path and -e $b_path) {385 if ($b_path) { 336 386 print "ready to delete backup\n" if $verbose; 337 if (! $ipprc->file_delete($backup )) {387 if (! $ipprc->file_delete($backup, $force)) { 338 388 print "failed to delete $backup\n"; 339 389 return 0; … … 344 394 print "original uri: $original is not a destreaked file no need to swap backup_result: $backup_result\n"; 345 395 # delete the 'backup' (destreaked target) file if it exists 346 if ($b_path and -e $b_path) {347 if (! $ipprc->file_delete($backup )) {396 if ($b_path) { 397 if (! $ipprc->file_delete($backup, $force)) { 348 398 print "failed to delete $backup\n"; 349 399 return 0; … … 386 436 $exit_code = $PS_EXIT_PROG_ERROR unless defined $exit_code; 387 437 388 # we wouldn't be here unless an entry already exists in the database 389 # my $command = "$magicdstool -adddestreakedfile"; 390 # $command .= " -magic_ds_id $magic_ds_id"; 391 # $command .= " -component $component"; 392 # $command .= " -fault $exit_code"; 393 # $command .= " -dbname $dbname" if defined $dbname; 394 395 # # Add the processed file to the database 396 # unless ($no_update) { 397 # my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = 398 # run(command => $command, verbose => $verbose); 399 # unless ($success) { 400 # carp("failed to update database for $magic_ds_id $component"); 401 # } 402 # } else { 403 # print "Skipping command: $command\n"; 404 # } 405 406 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 407 455 exit $exit_code; 408 456 }
Note:
See TracChangeset
for help on using the changeset viewer.
