IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 15, 2008, 2:24:27 PM (18 years ago)
Author:
bills
Message:

update processing for camera stage

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippScripts/scripts/ipp_cleanup.pl

    r19397 r19561  
    5050}
    5151
     52my %stages = ( chip => 1, camera => 1, fake => 1, warp => 1, stack => 1, diff  => 1);
     53unless ($stages{$stage}) {
     54    die "unknown stage $stage for ipp_cleanup.pl\n";
     55}
     56
    5257$ipprc->define_camera($camera);
    5358
    5459my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    55 
    56 my $fault = 0;
    5760
    5861# choice of files to delete depends on the stage
    5962if ($stage eq "chip") {
    6063   
     64    die "--stage_id required for stage chip\n" if !$stage_id;
    6165    ### select the imfiles for this entry
    6266
     
    8589        my $class_id = $imfile->{class_id};
    8690        my $path_base = $imfile->{path_base};
    87 
    88         # array of actual filenames to delete
    89         my @files = ();
    90 
    91         # delete the temporary image datafiles
    92         addFilename (\@files, "PPIMAGE.OUTPUT", $path_base, $class_id);
    93         addFilename (\@files, "PPIMAGE.OUTPUT.MASK", $path_base, $class_id);
    94         addFilename (\@files, "PPIMAGE.OUTPUT.WEIGHT", $path_base, $class_id);
    95         addFilename (\@files, "PPIMAGE.CHIP", $path_base, $class_id);
    96         addFilename (\@files, "PPIMAGE.CHIP.MASK", $path_base, $class_id);
    97         addFilename (\@files, "PPIMAGE.CHIP.WEIGHT", $path_base, $class_id);
    98         if ($mode eq "goto_purged") {
    99             # additional files to remove for 'purge' mode
    100             addFilename (\@files, "PPIMAGE.OUTPUT.FPA1", $path_base, $class_id);
    101             addFilename (\@files, "PPIMAGE.OUTPUT.FPA2", $path_base, $class_id);
    102             addFilename (\@files, "PPIMAGE.BIN1", $path_base, $class_id);
    103             addFilename (\@files, "PPIMAGE.BIN2", $path_base, $class_id);
    104             addFilename (\@files, "PPIMAGE.JPEG1", $path_base, $class_id);
    105             addFilename (\@files, "PPIMAGE.JPEG", $path_base, $class_id);
    106             addFilename (\@files, "PPIMAGE.STATS", $path_base, $class_id);
    107         }
     91        my $status = 1;
     92
     93        # don't clean up unless the data needed to update is available
     94        if ($mode eq "goto_cleaned") {
     95            my $config_file = $ipprc->filename("PPIMAGE.CONFIG", $path_base, $class_id);
     96
     97            if (!$config_file or ! -e $config_file) {
     98                print STDERR "skipping cleanup for chipRun $stage_id $class_id "
     99                    . " because config file is missing\n";
     100                $status = 0;
     101            }
     102        }
     103
     104        if ($status) {
     105            # array of actual filenames to delete
     106            my @files = ();
     107
     108            # delete the temporary image datafiles
     109            addFilename (\@files, "PPIMAGE.OUTPUT", $path_base, $class_id);
     110            addFilename (\@files, "PPIMAGE.OUTPUT.MASK", $path_base, $class_id);
     111            addFilename (\@files, "PPIMAGE.OUTPUT.WEIGHT", $path_base, $class_id);
     112            addFilename (\@files, "PPIMAGE.CHIP", $path_base, $class_id);
     113            addFilename (\@files, "PPIMAGE.CHIP.MASK", $path_base, $class_id);
     114            addFilename (\@files, "PPIMAGE.CHIP.WEIGHT", $path_base, $class_id);
     115            if ($mode eq "goto_purged") {
     116                # additional files to remove for 'purge' mode
     117                addFilename (\@files, "PPIMAGE.OUTPUT.FPA1", $path_base, $class_id);
     118                addFilename (\@files, "PPIMAGE.OUTPUT.FPA2", $path_base, $class_id);
     119                addFilename (\@files, "PPIMAGE.BIN1", $path_base, $class_id);
     120                addFilename (\@files, "PPIMAGE.BIN2", $path_base, $class_id);
     121                addFilename (\@files, "PPIMAGE.JPEG1", $path_base, $class_id);
     122                addFilename (\@files, "PPIMAGE.JPEG", $path_base, $class_id);
     123                addFilename (\@files, "PPIMAGE.STATS", $path_base, $class_id);
     124                addFilename (\@files, "PPIMAGE.CONFIG", $path_base, $class_id);
     125            }
    108126       
    109         # actual command to delete the files
    110         my $status = &delete_files (\@files);
     127            # actual command to delete the files
     128            $status = &delete_files (\@files);
     129        }
    111130
    112131        if ($status)  {
     
    119138            $command .= " -dbname $dbname" if defined $dbname;
    120139
    121             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     140            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     141                    run(command => $command, verbose => $verbose);
    122142            unless ($success) {
    123143                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     
    125145            }
    126146        } else {
    127             my $command = "$chiptool -updateimfile -chip_id $stage_id -class_id $class_id -code 1";
     147            my $command = "$chiptool -updateprocessedimfile -chip_id $stage_id -class_id $class_id -code 1";
    128148            $command .= " -dbname $dbname" if defined $dbname;
    129149
    130             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
     150            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     151                    run(command => $command, verbose => $verbose);
    131152            unless ($success) {
    132153                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    133154                &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code);
    134155            }
    135             $fault = 1;
    136156        }
    137157    }
    138158
    139 if (0) {
    140     # This block is not necessary
    141     # chiptool -tocleanedimfile and -topurgedimfile automatically update chipRun when the
    142     # last image gets set to purged or cleaned
    143 
    144     if (! $fault) {
    145         # set the state of the chipRun entry to "cleaned" or "purged" as needed
    146         my $command = "$chiptool -updaterun -chip_id $stage_id";
    147         if ($mode eq "goto_purged") {
    148             $command .= " -state purged";
    149         } else {
    150             $command .= " -state cleaned";
    151         }
    152         $command .= " -dbname $dbname" if defined $dbname;
    153 
    154         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) = run(command => $command, verbose => $verbose);
    155         unless ($success) {
    156             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    157             &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code);
    158         }
    159     }
    160 }
    161     exit 0;
    162 }
    163 
    164 # choice of files to delete depends on the stage
    165 if ($stage eq "camera") {
     159} elsif ($stage eq "camera") {
     160    die "--stage_id required for stage camera\n" if !$stage_id;
    166161    # this stage uses 'camtool'
    167162    my $camtool = can_run('camtool') or die "Can't find camtool";
     
    169164    # Get list of component imfiles
    170165    # XXX may need a different my_die for each stage
    171     my $imfiles;                      # Array of component files
     166    my $exps;                      # Array of component files
    172167    my $command = "$camtool -pendingcleanupexp -cam_id $stage_id"; # Command to run
    173168    $command .= " -dbname $dbname" if defined $dbname;
     
    175170    unless ($success) {
    176171        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    177         &my_die("Unable to perform camtool: $error_code", "cam", $stage_id, $error_code);
     172        &my_die("Unable to perform camtool: $error_code", "camera", $stage_id, $error_code);
    178173    }
    179174    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    180         &my_die("Unable to parse metadata config doc", "cam", $stage_id, $PS_EXIT_PROG_ERROR);
    181 
     175        &my_die("Unable to parse metadata config doc", "camera", $stage_id, $PS_EXIT_PROG_ERROR);
     176
     177    $exps = parse_md_list($metadata) or
     178        &my_die("Unable to parse metadata list", "camera", $stage_id, $PS_EXIT_PROG_ERROR);
     179
     180    my $n_exps = @$exps;
     181    &my_die("unexpected number of exposures $n_exps", "camera", $stage_id, $PS_EXIT_PROG_ERROR)
     182        if $n_exps != 1;
     183
     184    my $exp = $exps->[0];
     185    my $path_base = $exp->{path_base};
     186
     187    my $status = 1;
     188    # don't clean up unless the data needed to update is available
     189    if ($mode eq "goto_cleaned") {
     190        my $config_file = $ipprc->filename("PSASTRO.CONFIG", $path_base);
     191
     192        if (!$config_file or ! -e $config_file) {
     193            print STDERR "skipping cleanup for camRun $stage_id because config file is missing\n";
     194            $status = 0;
     195        }
     196    }
     197    if ($status) {
     198        my @files = ();
     199        # delete the temporary image datafiles
     200        addFilename (\@files, "PSASTRO.OUTPUT", $path_base);
     201        if ($mode eq "goto_purged") {
     202            # additional files to remove for 'purge' mode
     203            addFilename (\@files, "PPIMAGE.JPEG1", $path_base);
     204            addFilename (\@files, "PPIMAGE.JPEG2", $path_base);
     205            addFilename (\@files, "PSASTRO.STATS", $path_base);
     206        }
     207        # actual command to delete the files
     208        $status = &delete_files (\@files);
     209    }
     210
     211    if ($status)  {
     212        my $command = "$camtool -cam_id $stage_id -updaterun";
     213        if ($mode eq "goto_cleaned") {
     214            $command .= " -state cleaned";
     215        } else {
     216            $command .= " -state purged";
     217        }
     218        $command .= " -dbname $dbname" if defined $dbname;
     219        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     220            run(command => $command, verbose => $verbose);
     221        unless ($success) {
     222            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     223            &my_die("Unable to perform camtool: $error_code", "camera", $stage_id, $error_code);
     224        }
     225    } else {
     226        my $command = "$camtool -updateprocessedexp -cam_id $stage_id -code 1";
     227        $command .= " -dbname $dbname" if defined $dbname;
     228
     229        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     230            run(command => $command, verbose => $verbose);
     231        unless ($success) {
     232            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     233            &my_die("Unable to perform camtool: $error_code", "camera", $stage_id, $error_code);
     234        }
     235        exit $PS_EXIT_UNKNOWN_ERROR;
     236    }
    182237    exit 0;
    183 }
    184 
     238} elsif ($stage eq "warp") {
     239    die "--stage_id required for stage warp\n" if !$stage_id;
     240    # this stage uses 'warptool'
     241    my $warptool = can_run('warptool') or die "Can't find warptool";
     242
     243    # Get list of component imfiles
     244    # XXX may need a different my_die for each stage
     245    my $skyfiles;                      # Array of component files
     246    my $command = "$warptool -pendingcleanupskyfile -warp_id $stage_id"; # Command to run
     247    $command .= " -dbname $dbname" if defined $dbname;
     248    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     249            run(command => $command, verbose => $verbose);
     250    unless ($success) {
     251        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     252        &my_die("Unable to perform warptool: $error_code", "warp", $stage_id, $error_code);
     253    }
     254    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
     255        &my_die("Unable to parse metadata config doc", "warp", $stage_id, $PS_EXIT_PROG_ERROR);
     256
     257    $skyfiles = parse_md_list($metadata) or
     258        &my_die("Unable to parse metadata list", "warp", $stage_id, $PS_EXIT_PROG_ERROR);
     259
     260    my @files = ();
     261    foreach my $skyfile (@$skyfiles) {
     262        my $path_base = $skyfile->{path_base};
     263        my $skycell_id = $skyfile->{skycell_id};
     264
     265        my $status = 1;
     266        if ($mode eq "goto_cleaned") {
     267            my $config_file = $ipprc->filename("PSWARP.CONFIG", $path_base, $skycell_id);
     268
     269            if (!$config_file or ! -e $config_file) {
     270                print STDERR "skipping cleanup for warpRun $stage_id $skycell_id" .
     271                    " because config file is missing\n";
     272                $status = 0;
     273            }
     274        }
     275        if ($status) {
     276            # delete the temporary image datafiles
     277            addFilename(\@files, "PSWARP.OUTPUT", $path_base, $skycell_id );
     278            addFilename(\@files, "PSWARP.OUTPUT.MASK", $path_base, $skycell_id);
     279            addFilename(\@files, "PSWARP.OUTPUT.WEIGHT", $path_base, $skycell_id);
     280            addFilename(\@files, "PSWARP.OUTPUT.SOURCES", $path_base, $skycell_id);
     281
     282            if ($mode eq "goto_purged") {
     283                # additional files to remove for 'purge' mode
     284                addFilename(\@files, "PSWARP.BIN1", $path_base, $skycell_id );
     285                addFilename(\@files, "PSWARP.BIN2", $path_base, $skycell_id );
     286                addFilename(\@files, "SKYCELL.STATS", $path_base, $skycell_id );
     287                # addFilename(\@files, "PSPHOT.PSF.SKY.SAVE", $path_base);
     288
     289                # XXX: do we want to delete these?
     290                # addFilename(\@files, "TRACE.EXP", $path_base, $skycell_id);
     291                # addFilename(\@files, "PSWARP.CONFIG", $path_base, $skycell_id);
     292            }
     293            # actual command to delete the files
     294            $status = &delete_files (\@files);
     295        }
     296
     297        if ($status)  {
     298            my $command = "$warptool -warp_id $stage_id -skycell_id $skycell_id";
     299            if ($mode eq "goto_purged") {
     300                $command .= " -topurgedskyfile";
     301            } else {
     302                $command .= " -tocleanedskyfile";
     303            }
     304            $command .= " -dbname $dbname" if defined $dbname;
     305
     306            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     307                    run(command => $command, verbose => $verbose);
     308            unless ($success) {
     309                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     310                &my_die("Unable to perform warptool: $error_code", "warp", $stage_id, $error_code);
     311            }
     312         } else {
     313            # XXX: -updateskyfile mode does not exist, need to add it
     314            my $command = "$warptool -updateskyfile -warp_id $stage_id -skycell_id $skycell_id -code 1";
     315            $command .= " -dbname $dbname" if defined $dbname;
     316
     317            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     318                run(command => $command, verbose => $verbose);
     319            unless ($success) {
     320                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     321                &my_die("Unable to perform warptool: $error_code", "warp", $stage_id, $error_code);
     322            }
     323            exit $PS_EXIT_UNKNOWN_ERROR;
     324        }
     325    }
     326    exit 0;
     327}
     328
     329# left TODO
    185330# fake : faketool : -pendingcleanupimfile (loop over imfiles)
    186 # warp : warptool : -pendingcleanupskyfile (loop over skyfiles)
    187 
    188 die "unknown stage for ipp_cleanup.pl\n";
    189 exit 1;
     331# stack: stacktool : -pendingcleanupskyfile (loop over skyfiles)
     332# diff:  difftool : -pendingcleanupskyfile
     333
     334die "ipp_cleanup.pl -stage $stage not yet implemented\n";
    190335
    191336sub delete_files
     
    196341    foreach my $file (@$files) {
    197342        print STDERR "unlinking $file\n";
     343        # XXX: need to handle files in nebulous
    198344        unlink $file;
    199345    }
     
    217363{
    218364    my $msg = shift; # Warning message on die
    219     my $stage = shift; # Chiptool identifier
    220     my $stage_id = shift; # Chiptool identifier
    221     my $exit_code = shift; # Exit code to add
    222     # outputImage and outroot are globals
     365    my $stage = shift; # stage name
     366    my $stage_id = shift; # identifier
     367    my $exit_code = shift; # Exit code
     368    # outputImage and path_base are globals
    223369
    224370    carp($msg);
Note: See TracChangeset for help on using the changeset viewer.