IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

updates from trunk

Location:
branches/tap_branches
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/tap_branches

  • branches/tap_branches/ippScripts/scripts/magic_destreak_cleanup.pl

    r25837 r27838  
    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 $missing_tools;
    3132my $magicdstool   = can_run('magicdstool') or (warn "Can't find magicdstool" 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.");
     
    6163$ipprc->redirect_output($logfile) or my_die( "Unable to redirect output", $magic_ds_id, $PS_EXIT_SYS_ERROR ) if $logfile;
    6264
    63 if (0) {
    64 my $nebulousServer = metadataLookupStr( $ipprc->{_siteConfig}, 'NEB_SERVER' );
    65 &my_die("cannot find NEB_SERVER in site configuration", $magic_ds_id, $PS_EXIT_CONFIG_ERROR) if !$nebulousServer;
    66 
    67 my $nebulous = eval { Nebulous::Client->new( proxy => $nebulousServer ); };
    68 if ($@ or not defined $nebulous) {
    69     &my_die ("Unable to create a Nebulous::Client object with proxy $nebulousServer", $magic_ds_id, $PS_EXIT_CONFIG_ERROR);
    70 }
    71 }
    7265
    7366$dbname = metadataLookupStr( $ipprc->{_siteConfig}, 'DBNAME' ) if !$dbname;
     
    8679my $dbh = DBI->connect($dsn, $dbuser, $dbpassword) or die "Cannot connect to mysql server\n";
    8780
    88 my $q1 = "SELECT magicDSRun.*, camera, camProcessedExp.path_base AS cam_path_base, magicRun.inverse"
    89          . " FROM magicDSRun JOIN magicRun USING(magic_id) JOIN rawExp USING(exp_id) LEFT JOIN camProcessedExp USING(cam_id)"
     81my $q1 = "SELECT magicDSRun.*, camera, camProcessedExp.path_base AS cam_path_base, camRun.reduction AS cam_reduction, magicRun.inverse"
     82         . " FROM magicDSRun JOIN magicRun USING(magic_id) JOIN rawExp USING(exp_id) LEFT JOIN camProcessedExp USING(cam_id) LEFT JOIN camRun USING(cam_id)"
    9083         . " WHERE magic_ds_id = $magic_ds_id";
    9184my $q2 = "SELECT * from magicDSFile where magic_ds_id = $magic_ds_id";
    92 
    93 # my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    9485
    9586my $stmt1 = $dbh->prepare($q1);
     
    10394my $stage_id = $run->{stage_id};
    10495my $cam_path_base = $run->{cam_path_base};
     96my $cam_reduction = $run->{cam_reduction};
     97$cam_reduction = 'DEFAULT' if !$cam_reduction or ($cam_reduction eq 'NULL');
    10598my $inverse = $run->{inverse};
     99
     100
     101&my_die("cleanup not supported for camera stage", $magic_ds_id, $PS_EXIT_PROG_ERROR) if $stage eq "camera";
    106102
    107103
     
    109105&my_die("clean not allowed for raw stage, use goto_restore", $magic_ds_id, $PS_EXIT_CONFIG_ERROR) if $stage eq "raw";
    110106
     107my $recipe_psastro = $ipprc->reduction($cam_reduction, 'PSASTRO'); # Recipe to use
     108&my_die("Unrecognised PSASTRO recipe", $magic_ds_id, $PS_EXIT_CONFIG_ERROR) unless defined $recipe_psastro;
     109
    111110
    112111my $stmt2 = $dbh->prepare($q2);
     
    114113
    115114my $num_components = 0;
     115my @components;
     116# save the data, so we can disconnect from the database
     117# deleting can take awhile
    116118while (my $comp = $stmt2->fetchrow_hashref()) {
     119        push @components, $comp;
    117120        $num_components++;
    118 
     121}
     122
     123$stmt2->finish();
     124$dbh->disconnect() or warn $dbh->errstr;
     125
     126# We no longer clean up the camera stage mask files, but the code was left in place in case
     127# we change our minds.
     128my $cleanup_cam_mask = 0;
     129
     130my $dynamicMasks;               # Use dynamic masks?
     131foreach my $comp (@components) {
    119132        my $component = $comp->{component};
    120133        my $backup_path_base = $comp->{backup_path_base};
     
    124137
    125138        if ($stage eq "chip") {
    126             # we use the mask output from the camera stage for input and replace
    127             # the output of the chip stage with that mask as well.
    128             my $cammask   = $ipprc->filename("PSASTRO.OUTPUT.MASK", $cam_path_base, $component);
     139            # Check to see if we're using dynamic masks
     140            if ($cleanup_cam_mask && !defined $dynamicMasks) {
     141                # Get the PSASTRO recipe
     142                my $command = "$ppConfigDump -camera $camera -recipe PSASTRO $recipe_psastro -dump-recipe PSASTRO -";
     143                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     144                    run(command => $command, verbose => $verbose);
     145                unless ($success) {
     146                    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     147                    &my_die("Unable to perform ppConfigDump: $error_code", $magic_ds_id, $component,
     148                            $PS_EXIT_CONFIG_ERROR);
     149                }
     150                my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     151                my $recipeData = $mdcParser->parse(join "", @$stdout_buf) or
     152                    &my_die("Unable to parse metadata config doc", $magic_ds_id, $component,
     153                            $PS_EXIT_CONFIG_ERROR);
     154
     155                $dynamicMasks = metadataLookupBool($recipeData, 'REFSTAR_MASK');
     156            }
    129157
    130158            if ($backup_path_base) {
    131159                $bimage  = $ipprc->filename("PPIMAGE.CHIP", $backup_path_base, $component);
    132                 $bch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $backup_path_base, $component);
     160
     161                if ($dynamicMasks) {
     162                    my $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $cam_path_base, $component);
     163                    # This is kludgey but correct
     164                    $bmask = dirname($backup_path_base) . "/SR_" . basename($mask);
     165                    $bch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $backup_path_base, $component);
     166                } else {
     167                    $bmask = $ipprc->filename("PPIMAGE.CHIP.MASK", $backup_path_base, $component);
     168                }
    133169                $bweight = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $backup_path_base, $component);
    134                 # This is kludgey but correct
    135                
    136                 my $prefix;
    137                 if ($backup_path_base =~ /\.SR/) {
    138                     $prefix = "";
    139                 } else {
    140                     $prefix = "SR_";
    141                 }
    142 
    143                 $bmask   = dirname($backup_path_base) . "/" . $prefix . basename($cammask);
    144170            }
    145171            if ($recovery_path_base) {
    146172                $rimage  = $ipprc->filename("PPIMAGE.CHIP", $recovery_path_base, $component);
    147                 $rch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $recovery_path_base, $component);
     173
     174                if ($dynamicMasks) {
     175                    my $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $cam_path_base, $component);
     176                    # This is kludgey but correct
     177                    $rmask = dirname($recovery_path_base) . "/" . basename($mask);
     178                    $rch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $recovery_path_base, $component);
     179                } else {
     180                    $rmask = $ipprc->filename("PPIMAGE.CHIP.MASK", $recovery_path_base, $component);
     181                }
    148182                $rweight = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $recovery_path_base, $component);
    149                 # This is kludgey but correct
    150                 $rmask   = dirname($recovery_path_base) . "/" . basename($cammask);
    151183            }
    152184        } elsif ($stage eq "camera") {
     
    160192                $bweight = $ipprc->filename("PSWARP.OUTPUT.VARIANCE", $backup_path_base);
    161193                $bsources = $ipprc->filename("PSWARP.OUTPUT.SOURCES", $backup_path_base);
    162             } 
     194            }
    163195            if ($recovery_path_base) {
    164196                $rimage  = $ipprc->filename("PSWARP.OUTPUT", $recovery_path_base);
     
    166198                $rweight = $ipprc->filename("PSWARP.OUTPUT.VARIANCE", $recovery_path_base);
    167199                $rsources = $ipprc->filename("PSWARP.OUTPUT.SOURCES", $recovery_path_base);
    168             } 
     200            }
    169201        } elsif ($stage eq "diff") {
    170202            my $name = "PPSUB.OUTPUT";
     
    183215        }
    184216
    185         delete_files($rimage, $rmask, $rweight, $rsources, $rastrom, $bimage, $bmask, $bweight, $bsources, $bastrom);
     217        delete_files($rimage, $rmask, $rweight, $rsources, $rastrom, $bimage, $bmask, $bweight, $bsources, $bastrom, $bch_mask, $rch_mask);
    186218
    187219        if ($stage eq "diff" and $inverse) {
     
    199231                $rsources = $ipprc->filename("$name.SOURCES", $recovery_path_base);
    200232            }
    201             delete_files($rimage, $rmask, $rweight, $rsources, undef, $bimage, $bmask, $bweight, $bsources, undef);
     233            # undef is not necessary, it's just to keep the lists in the same order.
     234            delete_files($rimage, $rmask, $rweight, $rsources, undef, $bimage, $bmask, $bweight, $bsources);
    202235        }
    203236}
     237
     238$dbh = DBI->connect($dsn, $dbuser, $dbpassword) or die "Cannot connect to mysql server\n";
    204239
    205240if (!$no_update and ($num_components > 0)) {
     
    211246if (!$no_update) {
    212247    my $result = $dbh->do("UPDATE magicDSRun SET state = 'cleaned' WHERE magic_ds_id = ?", undef, $magic_ds_id);
    213     my_die("attempt to update magicDSRun failed", $magic_ds_id, $PS_EXIT_UNKNOWN_ERROR) if $result eq "0E0";
     248    my_die("attempt to update magicDSRun.state failed", $magic_ds_id, $PS_EXIT_UNKNOWN_ERROR) if $result eq "0E0";
    214249} else {
    215250    print STDERR "skipping update of magicDSRun\n";
     
    225260                if (!$no_update) {
    226261                    print STDERR "deleting $file\n" if $verbose;
    227                     $ipprc->file_delete($file) or my_die("Failed to delete $file", $magic_ds_id, $PS_EXIT_UNKNOWN_ERROR);
     262                    $ipprc->file_delete($file, 1) or my_die("Failed to delete $file", $magic_ds_id, $PS_EXIT_UNKNOWN_ERROR);
    228263                    } else {
    229264                    print STDERR "skipping delete $file\n";
     
    246281    $exit_code = $PS_EXIT_PROG_ERROR unless defined $exit_code;
    247282
    248     my $command = "$magicdstool -updaterun -fault $exit_code";
     283    my $command = "$magicdstool -updaterun -set_state failed_cleanup";
    249284    $command   .= " -magic_ds_id $magic_ds_id";
    250285    $command   .= " -dbname $dbname" if defined $dbname;
Note: See TracChangeset for help on using the changeset viewer.