IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 18, 2010, 5:06:01 PM (16 years ago)
Author:
watersc1
Message:

Almost working version of the mask-stats/software revision code.

Almost.

Location:
branches/czw_branch/20100427
Files:
16 edited
2 copied

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20100427

  • branches/czw_branch/20100427/pstamp/scripts/Makefile.am

    r27704 r28017  
    33
    44install_files = \
     5        pstamp_cleanup.pl \
    56        pstamp_finish.pl \
    67        pstamp_insert_request.pl \
     
    2021        pstamp_checkdependent.pl \
    2122        request_finish.pl \
     23        detectability_respond.pl \
    2224        detect_query_read \
    2325        detect_response_create \
  • branches/czw_branch/20100427/pstamp/scripts/detectability_respond.pl

    r27643 r28017  
    4141my $EXTVER = 1.0;
    4242my $EXTNAME = 'MOPS_DETECTABILITY_RESPONSE';
    43 my ($req_id,$req_name,$product,$need_magic,$missing_tools);
    44 my ($request_file,$output,$dbname,$verbose,$save_temps);
     43my ($req_id,$req_name,$product,$need_magic,$missing_tools,$project);
     44my ($request_file,$output,$workdir,$dbname,$dbserver,$verbose,$save_temps);
    4545GetOptions(
    46     'input=s'          =>     \$request_file,
     46    'input=s'         =>      \$request_file,
    4747    'output=s'        =>      \$output,
     48    'workdir=s'       =>      \$workdir,
    4849    'dbname=s'        =>      \$dbname,
     50    'dbserver=s'      =>      \$dbserver,
    4951    'verbose'         =>      \$verbose,
    5052    'save-temps'      =>      \$save_temps,
     
    5557           -exitval => 3,
    5658    ) unless
    57     defined $request_file and defined $output and defined $dbname;
     59    defined $request_file and defined $output and defined $workdir and defined $dbname;
    5860
    5961my $detect_query_read = can_run('detect_query_read') or (warn "Can't find detect_query_read" and $missing_tools = 1);
     
    7173
    7274my $ipprc = PS::IPP::Config->new();
    73 #my $tmp_dir = "/data/${host}.0/tmp/";
     75
     76if (!$dbserver) {
     77    $dbserver = metadataLookupStr($ipprc->{_siteConfig}, 'PS_DBSERVER');
     78}
     79# This is hardcoded in for the moment.
     80$project = resolve_project($ipprc,"gpc1",$dbname,$dbserver);
     81my $imagedb = $project->{dbname};
     82if (!$imagedb) {
     83    carp("failed to find imagedb for project: $project");
     84}
    7485
    7586#
    7687# Parse input request file using detect_query_read (as it's already written).
    7788#
    78 
    7989my $dqr_command = "$detect_query_read --input $request_file";
    8090my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    8191    run(command => $dqr_command, verbose => $verbose);
    8292unless ($success) {
    83     my_die("Unable to perform $dqr_command error code: $error_code",-1,-1,-1,-1,-1,-1);
     93    # This is a problem, because I'm not sure how we handle a failure to read something.
     94    # We need to return a $PSTAMP_INVALID_REQUEST, I think, but if we can't read it,
     95    # we can't send that response back.
     96    die("Unable to perform $dqr_command error code: $error_code");
    8497}
    8598my %query = ();
     
    119132my %image_list_hash;
    120133for (my $i = 1; $i < $Nrows; $i++) {
    121 #    print "$i $Nrows $query{CONTENT}{RA1_DEG}[$i] $query{CONTENT}{DEC1_DEG}[$i]\n";
    122 
     134    # This could use the fact that locate_images now accepts position arrays, but
     135    # I'll save that for after I get the majority of things working.
    123136    my $image_set_tmp  = find_image_set($query{HEADER}{FPA_ID}[0],$query{HEADER}{STAGE}[0],
    124137                                        $query{HEADER}{MJD_OBS}[0],$query{HEADER}{FILTER}[0],
     
    126139                                        $query{CONTENT}{ROWNUM}[$i],$verbose);
    127140    unless (%$image_set_tmp) {
    128         my_die("No images were returned.",$query{HEADER}{QUERY_ID}[0],$query{HEADER}{FPA_ID}[0],
    129                $query{HEADER}{MJD_OBS}[0],$query{HEADER}{FILTER}[0],$query{HEADER}{OBSCODE}[0],
    130                $query{HEADER}{STAGE}[0]);
    131     }
    132     print "=== $image_set_tmp->{IMAGE}\n    $image_set_tmp->{PSF}\n    $image_set_tmp->{MASK}\n    $image_set_tmp->{WEIGHT}\n    $image_set_tmp->{SKY_COORDINATES}\n    $image_set_tmp->{ROWNUM}\n";
    133     # This appends, assuming that if we get an image, we also get the identical psf/mask/weight/etc.
     141        # No images were returned, so create a dummy entry that
     142        $image_list_hash{'no_image'}{IMAGE}    = 'no_image';
     143        $image_list_hash{'no_image'}{PSF}      = 'no_psf';
     144        $image_list_hash{'no_image'}{MASK}     = 'no_mask';
     145        $image_list_hash{'no_image'}{WEIGHT}   = 'no_weight';
     146        $image_list_hash{'no_image'}{CATALOG}  = 'no_catalog';
     147        $image_list_hash{'no_image'}{CLASS_ID} = 'no_class';
     148        $image_list_hash{'no_image'}{ERROR}    = $PSTAMP_NO_IMAGE_MATCH;
     149        push @{ $image_list_hash{'no_image'}{SKY_COORDINATES} }, "$query{CONTENT}{RA1_DEG}[$i] $query{CONTENT}{DEC1_DEG}[$i]";
     150        push @{ $image_list_hash{'no_image'}{ROWNUM} }, $query{CONTENT}{ROWNUM}[$i];
     151        next;
     152    }
     153#     print "=== $image_set_tmp->{IMAGE}\n    $image_set_tmp->{PSF}\n";
     154#     print "    $image_set_tmp->{MASK}\n    $image_set_tmp->{WEIGHT}\n";
     155#     print "    $image_set_tmp->{SKY_COORDINATES}\n    $image_set_tmp->{ROWNUM}\n";
     156
     157    # This indexes the results for identical images into the same hash.
    134158    $image_list_hash{$image_set_tmp->{IMAGE}}{IMAGE}    = $image_set_tmp->{IMAGE};
    135159    $image_list_hash{$image_set_tmp->{IMAGE}}{PSF}      = $image_set_tmp->{PSF};
     
    138162    $image_list_hash{$image_set_tmp->{IMAGE}}{CATALOG}  = $image_set_tmp->{CATALOG};
    139163    $image_list_hash{$image_set_tmp->{IMAGE}}{CLASS_ID} = $image_set_tmp->{CLASS_ID};
     164    $image_list_hash{$image_set_tmp->{IMAGE}}{ERROR}    = $image_set_tmp->{ERROR};
    140165    push @{ $image_list_hash{$image_set_tmp->{IMAGE}}{SKY_COORDINATES} }, $image_set_tmp->{SKY_COORDINATES};
    141166    push @{ $image_list_hash{$image_set_tmp->{IMAGE}}{ROWNUM} }, $image_set_tmp->{ROWNUM};
    142167}
     168
    143169my $i = 0;
    144 
    145170foreach my $k (keys %image_list_hash) {
     171    # If we errored out on finding an image, we need to not try to run psphot here.
     172    if ($image_list_hash{$k}{ERROR} != 0) {
     173        next;
     174    }
    146175    # Write coordinates of the requested targets to a file.
    147     my ($coordfile,$coordname) = tempfile("/tmp/detect.coords.$i.XXXX",
     176    my ($coordfile,$coordname) = tempfile("${workdir}/detect.coords.$i.XXXX",
    148177                                            UNLINK => !$save_temps);
    149     my ($targetfile,$targetname) = tempfile("/tmp/detect.targets.$i.XXXX",
     178    my ($targetfile,$targetname) = tempfile("${workdir}/detect.targets.$i.XXXX",
    150179                                            UNLINK => !$save_temps);
    151180
     
    153182        print $coordfile "$image_list_hash{$k}{SKY_COORDINATES}[$j]\n";
    154183    }
    155 
     184#    print "$k\n";
    156185    # Convert the sky coordinates to image coordinates with ppCoord.
    157186    my $command = "ppCoord -astrom $image_list_hash{$k}{CATALOG} -radec $coordname";
     
    171200    }
    172201
    173    
     202#     print "psphot $image_list_hash{$k}{PSF}\n";
    174203    # Run psphotForced on the target list.
    175     my $tmpdir  = tempdir("detect.$i.XXXX", DIR => "/tmp/", CLEANUP => !$save_temps);
     204    my $tmpdir  = tempdir("detect.$i.XXXX", DIR => "${workdir}/", CLEANUP => !$save_temps);
    176205    $image_list_hash{$k}{OUTROOT} = "$tmpdir/detectability.$query{HEADER}{STAGE}[0].$query{HEADER}{FPA_ID}[0]";
    177206   
     
    185214        run(command => $psphot_cmd, verbose => $verbose);
    186215    unless ($success) {
    187         my_die("Unable to perform $psphot_cmd. Error_code: $error_code",
    188                $query{HEADER}{QUERY_ID}[0],$query{HEADER}{FPA_ID}[0],
    189                $query{HEADER}{MJD_OBS}[0],$query{HEADER}{FILTER}[0],$query{HEADER}{OBSCODE}[0],
    190                $query{HEADER}{STAGE}[0],$error_code);
     216        $image_list_hash{$k}{ERROR} = $PSTAMP_SYSTEM_ERROR;
    191217    }
    192218}
     
    196222#
    197223my @rownums = ();
     224my @out_errors = ();
    198225my @psphot_Npix = ();
    199226my @psphot_Qfact= ();
    200227my @psphot_flux = ();
     228
    201229foreach my $k (keys %image_list_hash) {
    202     my $cmf = "$image_list_hash{$k}{OUTROOT}.$image_list_hash{$k}{CLASS_ID}.cmf";
    203    
    204     my ($tmp_Npix,$tmp_Qfact,$tmp_flux) = read_cmf_file($cmf,$image_list_hash{$k}{EXTENSION_BASE});
    205 
    206     push @rownums,        @{ $image_list_hash{$k}{ROWNUM} };
    207     push @psphot_Npix,    @{ $tmp_Npix };
    208     push @psphot_Qfact,   @{ $tmp_Qfact };
    209     push @psphot_flux,    @{ $tmp_flux };
     230    if ($image_list_hash{$k}{ERROR} == 0) {
     231        my $cmf = "$image_list_hash{$k}{OUTROOT}.$image_list_hash{$k}{CLASS_ID}.cmf";
     232       
     233        my ($tmp_Npix,$tmp_Qfact,$tmp_flux) = read_cmf_file($cmf,$image_list_hash{$k}{EXTENSION_BASE});
     234       
     235        push @rownums,        @{ $image_list_hash{$k}{ROWNUM} };
     236        push @out_errors,     (map { $image_list_hash{$k}{ERROR} }  @{ $image_list_hash{$k}{ROWNUM} });
     237        push @psphot_Npix,    @{ $tmp_Npix };
     238        push @psphot_Qfact,   @{ $tmp_Qfact };
     239        push @psphot_flux,    @{ $tmp_flux };
     240    }
     241    else {
     242        push @rownums,        @{ $image_list_hash{$k}{ROWNUM} };
     243        push @out_errors,     (map { $image_list_hash{$k}{ERROR} }  @{ $image_list_hash{$k}{ROWNUM} });
     244        push @psphot_Npix,    (map { 0 }  @{ $image_list_hash{$k}{ROWNUM} });
     245        push @psphot_Qfact,   (map { 0.0 }  @{ $image_list_hash{$k}{ROWNUM} });
     246        push @psphot_flux,    (map { 0.0 }  @{ $image_list_hash{$k}{ROWNUM} });
     247    }   
    210248}
    211249
     
    214252                    $query{HEADER}{MJD_OBS}[0],$query{HEADER}{filter}[0],
    215253                    $query{HEADER}{obscode}[0],
    216                     \@rownums, \@psphot_Npix, \@psphot_Qfact, \@psphot_flux);
    217 
     254                    \@rownums, \@out_errors, \@psphot_Npix, \@psphot_Qfact, \@psphot_flux);
     255# print "Wrote response file $output\n";
    218256#
    219257# Add to datastore
    220258#
    221 # my $finish_command = "dquery_finish.pl --req_id $req_id --req_name $req_name --product $product";
    222 # ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    223 #     run(command => $finish_command, verbose => $verbose);
    224 # unless ($success) {
    225 #     warn ("Unable to perform $finish_command error code: $error_code");
    226 # }
    227 
     259# Files are added to the datastore by dquery_finish.pl
    228260#
    229261# Cleanup
    230262#
    231263# Since everything is written to temporary files, there should be nothing to cleanup.
     264
    232265#
    233266# Utilities
     
    242275    my $index  = shift;
    243276    my $verbose = shift;
    244    
     277
     278    # This is the set of things that we need in order to run psphotForced
    245279    my $option_mask |= 1;
    246280    $option_mask |= $PSTAMP_SELECT_IMAGE;
     
    252286    my $mjd_max = $mjd + 1;
    253287
     288    # Construct a row list.
     289    my @rowList;
     290    $rowList[0]->{CENTER_X} = $ra;
     291    $rowList[0]->{CENTER_Y} = $dec;
     292    $rowList[0]->{ID} = 1;
     293    $rowList[0]->{STAGE} = $stage;
     294    $rowList[0]->{COORD_MASK} = 0;
     295
     296    #    print "$stage\n";
    254297    # Call the PStamp code to find the images that contain the target on the given MJD in the specified filter.
    255     my @images = locate_images($ipprc,$dbname,"bycoord",$stage,
    256                                undef,undef,undef,$option_mask,$need_magic,
    257                                $ra,$dec,$mjd_min,$mjd_max,$filter . ".00000",undef,$verbose); 
     298    my @images = locate_images($ipprc,$imagedb,
     299                                \@rowList,
     300                               "bycoord",$stage,
     301                               undef,undef,undef,
     302                               $option_mask,$need_magic,
     303                               # $ra,$dec,
     304                               $mjd_min,$mjd_max,$filter . ".00000",undef,$verbose); 
    258305
    259306    my %image_info  = ();
     
    270317            }
    271318            elsif ($stage eq 'stack') {
    272                 # Stacks hide the exposure name very well, so I'm
    273                 # choosing the stack_id as the FPA_ID to match. This
    274                 # probably needs to be approved somehow.
     319                # Stacks hide the exposure name very well, so we can only match against stage_id
    275320                if (${ $j }{stage_id} ne $FPA_ID) {
    276321                    next;
     
    285330            }
    286331            # Debug prints of all the components of this image
    287             foreach my $k (keys %{ $j }) {
    288                 print "$i $j $k ${ $j }{$k}\n";
    289             }
    290            
     332#           foreach my $k (keys %{ $j }) {
     333#               if ($k eq 'row_index') {
     334#                   print "$i $j $k @{${ $j }{$k} }\n";
     335#               }
     336#               print "$i $j $k ${ $j }{$k}\n";
     337#           }
     338
     339            # Check for existance of the images. Drawn mostly from pstampparse.pl
     340            my $run_state = ${ $j }{state};
     341            my $data_state = ${ $j }{data_state};
     342            $data_state = $run_state if $stage eq 'stack';
     343            my $fault = 0;
     344            if (($run_state eq 'goto_purged') or ($data_state eq 'purged') or
     345                ($run_state eq 'drop') or
     346                ($run_state eq 'error_cleaned') or
     347                ($run_state eq 'goto_scrubbed') or ($data_state eq 'scrubbed')) {
     348                # image is gone and it's not coming back
     349                $fault = $PSTAMP_GONE;
     350            }
     351            elsif  (($data_state ne 'full') or ($need_magic and (${ $j }{magicked} < 0))) {
     352                if (($stage eq 'stack')||($stage eq 'diff')) {
     353                    # updating stacks and diffs isn't implemented
     354                    $fault = $PSTAMP_NOT_IMPLEMENTED;
     355                }
     356                if ($stage eq 'chip') {
     357                    my $burntool_state = ${ $j }{burntool_state};
     358                    if ($burntool_state and (abs($burntool_state) < 14)) {
     359                        $fault = $PSTAMP_NOT_AVAILABLE;
     360                    }
     361                }
     362               
     363                if ($fault == 0) {
     364                    # This bombs us out to dqueryparse, which will then flag a job for this run to be updated.
     365                    my_die_for_update($data_state,$query{HEADER}{STAGE}[0],
     366                                      ${ $j }{stage_id},${ $j }{class_id} || ${ $j }{skycell_id},
     367                                      $need_magic,$imagedb,$PSTAMP_NOT_AVAILABLE);
     368                }
     369            }
     370
    291371            # This image matches, so we want to save the information into our output structure
    292372            $image_info{ROWNUM} = $index;
     
    295375            $image_info{MASK}   = ${ $j }{mask};
    296376            $image_info{WEIGHT} = ${ $j }{weight};
     377            $image_info{ERROR}  = $fault;
    297378            $image_info{SKY_COORDINATES} = "$ra $dec";
    298379            # To do sky->image coordinate transformations, we need to use the cmf/smf file. If
     
    405486    my $obscode = shift;
    406487    my $rownum_ref = shift;
     488    my $out_err_ref = shift;
    407489    my $psphot_Npix_ref = shift;
    408490    my $psphot_Qfact_ref = shift;
     
    413495    my $columns = [
    414496        # matching rownum from detectability original request
    415         { name => 'ROWNUM',   type => '20A', writetype => TSTRING },
     497        { name => 'ROWNUM',   type => 'V', writetype => TULONG },
     498        # any errors that occurred during processing
     499        { name => 'ERROR_CODE',   type => 'V', writetype => TULONG },
    416500        # number of pixels used in hypothetical PSF for the query detection
    417501        { name => 'DETECT_N', type => 'V',   writetype => TULONG },
     
    455539    for (my $i = 0; $i < $numRows; $i++) {
    456540        push @{$colData{'ROWNUM'}},      ${ $rownum_ref }[$i];
     541        push @{$colData{'ERROR_CODE'}},  ${ $out_err_ref }[$i];
    457542        push @{$colData{'DETECT_N'}},    ${ $psphot_Npix_ref }[$i];
    458543        push @{$colData{'DETECT_F'}},    ${ $psphot_Qfact_ref }[$i];
     
    529614
    530615}
     616
     617sub my_die_for_update {
     618    my $state = shift;
     619    my $stage = shift;
     620    my $stage_id = shift;
     621    my $component = shift;
     622    my $need_magic = shift;
     623    my $imagedb = shift;
     624    my $exit_code = shift;
     625
     626    print "$state $stage $stage_id $component $need_magic $imagedb\n";
     627    print STDERR "$state $stage $stage_id $component $need_magic $imagedb\n";
     628    exit($exit_code);
     629}
  • branches/czw_branch/20100427/pstamp/scripts/dquery_finish.pl

    r27578 r28017  
    2020use PS::IPP::Config qw( :standard );
    2121
    22 my ( $req_id, $req_name, $req_file, $product, $out_dir, $dbname, $dbserver, $verbose, $save_temps );
     22my ( $req_id, $req_name, $req_file, $product, $outdir, $dbname, $dbserver, $verbose, $save_temps );
    2323
    2424GetOptions(
     
    2727           'req_file=s' => \$req_file,
    2828           'product=s'  => \$product,
    29            'out_dir=s'  => \$out_dir,
     29           'outdir=s'   => \$outdir,
    3030           'dbname=s'   => \$dbname,
    3131           'dbserver=s' => \$dbserver,
     
    4141$err .= "--req_name is required\n" if !$req_name;
    4242$err .= "--product is required\n" if !$product;
    43 $err .= "--out_dir is required\n" if !$out_dir;
     43$err .= "--outdir is required\n" if !$outdir;
    4444
    4545die "$err" if $err;
     
    7676    die "product directory does not exist $prod_dir";
    7777}
    78 my $out_dir = "$prod_dir/$req_name";
     78my $outdir = "$prod_dir/$req_name";
    7979}
    80 if (! -e $out_dir ) {
     80if (! -e $outdir ) {
    8181    # something must have gone wrong at the parse stage
    82     print STDERR "output fileset directory $out_dir does not exist\n" if $verbose;
    83     if (! mkdir $out_dir ) {
     82    print STDERR "output fileset directory $outdir does not exist\n" if $verbose;
     83    if (! mkdir $outdir ) {
    8484        stop_request($req_id, $PS_EXIT_SYS_ERROR, $verbose);
    85         die "cannot create output directory $out_dir";
     85        die "cannot create output directory $outdir";
    8686    }
    87 } elsif (! -d $out_dir) {
     87} elsif (! -d $outdir) {
    8888    stop_request($req_id, $PS_EXIT_SYS_ERROR, $verbose);
    89     die "output fileset directory $out_dir exists but is not a directory";
     89    die "output fileset directory $outdir exists but is not a directory";
    9090}
    9191
     
    118118
    119119# XXX: have the jobs produce the reglist as with postage stamp requests
    120 my ($REGLIST, $reg_list) = tempfile("$out_dir/reqlist.XXXX", UNLINK => !$save_temps);
     120my ($REGLIST, $reg_list) = tempfile("$outdir/reqlist.XXXX", UNLINK => !$save_temps);
     121
    121122foreach my $job (@jobs) {
    122123    my $job_id = $job->{job_id};
    123124    my $response_file = "response${job_id}.fits";
    124     my $response_path = "$out_dir/$response_file";
     125    my $response_path = "$outdir/$response_file";
    125126
    126127    if (-e $response_path) {
    127128        # the job generated a response file put it into the Data Store
    128129        print $REGLIST "$response_file|||table|\n";
     130
     131        # do the same if we have an error file.  Should the parse data be uploaded as well?
     132        my $err_file = "parse_error.txt";
     133        if (-e "$outdir/$err_file") {
     134            print $REGLIST "$err_file|||text|\n";
     135        }
    129136    } else  {
    130137        print STDERR "detect_query response file for job $job_id not found\n" if $verbose;
     
    136143if (-s $reg_list) {
    137144    my $command = "$dsreg --add $req_name --product $product --list $reg_list";
    138     $command .= " --copy --datapath $out_dir";
     145    $command .= " --copy --datapath $outdir";
    139146    $command .= " --type MOPS_DETECTABILITY_RESPONSE";
     147    $command .= " --ps0 $req_id";
    140148    $command .= " --dbname $dbname" if $dbname;
    141149
     
    158166    my $verbose = shift;
    159167   
    160     my $command = "$pstamptool -updatereq -req_id $req_id -state stop";
    161     $command   .= " -fault $fault" if $fault;
     168    my $command = "$pstamptool -updatereq -req_id $req_id -set_state stop";
     169    $command   .= " -set_fault $fault" if $fault;
    162170    $command   .= " -dbname $dbname" if $dbname;
    163171    $command   .= " -dbserver $dbserver" if $dbserver;
  • branches/czw_branch/20100427/pstamp/scripts/dqueryparse.pl

    r27578 r28017  
    22#
    33# parse a MOPS_DETCTABILITY_QUERY table and create a results file
    4 #
    5 # Note: this file is currently only a placeholder which creates a fake response file
    6 # and adds a completed job to the database
    74#
    85
    96use strict;
    107use warnings;
    11 
     8use Carp;
    129use Getopt::Long qw( GetOptions );
    1310use Pod::Usage qw( pod2usage );
    1411use IPC::Cmd 0.36 qw( can_run run );
    1512
     13use PS::IPP::PStamp::RequestFile qw( :standard );
     14use PS::IPP::PStamp::Job qw( :standard );
    1615use PS::IPP::Config qw($PS_EXIT_SUCCESS
    1716                       $PS_EXIT_UNKNOWN_ERROR
     
    2625                       );
    2726
    28 my ($req_file, $req_id, $out_dir, $product, $mode, $dbname, $dbserver, $verbose, $save_temps);
    29 
     27my ($no_update, $imagedb, $label);
     28my ($req_file, $req_id, $outdir, $product, $mode, $dbname, $dbserver, $verbose, $save_temps);
     29my ($job_id,$rownum); # stuff from the post-update world
    3030#
    3131# parse args
     
    3535        'file=s'          =>      \$req_file,
    3636        'req_id=s'        =>      \$req_id,
    37         'out_dir=s'       =>      \$out_dir,
     37        'job_id=s'        =>      \$job_id,
     38        'rownum=s'        =>      \$rownum,
     39        'outdir=s'       =>      \$outdir,
     40        'label=s'         =>      \$label,
    3841        'product=s'       =>      \$product,
    3942        'mode=s'          =>      \$mode,
     
    4447) or pod2usage(2);
    4548
    46 my $err = "";
    47 
    48 if (!$req_file) {
    49     $err .= "--file is required\n";
    50 }
    51 if (!$req_id) {
    52     $err .= "--req_id is required\n";
    53 }
    54 if (!$out_dir) {
    55     $err .="--out_dir is required\n";
    56 }
    57 if (!$product) {
    58     $err .="--product is required\n";
    59 }
    60 
    61 
    62 die $err if ($err);
    63 
     49die "invalid mode '$mode'" unless ($mode eq "list_uri") or ($mode eq "queue_job");
     50die "--file or --job_id is required" if !$req_file;
     51
     52if ($mode ne "list_uri") {
     53    die "req_id is required" if !$req_id;
     54    die "outdir is required" if !$outdir;
     55    die "product is required" if !$product;
     56}
    6457my $missing_tools;
    6558my $pstamptool = can_run('pstamptool') or (warn "Can't find pstamptool" and $missing_tools =1);
    66 my $fakedresponse = can_run('fakedresponse.pl') or (warn "Can't find fakedresponse.pl" and $missing_tools =1);
     59my $detectresponse = can_run('detectability_respond.pl') or
     60    (warn "Can't find detectability_respond.pl" and $missing_tools = 1);
    6761my $fields = can_run('fields') or (warn "Can't find fields" and $missing_tools =1);
    6862
     
    7771}
    7872
     73# just deal with these arguments once and for all
     74$pstamptool .= " -dbname $dbname" if $dbname;
     75$pstamptool .= " -dbserver $dbserver" if $dbserver;
     76$detectresponse .= " --dbname $dbname" if $dbname;
     77
     78$no_update = 1 if $mode eq "list_job";
     79
     80# Unless we're running as a job, write the parse arguments in case we need to rerun this parsing.
     81if (!$job_id) {
     82    my $argslist = "$outdir/parse.args";
     83    open ARGSLIST, ">$argslist" or my_die("failed to open argslist file $argslist", $job_id, $PS_EXIT_UNKNOWN_ERROR);
     84    print ARGSLIST "--label $label --mode $mode --req_id $req_id --product $product --outdir $outdir --file $req_file\n";
     85    close ARGSLIST;
     86}
     87
    7988# get the query id and check the extname and version from the header
    80 my $fields_output;
     89my $fields_output; 
    8190{
    8291    my $command = "echo $req_file | $fields -x 0 EXTNAME EXTVER QUERY_ID";
     
    8493        run(command => $command, verbose => $verbose);
    8594   
    86 #   fields doesn't return zero when it succeeds
    87 #    unless ($success) {
    88 #        print STDERR @$stderr_buf;
    89 #    }
    9095    $fields_output = join "", @$stdout_buf;
    9196}
    9297my (undef, $extname, $extver, $req_name) = split " ", $fields_output;
    9398
    94 die "$req_file is missing one of EXTNAME EXTVER or QUERY_ID"
     99my_die("$req_file is missing one of EXTNAME EXTVER or QUERY_ID", $PS_EXIT_PROG_ERROR)
    95100    if !(defined($extname) and defined($extver) and defined($req_name));
    96 
    97 die "$req_file has EXTNAME $extname not MOPS_DETECTABILITY_QUERY table"
    98                 if $extname ne         "MOPS_DETECTABILITY_QUERY";
    99 die "$req_file is version $extver expecting 1" if $extver ne 1;
    100 
    101 if (0) {
    102 $out_dir .= "/$req_name";
    103 }
    104 if (! -e $out_dir ) {
    105     mkdir $out_dir or die "cannot create output directory $out_dir";
    106 } elsif (! -d $out_dir ) {
    107     die "output fileset directory $out_dir exists but is not a directory";
    108 }
    109 
    110 #
    111 # XXX Eventually we will parse the file here, to look up the list of input images to be processed
    112 # and queue a job for each image.
    113 # The request file will be one of the arguments. Each job will look at all rows and create entries
    114 # in the response file the coordinates that overlap the image.
    115 #
    116 # In the meantime we don't parse the file here, pass it to the program fakedresponse.
    117 # It creates a response file with a line for each row in the request file
    118 
    119 my $response_file = "$out_dir/response.fits";
     101my_die("$req_file has EXTNAME $extname not MOPS_DETECTABILITY_QUERY table", $PS_EXIT_PROG_ERROR)
     102    if $extname ne "MOPS_DETECTABILITY_QUERY";
     103my_die("$req_file is version $extver expecting 1", $PS_EXIT_PROG_ERROR)
     104    if $extver ne 1;
     105
     106# Set up the workdir for this query.
     107if (! -e $outdir ) {
     108    mkdir $outdir or my_die("cannot create output directory $outdir", $PS_EXIT_PROG_ERROR);
     109} elsif (! -d $outdir ) {
     110    my_die ("output fileset directory $outdir exists but is not a directory", $PS_EXIT_PROG_ERROR);
     111}
     112
     113
     114# Pass along the request file to the response generator.
     115my $response_file = "$outdir/${req_name}.dresponse.${req_id}.fits";
    120116my $fault;
     117my $data_to_update = '';
    121118{
    122     my $command = "$fakedresponse --input $req_file --output $response_file --workdir $out_dir";
     119    my $command = "$detectresponse --input $req_file --output $response_file --workdir $outdir";
    123120    $command .= " --save-temps" if $save_temps;
    124121    $command .= " --verbose" if $verbose;
     
    127124        run(command => $command, verbose => $verbose);
    128125    unless ($success) {
    129         warn("Unable to perform $command error code: $error_code");
    130     }
     126        warn("Warn! Unable to perform $command error code: $error_code");
     127    }
     128    # Use the fault code to see if we can regenerate the missing data.
    131129    $fault = $error_code >> 8;
    132 }
    133 
    134 my $job_id;
     130    if ($fault == $PSTAMP_NOT_AVAILABLE) {
     131        $data_to_update = (split /\n/, (join "", @$stdout_buf))[-1];   
     132    }   
     133}
     134
    135135my $result;
    136 {
    137     my $command = "$pstamptool -addjob -req_id $req_id -outputBase $out_dir";
    138     $command .= " -job_type detect_query -state stop -fault $fault";
     136# If we returned correctly with a valid response file, get a job ID
     137# for the completed work, and move the response to a standardized name.
     138if ($fault == 0) {
     139    my $command = "$pstamptool -addjob -req_id $req_id -outputBase $outdir";
     140    $command .= " -job_type detect_query -state stop -fault 0";
    139141    $command .= " -rownum 1";
    140     $command .= " -dbname $dbname" if $dbname;
    141     $command .= " -dbserver $dbserver" if $dbserver;
    142 
    143     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    144         run(command => $command, verbose => $verbose);
    145 
     142
     143    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     144        run(command => $command, verbose => $verbose);
    146145    if ($success) {
    147146        $job_id = join "", @$stdout_buf;
    148147        chomp $job_id;
    149148        if ($job_id && -e $response_file) {
    150             rename $response_file, "$out_dir/response${job_id}.fits";
     149            rename $response_file, "$outdir/response${job_id}.fits";
    151150        }
    152151        $result = 0;
     
    156155    }
    157156}
    158 
    159 
     157else {
     158    # Failed to run correctly, which means that we need to queue a job and flag data for updating.
     159    # Get the dependency id for the data we're requesting be updated.
     160    my $dep_id = queue_update_run($req_id,$job_id,$outdir,$label,$data_to_update);
     161
     162    # Link this request to a job and link that job to any dependency
     163    my $command = "$pstamptool -addjob -req_id $req_id -outputBase $outdir";
     164    $command .= " -job_type detect_query -state run -fault 0";
     165    $command .= " -rownum 1";
     166    $command .= " -dep_id $dep_id" if $dep_id;
     167
     168    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     169        run(command => $command, verbose => $verbose);
     170
     171    if ($success) {
     172        $job_id = join "", @$stdout_buf;
     173        chomp $job_id;
     174        if ($job_id && -e $response_file) {
     175            # We shouldn't have a response file at this stage.
     176            rename $response_file, "$outdir/response${job_id}.fits";
     177        }
     178        $result = 0;
     179    } else {
     180        warn("Unable to perform $command error code: $error_code");
     181        $result = $error_code >> 8;
     182    }
     183}
     184
     185# This does not set the request state to stop.  That will happen with the request_finish.pl script,
     186# which will notice that we've inserted the stopped job and decide we're finished. Easy enough.
    160187{
    161     my $command = "$pstamptool -updatereq -req_id $req_id -name $req_name -outProduct $product";
    162     $command .= " -fault $result" if $result;
    163     $command .= " -dbname $dbname" if $dbname;
    164     $command .= " -dbserver $dbserver" if $dbserver;
     188    my $command = "$pstamptool -updatereq -req_id $req_id -set_name $req_name -set_outProduct $product";
     189    $command .= " -set_fault $result" if $result;
    165190
    166191    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    167192        run(command => $command, verbose => $verbose);
    168193    unless ($success) {
    169         die "$command failed";
     194        my_die("$command failed",$PS_EXIT_UNKNOWN_ERROR);
    170195    }
    171196}
    172197 
    173198exit 0;
     199
     200
     201# If we have to queue an update run, do so and create a new dependent
     202sub queue_update_run {
     203    my ($req_id, $job_id, $outdir, $label, $data_to_update) = @_;
     204
     205    my ($state, $stage, $stage_id, $component, $need_magic, $imagedb) = split /\s+/, $data_to_update;
     206   
     207    if (($state ne 'cleaned') and ($state ne 'update') and ($state ne 'goto_cleaned')) {
     208        # We should have received one of these states, so if not, signal that we have a problem.
     209        my_die("$stage $stage_id is in unexpected state $state", $PS_EXIT_PROG_ERROR);
     210    }
     211    my $dep_id;
     212    my $command = "$pstamptool -getdependent -stage $stage -stage_id $stage_id -imagedb $imagedb -component $component ";
     213    $command .= " -outdir $outdir";
     214    $command .= " -need_magic" if $need_magic;
     215
     216    my $rlabel = "dq_ud_" . $label if $label;
     217    $command .= " -rlabel $rlabel" if $rlabel;
     218
     219    if (!$no_update) {
     220        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     221            run(command => $command, verbose => $verbose);
     222        unless ($success) {
     223            my_die("$command failed", $PS_EXIT_UNKNOWN_ERROR);
     224        }
     225        my $output = join "", @$stdout_buf;
     226        chomp $output;
     227        $dep_id = $output;
     228
     229        my_die("pstamptool -getdependent returned invalid dep_id", $PS_EXIT_PROG_ERROR) if !$dep_id;
     230    }
     231    else {
     232        print STDERR "skipping $command\n";
     233        $dep_id = 42;
     234    }
     235
     236    return($dep_id);
     237}
     238       
     239   
     240
     241sub my_die {
     242    my $msg = shift;
     243    my $fault = shift;
     244
     245    carp $msg;
     246
     247    # we don't fault the request here pstamp_parser_run.pl handles that if necessary
     248    exit $fault;
     249}
  • branches/czw_branch/20100427/pstamp/scripts/pstamp_checkdependent.pl

    r27751 r28017  
    2121use Carp;
    2222
     23# XXX: put this in a module somewhere
     24my $IPP_DIFF_MODE_WARP_WARP   = 1;
     25my $IPP_DIFF_MODE_WARP_STACK  = 2;
     26my $IPP_DIFF_MODE_STACK_WARP  = 3;
     27my $IPP_DIFF_MODE_STACK_STACK = 4;
    2328
    2429my ($dep_id, $stage, $stage_id, $component, $imagedb, $rlabel, $need_magic);
     
    3035    'stage_id=i'    =>  \$stage_id,
    3136    'component=s'   =>  \$component,
    32     'imagedb=s'     =>  \$imagedb,      # dbname for images
     37    'imagedb=s'     =>  \$imagedb,      # dbname for images.
    3338    'rlabel=s'      =>  \$rlabel,
    3439    'need_magic'    =>  \$need_magic,
     
    5661}
    5762
     63# Append imagedb to the ippTools
    5864$chiptool    .= " -dbname $imagedb";
    5965$warptool    .= " -dbname $imagedb";
    6066$difftool    .= " -dbname $imagedb";
     67$stacktool   .= " -dbname $imagedb";
    6168$magicdstool .= " -dbname $imagedb";
    62 
    6369
    6470my $ipprc = PS::IPP::Config->new();
     
    6773    $dbserver =  metadataLookupStr($ipprc->{_siteConfig}, 'PS_DBSERVER');
    6874}
    69 
    7075
    7176
     
    103108# Got "it"
    104109
     110my $magic_ok = 0;
     111if ($stage eq 'diff') {
     112    if ($it->{diff_mode} == $IPP_DIFF_MODE_STACK_STACK) {
     113        # stack stack diffs don't need magic, but since the warps need to have the chips destreaked
     114        # in order to be processed se set need_magic in the database for all runs
     115        # Now the diffs themselves don't need to be destreaked so
     116        $magic_ok = 1;
     117    }
     118}
    105119my $status = 0;
    106120if (($it->{state} eq 'full') or ($it->{state} eq 'update') and ($whole_run or ($it->{data_state} eq 'full'))
    107         and (!$need_magic or $it->{magicked} > 0)) {
    108 
    109     # This Dependency is satisfied. all done
     121        and (!$need_magic or $magic_ok or $it->{magicked} > 0)) {
     122
     123    # This Dependency is satisfied. All done!
    110124    my $command = "$pstamptool -updatedependent -set_state full -dep_id $dep_id";
    111125    $command .= " -dbname $dbname" if $dbname;
     
    123137} elsif (($it->{state} eq 'cleaned') or ($it->{state} eq 'update') and
    124138        ($whole_run or ($it->{data_state} eq 'cleaned'))) {
     139
     140    # Update has not been queued for this component yet. 
    125141
    126142    # XXX: if $whole_run this is going to repeatedly call -setimfiletoupdate. This will be a no-op
     
    140156    }
    141157} else {
     158    # update for this component has been queued by hasn't completed yet or the state is an error state
     159    # XXX: in this state we aren't checking the dependents anymore. If something goes wrong this
     160    # will never complete. Consider calling the 'queue_update' functions again just to check. They are relatively cheap
     161
     162
    142163    print "${stage}Run $stage_id state is $it->{state} $component data_state is $it->{data_state}\n";
    143164
     
    150171
    151172    # temporary hack to deal with data with old burntool tables. This check is now done by pstampparse.pl
    152     # so runs in this state will not get queued
     173    # so runs in this state should not get queued
    153174    if ($stage eq 'chip') {
    154175        my $burntool_state = $it->{burntool_state};
     
    169190    }
    170191    if (!$job_fault and ($stage eq 'chip')) {
    171         $job_fault = queue_update_magicDSRun($stage, $stage_id, $rlabel, $it->{raw_magicked}, $it->{dsRun_state});
     192        # chip processing is done, start destreaking.
     193        $job_fault = queue_update_magicDSRun($stage, $stage_id, $rlabel, $need_magic, $it->{raw_magicked}, $it->{dsRun_state});
    172194    }
    173195    if ($job_fault) {
     
    186208    my $need_magic = shift;
    187209
     210
    188211    my $dsRun_state;
    189212    my $raw_all_magicked = 1; # this gets cleared if any of the inputs aren't destreaked
     
    193216            $raw_all_magicked &= ($chip->{raw_magicked} > 0);
    194217
    195             if ($chip->{data_state} ne 'update') {
     218            if ($chip->{state} =~ /error/) {
     219                faultJobs('stop', undef, undef, $PSTAMP_GONE);
     220            } elsif (($chip->{data_state} ne 'update') and ($chip->{data_state} ne 'full')) {
    196221                my $command = "$chiptool -setimfiletoupdate -chip_id $chip_id -class_id $chip->{class_id}";
    197222                $command .= " -set_label $rlabel" if $rlabel;
     
    228253    }
    229254
    230     my $status = queue_update_magicDSRun('chip', $chip_id, $rlabel, $raw_all_magicked, $dsRun_state);
     255    my $status = queue_update_magicDSRun('chip', $chip_id, $rlabel, $need_magic, $raw_all_magicked, $dsRun_state);
    231256
    232257    return $status;
     
    247272
    248273    my $warp_id = $metadata->{warp_id};
     274    my $state = $metadata->{state};
     275    if ($state =~ /error/) {
     276        print STDERR "warpRun $warp_id has state $state faulting jobs\n";
     277        faultJobs('stop', undef, undef, $PSTAMP_GONE);
     278        exit 0;
     279    }
     280
    249281    if (!$whole_run) {
    250282        my $skycell = $metadata;
     
    256288            if !$data or scalar @$data == 0;
    257289
    258         my $good_to_go = 1;
     290        my $chips_ready = 1;
    259291        my @chipsToUpdate;
    260292        my $chip_id;
     
    262294            $chip_id = $chip->{chip_id};
    263295            if (($chip->{data_state} ne 'full') or ($need_magic and ($chip->{magicked} <= 0))) {
    264                 $good_to_go = 0;
     296                $chips_ready = 0;
    265297                push @chipsToUpdate, $chip;
    266298            } else {
     
    269301        }
    270302
    271         if ($good_to_go) {
     303        if ($chips_ready) {
     304            # the reason we defer setting the warp to update is so that we can handle error conditions at previous
     305            # stages more easily.
    272306            my $command = "$warptool -setskyfiletoupdate -warp_id $warp_id -skycell_id $skycell->{skycell_id}";
    273307            $command .= " -set_label $rlabel" if $rlabel;
     
    333367    my $need_magic = shift;
    334368
    335 # XXXX This is not ready to go yet XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxx
    336 
    337369    my $diff_id   = $metadata->{diff_id};
    338370    my $diff_mode = $metadata->{diff_mode};
     
    341373        my $skycell_id = $skycell->{skycell_id};
    342374
    343         # put this in a module somewhere
    344         my $IPP_DIFF_MODE_WARP_WARP   = 1;
    345         my $IPP_DIFF_MODE_WARP_STACK  = 2;
    346         my $IPP_DIFF_MODE_STACK_WARP  = 2;
    347         my $IPP_DIFF_MODE_STACK_STACK = 4;
    348375        if ($diff_mode == $IPP_DIFF_MODE_WARP_STACK ) {
    349             # check the state of the stack
    350             my $command = "$stacktool -sumkskyfile -stack_id $skycell->{stack2}";
     376            # check the state of the template stack
     377            my $command = "$stacktool -sumskyfile -stack_id $skycell->{stack2}";
    351378            my $stack = runToolAndParseExpectOne($command, $verbose);
    352379            my_die("failed to find stackSumSkyfile for stack_id $skycell->{stack2}", $PS_EXIT_UNKNOWN_ERROR) if !$stack;
     
    361388            # now check the warp
    362389            $command = "$warptool -warped -warp_id $skycell->{warp1} -skycell_id $skycell_id";
    363             my $warp = runToolAndExpectOne($command, $verbose);
    364             my_die("failed to find warpSkyfile for warpRun $skycell->{warp_id} skycell_id $skycell_id", $PS_EXIT_UNKNOWN_ERROR)
    365                 if !$warp;
    366         }
    367 
    368         my $good_to_go = 1;
    369         my @chipsToUpdate;
    370         my $chip_id;
    371         my $warp_id;
    372         my $data ;  #XXXX
    373         foreach my $chip (@$data) {
    374             $chip_id = $chip->{chip_id};
    375             if (($chip->{data_state} ne 'full') or ($need_magic and ($chip->{magicked} <= 0))) {
    376                 $good_to_go = 0;
    377                 push @chipsToUpdate, $chip;
    378             } else {
    379                 # this chip is good to go
    380             }
    381         }
    382 
    383         if ($good_to_go) {
    384             my $command = "$warptool -setskyfiletoupdate -warp_id $warp_id -skycell_id $skycell->{skycell_id}";
    385             $command .= " -set_label $rlabel" if $rlabel;
    386 
    387             if (!$no_update) {
    388                 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    389                             run(command => $command, verbose => $verbose);
    390                 unless ($success) {
    391                     my_die("failed to queue ${stage}Run $stage_id $component for update", $PS_EXIT_UNKNOWN_ERROR);
     390            my $warp = runToolAndParseExpectOne($command, $verbose);
     391            my_die("failed to find warpSkyfile for warpRun $skycell->{warp1} skycell_id $skycell_id", $PS_EXIT_UNKNOWN_ERROR) if !$warp;
     392
     393            if ($warp->{data_state} ne 'full') {
     394                return queue_update_warp($warp, 0, $rlabel, $need_magic);
     395            }
     396            # warps are ready fall through and queue the diff update
     397        } elsif ($diff_mode eq $IPP_DIFF_MODE_WARP_WARP) {
     398            my $command = "$warptool -warped -warp_id $skycell->{warp1} -skycell_id $skycell_id";
     399            my $warp1 = runToolAndParseExpectOne($command, $verbose);
     400            my_die("failed to find warpSkyfile for warpRun $skycell->{warp1} skycell_id $skycell_id", $PS_EXIT_UNKNOWN_ERROR) if !$warp1;
     401
     402            my $warps_ready = 1;
     403            my $status = 0;
     404            if ($warp1->{data_state} ne 'full') {
     405                $warps_ready = 0;
     406                $status = queue_update_warp($warp1, 0, $rlabel, $need_magic);
     407                if ($status) {
     408                    return $status;
    392409                }
    393             } else {
    394                 print "skipping $command\n";
    395             }
    396         } elsif (scalar @chipsToUpdate > 0) {
    397             return queue_update_chip($chip_id, 0, \@chipsToUpdate, $rlabel, $need_magic);
    398         }
    399     } else {
    400         my $warpRun = $metadata;
    401         my $warp_id = $warpRun->{warp_id};
    402         my $command = "$chiptool -listrun -chip_id $warpRun->{chip_id}";
    403         my $data = runToolAndParse($command, $verbose);
    404         my_die("failed to find chipRun $warpRun->{chip_id} for warpRun $warp_id", $PS_EXIT_UNKNOWN_ERROR)
    405             if !$data or scalar @$data != 1;
    406 
    407         my $chipRun = $data->[0];
    408 
    409         my $chipRunState = $chipRun->{state};
    410         if (($chipRunState =~ /purge/) or ($chipRunState =~ /scrub/)) {
    411             print STDERR "warpRun $warp_id depends on chipRun $chipRun->{chip_id} which is in state $chipRunState\n";
    412             faultJobs('stop', 'warp', $warp_id, $PSTAMP_GONE);
    413             return 0;
    414         }
    415         my $warpRunState = $warpRun->{state};
    416         if (($chipRunState eq 'full') and (! $need_magic or ($chipRun->{magicked} > 0)) and ($warpRunState eq 'cleaned')) {
    417             # The inputs and outputs are ready. Queue the warpRun for update.
    418 
    419             # providing no -skycell_id arguments changes all skyfiles with data_state = 'cleaned' to 'update'
    420             my $command = "$warptool -setskyfiletoupdate -warp_id $warp_id";
    421             $command .= " -set_label $rlabel" if $rlabel;
    422 
    423             if (!$no_update) {
    424                 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    425                             run(command => $command, verbose => $verbose);
    426                 unless ($success) {
    427                     my_die("failed to queue ${stage}Run $stage_id $component for update", $PS_EXIT_UNKNOWN_ERROR);
    428                 }
    429             } else {
    430                 print "skipping $command\n";
    431             }
    432         } elsif ($chipRunState eq 'cleaned' or
    433             (($chipRun->{state} eq 'full') and ($need_magic and ($chipRun->{magicked} < 0) and ($chipRun->{dsRun_state} ne 'new')))) {
    434             my $data = [$chipRun];
    435             return queue_update_chip($chipRun->{chip_id}, 1, $data, $rlabel, $need_magic);
    436         }
    437     }
    438 
    439     # return value may be the return status of script so zero is good
     410            }
     411            $command = "$warptool -warped -warp_id $skycell->{warp2} -skycell_id $skycell_id";
     412            my $warp2 = runToolAndParseExpectOne($command, $verbose);
     413            my_die("failed to find warpSkyfile for warpRun $skycell->{warp2} skycell_id $skycell_id", $PS_EXIT_UNKNOWN_ERROR) if !$warp2;
     414
     415            if ($warp2->{data_state} ne 'full') {
     416                $warps_ready = 0;
     417                $status = queue_update_warp($warp2, 0, $rlabel, $need_magic);
     418            }
     419
     420            if (!$warps_ready) {
     421                # don't queue the diff update yet
     422                return $status;
     423            }
     424
     425        } elsif ($diff_mode == $IPP_DIFF_MODE_STACK_STACK ) {
     426            # check the state of the input stack
     427            my $command = "$stacktool -sumskyfile -stack_id $skycell->{stack2}";
     428            my $stack1 = runToolAndParseExpectOne($command, $verbose);
     429            my_die("failed to find stackSumSkyfile for stack_id $skycell->{stack2}", $PS_EXIT_UNKNOWN_ERROR) if !$stack1;
     430
     431            if ($stack1->{state} ne 'full') {
     432                print STDERR "input stack for diffRun $diff_id $skycell_id is not in full state faulting jobs\n";
     433                # this faults all jobs depending on this dep_id
     434                faultJobs('stop', 'diff', $diff_id, $PSTAMP_GONE);
     435                return $PSTAMP_GONE;
     436            }
     437            # check the state of the template stack
     438            $command = "$stacktool -sumskyfile -stack_id $skycell->{stack2}";
     439            my $stack2 = runToolAndParseExpectOne($command, $verbose);
     440            my_die("failed to find stackSumSkyfile for stack_id $skycell->{stack2}", $PS_EXIT_UNKNOWN_ERROR) if !$stack2;
     441
     442            if ($stack2->{state} ne 'full') {
     443                print STDERR "template stack for diffRun $diff_id $skycell_id is not in full state faulting jobs\n";
     444                # this faults all jobs depending on this dep_id
     445                faultJobs('stop', 'diff', $diff_id, $PSTAMP_GONE);
     446                return $PSTAMP_GONE;
     447            }
     448
     449            # inputs are ready fall through and queue the diff update
     450        } elsif ($diff_mode == $IPP_DIFF_MODE_STACK_WARP ) {
     451            # check the state of the input stack
     452            my $command = "$stacktool -sumskyfile -stack_id $skycell->{stack1}";
     453            my $stack = runToolAndParseExpectOne($command, $verbose);
     454            my_die("failed to find stackSumSkyfile for stack_id $skycell->{stack1}", $PS_EXIT_UNKNOWN_ERROR) if !$stack;
     455
     456            if ($stack->{state} ne 'full') {
     457                print STDERR "input stack for diffRun $diff_id $skycell_id is not in full state faulting jobs\n";
     458                # this faults all jobs depending on this dep_id
     459                faultJobs('stop', 'diff', $diff_id, $PSTAMP_GONE);
     460                return $PSTAMP_GONE;
     461            }
     462
     463            # now check the template warp
     464            $command = "$warptool -warped -warp_id $skycell->{warp2} -skycell_id $skycell_id";
     465            my $warp = runToolAndParseExpectOne($command, $verbose);
     466            my_die("failed to find warpSkyfile for warpRun $skycell->{warp2} skycell_id $skycell_id", $PS_EXIT_UNKNOWN_ERROR) if !$warp;
     467
     468            if ($warp->{data_state} ne 'full') {
     469                return queue_update_warp($warp, 0, $rlabel, $need_magic);
     470            }
     471            # warps are ready fall through and queue the diff update
     472        } else {
     473            my_die("unexpected diff_mode found: $diff_mode", $PS_EXIT_PROG_ERROR);
     474        }
     475
     476        my $command = "$difftool -setskyfiletoupdate -diff_id $diff_id -skycell_id $skycell_id";
     477        $command .= " -set_label $rlabel" if $rlabel;
     478
     479        if (!$no_update) {
     480            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     481                        run(command => $command, verbose => $verbose);
     482            unless ($success) {
     483                my_die("failed to queue ${stage}Run $stage_id $component for update", $PS_EXIT_UNKNOWN_ERROR);
     484            }
     485        } else {
     486            print "skipping $command\n";
     487        }
     488    } else {
     489        # XXX todo whole_run
     490        return $PS_EXIT_PROG_ERROR;
     491    }
     492
     493    # return value is a unix style exit status so zero is good
    440494    return 0;
    441495}
     
    530584    my ($state, $stage, $stage_id, $job_fault) = @_;
    531585
    532     my $command = "$pstamptool -updatejob -state stop -fault $job_fault -dep_id $dep_id";
     586    my $command = "$pstamptool -updatejob -set_state stop -set_fault $job_fault -dep_id $dep_id";
    533587    $command .= " -dbname $dbname" if $dbname;
    534588    $command .= " -dbserver $dbserver" if $dbserver;
     
    549603    my $stage_id = shift;
    550604    my $rlabel  = shift;
     605    my $need_magic = shift;
    551606    my $input_magicked = shift;
    552607    my $dsRun_state = shift;
    553608
    554     # XXX: this code is only fully coded and tested for chip stage
     609    # XXX: this code assumes that destreaking is handled at the chip stage
    555610    my_die ("queue_update_magicDSRun only works for stage chip", $PS_EXIT_PROG_ERROR) if $stage ne 'chip';
    556611
     
    578633                print "skipping $command\n";
    579634            }
     635        } elsif ($dsRun_state eq 'failed_revert') {
     636            print "magicDSRun.state = $dsRun_state for chipRun $stage_id is in state failed_revert cannot update";
     637            faultJobs('stop', undef, undef, $PSTAMP_NOT_AVAILABLE);
    580638        } else {
    581639            print "magicDSRun.state = $dsRun_state for chipRun $stage_id";
     
    593651    carp $msg;
    594652
    595     my $command = "$pstamptool -updatedepedent -fault $fault -dep_id $dep_id";
     653    my $command = "$pstamptool -updatedependent -set_fault $fault -dep_id $dep_id";
    596654    $command .= " -dbname $dbname" if $dbname;
    597655    $command .= " -dbserver $dbserver" if $dbserver;
     
    600658                    run(command => $command, verbose => $verbose);
    601659        unless ($success) {
    602             my_die("failed to set pstampDependent.fault for dep_id: $dep_id",
    603                 $PS_EXIT_UNKNOWN_ERROR);
     660            carp "$cmd failed";
    604661        }
    605662    } else {
  • branches/czw_branch/20100427/pstamp/scripts/pstamp_dorequest.pl

    r19221 r28017  
    106106{
    107107    ## TODO: what about request status
    108     my $command = "$pstamptool -updatereq -req_id $request_id -state stop";
     108    my $command = "$pstamptool -updatereq -req_id $request_id -set_state stop";
    109109    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    110110        run(command => $command, verbose => $verbosity);
  • branches/czw_branch/20100427/pstamp/scripts/pstamp_finish.pl

    r27751 r28017  
    2525use PS::IPP::PStamp::Job qw( :standard );
    2626
    27 my ( $req_id, $req_name, $req_file, $out_dir, $product, $dbname, $dbserver, $verbose, $save_temps, $redirect_output);
     27my %imagedb_cache;
     28
     29my ( $req_id, $req_name, $req_file, $outdir, $product, $dbname, $dbserver, $verbose, $save_temps, $redirect_output);
    2830
    2931# the char to the right of the bar may be used as a single - alias for the longer name
     
    3436           'req_file=s'     => \$req_file,
    3537           'product=s'      => \$product,
    36            'out_dir=s'      => \$out_dir,
     38           'outdir=s'       => \$outdir,
    3739           'dbname=s'       => \$dbname,
    3840           'dbserver=s'     => \$dbserver,
     
    4446pod2usage( -msg => "Unknown option: @ARGV", -exitval => 2 ) if @ARGV;
    4547
    46 die "usage: --req_id id --req_name name --req_file file --product product --out_dir output_directory [--dbname dbname --verbose]\n"
    47     if !$req_id or !$req_name or !$req_file or !$product or !$out_dir;
     48die "usage: --req_id id --req_name name --req_file file --product product --outdir output_directory [--dbname dbname --verbose]\n"
     49    if !$req_id or !$req_name or !$req_file or !$product or !$outdir;
     50
     51die "outdir is NULL\n" if $outdir eq "NULL";
    4852
    4953my $ipprc = PS::IPP::Config->new(); # IPP Configuration
    5054if ($redirect_output) {
    51     my $logDest = "$out_dir/psfinish.$req_id.log";
     55    # XXX: what happens here if the directory does not exist? We check below
     56    my $logDest = "$outdir/psfinish.$req_id.log";
    5257    $ipprc->redirect_output($logDest);
    5358}
     
    7075
    7176if ($product eq "NULL") {
     77    # nothing more to do
    7278    stop_request_and_exit($req_id, $PS_EXIT_PROG_ERROR);
    7379}
    74 
    75 my $outputDataStoreRoot = metadataLookupStr($ipprc->{_siteConfig}, 'DATA_STORE_ROOT');
    76 exit ($PS_EXIT_CONFIG_ERROR) unless defined $outputDataStoreRoot; # lookup failure outputs a message
    7780
    7881my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     
    8285    my $fileset = $req_name;
    8386
    84     print STDERR "product: $product  REQ_NAME: $req_name $out_dir\n" if $verbose;
    85 
    86     if (!-e $out_dir) {
     87    print STDERR "product: $product  REQ_NAME: $req_name $outdir\n" if $verbose;
     88
     89    if (!-e $outdir) {
    8790        # something must have gone wrong parsing the request
    88         print STDERR  "output directory $out_dir does not exist\n";
    89 
    90         if (!mkdir $out_dir) {
    91             print STDERR "cannot create output directory $out_dir";
     91        print STDERR  "output directory $outdir does not exist\n";
     92
     93        if (!mkdir $outdir) {
     94            print STDERR "cannot create output directory $outdir";
    9295            stop_request_and_exit($req_id, $PS_EXIT_UNKNOWN_ERROR);
    9396        }
    9497
    9598
    96     } elsif (! -d $out_dir ) {
     99    } elsif (! -d $outdir ) {
    97100        # XXX TODO: fault the request so we pstamp_finish doesn't keep trying to process the
    98101        # request
    99         print STDERR "output directory $out_dir exists but is not a directory";
     102        print STDERR "output directory $outdir exists but is not a directory";
    100103        stop_request_and_exit($req_id, $PS_EXIT_UNKNOWN_ERROR);
    101104    }
     
    116119    }
    117120
    118     # at this point we need to find out what kind of request type it is and
    119     # split the processing depending on the request type
    120     # the only processing required for a detectabilty query is to build the output fileset.
    121 
    122     # the following is for a postage stamp request
    123 
    124     my ($rlf, $reglist_name) = tempfile ("$out_dir/reglist.XXXX", UNLINK => !$save_temps);
     121    # start building the list of files to be placed in the output fileset
     122    my ($rlf, $reglist_name) = tempfile ("$outdir/reglist.XXXX", UNLINK => !$save_temps);
     123
     124    # results file
    125125    print $rlf "results.fits|||table|\n";
     126    # human readable representation of the results file
    126127    print $rlf "results.mdc|||text|\n";
    127128
    128129    my $err_file = "parse_error.txt";
    129     if (-e "$out_dir/$err_file" ) {
     130    if (-e "$outdir/$err_file" ) {
    130131        print $rlf "$err_file|||text|\n";
    131132    }
    132133
    133     my ($tdf, $table_def_name) = tempfile ("$out_dir/tabledef.XXXX", UNLINK => !$save_temps);
    134 
     134    # The results table definition file
     135    my ($tdf, $table_def_name) = tempfile ("$outdir/tabledef.XXXX", UNLINK => !$save_temps);
    135136
    136137    # data for the header
    137138    print $tdf "$req_name|$req_id|\n";
     139
     140    # get the list of jobs generated for this request
    138141    my @jobs;
    139142    {
     
    151154                print STDERR "Request $req_id produced no jobs.\n"
    152155            }
    153             # This should not happen. A fake job should be queued
     156            # This should not happen. A fake job should have been entered
    154157            stop_request_and_exit($req_id, $PS_EXIT_PROG_ERROR);
    155158        } else {
     159if (0) {
    156160            my $metadata = $mdcParser->parse($output) or die("Unable to parse metdata config doc");
    157161
    158162            my $jobs = parse_md_list($metadata);
     163}
     164            my $jobs = parse_md_fast($mdcParser, $output);
    159165
    160166            @jobs = @$jobs;
     
    163169
    164170    my $exp_info;
    165     my $last_exp_id = -1;
    166171    foreach my $job (@jobs) {
    167172        my $job_id = $job->{job_id};
     
    171176        my $exp_id = $job->{exp_id};
    172177
    173 
    174178        if (($fault eq $PSTAMP_DUP_REQUEST) and ($req_name eq "NULL")) {
    175             # this request had a duplicate request name. We can't put the results
    176             # on the data store since the product name is already used
    177             # maybe we could be more clever about this and choose a fileset name
    178             stop_request_and_exit($req_id, $fault);
     179            # this request had a duplicate request name yet the parser didn't give
     180            # it an "ERROR style name.
     181            stop_request_and_exit($req_id, $PS_EXIT_PROG_ERROR);
    179182        }
    180183        my ($row, $req_info, $project) = get_request_info($rows, $rownum);
     
    198201            # get the metadata for the exposure (if any i.e. stack)
    199202            # returns an appropriate string if !$exp_id
    200             $exp_info = get_exposure_info($image_db, $exp_id);
    201             $last_exp_id = $exp_id;
     203            $exp_info = get_exposure_info($job_params, $image_db, $exp_id);
    202204        } else {
    203205            my $filter = $job_params->{filter};
    204206            $filter = "0" if !$filter;
    205207            $exp_info = "0|0|0|$filter|0|0";
    206             $last_exp_id = -1;
    207208        }
    208209
    209210        if (($job_type eq "stamp") || ($job_type eq "get_image") || ($job_type eq "none")) {
    210             my $jreglist = "$out_dir/reglist$job_id";
     211            my $jreglist = "$outdir/reglist$job_id";
    211212            if (open JRL, "<$jreglist") {;
    212213                # process the reglist file to get the list of files produced by this job
     
    225226                    # If not found check the PHU. If that doesn't work just set them to zero.
    226227                    # XXX do this more cleanly
    227                     my (undef, $ra_deg, $dec_deg) = split " ", `echo $out_dir/$img_name | fields -x 0 RA_DEG DEC_DEG`;
     228                    my (undef, $ra_deg, $dec_deg) = split " ", `echo $outdir/$img_name | fields -x 0 RA_DEG DEC_DEG`;
    228229                    if (!defined $ra_deg) {
    229                         (undef, $ra_deg, $dec_deg) = split " ", `echo $out_dir/$img_name | fields RA_DEG DEC_DEG`;
     230                        (undef, $ra_deg, $dec_deg) = split " ", `echo $outdir/$img_name | fields RA_DEG DEC_DEG`;
    230231                    }
    231232                    $ra_deg = 0.0 if (!$ra_deg);
     
    258259    # make the results file
    259260    {
    260         my $command = "$pstamp_results --input $table_def_name --output $out_dir/results.fits";
     261        my $command = "$pstamp_results --input $table_def_name --output $outdir/results.fits";
    261262        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    262263            run(command => $command, verbose => $verbose);
     
    266267        } else {
    267268            # dump a textual representation
    268             my $command = "$pstampdump $out_dir/results.fits > $out_dir/results.mdc";
     269            my $command = "$pstampdump $outdir/results.fits > $outdir/results.mdc";
    269270            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    270271                run(command => $command, verbose => $verbose);
     
    278279        # register the fileset
    279280        my $command = "$dsreg --list $reglist_name --add $fileset --product $product --type PSRESULTS";
    280         $command .= " --link --datapath $out_dir --ps0 $req_id";
    281         $command .= " --dbname $dbname" if $dbname;
     281        $command .= " --link --datapath $outdir --ps0 $req_id";
     282# XXX: let dsreg and config handle resolving dbname and dbserver
     283#        $command .= " --dbname $dbname" if $dbname;
    282284
    283285        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    292294    # set the request's state to stop
    293295    {
    294         my $command = "$pstamptool -updatereq -req_id $req_id -state stop -fault $request_fault";
     296        my $command = "$pstamptool -updatereq -req_id $req_id -set_state stop -set_fault $request_fault";
    295297        $command   .= " -dbname $dbname" if $dbname;
    296298        $command   .= " -dbserver $dbserver" if $dbserver;
     
    308310    my $fault  = shift;
    309311
    310     my $command = "$pstamptool -updatereq -req_id $req_id -state stop -fault $fault";
     312    my $command = "$pstamptool -updatereq -req_id $req_id -set_state stop -set_fault $fault";
    311313    $command   .= " -dbname $dbname" if $dbname;
    312314    $command   .= " -dbserver $dbserver" if $dbserver;
     
    345347    $data_group = "null" if !$data_group;
    346348
    347     # This is ugly, error prone and hard to change.
     349    # XXX: This is ugly, error prone and hard to change.
    348350    # Create a results file module and provide a list of the names (we have the data in the columns)
    349351    my $rowinfo = "$row->{PROJECT}|$row->{JOB_TYPE}|$row->{REQ_TYPE}|$row->{IMG_TYPE}|";
     
    376378    my $metadata = $mdcParser->parse($data) or die("Unable to parse metdata config doc");
    377379
     380    # no need to use parse_md_fast here
    378381    my $results = parse_md_list($metadata);
    379382    if (scalar @$results != 1) {
     
    385388
    386389sub get_exposure_info {
     390    my $job_params = shift;
    387391    my $image_db= shift;
    388392    my $exp_id = shift;
    389393
    390     if (!$exp_id or !$image_db) {
    391         # no exposure id just return zeros
    392         # XXX: we could put a value in for filter, but we don't have a good place to find it
    393 
    394         #"$mjd_obs|$ra_obs|$dec_obs|$filter|$exp_time|$fpa_id";
    395         return "0|0|0|0|0|0";
    396     }
    397 
    398     my $regtool = can_run('regtool') or (warn "Can't find regtool" and $missing_tools = 1);
    399     if ($missing_tools) {
    400         warn("Can't find required tools.");
    401         exit ($PS_EXIT_CONFIG_ERROR);
    402     }
    403 
    404     my $command = "$regtool -processedexp -dbname $image_db -exp_id $exp_id";
    405 
    406     # run the tool and parse the output
    407     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    408                 run(command => $command, verbose => $verbose);
    409     unless ($success) {
    410         # not sure if we should die here
    411         die "cannot get exposure information for $exp_id from image database $image_db";
    412     }
    413     my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    414 
    415     my $output = join "", @$stdout_buf;
    416     if (!$output) {
    417         print STDERR "no output returned from $command\n" if $verbose;
    418         return undef;
    419     }
    420     my $metadata = $mdcParser->parse($output) or die("Unable to parse metdata config doc");
    421 
    422     my $exposures = parse_md_list($metadata);
    423     my $numExp = @$exposures;
    424 
    425     die "unexpected number of exposures $numExp found for exp_id: $exp_id in DB: $image_db" if $numExp != 1;
     394    my ($dateobs, $ra, $decl, $filter, $exp_time, $exp_name);
     395
     396    $dateobs  = $job_params->{dateobs};
     397    $ra       = $job_params->{ra};
     398    $decl     = $job_params->{decl};
     399    $filter   = $job_params->{filter};
     400    $exp_time = $job_params->{exp_time};
     401    $exp_name = $job_params->{exp_name};
     402
     403    unless (defined $dateobs and defined $ra and defined $decl and defined $filter and defined $exp_time and defined $exp_name) {
     404        # job params don't have all of the values that we need (most likely this is a diff stage job)
     405        # go look up the exposure if we have one
     406        if (!$exp_id or !$image_db) {
     407            # no exposure id just return zeros
     408            # XXX: we could put a value in for filter, but we don't have a good place to find it
     409
     410            #"$mjd_obs|$ra_obs|$dec_obs|$filter|$exp_time|$fpa_id";
     411            return "0|0|0|0|0|0";
     412        }
     413
     414        my $exp;
     415        # get cache of exposures for this image_db
     416        my $exp_cache = $imagedb_cache{$image_db};
     417        if (defined $exp_cache) {
     418            $exp = $exp_cache->{$exp_id};
     419        }
     420
     421        unless (defined $exp) {
     422
     423            my $regtool = can_run('regtool') or (warn "Can't find regtool" and $missing_tools = 1);
     424            if ($missing_tools) {
     425                warn("Can't find required tools.");
     426                exit ($PS_EXIT_CONFIG_ERROR);
     427            }
     428
     429            my $command = "$regtool -processedexp -dbname $image_db -exp_id $exp_id";
     430
     431            # run the tool and parse the output
     432            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     433                        run(command => $command, verbose => $verbose);
     434            unless ($success) {
     435                # not sure if we should die here
     436                die "cannot get exposure information for $exp_id from image database $image_db";
     437            }
     438            my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     439
     440            my $output = join "", @$stdout_buf;
     441            if (!$output) {
     442                print STDERR "no output returned from $command\n" if $verbose;
     443                return undef;
     444            }
     445if (0) {
     446            my $metadata = $mdcParser->parse($output) or die("Unable to parse metdata config doc");
     447
     448            my $exposures = parse_md_list($metadata);
     449}
     450            my $exposures = parse_md_fast($mdcParser, $output);
     451            my $numExp = @$exposures;
     452
     453            die "unexpected number of exposures $numExp found for exp_id: $exp_id in DB: $image_db" if $numExp != 1;
     454
     455            $exp = $exposures->[0];
     456
     457            unless (defined $exp_cache) {
     458                my %new_exp_cache;
     459                $exp_cache = \%new_exp_cache;
     460                $imagedb_cache{$image_db} = $exp_cache;
     461            }
     462            $exp_cache->{$exp_id} = $exp;
     463        } else {
     464            print "found $exp_id in cache\n";
     465        }
     466       
     467        #my $info = "$mjd_obs|$ra_obs|$dec_obs|$filter|$exp_time|$fpa_id";
     468        $dateobs  = $exp->{dateobs};
     469        $ra       = $exp->{ra};
     470        $decl     = $exp->{decl};
     471        $filter   = $exp->{filter};
     472        $exp_time = $exp->{exp_time};
     473        $exp_name = $exp->{exp_name};
     474    }
     475
     476    die "failed to find exp_info for $exp_id" unless (defined $dateobs and defined $ra and defined $decl and defined $filter and defined $exp_time and defined $exp_name);
    426477   
    427     my $exp = $exposures->[0];
    428 
    429     #my $info = "$mjd_obs|$ra_obs|$dec_obs|$filter|$exp_time|$fpa_id";
    430 
    431478    use constant RADIANS_TO_DEGREES => 90. / atan2(1, 0);
    432     my $ra_deg   = $exp->{ra} * RADIANS_TO_DEGREES;
    433     my $decl_deg = $exp->{decl} * RADIANS_TO_DEGREES;
    434     my $mjd_obs = dateobs_to_mjd($exp->{dateobs});
    435 
    436     my $info = "$mjd_obs|$ra_deg|$decl_deg|$exp->{filter}|$exp->{exp_time}|$exp->{exp_name}";
     479    my $ra_deg   = $ra * RADIANS_TO_DEGREES;
     480    my $decl_deg = $decl * RADIANS_TO_DEGREES;
     481    my $mjd_obs = dateobs_to_mjd($dateobs);
     482
     483    my $info = "$mjd_obs|$ra_deg|$decl_deg|$filter|$exp_time|$exp_name";
    437484           
    438485    return $info;
  • branches/czw_branch/20100427/pstamp/scripts/pstamp_get_image_job.pl

    r26215 r28017  
    8787}
    8888
    89 my $out_dir = dirname($output_base);
     89my $outdir = dirname($output_base);
    9090my $prefix = basename($output_base) . "_";
    9191my $results_file = $output_base . ".bundle_results";
     
    102102    my $command = "$dist_bundle --camera $camera --stage $stage --stage_id $stage_id";
    103103    $command .= " --component $component";
    104     $command .= " --path_base $path_base --outdir $out_dir --results_file $results_file";
     104    $command .= " --path_base $path_base --outdir $outdir --results_file $results_file";
    105105    $command .= " --prefix $prefix";
    106106    $command .= " --magicked" if $magicked;
     
    139139}
    140140
    141 my $reglist = "$out_dir/reglist$job_id";
     141my $reglist = "$outdir/reglist$job_id";
    142142if (! open(REGLIST, ">$reglist") ) {
    143143    my_die("failed to open registration list: $reglist", $PS_EXIT_UNKNOWN_ERROR);
  • branches/czw_branch/20100427/pstamp/scripts/pstamp_job_run.pl

    r27751 r28017  
    7474my $ppstamp    = can_run('ppstamp') or (warn "Can't find ppstamp" and $missing_tools = 1);
    7575my $pstamp_get_image_job    = can_run('pstamp_get_image_job.pl') or (warn "Can't find pstamp_get_image_job.pl" and $missing_tools = 1);
     76my $dqueryparse = can_run('dqueryparse.pl') or (warn "Can't find dqueryparse.pl" and $missing_tools = 1);
    7677
    7778if ($missing_tools) {
     
    8384my $jobStatus;
    8485if ($jobType eq "stamp") {
    85     my $argslist = "$outputBase.args";
    86     open ARGSLIST, "<$argslist" or my_die("failed to open argslist file $argslist", $job_id, $PS_EXIT_UNKNOWN_ERROR);
    87     my $argString = <ARGSLIST>;
    88     close ARGSLIST;
    89     chomp $argString;
     86    my $params = read_params_file($outputBase);
     87
     88    my $argString;
     89    $argString = $params->{job_args};
    9090
    9191    # XXX: should we do any other sanity checking?
    92     my_die("arglist file $argslist is empty", $job_id, $PS_EXIT_DATA_ERROR) if !$argString;
     92    my_die("argument list is empty", $job_id, $PS_EXIT_DATA_ERROR) if !$argString;
     93
     94    # XXX: remove -astrom from argString and add it here
     95
     96    $argString .= " -file $params->{image}";
     97    $argString .= " -mask $params->{mask}";
     98    if ($options & $PSTAMP_SELECT_VARIANCE) {
     99        $argString .= " -variance $params->{weight}";
     100    }
    93101
    94102    my $command = "$ppstamp $outputBase $argString";
     
    119127        my %extensions = ( $PSTAMP_SELECT_IMAGE  => "fits",
    120128                           $PSTAMP_SELECT_MASK   => "mk.fits",
    121                            $PSTAMP_SELECT_WEIGHT => "wt.fits");
    122 
    123         my $output_mask = $options & ($PSTAMP_SELECT_IMAGE | $PSTAMP_SELECT_MASK | $PSTAMP_SELECT_WEIGHT);
     129                           $PSTAMP_SELECT_VARIANCE => "wt.fits");
     130
     131        my $output_mask = $options & ($PSTAMP_SELECT_IMAGE | $PSTAMP_SELECT_MASK | $PSTAMP_SELECT_VARIANCE);
    124132
    125133        foreach my $key (keys (%extensions)) {
     
    139147        }
    140148
    141         get_other_outputs($F, $outputBase, $options);
     149        get_other_outputs($F, $outputBase, $options, $params);
    142150
    143151        close $F;
     
    165173    }
    166174} elsif ($jobType eq "detect_query") {
    167     my_die("detect_query jobs not supported yet", $job_id,$PS_EXIT_CONFIG_ERROR);
     175    # detect_query jobs are basically holders to note that we need a file updated before we can continue.
     176    # Load the argument list that dqueryparse should have created the first time it ran, so we know how to
     177    # run it again the same way.
     178    my $argslist = "$outputBase/parse.args";
     179    open ARGSLIST, "<$argslist" or my_die("failed to open argslist file $argslist", $job_id, $PS_EXIT_UNKNOWN_ERROR);
     180    my $argString = <ARGSLIST>;
     181    close ARGSLIST;
     182    chomp $argString;
     183
     184    # XXX: should we do any other sanity checking?
     185    my_die("arglist file $argslist is empty", $job_id, $PS_EXIT_DATA_ERROR) if !$argString;
     186
     187    my $command = "$dqueryparse --job_id $job_id $argString";
     188    $command .= " --dbname $dbname" if $dbname;
     189    $command .= " --dbserver $dbserver" if $dbserver;
     190    $command .= " --verbose" if $verbose;
     191    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     192        run(command => $command, verbose => $verbose);
     193
     194    # Although dqueryparse can potentially force more updates (and more jobs), it should still return success.
     195    if ($success) {
     196        $jobStatus = $PS_EXIT_SUCCESS;
     197    } else {
     198        $jobStatus = $error_code >> 8;
     199        my_die("dqueryparse.pl failed with error code: $jobStatus", $job_id, $jobStatus);
     200    }
    168201} else {
    169202    my_die("unknown jobType $jobType found", $job_id, $PS_EXIT_PROG_ERROR);
     
    172205# mark the job stopped in the database
    173206{
    174     my $command = "$pstamptool -updatejob -job_id $job_id -state stop";
    175     $command .= " -fault $jobStatus" if $jobStatus;
     207    my $command = "$pstamptool -updatejob -job_id $job_id -set_state stop";
     208    $command .= " -set_fault $jobStatus" if $jobStatus;
    176209    $command .= " -dbname $dbname" if $dbname;
    177210    $command .= " -dbserver $dbserver" if $dbserver;
     
    212245    my $output_base = shift;
    213246    my $options = shift;
     247    my $params = shift;
    214248
    215249    if ($options & ( $PSTAMP_SELECT_CMF | $PSTAMP_SELECT_PSF | $PSTAMP_SELECT_BACKMDL)) {
    216         my $comp = read_params_file($output_base);
    217 
    218         my $stage = $comp->{stage};
     250        if (!$params) {
     251            $params = read_params_file($output_base);
     252        }
     253
     254        my $stage = $params->{stage};
    219255
    220256        # raw files don't have any other data products
     
    225261        # detected in pstampparse so that the user can be notified with
    226262        # a message in parse_error.txt ("warp do not have a background model")
    227         my $cmf_file = $comp->{cmf} if ($options & $PSTAMP_SELECT_CMF);
    228         my $psf_file = $comp->{psf} if ($options & $PSTAMP_SELECT_PSF);
    229         my $backmdl_file = $comp->{backmdl} if ($options & $PSTAMP_SELECT_BACKMDL);
    230         my $pattern_file = $comp->{pattern} if ($options & $PSTAMP_SELECT_BACKMDL);
     263        my $cmf_file = $params->{cmf} if ($options & $PSTAMP_SELECT_CMF);
     264        my $psf_file = $params->{psf} if ($options & $PSTAMP_SELECT_PSF);
     265        my $backmdl_file = $params->{backmdl} if ($options & $PSTAMP_SELECT_BACKMDL);
     266        my $pattern_file = $params->{pattern} if ($options & $PSTAMP_SELECT_BACKMDL);
    231267
    232268        my $outdir = dirname($output_base);
     
    317353        my $command = "$pstamptool -updatejob";
    318354        $command .= " -job_id $job_id";
    319         $command .= " -fault $exit_code";
     355        $command .= " -set_fault $exit_code";
    320356        # XXX: fix pstamptool to not require -state when -fault with nonzero value is provided
    321         $command .= " -state run";
     357        $command .= " -set_state run";
    322358        $command .= " -dbname $dbname" if defined $dbname;
    323359        $command .= " -dbserver $dbserver" if defined $dbserver;
  • branches/czw_branch/20100427/pstamp/scripts/pstamp_parser_run.pl

    r27751 r28017  
    2828my $redirect_output;
    2929my $product;
     30my $outdir;
    3031my $label;
    3132my $verbose;
     
    3738    'uri=s'             =>  \$uri,
    3839    'product=s'         =>  \$product,
     40    'outdir=s'          =>  \$outdir,
    3941    'label=s'           =>  \$label,
    4042    'redirect-output'   =>  \$redirect_output,
     
    8183}
    8284
    83 # workdir is where all of the files generated for this request are placed
    84 # NOTE: this location needs to be kept in sync with the web interface ( request.php )
    85 my $datestr = strftime "%Y%m%d", gmtime;
    86 my $datedir = "$pstamp_workdir/$datestr";
    87 if (! -e $datedir ) {
    88     mkdir $datedir or my_die( "failed to create working directory $datedir for request id $req_id", $req_id,
     85if (!$outdir or ($outdir eq "NULL")) {
     86    # outdir is where all of the files generated for this request are placed
     87    # NOTE: this location needs to be kept in sync with the web interface ( request.php )
     88    my $datestr = strftime "%Y%m%d", gmtime;
     89    my $datedir = "$pstamp_workdir/$datestr";
     90    if (! -e $datedir ) {
     91        mkdir $datedir or my_die( "failed to create working directory $datedir for request id $req_id", $req_id,
     92            $PS_EXIT_CONFIG_ERROR);
     93    }
     94
     95    $outdir = "$datedir/$req_id";
     96}
     97
     98if (! -e $outdir ) {
     99    mkdir $outdir or my_die("failed to create working directory $outdir for request id $req_id", $req_id,
    89100        $PS_EXIT_CONFIG_ERROR);
    90101}
    91 
    92 my $workdir = "$datedir/$req_id";
    93 if (! -e $workdir ) {
    94     mkdir $workdir or my_die("failed to create working directory $workdir for request id $req_id", $req_id,
    95         $PS_EXIT_CONFIG_ERROR);
    96 }
     102   
    97103
    98104if ($redirect_output) {
    99     my $logDest = "$workdir/psparse.$req_id.log";
     105    my $logDest = "$outdir/psparse.$req_id.log";
    100106    $ipprc->redirect_output($logDest);
    101107}
     
    108114
    109115my $fn = basename($uri);
    110 my $new_uri = "$workdir/$fn";
     116my $new_uri = "$outdir/$fn";
    111117if ($uri =~ /^http:/) {
    112118    # if the uri is an http uri download the file
     
    118124    }
    119125} elsif ($uri ne $new_uri) {
    120     # put a link to the file into the workdir
     126    # copy the request file into outdir
    121127    if (-e $new_uri) {
     128        # file exists already delete it incase the previous copy is bogus
    122129        unlink $new_uri or my_die("failed to unlink $new_uri", $req_id, $PS_EXIT_UNKNOWN_ERROR);
    123130    }
    124131    if (! copy $uri, $new_uri) {
    125         my_die ("failed to copy request file $uri to workdir $workdir", $req_id, $PS_EXIT_UNKNOWN_ERROR);
     132        my_die ("failed to copy request file $uri to workdir $outdir", $req_id, $PS_EXIT_UNKNOWN_ERROR);
    126133    }
    127134}
     
    152159        } elsif ($request_type eq "MOPS_DETECTABILITY_QUERY") {
    153160            $reqType = 'dquery';
    154             $parse_cmd = $dqueryparse;
     161            $parse_cmd = "$dqueryparse";
     162            $parse_cmd .= " --label $label" if $label;
    155163        } else {
    156164            print STDERR "Unknown request type $request_type found in $uri";
     
    172180    # that they sent us a request file that we don't understand
    173181
    174     my $command = "$pstamptool -updatereq -req_id $req_id -state run";
    175     $command   .= " -reqType unknown";
    176     $command   .= " -fault $PS_EXIT_DATA_ERROR";
     182    my $command = "$pstamptool -updatereq -req_id $req_id -set_state run";
     183    $command   .= " -set_reqType unknown";
     184    $command   .= " -set_fault $PS_EXIT_DATA_ERROR";
    177185    $command   .= " -dbname $dbname" if $dbname;
    178186    $command   .= " -dbserver $dbserver" if $dbserver;
     
    185193}
    186194
    187 $parse_cmd .= " --mode queue_job --req_id $req_id --product $product --out_dir $workdir --file $uri";
     195$parse_cmd .= " --mode queue_job --req_id $req_id --product $product --outdir $outdir --file $uri";
    188196$parse_cmd .= " --dbname $dbname" if $dbname;
    189197$parse_cmd .= " --dbserver $dbserver" if $dbserver;
     
    193201my $fault;
    194202{
    195     my $error_file_name = "$workdir/parse_error.txt";
     203    my $error_file_name = "$outdir/parse_error.txt";
    196204    # get rid of any error file from previous attempt to parse this request
    197205    unlink $error_file_name if (-e $error_file_name);
     
    218226    unless ($success) {
    219227        $fault = $error_code >> 8;
    220         $newState = "stop";
     228#        $newState = "stop";
    221229    }
    222230}
     
    226234#
    227235{
    228     my $command = "$pstamptool -updatereq -req_id $req_id -state $newState";
    229     $command   .= " -reqType $reqType" if $reqType;
    230     $command   .= " -uri $new_uri" if $new_uri;
    231     $command   .= " -fault $fault" if $fault;
     236    my $command = "$pstamptool -updatereq -req_id $req_id -set_state $newState";
     237    $command   .= " -set_outdir $outdir";
     238    $command   .= " -set_reqType $reqType" if $reqType;
     239    $command   .= " -set_uri $new_uri" if $new_uri;
     240    $command   .= " -set_fault $fault" if $fault;
    232241    $command   .= " -dbname $dbname" if $dbname;
    233242    $command   .= " -dbserver $dbserver" if $dbserver;
     
    268277    carp($msg);
    269278
    270     my $command = "$pstamptool -updatereq -req_id $req_id  -fault $fault";
     279    my $command = "$pstamptool -updatereq -req_id $req_id  -set_fault $fault";
    271280    $command   .= " -dbname $dbname" if $dbname;
    272281    $command   .= " -dbserver $dbserver" if $dbserver;
  • branches/czw_branch/20100427/pstamp/scripts/pstampparse.pl

    r27783 r28017  
    1717use Carp;
    1818use POSIX;
    19 use DateTime;
     19use Time::HiRes qw(gettimeofday);
    2020
    2121my $verbose;
     
    2525my $request_file_name;
    2626my $mode = "list_uri";
    27 my $out_dir;
     27my $outdir;
    2828my $product;
    2929my $label;
     
    3434    'file=s'    =>  \$request_file_name,
    3535    'req_id=s'  =>  \$req_id,
    36     'out_dir=s' =>  \$out_dir,
     36    'outdir=s'  =>  \$outdir,
    3737    'product=s' =>  \$product,
    3838    'label=s'   =>  \$label,
     
    5050if ($mode ne "list_uri") {
    5151    die "req_id is required"   if !$req_id;
    52     die "out_dir is required"  if !$out_dir;
     52    die "outdir is required"  if !$outdir;
    5353    die "product is required"  if !$product;
    5454}
     
    129129    # update the database with the request name. This will be used as the
    130130    # the output data store's product name
    131     my $command = "$pstamptool -updatereq -req_id $req_id  -name $req_name";
    132     $command .= " -outProduct $product";
     131    my $command = "$pstamptool -updatereq -req_id $req_id  -set_name $req_name";
     132    $command .= " -set_outProduct $product";
    133133    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    134134        run(command => $command, verbose => $verbose);
     
    147147my $rows;
    148148{
     149    my $start_request_file = gettimeofday();
    149150    my $command = "$pstampdump $request_file_name";
    150151    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     
    154155    }
    155156    if (@$stdout_buf) {
    156         my $table =  $mdcParser->parse(join "", @$stdout_buf) or
    157             my_die("Unable to parse metdata config doc", $PS_EXIT_UNKNOWN_ERROR);
    158         $rows = parse_md_list($table);
    159     }
     157        $rows = parse_md_fast($mdcParser, join "", @$stdout_buf);
     158    }
     159    my $dtime_request_file = gettimeofday() - $start_request_file;
     160    print "Time to read and parse request file: $dtime_request_file\n";
    160161
    161162}
     
    223224    my $rownum   = $row->{ROWNUM};
    224225    if (!validID($rownum)) {
    225         print STDERR "$rownum is not a valid ROWNUM\n"  if $verbose;
     226        print STDERR "$rownum is not a valid ROWNUM\n";
    226227        insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
    227228        return 0;
     
    229230    my $job_type = $row->{JOB_TYPE};
    230231    if (($job_type ne "stamp") and ($job_type ne "get_image")) {
    231         print STDERR "$job_type is not a valid JOB_TYPE\n"  if $verbose;
     232        print STDERR "$job_type is not a valid JOB_TYPE\n";
    232233        insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
    233234        return 0;
     
    237238    if (($req_type ne "byid") and ($req_type ne "bycoord") and ($req_type ne "byexp") and
    238239        ($req_type ne "byskycell") and ($req_type ne "bydiff")) {
    239         print STDERR "$req_type is not a valid REQ_TYPE\n"  if $verbose;
     240        print STDERR "$req_type is not a valid REQ_TYPE\n";
    240241        insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
    241242        return 0;
    242243    }
     244    if ($job_type eq 'get_image') {
     245        unless ($req_type eq 'byid' or $req_type eq 'byexp') {
     246            print STDERR "REQ_TYPE must be 'byid' or 'byexp' for JOB_TYPE 'get_image'\n";
     247            insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
     248            return 0;
     249        }
     250    }
    243251
    244252
    245253    my $component = $row->{COMPONENT};
    246254    if (!defined $component or (lc($component) eq "null") or (lc($component) eq "all")) {
    247         $row->{COMPONENT} = $component = "";
     255        if ($job_type eq 'get_image') {
     256            $row->{COMPONENT} = 'all';
     257        } else {
     258            $row->{COMPONENT} = $component = "";
     259        }
    248260    }
    249261    $row->{TESS_ID} = "" if !defined $row->{TESS_ID};
     
    258270    my $mjd_min = $row->{MJD_MIN};
    259271    if (defined($mjd_min) and !validNumber($mjd_min)) {
    260         print STDERR "$mjd_min is not a valid MJD_MIN\n"  if $verbose;
     272        print STDERR "$mjd_min is not a valid MJD_MIN\n";
    261273        insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
    262274        return 0;
     
    264276    my $mjd_max = $row->{MJD_MAX};
    265277    if (defined($mjd_max) and !validNumber($mjd_max)) {
    266         print STDERR "$mjd_max is not a valid MJD_MAX\n"  if $verbose;
     278        print STDERR "$mjd_max is not a valid MJD_MAX\n";
    267279        insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
    268280        return 0;
     
    288300
    289301    if (!$skycenter and !$component) {
    290         print STDERR "COMPONENT must be specified for pixel coordinate ROI center\n" if $verbose;
     302        print STDERR "COMPONENT must be specified for pixel coordinate ROI center\n";
    291303        insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
    292304        return 0;
     
    295307    my $stage = $row->{IMG_TYPE};
    296308    if (!check_image_type($stage)) {
    297         print STDERR "invalid IMG_TYPE for row $rownum\n" if $verbose;
     309        print STDERR "invalid IMG_TYPE for row $rownum\n";
    298310        insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
    299311        return 0;
     
    301313
    302314    if ((($job_type eq "stamp") or ($req_type eq "bycoord")) and ! validROI($row)) {
    303         print STDERR "invalid ROI for row $rownum\n" if $verbose;
     315        print STDERR "invalid ROI for row $rownum\n";
    304316        insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
    305317        return 0;
     
    307319
    308320    if (($req_type eq "byexp") and ($stage eq "stack")) {
    309         print STDERR "byexp not implemented for stack stage. row: $rownum\n" if $verbose;
     321        print STDERR "byexp not implemented for stack stage. row: $rownum\n";
    310322        insertFakeJobForRow($row, 1, $PSTAMP_NOT_IMPLEMENTED);
    311323        return 0;
     
    319331    if ($req_type eq "bycoord") {
    320332        if (!$skycenter) {
    321             print STDERR "center must be specified in sky coordintes for bycoord" if $verbose;
     333            print STDERR "center must be specified in sky coordintes for bycoord";
    322334            insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
    323335            return 0;
     
    327339    if (($req_type eq "byid") or ($req_type eq "bydiff")) {
    328340        if (!validID($row->{ID})) {
    329             print STDERR "ID must be a positive integer for req_type $req_type\n" if $verbose;
     341            print STDERR "ID must be a positive integer for req_type $req_type\n";
    330342            insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
    331343            return 0
     
    349361    my $proj_hash = resolve_project($ipprc, $project, $dbname, $dbserver);
    350362    if (!$proj_hash) {
    351         print STDERR "project $project not found\n"  if $verbose;
     363        print STDERR "project $project not found\n" ;
    352364        foreach $row (@$rowList) {
    353365            insertFakeJobForRow($row, 1, $PSTAMP_UNKNOWN_PRODUCT);
     
    383395        }
    384396    }
     397
     398    $need_magic = 0 if $stage eq 'stack';
    385399   
    386400    my $numRows = scalar @$rowList;
    387 
    388 #    $tess_id = "" if !defined $tess_id;
    389 #    $component = "" if !defined $component;
    390401
    391402    print "Collected $numRows rows beginning with row $rownum. $req_type $stage $id $tess_id $component\n";
     
    393404    # Call PS::IPP::PStamp::Job locate_images subroutine to get the images for this
    394405    # request specification. An array reference is returned.
    395     my $start_locate = DateTime->now->mjd;
     406    my $start_locate = gettimeofday();
    396407
    397408    # XXX: perhaps we should get rid of most of this argument list.
     
    402413                $option_mask, $need_magic, $mjd_min, $mjd_max, $filter, $data_group, $verbose);
    403414
    404     # XXX: why use mjd? It doesn't have great precision.
    405     my $dtime_locate = (DateTime->now->mjd - $start_locate) * 86400.;
     415    my $dtime_locate = gettimeofday() - $start_locate;
    406416    print "Time to locate_images for row $rownum $dtime_locate\n";
    407417
    408     if (!$imageList or !@$imageList) {
    409         print STDERR "no matching images found for row $rownum\n" if $verbose;
    410         # note in this case queueJobs inserts the fake job for these rows
    411     }
    412     # handle this
     418    # handle this XXX: what did I mean by this comment
    413419    $row->{need_magic} = $need_magic;
    414420
     
    502508    $image->{job_args} = $args;
    503509
    504     # XXX: we can get rid of the following everything that we need is
    505     # in the params file
    506 
    507     $args .= " -file $imagefile";
    508 
    509     if (($option_mask & $PSTAMP_SELECT_MASK) &&  $image->{mask} ) {
    510         $args .= " -mask $image->{mask}";
    511     }
    512     if (($option_mask & $PSTAMP_SELECT_WEIGHT) and $image->{weight} ) {
    513         $args .= " -variance $image->{weight}";
    514     }
    515 
    516510    my $base = basename($image->{image});
    517511    if (! $base =~ /.fits$/ ) {
     
    520514    $base =~ s/.fits$//;
    521515           
    522     my $output_base = "$out_dir/${rownum}_${job_num}_${base}";
    523     my $argslist = "${output_base}.args";
    524 
    525     # copy the argument list to a file
    526     open ARGSLIST, ">$argslist" or my_die("failed to open $argslist", $PS_EXIT_UNKNOWN_ERROR);
    527     print ARGSLIST "$args\n";
    528     close ARGSLIST or my_die("failed to close $argslist", $PS_EXIT_UNKNOWN_ERROR);
    529 
     516    my $output_base = "$outdir/${rownum}_${job_num}_${base}";
    530517    write_params($output_base, $image);
    531518
     
    536523    # XXX: this code is repeated in queueGetImageJobs we should encapsulate it in a subroutine and share it
    537524    if ($stage ne 'raw') {
    538         # not ready to handle diff update yet. May never support stack
    539         my $allow_wait_for_update = (($stage ne 'stack') and ($stage ne 'diff'));
     525        # updates for stack stage not supported yet
     526        my $allow_wait_for_update = ($stage ne 'stack');
    540527        my $run_state = $image->{state};
    541528        my $data_state = $image->{data_state};
     
    548535            $newState = 'stop';
    549536            $fault = $PSTAMP_GONE;
    550         } elsif ($allow_wait_for_update and
    551                 (($data_state ne 'full') or ($need_magic and ($image->{magicked} < 0)))) {
     537        } elsif (($data_state ne 'full') or ($need_magic and ($image->{magicked} < 0))) {
    552538            if ($stage eq 'chip') {
    553539                my $burntool_state = $image->{burntool_state};
     
    556542                    $fault = $PSTAMP_NOT_AVAILABLE;
    557543                }
     544            }
     545            if (!$allow_wait_for_update) {
     546                print STDERR "wait for update not supported for stage $stage yet\n";
     547                $newState = 'stop';
     548                $fault = $PSTAMP_NOT_AVAILABLE;
    558549            }
    559550            if (!$fault) {
     
    658649}
    659650
    660 #        $num_jobs = queueGetImageJobs($firstRow, $imageList, $stage, $need_magic, $mode);
    661651sub queueGetImageJobs
    662652{
     
    706696        my $exp_id = $image->{exp_id};
    707697           
    708         my $output_base = "$out_dir/${rownum}_${job_num}";
     698        my $output_base = "$outdir/${rownum}_${job_num}";
    709699
    710700        write_params($output_base, $image);
     
    731721                    # cause the image to be re-made
    732722                    # set up to queue an update run
    733                     queue_update_run(\$newState, \$fault, \$dep_id, $image->{image_db},
     723                    queue_update_run(\$newState, \$fault, \$dep_id, $image->{imagedb},
    734724                        $run_state, $stage, $image->{stage_id}, $image->{component}, $need_magic);
    735725                }
     
    878868    my ($r_jobState, $r_fault, $r_dep_id, $imagedb, $state, $stage, $stage_id, $component, $need_magic) = @_;
    879869
     870    # XXX: The update process for warp and subsequent stages requires
     871    # destreaking to run because the -pending queries require it when magicked > 0
     872    # queries.
     873    # The case of stack-stack diffs is taken care of in pstamp_checkdependent
     874    $need_magic = 1 if $imagedb eq 'gpc1';
     875
    880876    if (($state ne 'cleaned') and ($state ne 'update') and ($state ne 'goto_cleaned')) {
    881877        my_die("$stage $stage_id is in unexpected state $state", $PS_EXIT_PROG_ERROR);
     
    883879
    884880    my $dep_id;
    885     my $command = "$pstamptool -getdependent -stage $stage -stage_id $stage_id -imagedb $imagedb -component $component";
     881    my $command = "$pstamptool -getdependent -stage $stage -stage_id $stage_id -imagedb $imagedb -component $component -outdir $outdir";
    886882    $command .= " -need_magic" if $need_magic;
    887883
  • branches/czw_branch/20100427/pstamp/scripts/request_finish.pl

    r24831 r28017  
    2121use PS::IPP::Config qw( :standard );
    2222
    23 my ( $req_id, $req_name, $req_file, $req_type, $out_dir, $product, $dbname, $dbserver, $verbose, $save_temps, $redirect_output );
     23my ( $req_id, $req_name, $req_file, $req_type, $outdir, $product, $dbname, $dbserver, $verbose, $save_temps, $redirect_output );
    2424
    2525GetOptions(
     
    2828           'req_file=s' => \$req_file,
    2929           'req_type=s' => \$req_type,
    30            'out_dir=s'  => \$out_dir,
     30           'outdir=s'  => \$outdir,
    3131           'product=s'  => \$product,
    3232           'dbname=s'   => \$dbname,
     
    4646$err .= "--req_name is required\n" if !$req_name;
    4747$err .= "--product is required\n" if !$product;
    48 # $err .= "--out_dir is required\n" if !$out_dir;
     48# $err .= "--outdir is required\n" if !$outdir;
    4949
    5050die "$err" if $err;
    5151
    5252
    53 if (!$out_dir) {
    54     $out_dir = dirname($req_file);
     53if (!$outdir) {
     54    $outdir = dirname($req_file);
    5555}
    5656
    5757if ($redirect_output) {
    58     my $logDest = "$out_dir/reqfinish.$req_id.log";
     58    my $logDest = "$outdir/reqfinish.$req_id.log";
    5959    my $ipprc = PS::IPP::Config->new();
    6060    $ipprc->redirect_output($logDest);
     
    7979}
    8080if ($finish_cmd) {
    81     my $command = $finish_cmd . " --req_id $req_id --req_name $req_name --req_file $req_file --product $product --out_dir $out_dir";
     81    my $command = $finish_cmd . " --req_id $req_id --req_name $req_name --req_file $req_file --product $product --outdir $outdir";
    8282    $command   .= " --dbname $dbname" if $dbname;
    8383    $command   .= " --dbserver $dbserver" if $dbserver;
  • branches/czw_branch/20100427/pstamp/src/ppstampMakeStamp.c

    r27461 r28017  
    3636    double d_before = check->sky->d;
    3737    psLogMsg("ppstampMakeStamp", 2, "Before fit  Center Pixel RA: %f   DEC: %f (degrees)\n",
    38              r_before * PS_DEG_RAD, d_before * PS_DEG_RAD);
     38             r_before * PS_DEG_RAD, d_before * PS_DEG_RAD);
    3939
    4040    if (outFPA->toSky->type != PS_PROJ_TAN) {
    41         // we need to make astrometry terms for the output which are centered on the output chip center,
    42         // but we keep the original plate scale
    43         psFree(outFPA->toSky);
    44         outFPA->toSky = psProjectionAlloc (r_before, d_before, inFPA->toSky->Xs, inFPA->toSky->Ys, PS_PROJ_TAN);
    45 
    46         if (!pmAstromLinearizeToSky(inFPA, inChip, outFPA, outChip, roi)) {
     41        // we need to make astrometry terms for the output which are centered on the output chip center,
     42        // but we keep the original plate scale
     43        psFree(outFPA->toSky);
     44        outFPA->toSky = psProjectionAlloc (r_before, d_before, inFPA->toSky->Xs, inFPA->toSky->Ys, PS_PROJ_TAN);
     45
     46        if (!pmAstromLinearizeToSky(inFPA, inChip, outFPA, outChip, roi)) {
    4747            psFree(check);
    4848            psError(PS_ERR_UNKNOWN, false, "Failed to linearize astrometry\n");
     
    5656
    5757        psLogMsg("ppstampMakeStamp", 2, "After fit:  Center Pixel RA: %f   DEC: %f (degrees)\n",
    58                 r_after * PS_DEG_RAD, d_after * PS_DEG_RAD);
    59         psLogMsg("ppstampMakeStamp", 2, "Error in fit to astrometry %.2f    %.2f (arcseconds)\n", 
    60                 (r_after - r_before) *  PS_DEG_RAD * 3600, (d_after - d_before) * PS_DEG_RAD * 3600);
     58                r_after * PS_DEG_RAD, d_after * PS_DEG_RAD);
     59        psLogMsg("ppstampMakeStamp", 2, "Error in fit to astrometry %.2f    %.2f (arcseconds)\n",
     60                (r_after - r_before) *  PS_DEG_RAD * 3600, (d_after - d_before) * PS_DEG_RAD * 3600);
    6161
    6262        // XXX: should we fail if the fit is bad ??
     
    238238        return PS_EXIT_DATA_ERROR;
    239239    }
    240     char *fpaName = psMetadataLookupStr(NULL, input->fpa->concepts, "FPA.OBS"); // Name of FPA
    241240    pmFPAview *outview = pmFPAviewAlloc(0);
    242     pmFPAAddSourceFromView(output->fpa, fpaName, outview, output->format);
     241    pmFPAAddSourceFromView(output->fpa, outview, output->format);
    243242
    244243    outview->chip = 0;
  • branches/czw_branch/20100427/pstamp/src/ppstampMosaic.c

    r18712 r28017  
    2424    pmChip  *inChip = pmFPAviewThisChip(view, input->fpa);
    2525    if (!mChip->hdu && !mChip->parent->hdu) {
    26         const char *name = psMetadataLookupStr(&status, input->fpa->concepts, "FPA.OBS"); // Name of FPA
    27         pmFPAAddSourceFromView(mosaic->fpa, name, mosaicView, mosaic->format);
     26        pmFPAAddSourceFromView(mosaic->fpa, mosaicView, mosaic->format);
    2827    }
    2928    psFree(mosaicView);
  • branches/czw_branch/20100427/pstamp/test/detect_query_create

    r27784 r28017  
    1616     $output,                   # Name of output table
    1717     $query_id,
     18     $nostage,
    1819     );
    1920
     
    2223           'output|o=s'   => \$output,
    2324           'query_id|q=s'  => \$query_id,
     25           'nostage'      => \$nostage,
    2426) or pod2usage( 2 );
    2527
     
    6668#        }
    6769];
     70unless(defined($nostage)) {
     71    push @{ $header },        { name =>  'STAGE',
     72                                writetype => TSTRING,
     73                                comment => 'processing stage to examine',
     74                                value => undef
     75    };
     76}
    6877
    6978# Specification of columns to write
Note: See TracChangeset for help on using the changeset viewer.