IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Feb 11, 2011, 4:42:29 PM (15 years ago)
Author:
watersc1
Message:

Caught up with the trunk. Now to look for bugs.

Location:
branches/czw_branch/20101203
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20101203

  • branches/czw_branch/20101203/ippScripts/scripts/chip_imfile.pl

    r30118 r30587  
    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/czw_branch/20101203/ippScripts/scripts/ipp_apply_burntool_single.pl

    r30586 r30587  
    1515my $REALRUN = 1;
    1616
    17 my ( $class_id, $exp_id, $this_uri, $previous_uri, $imfile_state, $camera, $dbname, $logfile, $verbose, $save_temps, $rerun );
     17my ( $class_id, $exp_id, $this_uri, $previous_uri, $imfile_state, $camera, $dbname, $logfile, $verbose, $save_temps );
     18my ( $rerun, $fixit );
     19my $continue = 0;
    1820GetOptions(
    1921    'exp_id=s'         => \$exp_id,   # exposure identifier
     
    2628    'logfile=s'         => \$logfile,
    2729    'rerun'             => \$rerun,
     30#    'fix|f'             => \$fixit,
     31    'continue=i'        => \$continue,
    2832    'verbose'           => \$verbose,   # Print to stdout
    2933    'save-temps'        => \$save_temps, # Save temporary files?
     
    3337pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    3438pod2usage(
    35     -msg => "Required options: --class_id --this_uri --dbname",
     39    -msg => "Required options: --class_id --this_uri --exp_id --dbname",
    3640    -exitval => 3,
    3741    ) unless
    3842    defined $class_id and
    3943    defined $this_uri and
     44    defined $exp_id and
    4045    defined $dbname;
    4146
     
    9398print ">>$burntoolStateGood<<\n";
    9499
     100# Determine what to do if we're fixing.
     101# if ($fixit) {
     102#     ($exp_id,$this_uri,$previous_uri,$continue) = fix_burntool($exp_id,$this_uri,$class_id);
     103# }
     104
     105
     106# Precalculate what we should be able to do if we're continuing
     107my @continue_uris;
     108my @continue_exp_ids;
     109my @continue_states;
     110if ($continue > 0) {
     111    my $regtool_get_date   = "$regtool -processedimfile -exp_id $exp_id -class_id $class_id -dbname $dbname";
     112    my $dateobs;
     113    my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     114        run ( command => $regtool_get_date, verbose => $verbose );
     115    unless ($success) {
     116        $continue = 0;
     117        last;
     118    }
     119    my $imfile_data = $mdcParser->parse(join "", @$stdout_buf);
     120    my $imfile_data2 = parse_md_list($imfile_data);
     121    if ($#{ $imfile_data2 } > 0) {
     122        &my_die("Too many entries returned for date query", $exp_id, $class_id, $PS_EXIT_SYS_ERROR);
     123    }
     124    foreach my $entry (@$imfile_data2) {
     125        $dateobs = $entry->{dateobs};
     126    }
     127    my $date = $dateobs; $date =~ s/T.*//;
     128
     129    my $regtool_status_cmd = "$regtool -checkstatus -dateobs_begin $dateobs -dateobs_end ${date}T17:30:00 -class_id $class_id -dbname $dbname";
     130    ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     131        run ( command => $regtool_status_cmd, verbose => $verbose );
     132    unless ($success) {
     133        $continue = 0;
     134    }
     135    if ($continue != 0) {
     136        my $night_data = $mdcParser->parse(join "", @$stdout_buf);
     137        my $night_data2 = parse_md_list($night_data);
     138        my $addable = 0;
     139       
     140        foreach my $entry (@$night_data2) {
     141            my ($this_exp_id,$this_uri,$this_state);
     142            if ($entry->{exp_id} == $exp_id) {
     143                $addable = 1;
     144                next;
     145            }
     146            if (($addable == 1)&&($#continue_exp_ids < $continue)) {
     147                $this_exp_id = $entry->{exp_id};
     148                $this_uri    = $entry->{uri};
     149                $this_state  = $entry->{imfile_state};
     150                print ">> $this_exp_id $this_uri $this_state\n";
     151                if ($this_state eq 'pending_burntool') {
     152                    push @continue_exp_ids, $this_exp_id;
     153                    push @continue_uris, $this_uri;
     154                    push @continue_states, $this_state;
     155                }
     156                else {
     157                    last;
     158                }
     159            }
     160            if ($#continue_exp_ids >= $continue) {
     161                last;
     162            }
     163        }
     164    }
     165}
     166$continue = $#continue_exp_ids + 1;
     167
     168# Look over at least one uri/imfile/exp_id and do burntool on it.
     169my $next_exp_id;
     170for (my $iteration = 0; $iteration <= $continue; $iteration ++) {
    95171# Set up files
    96 my $rawImfile = $this_uri;
    97 my $rawImfileReal = $ipprc->file_resolve($rawImfile, 0);
    98 
    99 my $outTable  = $this_uri;
    100 $outTable  =~ s/fits$/burn.tbl/;
    101 my $outTableReal = $ipprc->file_resolve($outTable, 1);
    102 
    103 my $previousTable;
    104 my $previousTableReal;
    105 if ($previous_uri) {
    106     $previousTable = $previous_uri;
    107     $previousTable =~ s/fits$/burn.tbl/;
    108     $previousTableReal = $ipprc->file_resolve($previousTable, 0);
    109 }
    110 
     172    my $rawImfile = $this_uri;
     173    my $rawImfileReal = $ipprc->file_resolve($rawImfile, 0);
     174   
     175    my $outTable  = $this_uri;
     176    $outTable  =~ s/fits$/burn.tbl/;
     177    my $outTableReal = $ipprc->file_resolve($outTable, 1);
     178   
     179    my $previousTable;
     180    my $previousTableReal;
     181    if ($previous_uri) {
     182        $previousTable = $previous_uri;
     183        $previousTable =~ s/fits$/burn.tbl/;
     184        $previousTableReal = $ipprc->file_resolve($previousTable, 0);
     185    }
     186   
    111187# Set state to processing:
    112 my $burntool_state = 0;
    113 
    114 my $status = vsystem ("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state -1", $REALRUN);
    115 if ($status) {
    116     &my_die("failed to update imfile");
    117 }
    118 $burntool_state = 1;
    119 
    120 
     188    my $burntool_state = 0;
     189   
     190    my $status = vsystem ("$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state -1", $REALRUN);
     191    if ($status) {
     192        &my_die("failed to update imfile");
     193    }
     194    $burntool_state = 1;
     195   
     196   
    121197# funpack
    122 my $tempfile = new File::Temp ( TEMPLATE => "burntool.${exp_id}.${class_id}.XXXX",
    123                                 DIR => '/tmp/',
    124                                 UNLINK => !$save_temps,
    125                                 SUFFIX => '.fits');
    126 my $tempPixels = $tempfile->filename;
    127 
    128 $status = vsystem ("$funpack -S $rawImfileReal > $tempPixels", $REALRUN);
    129 if ($status) {
    130     &my_die("failed on funpack",$exp_id,$class_id);
    131 }
    132 
     198    my $tempfile = new File::Temp ( TEMPLATE => "burntool.${exp_id}.${class_id}.XXXX",
     199                                    DIR => '/tmp/',
     200                                    UNLINK => !$save_temps,
     201                                    SUFFIX => '.fits');
     202    my $tempPixels = $tempfile->filename;
     203   
     204    $status = vsystem ("$funpack -S $rawImfileReal > $tempPixels", $REALRUN);
     205    if ($status) {
     206        &my_die("failed on funpack",$exp_id,$class_id);
     207    }
     208   
    133209# burntool
    134 if (($previousTableReal)&&($previousTableReal ne '')) {
    135     $status = vsystem ("$burntool $tempPixels in=$previousTableReal out=$outTableReal tableonly=t persist=t", $REALRUN);
    136 }
    137 else {
    138     $status = vsystem ("$burntool $tempPixels out=$outTableReal tableonly=t persist=t", $REALRUN);
    139 }
    140 if ($status) {
    141     &my_die("failed on burntool",$exp_id,$class_id);
    142 }
    143 &my_die("Unable to find output file: $outTableReal", $exp_id, $class_id) unless $ipprc->file_exists($outTableReal);
    144 
     210    if (($previousTableReal)&&($previousTableReal ne '')) {
     211        $status = vsystem ("$burntool $tempPixels in=$previousTableReal out=$outTableReal tableonly=t persist=t", $REALRUN);
     212    }
     213    else {
     214        $status = vsystem ("$burntool $tempPixels out=$outTableReal tableonly=t persist=t", $REALRUN);
     215    }
     216    if ($status) {
     217        &my_die("failed on burntool",$exp_id,$class_id);
     218    }
     219    &my_die("Unable to find output file: $outTableReal", $exp_id, $class_id) unless $ipprc->file_exists($outTableReal);
     220   
    145221# Replicate files
    146 $status = vsystem ("$nebXattr --write $outTable user.copies:2",$REALRUN);
    147 $status = vsystem ("$nebreplicate --set_copies 2 $outTable",$REALRUN);
    148 
     222    $status = vsystem ("$nebXattr --write $outTable user.copies:2",$REALRUN);
     223    $status = vsystem ("$nebreplicate --set_copies 2 $outTable",$REALRUN);
     224
     225# Prep for next iteration if necessary.
     226    if ($iteration < $continue) {
     227        $next_exp_id = shift(@continue_exp_ids);
     228        my $command = "$regtool -dbname $dbname -updateprocessedimfile -exp_id $next_exp_id -class_id $class_id -set_state check_burntool";
     229        $status = vsystem ($command, $REALRUN);
     230        if ($status) {
     231            $continue = 0;
     232        }
     233    }
    149234# Set state to finished.
    150 my $command = "$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state $outState";
    151 if ($imfile_state ne 'full') {
    152     $command .= " -set_state full ";
    153 }
    154 $status = vsystem ($command, $REALRUN);
    155 if ($status) {
    156     &my_die("failed to update imfile");
    157 }
    158 
     235    my $command = "$regtool -dbname $dbname -updateprocessedimfile -exp_id $exp_id -class_id $class_id -burntool_state $outState";
     236    if ($imfile_state ne 'full') {
     237        $command .= " -set_state full ";
     238    }
     239    $status = vsystem ($command, $REALRUN);
     240    if ($status) {
     241        &my_die("failed to update imfile");
     242    }
     243
     244# Set values for the next iteration if we are doing another iteration.
     245    $previous_uri = $this_uri;
     246    if ($iteration < $continue) {
     247        $this_uri = shift (@continue_uris);
     248        $exp_id   = $next_exp_id;
     249        $imfile_state = shift(@continue_states);
     250    }
     251
     252}
    159253exit 0;
    160254
     
    183277    exit 1;
    184278}
    185 
    186 
    187    
     279       
     280# sub fix_burntool {
     281#     my ($exp_id,$this_uri,$class_id,$burntoolGoodState) = @_;
     282#     my ($dateobs,$exp_name);
     283#     # Calculate the date for this exposure, and calculate back to find the burntool period.
     284#     my $regtool_get_date   = "$regtool -processedimfile -exp_id $exp_id -class_id $class_id -dbname $dbname";
     285#     my ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     286#       run ( command => $regtool_get_date, verbose => $verbose );
     287#     unless ($success) {
     288#       $continue = 0;
     289#       return($exp_id,$this_uri,undef,0);
     290#     }
     291#     my $imfile_data = $mdcParser->parse(join "", @$stdout_buf);
     292#     foreach my $entry (@$imfile_data) {
     293#       if ($entry->{name} eq 'dateobs') {
     294#           $dateobs = $entry->{value};
     295#       }
     296#       if ($entry->{name} eq 'exp_name') {
     297#           $exp_name = $entry->{value};
     298#       }
     299#     }
     300#     my $date = $dateobs; $date =~ s/T.*//;
     301#     my $time = $dateobs; $time =~ s/.*T//;
     302#     my ($hour,$min,$sec) = split /\:/, $time; #/;
     303#     if ($min >= 30) {
     304#       $min -= 30;
     305#     }
     306#     else {
     307#       $min += 30;
     308#       $hour -= 1;
     309#     }
     310#     my $dateobs_begin = sprintf("%sT%02d:%02d:%02d",$date,$hour,$min,$sec);
     311
     312
     313#     # Get the night data for this date range.
     314#     my $regtool_status_cmd = "$regtool -checkstatus -dateobs_begin $dateobs_begin -dateobs_end $dateobs -class_id $class_id -dbname $dbname";
     315#     ($success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     316#       run ( command => $regtool_get_date, verbose => $verbose );
     317#     unless ($success) {
     318#       return($exp_id,$this_uri,undef,0);
     319#     }
     320
     321#     my $night_data = $mdcParser->parse(join "", @$stdout_buf);
     322
     323#     my $mode;
     324#     my ($row_exp_id,$row_uri,$row_data_state,$row_bt_state);
     325#     my $entry = @$night_data[-1];
     326#     foreach my $row (@$entry) {  # This is a single exposure, so let's get everything we'll need here.
     327#       if ($row->{name} eq 'exp_id') {
     328#           $row_exp_id = $row->{value};
     329#       }
     330#       elsif ($row->{name} eq 'uri') {
     331#           $row_uri = $row->{uri};
     332#       }
     333#       elsif ($row->{name} eq 'data_state') {
     334#           $row_data_state = $row->{data_state};
     335#       }               
     336#       elsif ($row->{name} eq 'burntool_state') {
     337#           $row_bt_state = $row->{burntool_state};
     338#       }               
     339#     }
     340#     # Determine what to do.
     341#     if ($row_exp_id == $exp_id) {
     342#       if (($row_bt_state != $burntoolStateGood)) {
     343#           # Never been run.
     344#           $mode = 1;
     345#       }
     346#       else {
     347#           $mode = 0;
     348#       }
     349#     }
     350#     if ($mode == 0) {
     351#       # If we're here, then the database thinks we have a table for this uri on disk. Let's see if that's true.
     352#       # Zero byte file/good alternate
     353#       # Inconsistent md5sums
     354#       # Missing this table only.
     355#       my $neb = $ipprc->nebulous();
     356#       my $table_key = $this_uri; $table_key =~ s/fits/burn.tbl/;
     357
     358#       my $neb_instances = $neb->find_instances($table_key, 'any');
     359
     360#       my $Ninstances = $#{ $neb_instances } + 1;
     361
     362#       if (($Ninstances == 0)||($Ninstances == 1)) {
     363#           #Missing this table only.  This should fall through to do a regular pass on this uri
     364#           $continue = 0;
     365#           $entry = @$night_data[-2];
     366#           foreach my $row (@$entry) {  # This is a single exposure, so let's get everything we'll need here.
     367#               if ($row->{name} eq 'exp_id') {
     368#                   $row_exp_id = $row->{value};
     369#               }
     370#               elsif ($row->{name} eq 'uri') {
     371#                   $row_uri = $row->{uri};
     372#               }
     373#               elsif ($row->{name} eq 'data_state') {
     374#                   $row_data_state = $row->{data_state};
     375#               }               
     376#               elsif ($row->{name} eq 'burntool_state') {
     377#                   $row_bt_state = $row->{burntool_state};
     378#               }               
     379#           }
     380#           $previous_uri = $row_uri;
     381#           # Go through to regular processing of this exposure.
     382#       }
     383#       elsif ($Ninstances == 2) {
     384#           $md5sum_A = md5sum(${ $neb_instances }[0]);
     385#           $md5sum_B = md5sum(${ $neb_instances }[1]);
     386#           if ($md5sum_A != $md5sum_B) {
     387#               # md5sums are different
     388#               if ($md5sum_A = 'd41d8cd98f00b204e9800998ecf8427e') {
     389#                   # copy B -> A
     390#               }
     391#               elsif ($md5sum_B = 'd41d8cd98f00b204e9800998ecf8427e') {
     392#                   # copy A -> B
     393#               }
     394#               else {
     395#                   # different but unknown why
     396#               }
     397#           }
     398#       }
     399#     }
     400
     401#     if ($mode == 1) {
     402#       foreach my $entry (reverse(@$night_data)) {  # reverse it so we can start with the exposure we have and go backwards
     403#           foreach my $row (@$entry) {  # This is a single exposure, so let's get everything we'll need here.
     404#               if ($row->{name} eq 'exp_id') {
     405#                   $row_exp_id = $row->{value};
     406#               }
     407#               elsif ($row->{name} eq 'uri') {
     408#                   $row_uri = $row->{uri};
     409#               }
     410#               elsif ($row->{name} eq 'data_state') {
     411#                   $row_data_state = $row->{data_state};
     412#               }               
     413#               elsif ($row->{name} eq 'burntool_state') {
     414#                   $row_bt_state = $row->{burntool_state};
     415#               }               
     416#           }
     417#       }
     418#     }
     419
     420#     return($exp_id,$this_uri,$previous_uri,$continue);
     421# }
  • branches/czw_branch/20101203/ippScripts/scripts/ipp_cleanup.pl

    r30586 r30587  
    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/czw_branch/20101203/ippScripts/scripts/magic_destreak_cleanup.pl

    r30586 r30587  
    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/czw_branch/20101203/ippScripts/scripts/nightly_science.pl

    r30586 r30587  
    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/czw_branch/20101203/ippScripts/scripts/register_exp.pl

    r30586 r30587  
    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/czw_branch/20101203/ippScripts/scripts/warp_skycell.pl

    r27754 r30587  
    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.