IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 17, 2009, 12:08:50 PM (17 years ago)
Author:
beaumont
Message:

merged with head

Location:
branches/cnb_branches/cnb_branch_20090301
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/cnb_branches/cnb_branch_20090301

  • branches/cnb_branches/cnb_branch_20090301/ippScripts/scripts/ipp_cleanup.pl

    r21371 r23352  
    1818use Pod::Usage qw( pod2usage );
    1919
    20 my $ipprc = PS::IPP::Config->new(); # this is used for PATH, NEB filename conversions
    21 
    2220# Parse the command-line arguments
    2321my ($stage, $camera, $stage_id, $mode, $path_base, $dbname, $verbose, $no_op, $helplist);
    2422GetOptions('stage=s'        => \$stage,     # which analysis stage to clean?
    25            'camera|i=s'     => \$camera,    # user-supplied camera name
    26            'stage_id=s'     => \$stage_id,  # id for this stage (only needed for certain stages)
    27            'mode|m=s'       => \$mode,      # cleanup mode (clean / purge)
    28            'path_base=s'    => \$path_base, # basename for files
    29            'dbname|d=s'     => \$dbname,    # Database name
     23           'camera|i=s'     => \$camera,    # user-supplied camera name
     24           'stage_id=s'     => \$stage_id,  # id for this stage (only needed for certain stages)
     25           'mode|m=s'       => \$mode,      # cleanup mode (clean / purge)
     26           'path_base=s'    => \$path_base, # basename for files
     27           'dbname|d=s'     => \$dbname,    # Database name
    3028           'verbose'        => \$verbose,   # Print to stdout
    31            'no-op'          => \$no_op,     # pretend but don't actually inject
    32            'helplist'       => \$helplist   # give help listing
    33            ) or pod2usage( 2 );
    34 
    35 pod2usage( -msg => "remove temporary / all data files for an IPP analysis stage", 
    36            -exitval => 2) if defined $helplist;
    37 
    38 pod2usage( -msg => "Usage: $0 --camera (name) --stage (stage) --stage_id (stage_id) --mode (mode) [--path_base (path)] [--dbname dbname] [--no-op] [--help]", 
    39            -exitval => 2 ) if scalar @ARGV;
     29           'no-op'          => \$no_op,     # pretend but don't actually inject
     30           'helplist'       => \$helplist   # give help listing
     31           ) or pod2usage( 2 );
     32
     33pod2usage( -msg => "remove temporary / all data files for an IPP analysis stage",
     34           -exitval => 2) if defined $helplist;
     35
     36pod2usage( -msg => "Usage: $0 --camera (name) --stage (stage) --stage_id (stage_id) --mode (mode) [--path_base (path)] [--dbname dbname] [--no-op] [--help]",
     37           -exitval => 2 ) if scalar @ARGV;
    4038
    4139pod2usage( -msg => "Required options:--camera (name) --stage (stage) --mode (mode)",
    42            -exitval => 3) unless
     40           -exitval => 3) unless
    4341    defined $camera and
    4442    defined $stage and
    4543    defined $mode;
    4644
    47 # $mode must be one of "goto_cleaned" or "goto_purged"
    48 unless (($mode eq "goto_cleaned") || ($mode eq "goto_purged")) {
    49     die "invalid cleanup mode $mode\n";   
    50 }
     45my $ipprc = PS::IPP::Config->new( $camera ) or my_die("Unable to set up", $stage_id, $PS_EXIT_CONFIG_ERROR); # this is used for PATH, NEB filename conversions
     46
     47# $mode must be one of "goto_cleaned", "goto_scrubbed", or
     48# "goto_purged" goto_cleaned and goto_scrubbed both result in
     49# 'cleaned' on success ('scrubbed' allows chips without config files
     50# to be cleaned; they cannot be recovered, but the small data is left
     51# behind). XXX make 'scrubbed' a data_state?
     52unless (($mode eq "goto_cleaned") || ($mode eq "goto_scrubbed") || ($mode eq "goto_purged")) {
     53    die "invalid cleanup mode $mode\n";
     54}
     55
     56my $error_state;
     57if ($mode eq "goto_cleaned")  { $error_state = "error_cleaned";  }
     58if ($mode eq "goto_scrubbed") { $error_state = "error_scrubbed"; }
     59if ($mode eq "goto_purged")   { $error_state = "error_purged";   }
     60
    5161
    5262my %stages = ( chip => 1, camera => 1, fake => 1, warp => 1, stack => 1, diff  => 1);
     
    5565}
    5666
    57 $ipprc->define_camera($camera);
    58 
    5967my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    6068
    6169# choice of files to delete depends on the stage
    6270if ($stage eq "chip") {
    63    
     71
    6472    die "--stage_id required for stage chip\n" if !$stage_id;
    6573    ### select the imfiles for this entry
     
    7886        &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code);
    7987    }
     88
     89    # if there are no chipProcessedImfiles (@$stdout_buf == 0), the reset the state to 'new'
     90    if (@$stdout_buf == 0)  {
     91        my $command = "$chiptool -chip_id $stage_id -updaterun -set_state new";
     92        $command .= " -dbname $dbname" if defined $dbname;
     93
     94        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     95            run(command => $command, verbose => $verbose);
     96        unless ($success) {
     97            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     98            &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code);
     99        }
     100        exit 0;
     101    }
     102
    80103    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    81104        &my_die("Unable to parse metadata config doc", "chip", $stage_id, $PS_EXIT_PROG_ERROR);
     
    87110    # loop over all of the imfiles, determine the path_base and class_id for each
    88111    foreach my $imfile (@$imfiles) {
    89         my $class_id = $imfile->{class_id};
    90         my $path_base = $imfile->{path_base};
     112        my $class_id = $imfile->{class_id};
     113        my $path_base = $imfile->{path_base};
    91114        my $status = 1;
    92115
    93116        # don't clean up unless the data needed to update is available
     117        # modes goto_purged and goto_scrubbed will remove files even if the config is non-existent
    94118        if ($mode eq "goto_cleaned") {
    95119            my $config_file = $ipprc->filename("PPIMAGE.CONFIG", $path_base, $class_id);
     
    124148                addFilename (\@files, "PPIMAGE.CONFIG", $path_base, $class_id);
    125149            }
    126        
     150
    127151            # actual command to delete the files
    128152            $status = &delete_files (\@files);
    129153        }
    130154
    131         if ($status)  {
    132             my $command = "$chiptool -chip_id $stage_id -class_id $class_id";
     155        if ($status)  {
     156            my $command = "$chiptool -chip_id $stage_id -class_id $class_id";
    133157            if ($mode eq "goto_purged") {
    134158                $command .= " -topurgedimfile";
     
    136160                $command .= " -tocleanedimfile";
    137161            }
     162            $command .= " -dbname $dbname" if defined $dbname;
     163
     164            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     165                    run(command => $command, verbose => $verbose);
     166            unless ($success) {
     167                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     168                &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code);
     169            }
     170        } else {
     171
     172            # if an error happens for one chip, the chipRun will stay in goto_*, but the chips will go to error_* (matching the goto_*)
     173            my $command = "$chiptool -updateprocessedimfile -chip_id $stage_id -class_id $class_id -set_state $error_state";
    138174            $command .= " -dbname $dbname" if defined $dbname;
    139175
    140             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     176            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    141177                    run(command => $command, verbose => $verbose);
    142             unless ($success) {
    143                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    144                 &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code);
    145             }
    146         } else {
    147             my $command = "$chiptool -updateprocessedimfile -chip_id $stage_id -class_id $class_id -code 1";
    148             $command .= " -dbname $dbname" if defined $dbname;
    149 
    150             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    151                     run(command => $command, verbose => $verbose);
    152             unless ($success) {
    153                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    154                 &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code);
    155             }
    156         }
    157     }
    158 
    159 } elsif ($stage eq "camera") {
     178            unless ($success) {
     179                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     180                &my_die("Unable to perform chiptool: $error_code", "chip", $stage_id, $error_code);
     181            }
     182        }
     183    }
     184    exit 0;
     185}
     186
     187if ($stage eq "camera") {
    160188    die "--stage_id required for stage camera\n" if !$stage_id;
    161189    # this stage uses 'camtool'
     
    210238
    211239    if ($status)  {
    212         my $command = "$camtool -cam_id $stage_id -updaterun";
     240        my $command;
    213241        if ($mode eq "goto_cleaned") {
    214             $command .= " -state cleaned";
    215         } else {
    216             $command .= " -state purged";
     242            $command = "$camtool -updaterun -cam_id $stage_id -set_state cleaned";
     243        }
     244        if ($mode eq "goto_scrubbed") {
     245            $command = "$camtool -updaterun -cam_id $stage_id -set_state cleaned";
     246        }
     247        if ($mode eq "goto_purged") {
     248            $command = "$camtool -updaterun -cam_id $stage_id -set_state purged";
    217249        }
    218250        $command .= " -dbname $dbname" if defined $dbname;
     
    224256        }
    225257    } else {
    226         my $command = "$camtool -updateprocessedexp -cam_id $stage_id -code 1";
     258        # since 'camera' has only a single imfile, we can just update the run
     259        my $command = "$camtool -updaterun -cam_id $stage_id -set_state $error_state";
    227260        $command .= " -dbname $dbname" if defined $dbname;
    228261
     
    236269    }
    237270    exit 0;
    238 } elsif ($stage eq "warp") {
     271}
     272
     273if ($stage eq "warp") {
    239274    die "--stage_id required for stage warp\n" if !$stage_id;
    240275    # this stage uses 'warptool'
     
    295330        }
    296331
    297         if ($status)  {
    298             my $command = "$warptool -warp_id $stage_id -skycell_id $skycell_id";
     332        if ($status)  {
     333            my $command = "$warptool -warp_id $stage_id -skycell_id $skycell_id";
    299334            if ($mode eq "goto_purged") {
    300335                $command .= " -topurgedskyfile";
     
    302337                $command .= " -tocleanedskyfile";
    303338            }
    304             $command .= " -dbname $dbname" if defined $dbname;
    305 
    306             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     339            $command .= " -dbname $dbname" if defined $dbname;
     340
     341            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    307342                    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             }
     343            unless ($success) {
     344                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     345                &my_die("Unable to perform warptool: $error_code", "warp", $stage_id, $error_code);
     346            }
    312347         } 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";
     348            my $command = "$warptool -updateskyfile -warp_id $stage_id -skycell_id $skycell_id -set_state $error_state";
    315349            $command .= " -dbname $dbname" if defined $dbname;
    316350
    317351            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    318352                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             }
     353            unless ($success) {
     354                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     355                &my_die("Unable to perform warptool: $error_code", "warp", $stage_id, $error_code);
     356            }
    323357            exit $PS_EXIT_UNKNOWN_ERROR;
    324         }
     358        }
    325359    }
    326360    exit 0;
     
    329363# left TODO
    330364# fake : faketool : -pendingcleanupimfile (loop over imfiles)
    331 # stack: stacktool : -pendingcleanupskyfile (loop over skyfiles)
    332 # diff:  difftool : -pendingcleanupskyfile
     365# stack: stacktool : -pendingcleanupskyfile
     366# diff:  difftool : -pendingcleanupskyfile (loop over skyfiles)
    333367
    334368die "ipp_cleanup.pl -stage $stage not yet implemented\n";
    335369
    336 sub delete_files 
     370sub delete_files
    337371{
    338372    my $files = shift; # reference to a list of files to unlink
    339    
    340     # this script is, of course, very dangerous. 
     373
     374    # this script is, of course, very dangerous.
    341375    foreach my $file (@$files) {
    342         print STDERR "unlinking $file\n";
     376        print STDERR "unlinking $file\n";
    343377        $ipprc->file_delete($file);
    344378    }
     
    346380}
    347381
    348 sub addFilename 
     382sub addFilename
    349383{
    350384    my $files      = shift; # reference to a list of files to unlink
     
    359393}
    360394
     395# XXX we currently do not set the error state in the db on my_die
    361396sub my_die
    362397{
Note: See TracChangeset for help on using the changeset viewer.