IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 3, 2010, 8:50:52 AM (16 years ago)
Author:
eugene
Message:

updates from trunk

Location:
branches/simtest_nebulous_branches
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/simtest_nebulous_branches

  • branches/simtest_nebulous_branches/ippScripts/scripts/magic_destreak_revert.pl

    r25024 r27840  
    88use Sys::Hostname;
    99my $host = hostname();
     10my $date = `date`;
    1011print "\n\n";
    11 print "Starting script $0 on $host\n\n";
     12print "Starting script $0 on $host at $date\n\n";
    1213
    1314use vars qw( $VERSION );
     
    3031my $magicdstool   = can_run('magicdstool') or (warn "Can't find magicdstool" and $missing_tools = 1);
    3132my $isdestreaked = can_run('isdestreaked') or (warn "Can't find isdestreaked" and $missing_tools = 1);
     33my $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
    3234if ($missing_tools) {
    3335    warn("Can't find required tools.");
     
    3638
    3739# Parse the command-line arguments
    38 my ($magic_ds_id, $camera, $streaks, $stage, $stage_id, $component, $uri, $path_base, $inverse, $cam_path_base);
     40my ($magic_ds_id, $camera, $streaks, $stage, $stage_id, $component, $uri, $path_base, $bothways, $cam_path_base, $cam_reduction);
    3941my ($outroot, $recoveryroot, $replace, $release, $bytes, $md5sum);
    4042my ($dbname, $save_temps, $verbose, $no_update, $no_op, $logfile);
     
    4850           'path_base=s'    => \$path_base,  # path_base of the input
    4951           '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
    5053           'outroot=s'      => \$outroot,     # "directory" for temporary images (may be nebulous)
    5154           'recoveryroot=s' => \$recoveryroot,# "directory" for saving the images of excised pixels
    5255           'replace=s'      => \$replace,    # replace the input images with the results.
     56           'bothways=s'     => \$bothways,   # run has inverse files (bothways diff)
    5357           'save-temps'     => \$save_temps, # Save temporary files?
    5458           'dbname=s'       => \$dbname,     # Database name
     
    7882$ipprc->redirect_output($logfile) or my_die( "Unable to redirect output", $magic_ds_id, $component, $PS_EXIT_SYS_ERROR ) if $logfile;
    7983
     84$cam_reduction = 'DEFAULT' if !defined $cam_reduction or ($cam_reduction eq "NULL");
     85my $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
    8088my $nebulousServer = metadataLookupStr( $ipprc->{_siteConfig}, 'NEB_SERVER' );
    8189&my_die("cannot find NEB_SERVER in site configuration", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR) if !$nebulousServer;
     
    111119}
    112120
    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)
    114122    if ($replace eq "T") and !$nebulousInput;
    115123
     
    155163    $bimage = $backup_path_base . ".fits";
    156164} 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
    157184    # we use the mask output from the camera stage for input and replace
    158185    # the output of the chip stage with that mask as well.
    159186    $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);
    162187    $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    }
    163195
    164196    $bimage  = $ipprc->filename("PPIMAGE.CHIP", $backup_path_base, $class_id);
     
    191223}
    192224
    193 revert_files($image, $mask, $weight, $sources, $astrom, $bimage, $bmask, $bweight, $bsources, $bastrom);
    194 
    195 if ($stage eq "diff") {
     225revert_files($replace, $image, $mask, $weight, $sources, $astrom, $bimage, $bmask, $bweight, $bsources, $bastrom);
     226
     227if ($stage eq "diff" and $bothways) {
    196228    my $name = "PPSUB.INVERSE";
    197229    $image  = $ipprc->filename($name, $path_base);
     
    203235    $bweight = $ipprc->filename("$name.VARIANCE", $backup_path_base);
    204236    $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);
    206238}
    207239
    208240# now revert the row in the database
    209241{
    210     my $command = "$magicdstool -revertdestreakedfile";
     242    my $command = "$magicdstool -revertdestreakedfile -i_am_sure";
    211243    $command   .= " -magic_ds_id $magic_ds_id";
    212244    $command   .= " -component $component";
     
    231263
    232264sub revert_files {
     265    my $replace = shift;
     266    return if !$replace;
     267
    233268    my $image = shift;
    234269    my $mask = shift;
     
    249284    if ($mask) {
    250285        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);
    259287        }
    260288    }
     
    264292            &my_die("failed to restore chip mask file", $magic_ds_id, $component, $PS_EXIT_CONFIG_ERROR);
    265293        }
    266     } 
     294    }
    267295
    268296
     
    291319        run(command => $command, verbose => $verbose);
    292320
     321    if (!defined $error_code) {
     322        print STDERR "run( $command ) returned undef error_code!!!!!\n";
     323        return $PS_EXIT_UNKNOWN_ERROR;
     324    }
    293325    return $error_code >> 8;
    294326}
     
    298330    my $original = shift;
    299331    my $backup   = shift;
     332    my $force = 1; # force deletion of backup files in nebulous
    300333
    301334    my $o_path = $ipprc->file_resolve($original);
     
    323356
    324357    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        }
    325371        # XXX TODO if stage is raw, check that backup has the correct size and md5sum
    326372
     373        if ($verbose) {
     374            print "ready to swap $backup\n";
     375            print "           to $original\n";
     376        }
    327377        # 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;
    329378
    330379        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";
    332382            return 0;
    333383        }
    334384
    335         if ($b_path and -e $b_path) {
     385        if ($b_path) {
    336386            print "ready to delete backup\n" if $verbose;
    337             if (! $ipprc->file_delete($backup)) {
     387            if (! $ipprc->file_delete($backup, $force)) {
    338388                print "failed to delete $backup\n";
    339389                return 0;
     
    344394        print "original uri: $original is not a destreaked file no need to swap backup_result: $backup_result\n";
    345395        # 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)) {
    348398                print "failed to delete $backup\n";
    349399                return 0;
     
    386436    $exit_code = $PS_EXIT_PROG_ERROR unless defined $exit_code;
    387437
    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
    407455    exit $exit_code;
    408456}
Note: See TracChangeset for help on using the changeset viewer.