IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 11, 2011, 2:49:34 PM (15 years ago)
Author:
eugene
Message:

merge changes from trunk

Location:
branches/eam_branches/ipp-20101205/ippScripts/scripts
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20101205/ippScripts/scripts/chip_imfile.pl

    r30102 r30579  
    325325        # get the UNIX version of the (possible) neb: or path: filename
    326326        my $uriReal = $ipprc->file_resolve( $uri );
     327        &my_die("Unable to resolve $uri on $host", $exp_id, $chip_id, $class_id, $PS_EXIT_SYS_ERROR) if !$uriReal;
    327328
    328329        # funpack into the temp file.
  • branches/eam_branches/ipp-20101205/ippScripts/scripts/dist_advancerun.pl

    r28963 r30579  
    2323use PS::IPP::Config 1.01 qw( :standard );
    2424
    25 my $ipprc = PS::IPP::Config->new(); # IPP configuration
    2625
    2726use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     
    2928
    3029# Parse the command-line arguments
    31 my ($dist_id, $stage, $stage_id, $outdir, $clean);
     30my ($dist_id, $stage, $stage_id, $outdir, $clean, $camera);
    3231my ($dbname, $save_temps, $verbose, $no_update, $no_op, $logfile);
    3332
    3433GetOptions(
    35            'dist_id=s'  => \$dist_id,# Magic destreak run identifier
     34           'dist_id=s'      => \$dist_id,# Magic destreak run identifier
     35           'camera=s'       => \$camera,
    3636           'stage=s'        => \$stage,      # raw, chip, warp, or diff
    3737           'stage_id=s'     => \$stage_id,   # exp_id, chip_id, warp_id, or diff_id
     
    5353    defined $stage_id and
    5454    defined $outdir;
     55
     56my $ipprc = PS::IPP::Config->new($camera); # IPP configuration
    5557
    5658$ipprc->redirect_output($logfile) if $logfile;
     
    134136}
    135137
    136 # XXX should we create a file rule for this?
    137 my $dbinfo_file = "$outdir/dbinfo.$stage.$stage_id.mdc";
    138 
    139 {
    140     my $command = "$tool_cmd $exportarg -outfile $dbinfo_file";
     138
     139# work around the fact that $ipprc->file_create does not actually create a file on disk
     140# unless the scheme is nebulous
     141sub create_file {
     142    my $rule = shift;
     143    my $path_base = shift;
     144    my $ref = shift;
     145
     146    my $file;
     147
     148    my $error;
     149    $file = $ipprc->prepare_output($rule, $path_base, undef, 1, \$error)
     150        or &my_die("Unable to prepare outut for $rule", $dist_id, $PS_EXIT_SYS_ERROR);
     151
     152    my $scheme = file_scheme($file);
     153    $scheme = "" if !$scheme;
     154
     155    my $resolved;
     156    if ($scheme) {
     157        $ipprc->file_create($file)
     158            or &my_die("Unable to create $file", $dist_id, $PS_EXIT_SYS_ERROR);
     159
     160        $resolved = $ipprc->file_resolve($file)
     161            or &my_die("Unable to resolve $file", $dist_id, $PS_EXIT_SYS_ERROR);
     162
     163        if ($scheme eq 'neb') {
     164            &my_die("$resolved not found", $dist_id, $PS_EXIT_SYS_ERROR) unless ($resolved and -e $resolved);
     165    }
     166    } else {
     167        $resolved = $file;
     168    }
     169    $$ref = $resolved;
     170
     171    return $file
     172}
     173
     174my $dbinfo_root = "$outdir/dbinfo.$stage.$stage_id";
     175my $resolved;
     176my $dbinfo_file = create_file("DIST.OUTPUT.DBINFO", $dbinfo_root, \$resolved);
     177
     178{
     179    my $command = "$tool_cmd $exportarg -outfile $resolved";
    141180    $command .= " -clean" if ((defined $clean) and ($stage ne "raw"));
    142181    $command .= " -dbname $dbname" if defined $dbname;
     
    149188    }
    150189}
    151 my $dirinfo = "$outdir/dirinfo.$stage.$stage_id.mdc";
     190
     191my $dirinfo_root = "$outdir/dirinfo.$stage.$stage_id";
     192my $dirinfo = create_file("DIST.OUTPUT.DIRINFO", $dirinfo_root, \$resolved);
     193
    152194{
    153195    my $command = "$tool_cmd $list_mode";
     
    168210        &my_die("Unable to parse metadata list", $dist_id, $PS_EXIT_UNKNOWN_ERROR);
    169211
    170     open MANIFEST, ">$dirinfo" or
    171         &my_die("Unable to open dirinfo file $dirinfo",  $dist_id, $PS_EXIT_UNKNOWN_ERROR);
     212    open MANIFEST, ">$resolved" or
     213        &my_die("Unable to open dirinfo file $resolved",  $dist_id, $PS_EXIT_UNKNOWN_ERROR);
    172214
    173215    my $destdir;
     
    197239        &my_die("unable to find path",  $dist_id, $PS_EXIT_UNKNOWN_ERROR) if !$path;
    198240        my $component_dir = find_componentdir($destdir, $path);
    199 #        print MANIFEST "$component METADATA\n";
    200241        print MANIFEST "\t" , "$component", "\tSTR\t", $component_dir, "\n";
    201242    }
     
    217258    }
    218259}
    219 
    220260
    221261exit 0;
  • branches/eam_branches/ipp-20101205/ippScripts/scripts/dist_bundle.pl

    r30102 r30579  
    1616
    1717use IPC::Cmd 0.36 qw( can_run run );
    18 use File::Temp qw( tempfile );
     18use File::Temp qw( tempfile tempdir );
    1919use File::Basename qw( basename );
    2020use Digest::MD5::File qw( file_md5_hex );
     
    7171# Parse the command-line arguments
    7272my ($camera, $stage, $stage_id, $component, $path_base, $chip_path_base, $alt_path_base, $clean);
    73 my ($outdir, $run_state, $data_state, $magicked, $no_magic, $poor_quality, $results_file, $prefix);
     73my ($outroot, $run_state, $data_state, $magicked, $no_magic, $poor_quality, $results_file, $prefix);
    7474my ($dbname, $save_temps, $verbose, $no_update, $logfile);
    7575
     
    8888           'magicked'       => \$magicked,   # magicked state for this component
    8989           'alt_path_base=s'=> \$alt_path_base,  # path to alternate inputs
    90            'outdir=s'       => \$outdir,     # "directory" for outputs
     90           'outroot=s'      => \$outroot,    # outroot
    9191           'prefix=s'       => \$prefix,     # "prefix" to apply to filenames
    9292           'clean'          => \$clean,      # create clean distribution
     
    9999
    100100pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    101 pod2usage( -msg => "Required options: --camera --stage --stage_id --component --path_base --outdir",
     101pod2usage( -msg => "Required options: --camera --stage --stage_id --component --path_base --outroot",
    102102           -exitval => 3) unless
    103103    defined $camera and
     
    106106    defined $component and
    107107    defined $path_base and
    108     defined $outdir;
     108    defined $outroot;
    109109
    110110$ipprc->redirect_output($logfile) if $logfile;
     
    116116$ipprc->define_camera($camera);
    117117
    118 # create the output directories if it is not a nebulous path and it doesn't exist
    119 if (index($outdir, "neb://") != 0) {
    120     if (! -e $outdir ) {
    121         my $code = system "mkdir -p $outdir";
    122         &my_die("cannot create output directory $outdir", $component,
    123                 $code >> 8) if $code;
    124     }
    125 }
     118$ipprc->outroot_prepare($outroot);
    126119
    127120# Get the list of data products for this component
     
    138131# set up directory for temporary files
    139132
    140 my $tmpdir  = "$outdir/tmpdir.$component.$$";
    141 if (-e $tmpdir) {
    142     if (-d $tmpdir) {
    143         my $rc = system "rm -r $tmpdir";
    144         &my_die("cannot rm $tmpdir return code: $rc", $component, $PS_EXIT_UNKNOWN_ERROR) if $rc;
    145     } else {
    146         unlink $tmpdir or &my_die("cannot delete $tmpdir", $component, $PS_EXIT_UNKNOWN_ERROR);
    147     }
    148 }
    149 mkdir $tmpdir or &my_die("cannot create temporary directory $tmpdir", $component,
    150                        $PS_EXIT_UNKNOWN_ERROR);
     133my $temproot = metadataLookupStr($ipprc->{_siteConfig}, "TEMP.DIR");
     134$temproot = "/tmp" if !defined $temproot;
     135&my_die("directory for TEMP.DIR $temproot does not exist", $component, $PS_EXIT_CONFIG_ERROR) if ! -e $temproot;
     136
     137my $tmpdir  = tempdir("$temproot/dist.XXXX", CLEANUP => !$save_temps);
    151138
    152139#
     
    349336if ($num_files) {
    350337    # create the tarfile
    351     # XXX TODO: create a file rule for the tar file name
    352     my $tbase = basename($path_base);
    353     $tbase .= ".$component" if $component;
    354     $file_name = ($prefix ? $prefix : "") . "$tbase.tgz";
    355     my $tarfile = "$outdir/$file_name";
     338#    my $tbase = basename($path_base);
     339#    $tbase .= ".$component" if $component;
     340#    $file_name = ($prefix ? $prefix : "") . "$tbase.tgz";
     341    my $error;
     342    my $output_tarfile;
     343    my $rule;
     344    if ($stage eq 'chip' or $stage eq 'chip_bg' or $stage eq 'raw') {
     345        $rule = "DIST.OUTPUT.CHIP.BUNDLE";
     346    } else {
     347        $rule = "DIST.OUTPUT.BUNDLE";
     348    }
     349    $output_tarfile = $ipprc->prepare_output($rule, $outroot, $component, 1, \$error)
     350            or &my_die("Failed to prepare output tarfile: $error", $component, $error);
     351    $file_name = basename($output_tarfile);
     352
     353
     354    my $scheme = file_scheme($output_tarfile);
     355
     356    my $tarfile;
     357    if ($scheme) {
     358        $ipprc->file_create($output_tarfile)
     359            or &my_die("Failed to create $output_tarfile: $error", $component, $error);
     360        $tarfile = $ipprc->file_resolve($output_tarfile);
     361
     362        if ($scheme eq 'neb') {
     363            &my_die("output file $output_tarfile not found", $component, $PS_EXIT_SYS_ERROR)
     364                unless ($tarfile and -e $tarfile);
     365        }
     366    } else {
     367        # no scheme the filename and the resolved filename are the same
     368        $tarfile = $output_tarfile;
     369    }
    356370
    357371    my $command = "tar -C $tmpdir --owner=ipp --group=users -czhf $tarfile .";
  • branches/eam_branches/ipp-20101205/ippScripts/scripts/dist_component.pl

    r27718 r30579  
    2121use PS::IPP::Metadata::Config;
    2222use PS::IPP::Metadata::List qw( parse_md_list );
    23 
    2423use PS::IPP::Config 1.01 qw( :standard );
    25 
    26 my $ipprc = PS::IPP::Config->new(); # IPP configuration
    2724
    2825use Getopt::Long qw( GetOptions :config auto_help auto_version gnu_getopt );
     
    7774    defined $outdir;
    7875
     76my $ipprc = PS::IPP::Config->new($camera); # IPP configuration
    7977$ipprc->redirect_output($logfile) if $logfile;
     78
     79my $temproot = metadataLookupStr($ipprc->{_siteConfig}, "TEMP.DIR");
     80
     81$temproot = "/tmp" if !defined $temproot;
    8082
    8183if (($stage eq 'raw') and !$clean and !defined $chip_path_base) {
     
    8587my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    8688
    87 my ($rf, $rf_name) = tempfile("/tmp/bundleresults.$dist_id.$component.XXXX", UNLINK => !$save_temps);
     89my ($rf, $rf_name) = tempfile("$temproot/bundleresults.$dist_id.$component.XXXX", UNLINK => !$save_temps);
    8890close $rf;
     91
     92my $basename = basename($path_base);
     93my $outroot = "$outdir/$basename";
    8994
    9095my ($file_name, $bytes, $md5sum);
     
    9297    my $command = "$dist_make_bundle --camera $camera --stage $stage --stage_id $stage_id";
    9398    $command .= " --results_file $rf_name";
    94     $command .= " --component $component --path_base $path_base --outdir $outdir";
     99    $command .= " --component $component --path_base $path_base --outroot $outroot";
    95100    $command .= " --chip_path_base $chip_path_base" if $chip_path_base;
    96101    $command .= " --state $run_state" if defined $run_state;
     
    136141    &my_die("undefined file md5sum from dist_bundle.pl", $dist_id, $component, $outdir, $PS_EXIT_PROG_ERROR) unless defined $md5sum;
    137142}
     143
    138144
    139145{
  • branches/eam_branches/ipp-20101205/ippScripts/scripts/dist_defineruns.pl

    r29068 r30579  
    4242
    4343# Parse the command-line arguments
    44 my ($stage, $stage_limit, $dist_root, $no_magic);
     44my ($stage, $stage_limit, $dist_root, $workdir, $no_magic);
    4545my ($dbname, $save_temps, $verbose, $no_update, $logfile);
    4646my @labels;
     
    4949           'stage=s'        => \$stage,      # stage to queue
    5050           'label=s'        => \@labels,     # labels
     51           'workdir=s'      => \$workdir,     # workdir
    5152           'stage_limit=s'  => \$stage_limit,# maximum number of runs queued for each stage
    52            'dist_root=s'    => \$dist_root,  # root of distribution work area
     53#           'dist_root=s'    => \$dist_root,  # root of distribution work area
    5354           'no_magic'       => \$no_magic,   # queue runs without requiring magic (for testing only)
    5455           'dbname=s'       => \$dbname,     # Database name
     
    6667$ipprc->redirect_output($logfile) if $logfile;
    6768
    68 if (!$dist_root) {
    69     $dist_root = metadataLookupStr($ipprc->{_siteConfig}, "DISTRIBUTION_ROOT");
    70     &my_die("failed to find DISTRIBUTION_ROOT in site configuration", $PS_EXIT_CONFIG_ERROR) if !$dist_root;
     69if (!$workdir) {
     70    print "workdir not supplied will use DISTRIBUTION_ROOT\n";
     71    # old method where we set workdir based on a config file
     72    if (!$dist_root) {
     73        $dist_root = metadataLookupStr($ipprc->{_siteConfig}, "DISTRIBUTION_ROOT");
     74        &my_die("failed to find DISTRIBUTION_ROOT in site configuration", $PS_EXIT_CONFIG_ERROR) if !$dist_root;
     75    }
     76
     77    my ($day, $month, $year) = (gmtime)[3,4,5];
     78    my $datestr = sprintf "%04d%02d%02d", $year+1900, $month + 1, $day;
     79
     80    $workdir = $dist_root . "/$datestr";
     81
     82    print "workdir is $workdir\n";
    7183}
    72 
    73 my ($day, $month, $year) = (gmtime)[3,4,5];
    74 my $datestr = sprintf "%04d%02d%02d", $year+1900, $month + 1, $day;
    75 
    76 my $workdir = "$dist_root/$datestr";
    77 
    78 print "workdir is $workdir\n";
    7984
    8085# if stage is not supplied as an argument, loop over all stages
     
    9095        my $command = "$disttool -definebyquery -stage $stage -workdir $workdir -label $label";
    9196        $command .= " -no_magic" if $no_magic;
    92         $command .= " -dry_run" if $no_update;
     97        $command .= " -pretend" if $no_update;
    9398        $command .= " -limit $stage_limit" if $stage_limit;
    9499        $command .= " -set_label $label";
  • branches/eam_branches/ipp-20101205/ippScripts/scripts/dist_make_fileset.pl

    r28963 r30579  
    9696# make sure that the database info file for this run exists
    9797my $dbinfo_file = "$dist_dir/dbinfo.$stage.$stage_id.mdc";
    98 if (! -e "$dbinfo_file" ) {
     98if (! $ipprc->file_exists($dbinfo_file) ) {
    9999    &my_die("dbinfo file for dist run $dbinfo_file not found", $dist_id, $dest_id, $PS_EXIT_UNKNOWN_ERROR);
    100100}
     
    103103# make sure that the dirinfo file for this run exists
    104104my $dirinfo_file = "$dist_dir/dirinfo.$stage.$stage_id.mdc";
    105 if (! -e "$dirinfo_file" ) {
     105if (!$ipprc->file_exists($dirinfo_file)) {
    106106    &my_die("dirinfo file for dist run $dirinfo_file not found", $dist_id, $dest_id, $PS_EXIT_UNKNOWN_ERROR);
    107107}
     
    277277    $command .= " -dbname $dbname" if $dbname;
    278278
    279     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    280         run(command => $command, verbose => $verbose);
    281     unless ($success) {
    282         $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    283         print STDERR "Unable to perform $command error_code: $error_code\n";
     279    if (!$no_update) {
     280        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     281            run(command => $command, verbose => $verbose);
     282        unless ($success) {
     283            $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     284            print STDERR "Unable to perform $command error_code: $error_code\n";
     285        }
     286    } else {
     287        print STDERR "skipping $command\n";
    284288    }
    285289    exit $fault;
  • branches/eam_branches/ipp-20101205/ippScripts/scripts/ipp_cleanup.pl

    r30446 r30579  
    207207            }
    208208
    209             # Tell magicdstool that we've cleaned up this data, so it needs to do the same if it needs to do the same.
    210             my $magicdstool = can_run('magicdstool') or die "Can't find magicdstool";
    211             $command = "$magicdstool -stage $stage -stage_id $stage_id -updaterun -set_state goto_cleaned -set_label goto_cleaned";
    212             $command .= " -dbname $dbname" if defined $dbname;
    213             ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    214                 run(command => $command, verbose => $verbose);
    215             unless ($success) {
    216                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    217                 &my_die("Unable to perform magicdstool: $error_code", "$stage", $stage_id, $error_code);
    218             }
     209            set_destreak_goto_cleaned();
    219210
    220211        } else {
     
    324315        }
    325316
    326         # Tell magicdstool that we've cleaned up this data, so it needs to do the same if it needs to do the same.
    327         my $magicdstool = can_run('magicdstool') or die "Can't find magicdstool";
    328         $command = "$magicdstool -stage $stage -stage_id $stage_id -updaterun -set_state goto_cleaned -set_label goto_cleaned";
    329         $command .= " -dbname $dbname" if defined $dbname;
    330         ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    331             run(command => $command, verbose => $verbose);
    332         unless ($success) {
    333             $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    334             &my_die("Unable to perform magicdstool: $error_code", "$stage", $stage_id, $error_code);
    335         }
     317        set_destreak_goto_cleaned();
    336318
    337319    } else {
     
    469451            }
    470452
    471             # Tell magicdstool that we've cleaned up this data, so it needs to do the same if it needs to do the same.
    472             my $magicdstool = can_run('magicdstool') or die "Can't find magicdstool";
    473             $command = "$magicdstool -stage $stage -stage_id $stage_id -updaterun -set_state goto_cleaned -set_label goto_cleaned";
    474             $command .= " -dbname $dbname" if defined $dbname;
    475             ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    476                 run(command => $command, verbose => $verbose);
    477             unless ($success) {
    478                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    479                 &my_die("Unable to perform magicdstool: $error_code", "$stage", $stage_id, $error_code);
    480             }
     453            set_destreak_goto_cleaned();
    481454
    482455         } else {
     
    603576            }
    604577
    605             # Tell magicdstool that we've cleaned up this data, so it needs to do the same if it needs to do the same.
    606             my $magicdstool = can_run('magicdstool') or die "Can't find magicdstool";
    607             $command = "$magicdstool -stage $stage -stage_id $stage_id -updaterun -set_state goto_cleaned -set_label goto_cleaned";
    608             $command .= " -dbname $dbname" if defined $dbname;
    609             ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    610                 run(command => $command, verbose => $verbose);
    611             unless ($success) {
    612                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    613                 &my_die("Unable to perform magicdstool: $error_code", "$stage", $stage_id, $error_code);
    614             }
     578            set_destreak_goto_cleaned();
    615579
    616580        } else {
     
    759723            }
    760724
    761             # Tell magicdstool that we've cleaned up this data, so it needs to do the same if it needs to do the same.
    762             my $magicdstool = can_run('magicdstool') or die "Can't find magicdstool";
    763             $command = "$magicdstool -stage $stage -stage_id $stage_id -updaterun -set_state goto_cleaned -set_label goto_cleaned";
    764             $command .= " -dbname $dbname" if defined $dbname;
    765             ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    766                 run(command => $command, verbose => $verbose);
    767             unless ($success) {
    768                 $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    769                 &my_die("Unable to perform magicdstool: $error_code", "$stage", $stage_id, $error_code);
    770             }
     725            set_destreak_goto_cleaned();
    771726
    772727        } else {
     
    20622017}
    20632018
     2019# this gets set to 1 the first time we set the corresponding destreak run to be cleaned
     2020my $ds_done = 0;
     2021sub set_destreak_goto_cleaned {
     2022
     2023    return if $ds_done;
     2024
     2025    # Tell magicdstool that we've cleaned up this data, so it needs to do the same if it needs to do the same.
     2026    my $magicdstool = can_run('magicdstool') or die "Can't find magicdstool";
     2027    my $command = "$magicdstool -stage $stage -stage_id $stage_id -updaterun -set_state goto_cleaned -set_label goto_cleaned";
     2028    $command .= " -dbname $dbname" if defined $dbname;
     2029    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     2030        run(command => $command, verbose => $verbose);
     2031    unless ($success) {
     2032        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     2033            &my_die("Unable to perform magicdstool: $error_code", "$stage", $stage_id, $error_code);
     2034    }
     2035    $ds_done = 1;
     2036}
     2037
    20642038# XXX we currently do not set the error state in the db on my_die
    20652039sub my_die
  • branches/eam_branches/ipp-20101205/ippScripts/scripts/magic_destreak_cleanup.pl

    r30446 r30579  
    159159        my $component = $comp->{component};
    160160        my $backup_path_base = $comp->{backup_path_base};
    161         my $recovery_path_base = $comp->{recovery_path_base};
    162161        my ($bimage, $bmask, $bch_mask, $bweight, $bsources, $bastrom);
    163162        my ($rimage, $rmask, $rch_mask, $rweight, $rsources, $rastrom);
     
    197196                $bsources = $ipprc->filename("PSPHOT.OUTPUT", $backup_path_base, $component);
    198197            }
    199             if ($recovery_path_base) {
    200                 $rimage  = $ipprc->filename("PPIMAGE.CHIP", $recovery_path_base, $component);
    201 
    202                 if ($dynamicMasks) {
    203                     my $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $cam_path_base, $component);
    204                     # This is kludgey but correct
    205                     $rmask = dirname($recovery_path_base) . "/" . basename($mask);
    206                     $rch_mask= $ipprc->filename("PPIMAGE.CHIP.MASK", $recovery_path_base, $component);
    207                 } else {
    208                     $rmask = $ipprc->filename("PPIMAGE.CHIP.MASK", $recovery_path_base, $component);
    209                 }
    210                 $rweight = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $recovery_path_base, $component);
    211             }
    212198        } elsif ($stage eq "camera") {
    213199            if ($backup_path_base) {
     
    221207                $bsources = $ipprc->filename("PSWARP.OUTPUT.SOURCES", $backup_path_base);
    222208            }
    223             if ($recovery_path_base) {
    224                 $rimage  = $ipprc->filename("PSWARP.OUTPUT", $recovery_path_base);
    225                 $rmask   = $ipprc->filename("PSWARP.OUTPUT.MASK", $recovery_path_base);
    226                 $rweight = $ipprc->filename("PSWARP.OUTPUT.VARIANCE", $recovery_path_base);
    227                 $rsources = $ipprc->filename("PSWARP.OUTPUT.SOURCES", $recovery_path_base);
    228             }
    229209        } elsif ($stage eq "diff") {
    230210            my $name = "PPSUB.OUTPUT";
     211            if ($backup_path_base) {
     212                $bimage  = $ipprc->filename($name, $backup_path_base);
     213                $bmask   = $ipprc->filename("$name.MASK", $backup_path_base);
     214                $bweight = $ipprc->filename("$name.VARIANCE", $backup_path_base);
     215                # bills 2011-01-24
     216                # don't clean up the uncensored Diff sources file
     217                # $bsources = $ipprc->filename("$name.SOURCES", $backup_path_base);
     218            }
     219        }
     220
     221        delete_files($bimage, $bmask, $bweight, $bsources, $bastrom, $bch_mask, $rch_mask);
     222
     223        if ($stage eq "diff" and $warp_warp) {
     224            my $name = "PPSUB.INVERSE";
    231225            if ($backup_path_base) {
    232226                $bimage  = $ipprc->filename($name, $backup_path_base);
     
    237231                # $bsources = $ipprc->filename("$name.SOURCES", $backup_path_base);
    238232            }
    239             if ($recovery_path_base) {
    240                 $rimage  = $ipprc->filename($name, $recovery_path_base);
    241                 $rmask   = $ipprc->filename("$name.MASK", $recovery_path_base);
    242                 $rweight = $ipprc->filename("$name.VARIANCE", $recovery_path_base);
    243                 $rsources = $ipprc->filename("$name.SOURCES", $recovery_path_base);
    244             }
    245         }
    246 
    247         delete_files($rimage, $rmask, $rweight, $rsources, $rastrom, $bimage, $bmask, $bweight, $bsources, $bastrom, $bch_mask, $rch_mask);
    248 
    249         if ($stage eq "diff" and $warp_warp) {
    250             my $name = "PPSUB.INVERSE";
    251             if ($backup_path_base) {
    252                 $bimage  = $ipprc->filename($name, $backup_path_base);
    253                 $bmask   = $ipprc->filename("$name.MASK", $backup_path_base);
    254                 $bweight = $ipprc->filename("$name.VARIANCE", $backup_path_base);
    255                 # bills 2011-01-24
    256                 # don't clean up the uncensored sources file
    257                 # $bsources = $ipprc->filename("$name.SOURCES", $backup_path_base);
    258             }
    259             if ($recovery_path_base) {
    260                 $rimage  = $ipprc->filename($name, $recovery_path_base);
    261                 $rmask   = $ipprc->filename("$name.MASK", $recovery_path_base);
    262                 $rweight = $ipprc->filename("$name.VARIANCE", $recovery_path_base);
    263                 $rsources = $ipprc->filename("$name.SOURCES", $recovery_path_base);
    264             }
    265             # undef is not necessary, it's just to keep the lists in the same order.
    266             delete_files($rimage, $rmask, $rweight, $rsources, undef, $bimage, $bmask, $bweight, $bsources);
     233            delete_files($bimage, $bmask, $bweight, $bsources);
    267234        }
    268235        my $command = "$magicdstool -tocleanedfile -magic_ds_id $magic_ds_id -component $component";
  • branches/eam_branches/ipp-20101205/ippScripts/scripts/nightly_science.pl

    r30446 r30579  
    12661266}
    12671267
     1268sub multi_date_verify_uniqueness_diff {
     1269    my $warp_id_1 = shift;
     1270    my $warp_id_2 = shift;
     1271    my $date = shift;
     1272    my $target = shift;
     1273
     1274    my $db = init_gpc_db();
     1275    $date =~ s/-//g;
     1276    my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction) = get_tool_parameters($date,$target);
     1277
     1278    my $count = 0;
     1279   
     1280    my $sth = "SELECT DISTINCT diff_id from diffRun JOIN diffInputSkyfile USING(diff_id) where (label = '$label' OR label = 'goto_cleaned') AND warp1 = $warp_id_1 AND warp2 = $warp_id_2";
     1281    my $data_ref = $db->selectall_arrayref( $sth );
     1282    $count += $#{ $data_ref } + 1;
     1283
     1284    $sth = "SELECT DISTINCT diff_id from diffRun JOIN diffInputSkyfile USING(diff_id) where (label = '$label' OR label = 'goto_cleaned') AND warp1 = $warp_id_2 AND warp2 = $warp_id_1";
     1285    $data_ref = $db->selectall_arrayref( $sth );
     1286    $count += $#{ $data_ref } + 1;
     1287
     1288    return($count);
     1289}
     1290
    12681291sub pre_diff_queue {
    12691292    my $date = shift;
     
    13751398        $metadata_out{nsDiffState} = 'DIFFING';
    13761399    }
    1377 
     1400    if ($metadata_out{nsDiffState} eq 'FINISHED_DIFFS') {
     1401        foreach my $target (sort (keys %science_config)) {
     1402            if ($science_config{$target}{DIFFABLE} == 1) {
     1403                foreach my $filter (@filter_list) {
     1404                    multi_date_diff_queue($date,$target,$filter,$pretend);
     1405                }
     1406            }
     1407        }
     1408    }
    13781409#     if (($Npotential == $Nnoexp)&&($metadata_out{nsObservingState} eq 'END_OF_NIGHT')&&($is_processing == 0)) {
    13791410#       $metadata_out{nsDiffState} = 'FINISHED_DIFFS';
     
    15111542
    15121543}
     1544
     1545sub multi_date_diff_queue {
     1546    my $date = shift;
     1547    my $target = shift;
     1548    my $filter = shift;
     1549    my $pretend = shift;
     1550    my ($label,$workdir,$obs_mode,$object,$comment,$tess_id,$dist_group,$data_group,$reduction) = get_tool_parameters($date,$target);
     1551
     1552    my $db = init_gpc_db();
     1553
     1554    my $obj_sth = "select DISTINCT rawExp.object from warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) ";
     1555    $obj_sth .= " WHERE warpRun.state = 'full' AND warpRun.label = '$label' AND rawExp.filter = '$filter' ORDER BY rawExp.object";
     1556
     1557    my $object_ref = $db->selectall_arrayref( $obj_sth );
     1558
     1559    my $Npotential = 0;
     1560    my $Nqueued = 0;
     1561   
     1562    foreach my $object_row (@{ $object_ref }) {
     1563        my $this_object = shift @{ $object_row };
     1564#       my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment from warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) ";
     1565#       $input_sth .= " WHERE warpRun.state = 'full' AND warpRun.label = '$label' AND warpRun.data_group = '$data_group' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' ";
     1566#       $input_sth .= " ORDER BY dateobs ";
     1567       
     1568        my $input_sth = "select exp_id,warp_id,dateobs,rawExp.comment,warpRun.state AS warp_state FROM ";
     1569        $input_sth .=   " rawExp LEFT JOIN chipRun USING (exp_id) LEFT JOIN camRun USING (chip_id) LEFT JOIN fakeRun USING (cam_id) LEFT JOIN warpRun USING (fake_id) ";
     1570        $input_sth .=   " WHERE warpRun.label = '$label' AND rawExp.filter = '$filter' AND rawExp.object = '$this_object' ";
     1571        $input_sth .=   " ORDER BY dateobs ";
     1572
     1573        my $warps = $db->selectall_arrayref( $input_sth );
     1574
     1575        # Each comment should only appear once. Therefore, if we see it more than once, we assume the first is extra.
     1576        my %comment_hash = ();
     1577        foreach my $this_warp (@{ $warps }) {
     1578            my $this_comment = ${ $this_warp }[3];
     1579            my $this_exp_id  = ${ $this_warp }[0];
     1580            $comment_hash{$this_comment} = $this_exp_id;
     1581        }
     1582       
     1583        if (($#{ $warps } + 1) % 2 != 0) {
     1584            print STDERR "md_diff_queue: Number of input warps to make diffs is not even for target $target and object $this_object! $#{ $warps } ";
     1585            if ($#{ $warps} + 1 == 1) {
     1586                print STDERR ": I can do no diffs with only one exposure.\n";
     1587                next;
     1588            }
     1589            else {
     1590                print STDERR ": I should declare an exposure to be faulty.\n";
     1591                my @keep_warps = ();
     1592#               print "@{ $warps }\n";
     1593                foreach my $this_warp (@{ $warps }) {
     1594                    my $this_comment = ${ $this_warp }[3];
     1595                    my $this_exp_id  = ${ $this_warp }[0];
     1596                    if ($comment_hash{$this_comment} == $this_exp_id) {
     1597                        push @keep_warps, $this_warp;
     1598                    }
     1599                    else {
     1600                        print STDERR "md_diff_queue: excluding $this_exp_id for $this_object\n";
     1601                    }
     1602                }
     1603                @{ $warps } = @keep_warps;
     1604#               print "@{ $warps }\n";
     1605            }
     1606        }
     1607       
     1608        while ($#{ $warps } > -1) {
     1609            my $input_warp = shift @{ $warps };
     1610            my $input_exp_id = ${ $input_warp }[0];
     1611            my $input_comment = ${ $input_warp }[3];
     1612
     1613           
     1614            my $template_warp = shift @{ $warps };
     1615
     1616            my $template_exp_id = ${ $template_warp }[0];
     1617           
     1618            my $input_warp_id = ${ $input_warp }[1];
     1619            my $template_warp_id = ${ $template_warp }[1];
     1620
     1621            my $input_warp_state = ${ $input_warp }[4];
     1622            my $template_warp_state = ${ $template_warp }[4];
     1623           
     1624            unless(defined($template_warp)&& defined($template_exp_id)) {
     1625                print STDERR "md_diff received an undef! $input_exp_id $input_comment $this_object T: $template_warp V: @$template_warp\n";
     1626                next;
     1627            }
     1628            $Npotential++;
     1629           
     1630            unless (defined($input_warp_id) && defined($template_warp_id) &&
     1631                    ($input_warp_state eq 'full')&&($template_warp_state eq 'full')) {
     1632                print STDERR "md_Diff for this $date $target $input_exp_id ($input_warp_id $input_warp_state) $template_exp_id ($template_warp_id $template_warp_state) not fully processed\n";
     1633                next;
     1634            }
     1635
     1636            if (multi_date_verify_uniqueness_diff($input_warp_id,$template_warp_id,$date,$target) != 0) {
     1637                $Nqueued++;
     1638                print STDERR "md_Diffs already queued for this $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment\n";
     1639                next;
     1640            }
     1641
     1642            my $new_data_group = "${data_group}.multi";
     1643            my $cmd = "$difftool -dbname $dbname  -definewarpwarp ";
     1644            $cmd .= "-input_label $label  -template_label $label ";
     1645            $cmd .= "-backwards "; # Needed because difftool assumes a different date sorting.
     1646            $cmd .= "-set_workdir $workdir  -set_dist_group $dist_group  -set_data_group $new_data_group ";
     1647            $cmd .= " -simple  -set_label $label -exp_id $input_exp_id -template_exp_id $template_exp_id ";
     1648#               $cmd .= " -pretend ";
     1649            if (defined($pretend)) {
     1650                $cmd .= ' -pretend ';
     1651            }
     1652            if ($debug == 1) {
     1653                $cmd .= ' -pretend ';
     1654                print STDERR "md_Diffs would like to queue for this $date $target $input_exp_id $template_exp_id ($input_warp_id $template_warp_id) $this_object $input_comment\n";
     1655                print STDERR "md_diff_queue: $cmd\n";
     1656                print STDERR " $input_warp_id $template_warp_id\n";
     1657            }
     1658           
     1659            if (($debug == 0)&&(!defined($pretend))) {
     1660                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     1661                    run ( command => $cmd, verbose => $verbose );
     1662                unless ($success) {
     1663                    $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     1664                    &my_die("Unable to perform difftool: $error_code", 0,0,$date, $PS_EXIT_SYS_ERROR);
     1665                }
     1666                $Nqueued++;
     1667            }
     1668        }
     1669    }
     1670    $metadata_out{nsDiffPotential} += $Npotential;
     1671    $metadata_out{nsDiffQueued}    += $Nqueued;
     1672#      if (($metadata_out{nsDiffPotential} == $metadata_out{nsDiffQueued})&&($metadata_out{nsObservingState} eq 'END_OF_NIGHT')) {
     1673#       $metadata_out{nsDiffState} = 'FINISHED_DIFFS';
     1674#      }       
     1675
     1676}
    15131677           
    15141678
  • branches/eam_branches/ipp-20101205/ippScripts/scripts/register_exp.pl

    r30446 r30579  
    255255        if (exists($nightlyscience_config{$target}{OBSMODE})) {
    256256            $possible++;
    257             if ($obsmode =~ /$nightlyscience_config{$target}{OBSMODE}/) {
     257            if ($obsmode =~ /^$nightlyscience_config{$target}{OBSMODE}$/) {
    258258                $match++;
    259259            }
     
    261261        if (exists($nightlyscience_config{$target}{OBJECT})) {
    262262            $possible++;
    263             if ($object =~ /$nightlyscience_config{$target}{OBJECT}/) {
     263            if ($object =~ /^$nightlyscience_config{$target}{OBJECT}$/) {
    264264                $match++;
    265265            }
     
    267267        if (exists($nightlyscience_config{$target}{COMMENT})) {
    268268            $possible++;
    269             if ($comment =~ /$nightlyscience_config{$target}{COMMENT}/) {
     269            if ($comment =~ /^$nightlyscience_config{$target}{COMMENT}$/) {
    270270                $match++;
    271271            }
  • branches/eam_branches/ipp-20101205/ippScripts/scripts/warp_skycell.pl

    r27754 r30579  
    7171my $ipprc = PS::IPP::Config->new( $camera ) or my_die( "Unable to set up", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_CONFIG_ERROR ); # IPP configuration
    7272
    73 my $logDest = $ipprc->filename("LOG.EXP", $outroot, $skycell_id) or my_die( "Unable to get log filename", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR );
    74 $logDest .= ".update" if ($run_state eq 'update');
     73my ($logDest, $traceDest);
     74if ($run_state eq 'new') {
     75    $logDest = prepare_output("LOG.EXP", $outroot, $skycell_id, 0);
     76    $traceDest = prepare_output("TRACE.EXP", $outroot, $skycell_id, 1);
     77} elsif ($run_state eq 'update')  {
     78    $logDest = prepare_output("LOG.EXP.UPDATE", $outroot, $skycell_id, 0);
     79    $traceDest = prepare_output("TRACE.EXP.UPDATE", $outroot, $skycell_id, 1);
     80} else {
     81    &my_die( "invalid run_state: $run_state", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_CONFIG_ERROR );
     82}
     83
     84my $neb;
     85my $scheme = file_scheme($outroot);
     86if ($scheme and $scheme eq 'neb') {
     87    $neb = $ipprc->nebulous();
     88}
    7589
    7690$ipprc->redirect_output($logDest) or my_die( "Unable to redirect output", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR ) if $redirect;
     
    117131    unless ($success) {
    118132        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
    119         &my_die("Unable to perform ppConfigDump: $error_code", $warp_id, $error_code);
     133        &my_die("Unable to perform ppConfigDump: $error_code", $warp_id, $skycell_id, $tess_dir, $error_code);
    120134    }
    121135    my $metadata = $mdcParser->parse(join "", @$stdout_buf) or
    122         &my_die("Unable to parse metadata config doc", $warp_id, $PS_EXIT_PROG_ERROR);
     136        &my_die("Unable to parse metadata config doc", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_PROG_ERROR);
    123137    $astromSource = metadataLookupStr($metadata, 'ASTROM.SOURCE');
    124138}
     
    141155
    142156
    143 my $outputImage = $ipprc->filename("PSWARP.OUTPUT", $outroot, $skycell_id );
    144 my $outputMask = $ipprc->filename("PSWARP.OUTPUT.MASK", $outroot, $skycell_id);
    145 my $outputWeight = $ipprc->filename("PSWARP.OUTPUT.VARIANCE", $outroot, $skycell_id);
    146 my $outputSources = $ipprc->filename("PSWARP.OUTPUT.SOURCES", $outroot, $skycell_id);
    147 my $outputPSF = $ipprc->filename("PSPHOT.PSF.SKY.SAVE", $outroot);
    148 my $outputBin1 = $ipprc->filename("PSWARP.BIN1", $outroot, $skycell_id );
    149 my $outputBin2 = $ipprc->filename("PSWARP.BIN2", $outroot, $skycell_id );
    150 my $outputStats = $ipprc->filename("SKYCELL.STATS", $outroot, $skycell_id );
    151 my $traceDest = $ipprc->filename("TRACE.EXP", $outroot, $skycell_id);
    152 my $configuration =  $ipprc->filename("PSWARP.CONFIG", $outroot, $skycell_id);
    153 
    154 if ($run_state eq 'update') {
    155     $traceDest .= ".update";
    156     $outputStats .= ".update";
    157 }
    158 
    159 my $skyFile = $ipprc->filename("SKYCELL.TEMPLATE", $outroot, $skycell_id );
     157my $outputImage = prepare_output ("PSWARP.OUTPUT", $outroot, $skycell_id, 1);
     158my $outputMask = prepare_output ("PSWARP.OUTPUT.MASK", $outroot, $skycell_id, 1);
     159my $outputWeight = prepare_output ("PSWARP.OUTPUT.VARIANCE", $outroot, $skycell_id, 1);
     160my $outputSources = prepare_output ("PSWARP.OUTPUT.SOURCES", $outroot, $skycell_id, 1);
     161my $outputPSF = prepare_output ("PSPHOT.PSF.SKY.SAVE", $outroot, 1);
     162my $outputBin1 = prepare_output ("PSWARP.BIN1", $outroot, $skycell_id, 1);
     163my $outputBin2 = prepare_output ("PSWARP.BIN2", $outroot, $skycell_id, 1);
     164my $outputStats = prepare_output ("SKYCELL.STATS", $outroot, $skycell_id, 1);
     165my $configuration;
     166
     167my $dump_config = 1;
     168if ($run_state eq 'new') {
     169    $configuration =  prepare_output ("PSWARP.CONFIG", $outroot, $skycell_id, 1);
     170} else {
     171    $configuration =  $ipprc->filename("PSWARP.CONFIG", $outroot, $skycell_id) or
     172        &my_die("Missing entry from camera config PSWARP.CONFIG", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_CONFIG_ERROR);
     173    if ($ipprc->file_exists($configuration)) {
     174        $dump_config = 0;
     175    } else {
     176        print STDERR "WARNING: Config dump file $configuration is missing. Using current recipes and file rules.\n";
     177
     178        # XXX: should we create a new config dump file?
     179        # I vote yes but only if we can distingusing between temporarily unavailable and GONE.
     180        my $gone = 0;
     181        if (storage_object_exists($configuration, \$gone)) {
     182            if ($gone) {
     183                $configuration = prepare_output('PSWARP.CONFIG', $outroot, $skycell_id, 1);
     184                # if we dump the config we need to insure that the config dump represents
     185                # the full processing
     186            } else {
     187                # file is temporarily not available. Don't dump config.
     188                $dump_config = 0;
     189            }
     190        }
     191    }
     192}
     193
     194
     195my $skyFile = prepare_output ("SKYCELL.TEMPLATE", $outroot, $skycell_id, 1);
    160196$ipprc->skycell_file( $tess_dir, $skycell_id, $skyFile, $verbose ) or &my_die("Unable to generate template skycell", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR);
    161197## XXX this seems to have insufficient error checking: dvoImageExtract can fail to write and still return a valid exit status
     
    171207foreach my $imfile (@$imfiles) {
    172208    my $image = $imfile->{uri}; # Image name
    173     my $weight = $ipprc->filename("PPIMAGE.CHIP.VARIANCE", $imfile->{chip_path_base}, $imfile->{class_id}); # Mask name
     209    my $weight = $ipprc->filename ("PPIMAGE.CHIP.VARIANCE", $imfile->{chip_path_base}, $imfile->{class_id}); # Mask name
    174210
    175211    my $mask;                   # Mask name
    176212    if ($dynamicMasks) {
    177         $mask = $ipprc->filename("PSASTRO.OUTPUT.MASK", $imfile->{cam_path_base}, $imfile->{class_id});
     213        $mask = $ipprc->filename ("PSASTRO.OUTPUT.MASK", $imfile->{cam_path_base}, $imfile->{class_id});
    178214    } else {
    179         $mask = $ipprc->filename("PPIMAGE.CHIP.MASK", $imfile->{chip_path_base}, $imfile->{class_id});
     215        $mask = $ipprc->filename ("PPIMAGE.CHIP.MASK", $imfile->{chip_path_base}, $imfile->{class_id});
    180216    }
    181217
     
    186222    # Astrometry file: astrometry is done at the camera stage, and always results in a MEF file
    187223    # XXX allow an option to use the image header astrometry?
    188     my $astrom = $ipprc->filename($astromSource, $imfile->{cam_path_base});
     224    my $astrom = $ipprc->filename ($astromSource, $imfile->{cam_path_base});
    189225
    190226    &my_die("Couldn't find input file: $astrom", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless defined $astrom and $ipprc->file_exists($astrom);
     
    245281        $do_stats = 1;
    246282    } else {
    247         #$command .= " -ipprc $configuration";
    248         my $resolved = $ipprc->file_resolve($configuration);
    249         $command .= " -ipprc $resolved";
     283        $command .= " -ipprc $configuration";
    250284    }
    251285    if ($do_stats) {
     
    263297    if ($do_stats) {
    264298        # Check first for the stats file
     299        check_output($outputStats, 0);
    265300        my $outputStatsReal = $ipprc->file_resolve($outputStats);
    266         &my_die("Couldn't find expected output file: $outputStats", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStatsReal);
     301#        &my_die("Couldn't find expected output file: $outputStats", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputStatsReal);
    267302        &my_die("Stats file has zero size: $outputStats", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless -s $outputStatsReal;
    268303
    269         # measure chip stats
     304        # measure skycell stats
    270305        $command = "$ppStatsFromMetadata $outputStatsReal - WARP_SKYCELL";
    271306        ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    283318
    284319        if (!$quality) {
    285             &my_die("Couldn't find expected output file: $outputImage", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputImage);
    286             &my_die("Couldn't find expected output file: $outputMask", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
    287             &my_die("Couldn't find expected output file: $outputWeight", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputWeight);
    288             &my_die("Couldn't find expected output file: $outputSources", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
    289             &my_die("Couldn't find expected output file: $outputPSF", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) if metadataLookupBool($recipe, 'PSF') and not $ipprc->file_exists($outputPSF);
    290             if ($run_state eq 'new') {
    291                 &my_die("Couldn't find expected output file: $configuration", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($configuration);
     320        #    &my_die("Couldn't find expected output file: $outputImage", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputImage);
     321        #    &my_die("Couldn't find expected output file: $outputMask", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputMask);
     322        #    &my_die("Couldn't find expected output file: $outputWeight", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputWeight);
     323        #    &my_die("Couldn't find expected output file: $outputSources", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($outputSources);
     324        #    &my_die("Couldn't find expected output file: $outputPSF", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) if metadataLookupBool($recipe, 'PSF') and not $ipprc->file_exists($outputPSF);
     325
     326            check_output($outputImage, 0);
     327            check_output($outputMask, 0);
     328            check_output($outputWeight, 0);
     329            check_output($outputSources, 1);
     330            check_output($outputPSF, 1) if metadataLookupBool($recipe, 'PSF')  ;
     331            if ($dump_config)  {
     332                check_output($configuration, 1);
     333#                &my_die("Couldn't find expected output file: $configuration", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($configuration);
    292334            }
    293335        }
     
    335377    }
    336378}
     379
     380exit 0;
     381
     382# Prepare to write to an output file
     383#   Lookup the filename in the rules.
     384#   Make sure that if file exists and is a nebulous file that there is only one instance
     385#   Deal with files that have been lost.
     386sub prepare_output
     387{
     388    my $filerule = shift;
     389    my $outroot  = shift;
     390    my $skycell_id = shift;
     391    my $delete = shift;
     392    $delete = 0 if !defined $delete;
     393
     394    my $error;
     395    my $output = $ipprc->prepare_output($filerule, $outroot, $skycell_id, $delete, \$error)
     396                    or &my_die("failed to prepare output file for: $filerule", $warp_id, $skycell_id, $tess_dir, $error);
     397    return $output;
     398}
     399
     400sub check_output
     401{
     402    my $file = shift;
     403    my $replicate = shift;
     404
     405    if (!defined $file) {
     406        return;
     407    }
     408
     409    &my_die("Couldn't find expected output file: $file",  $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR) unless $ipprc->file_exists($file);
     410
     411    if ($replicate and $neb) {
     412        $ipprc->replicate_file($file) or &my_die("failed to replicate: $file\n",  $warp_id, $skycell_id, $tess_dir, $PS_EXIT_SYS_ERROR);
     413    }
     414}
     415
     416# subroutine to check the status of a nebulous file. Used to distinguish between a storage object that
     417# does not exist and one that all of the instances have been lost.
     418# XXXX This should be implemented properly in Nebulous
     419# For now uses Bill's script 'whichnode' which queries the nebulous database directly
     420
     421my $whichnode;
     422sub storage_object_exists
     423{
     424    return 0 if !$neb;
     425
     426    my $file = shift;
     427    my $ref_all_gone = shift;
     428
     429    my $exists = $neb->storage_object_exists($file);
     430    if (!$exists) {
     431        return 0;
     432    }
     433
     434    if (!$whichnode) {
     435        $whichnode = can_run('whichnode') or
     436            &my_die("Can't find whichnode",  $warp_id, $skycell_id, $tess_dir, $PS_EXIT_CONFIG_ERROR);
     437    }
     438
     439    my $command = "$whichnode $file";
     440
     441    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     442        run(command => $command, verbose => $verbose);
     443    unless ($success) {
     444        $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     445        &my_die("Unable to perform whichnode: $error_code", $warp_id, $skycell_id, $tess_dir, $PS_EXIT_CONFIG_ERROR);
     446    }
     447
     448    my @lines = split "\n", (join "", @$stdout_buf);
     449
     450    if (scalar @lines == 0) {
     451        # no output the file is really and truely gone
     452        # XXX: this is now caught above
     453        print STDERR "storage object for $file does not exist\n";
     454        return 0;
     455    }
     456
     457    my $numGone = 0;
     458    my $numNotGone = 0;
     459    foreach my $line (@lines) {
     460        chomp $line;
     461
     462        # output lines are either
     463        #   "volume available"
     464        # or
     465        #   "volume not available"
     466
     467        my ($volume, $answer, undef) = split " ", $line;
     468        # our hack is if the volume has an X in the name it's gone
     469        if ($volume =~ /X/) {
     470            print STDERR "$file is on $volume which is gone\n";
     471            $numGone++;
     472        } elsif ($answer eq 'available') {
     473            $numNotGone++;
     474        } elsif ($answer eq 'not') {
     475            print STDERR "$file is on $volume which is not available\n";
     476            $numNotGone++;
     477        } else {
     478            print STDERR "unexpected output from whichnode: $line\n";
     479        }
     480    }
     481    # if there are any instances that are not on a gone volume set all_gone to 0
     482    if ($numNotGone == 0 and $numGone > 0) {
     483        $$ref_all_gone = 1;
     484    } else {
     485        $$ref_all_gone = 0;
     486    }
     487
     488    # storage object exists so return true
     489    return 1;
     490}
     491
    337492
    338493sub my_die
Note: See TracChangeset for help on using the changeset viewer.