IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Nov 20, 2009, 4:13:39 PM (17 years ago)
Author:
eugene
Message:

updates from head

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20091113/pstamp/scripts/pstampparse.pl

    r26083 r26236  
    9898
    9999# make sure the file contains what we are expecting
    100 
    101 # we shouldn't get here if this is the case so just die. No need to notify the client
     100# This program shouldn't have been run if the request file is bogus.
     101# No need to notify the client
    102102my_die("$request_file_name is not a PS1_PS_REQEST", $PS_EXIT_PROG_ERROR) if $extname ne "PS1_PS_REQUEST";
    103103my_die("REQ_NAME not found in $request_file_name", $PS_EXIT_PROG_ERROR)  if (!$req_name);
     
    165165    # XXX: TODO: sanity check all parameters
    166166
    167     # XXX: TODO: We shouldn't really just die in this loop.
    168     # If we encounter an error for a particular row
    169     # add a job with the proper fault code. If there is a db or config error we should probably just
    170     # trash the request.
     167    # If we encounter an error for a particular row add a job with the proper fault code.
     168    # If we encounter an error in this loop we shouldn't really just die.
     169    # We only do that now in the case of I/O or DB errors or the like.
    171170
    172171    my $rownum   = $row->{ROWNUM};
     
    236235    }
    237236
    238     # collect rows with the same images of interest in a list so that they
    239     # can be looked up together
     237    # For "stamp" and "list_uri" jobs collect rows with the same images of interest in a list so that they
     238    # can be looked up together.
    240239    if (@rowList) {
    241240        my $firstRow = $rowList[0];
    242         # note order of these parameters matters
    243         if (same_images_of_interest($firstRow, $row)) {
     241        if (($firstRow->{JOB_TYPE} ne "get_image") and same_images_of_interest($firstRow, $row)) {
    244242
    245243            # add this row to the list and move on
     
    305303    my $have_skycells = shift;
    306304    my $need_magic = shift;
     305    my $mode = shift;
    307306
    308307    my $num_jobs = 0;
     
    395394        print ARGSLIST "$args\n";
    396395        close ARGSLIST or my_die("failed to close $argslist", $PS_EXIT_UNKNOWN_ERROR);
     396
     397        write_params($output_base, $image);
    397398
    398399        my $newState = "run";
     
    476477        }
    477478    } elsif ($job_type eq "get_image") {
    478         print STDERR "get_image jobs not implemented yet" if $verbose;
    479         foreach my $row (@$rowList) {
    480             insertFakeJobForRow($row, 1, $PSTAMP_NOT_IMPLEMENTED);
    481             $num_jobs++;
    482         }
     479        my $n = scalar @$rowList;
     480
     481        my_die( "error: unexpected number of rows for get_image request: $n", $PS_EXIT_PROG_ERROR) if $n != 1;
     482
     483        $num_jobs = queueGetImageJobs($firstRow, $imageList, $stage, $need_magic, $mode);
     484
    483485    } else {
    484486        if (!$imageList or (scalar @$imageList eq 0)) {
     
    582584           
    583585            foreach my $row (@$rowList) {
    584                 $num_jobs += queueJobsForRow($row, $stage, $thisRun, $have_skycells, $need_magic);
     586                $num_jobs += queueJobsForRow($row, $stage, $thisRun, $have_skycells, $need_magic, $mode);
    585587            }
    586588        }
     589    }
     590    return $num_jobs;
     591}
     592
     593#        $num_jobs = queueGetImageJobs($firstRow, $imageList, $stage, $need_magic, $mode);
     594sub queueGetImageJobs
     595{
     596    my $row = shift;
     597    my $imageList = shift;
     598    my $stage = shift;
     599    my $need_magic = shift;
     600    my $mode = shift;
     601
     602    my $num_jobs = 0;
     603    my $rownum = $row->{ROWNUM};
     604    my $option_mask = $row->{OPTION_MASK};
     605
     606    # For dist_bundle we need
     607    #  --camera from $image
     608    #  --stage
     609    #  --stage_id from $image
     610    #  --component from $image
     611    #  --path_base
     612    #  --outdir global to this script
     613
     614    # loop over images
     615    my $job_num = 0;
     616    foreach my $image (@$imageList) {
     617        my $stage_id = $image->{stage_id};
     618        my $component = $image->{component};
     619
     620        # skip faulted components for now. Should we even be here?
     621        if ($image->{fault} > 0) {
     622            printf STDERR "skipping faulted component for $stage $stage_id $component\n" if $verbose;
     623            next;
     624        }
     625
     626        $job_num++;
     627
     628        my $imagefile = $image->{image};
     629        if (($stage ne "stack") and ($need_magic and !$image->{magicked})) {
     630            # we only get here if req_type is (byid or byexp). For other types the test for magicked is performed
     631            # in locate_images because it's much more efficient to do the test in the database.
     632            # For these two modes we fall through to here in order to give feedback to the requestor as
     633            # to why the request failed to queue jobs.
     634            print STDERR "skipping non-magicked image $imagefile\n" if $verbose;
     635            insertFakeJobForRow($row, $job_num, $PSTAMP_NOT_DESTREAKED);
     636            $num_jobs++;
     637
     638            next;
     639        }
     640        my $exp_id = $image->{exp_id};
     641           
     642        my $output_base = "$out_dir/${rownum}_${job_num}";
     643
     644        write_params($output_base, $image);
     645
     646        my $newState = "run";
     647        my $fault = 0;
     648        my $dep_id;
     649
     650        if ($stage ne 'raw') {
     651            my $run_state = $image->{state};
     652            my $data_state = $image->{data_state};
     653            $data_state = $run_state if $stage eq "stack";
     654            if (($run_state eq 'goto_purged') or ($data_state eq 'purged') or
     655                ($run_state eq 'goto_scrubbed') or ($data_state eq 'scrubbed')) {
     656                # image is gone and it's not coming back
     657                $newState = 'stop';
     658                $fault = $PSTAMP_GONE;
     659            } elsif (($data_state ne 'full') or ($run_state ne 'full' )) {
     660                # don't wait for update unless the caller asks us to
     661                if (!($option_mask & $PSTAMP_WAIT_FOR_UPDATE)) {
     662                    $newState = 'stop';
     663                    $fault = $PSTAMP_NOT_AVAILABLE;
     664                } else {
     665                    # cause the image to be re-made
     666                    # set up to queue an update run
     667                    queue_update_run(\$newState, \$fault, \$dep_id, $image->{image_db},
     668                        $run_state, $stage, $image->{stage_id}, $need_magic, $image->{label});
     669                }
     670            }
     671        }
     672
     673        $num_jobs++;
     674        my $command = "$pstamptool -addjob  -req_id $req_id -job_type $row->{JOB_TYPE}"
     675                        . " -outputBase $output_base -rownum $rownum -state $newState -options $option_mask";
     676        $command .= " -fault $fault" if $fault;
     677        $command .= " -exp_id $exp_id" if $exp_id;
     678        $command .= " -dep_id $dep_id" if $dep_id;
     679
     680        if ($mode eq "list_job") {
     681            # this is a debugging mode, just print the pstamptool that would have run
     682            # this is sort of like the mode -noupdate that some other tools support
     683            print "$command\n";
     684        } elsif (!$no_update) {
     685            # mode eq "queue_job"
     686            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     687                run(command => $command, verbose => $verbose);
     688            unless ($success) {
     689                print STDERR @$stderr_buf;
     690                # XXX TODO: now what? Should we mark the error state for the request?
     691                # should we keep going for other uris? If so how do we report that some
     692                # of the work that the request wanted isn't going to get done
     693                my_die("failed to queue job for request $req_id", $PS_EXIT_UNKNOWN_ERROR);
     694            }
     695        } else {
     696            print "skipping command: $command\n";
     697        }
     698    }
     699    if ( $num_jobs == 0 ) {
     700        print STDERR "no jobs for row $rownum\n" if $verbose;
     701        insertFakeJobForRow($row, 1, $PSTAMP_NO_JOBS_QUEUED);
     702        $num_jobs = 1;
    587703    }
    588704    return $num_jobs;
     
    677793    return 0 if ($r1->{REQ_TYPE} ne $r2->{REQ_TYPE});
    678794    return 0 if ($r1->{IMG_TYPE} ne $r2->{IMG_TYPE});
    679     return 0 if ($r1->{ID} ne $r2->{ID});
    680     return 0 if ($r1->{TESS_ID} ne $r2->{TESS_ID});
    681     return 0 if ($r1->{REQFILT} ne $r2->{REQFILT});
    682     return 0 if ($r1->{LABEL} ne $r2->{LABEL});
    683     return 0 if ($r1->{MJD_MIN} ne $r2->{MJD_MAX});
    684     return 0 if ($r1->{MJD_MAX} ne $r2->{MJD_MAX});
    685     return 0 if ($r1->{inverse} ne $r2->{inverse});
     795    return 0 if ($r1->{ID}       ne $r2->{ID});
     796    return 0 if ($r1->{TESS_ID}  ne $r2->{TESS_ID});
     797    return 0 if ($r1->{REQFILT}  ne $r2->{REQFILT});
     798    return 0 if ($r1->{LABEL}    ne $r2->{LABEL});
     799    return 0 if ($r1->{MJD_MIN}  ne $r2->{MJD_MAX});
     800    return 0 if ($r1->{MJD_MAX}  ne $r2->{MJD_MAX});
     801    return 0 if ($r1->{inverse}  ne $r2->{inverse});
    686802
    687803    if (defined($r1->{COMPONENT})) {
     
    759875}
    760876
     877sub write_params {
     878    my $output_base = shift;
     879    my $image = shift;
     880
     881    # write the contents of this "image" as a metadata config doc
     882    # Simply treat all values as strings. This is ok since we are only going to
     883    # read it from another perl script
     884    my $mdc_file = "${output_base}.mdc";
     885    open P, ">$mdc_file" or my_die("failed to open $mdc_file", $PS_EXIT_UNKNOWN_ERROR);
     886
     887    print P "params METADATA\n";
     888
     889    foreach my $key (keys %$image) {
     890        my $value = $image->{$key};
     891        if (defined $value) {
     892            printf P "  %-20s STR     %s\n", $key, $value;
     893        } else {
     894            printf P "  %-20s STR     NULL\n", $key;
     895        }
     896    }
     897
     898    print P "END\n";
     899    close P or my_die("failed to close $mdc_file", $PS_EXIT_UNKNOWN_ERROR);
     900}
     901
    761902sub my_die
    762903{
Note: See TracChangeset for help on using the changeset viewer.