IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 9, 2013, 2:08:27 PM (13 years ago)
Author:
bills
Message:

beginning rework of the postage stamp parser

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pstamp/scripts/pstampparse.pl

    r35380 r35384  
    211211print "\n$nRows rows read from request file\n";
    212212
    213 # If this is a big request and it came from the upload page and doesn't have a specific label assigned
    214 # change it to the generic one that has lower with lower priority
    215 
    216 #
    217 # Loop over rows in the request file collecting consecutive rows that have the "same images of interest"
    218 # in the sense that their selection parameters will yield the same target "Runs".
    219 # Process the groups of rows together to reduce lookup time and to potentially make multiple
    220 # stamps from the same ppstamp process.
    221 
    222 my @rowList;
     213
    223214my $num_jobs = 0;
    224215my $imageList;
    225216my $stage;
    226 my $need_magic;
    227217foreach my $row (@$rows) {
     218
    228219    if ($label eq 'WEB.UP' and ($nRows > 500 or $num_jobs > 500) and $req_id and !$no_update) {
     220        # this is a big request and it came from the upload page and doesn't have a specific label assigned
     221        # change it to the generic one that has lower with lower priority
    229222        $label = 'WEB.BIG';
    230223        print "\nChanging label for big WEB.UP request to $label\n";
     
    237230        }
    238231    }
    239     # sanity check the paramaters
     232
     233    # validate the paramaters
    240234    if (!checkRow($row)) {
    241235        # when it enconters an error checkRow adds a fake job with an appropriate error code to the database
     
    247241    $row->{error_code} = 0;
    248242
    249     if (scalar @rowList == 0) {
    250         push @rowList, $row;
    251         next;
    252     }
    253 
    254     my $firstRow = $rowList[0];
    255     if (same_images_of_interest($firstRow, $row)) {
    256         # add this row to the list and move on
    257         push @rowList, $row;
    258         next;
    259     }
    260 
    261     # the images of interest for this new row doesn't match the list.
    262     # process the list ...
    263     $num_jobs += processRows($action, \@rowList);
    264 
    265     # and reset the list to contain just the new row
    266     @rowList = ($row);
    267 }
    268 
    269 # out of rows process the list
    270 if (scalar @rowList > 0) {
    271     $num_jobs += processRows($action, \@rowList);
     243    $num_jobs += processRow($action, $row);
    272244}
    273245
     
    283255    my $row = shift;
    284256
     257    # check validity of the paramters in a request specification
    285258    # If we encounter an error for a particular row add a job with the proper fault code.
     259    # also adjust some paramterers like filter and set defaults for some others
    286260
    287261    my $stage = $row->{IMG_TYPE};
     
    315289    }
    316290
    317 
    318291    my $component = $row->{COMPONENT};
    319292    if (!defined $component or (lc($component) eq "null") or (lc($component) eq "all")) {
     
    345318        return 0;
    346319    }
     320
     321    my $fwhm_min = $row->{FWHM_MIN};
     322    if (!defined $fwhm_min) {
     323        $row->{FWHM_MIN} = 0;
     324    } elsif (!validNumber($fwhm_min)) {
     325        print STDERR "$fwhm_min is not a valid FWHM_MIN\n";
     326        insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
     327        return 0;
     328    }
     329    my $fwhm_max = $row->{FWHM_MAX};
     330    if (!defined $fwhm_max) {
     331        $row->{FWHM_MAX} = 0;
     332    } elsif (!validNumber($fwhm_max)) {
     333        print STDERR "$fwhm_max is not a valid FWHM_MAX\n";
     334        insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
     335        return 0;
     336    }
     337
    347338    my $data_group = $row->{DATA_GROUP};
    348339    if (!defined $data_group) {
     
    410401    }
    411402
     403
    412404    return 1;
    413405}
     
    418410
    419411    $num_jobs = 1;
     412    return $num_jobs;
     413}
     414
     415sub processRow {
     416    my $action  = shift;
     417    my $row     = shift;
     418
     419    my $num_jobs = 0;
     420
     421    my $project  = $row->{PROJECT};
     422
     423    # note: resolve_project avoids running pstamptool every time by remembering the
     424    # last project resolved
     425    my $proj_hash = resolve_project($ipprc, $project, $dbname, $dbserver);
     426    if (!$proj_hash) {
     427        insertFakeJobForRow($row, 1, $PSTAMP_UNKNOWN_PROJECT);
     428        $num_jobs++;
     429        return $num_jobs;
     430    }
     431    my $image_db   = $proj_hash->{dbname};
     432    my $camera     = $proj_hash->{camera};
     433
     434    my $req_type    = $row->{REQ_TYPE};
     435    my $rownum      = $row->{ROWNUM};
     436
     437    # Since user can get unmagicked data "by coordinate" requests can go back in time
     438    # to dredge unusable data from the "dark days"...
     439    if ($req_type eq 'bycoord' and $row->{MJD_MIN} == 0) {
     440        # ... so unless the user sets mjd_min clamp it to 2009-04-01
     441        # XXX: This value should live in the pstampProject table not be hardcoded here
     442        $row->{MJD_MIN} = 54922;
     443    }
     444
     445    if (($req_type eq 'byskycell') or ($req_type eq 'bycoord')) {
     446        # avoid error from print below if $id isn't needed
     447        $row->{ID} = "" if !$row->{ID};
     448    }
     449   
     450    # Call PS::IPP::PStamp::Job locate_images subroutine to get the images for this
     451    # request specification. An array reference is returned.
     452    my $start_locate = gettimeofday();
     453
     454    print "\nCalling new_locate_images for row: $rownum\n";
     455
     456    $imageList = new_locate_images($ipprc, $image_db, $camera, $row, $verbose);
     457
     458    my $dtime_locate = gettimeofday() - $start_locate;
     459    print "Time to locate_images for row $rownum $dtime_locate\n";
     460
     461    my @rowList = ($row);
     462    $num_jobs += queueJobs($action, \@rowList, $imageList);
     463
     464    # if this row slipped through without a job being added add one.
     465    if ($row->{job_num} == 0) {
     466        print "row $row->{ROWNUM} produced no jobs\n";
     467        print STDERR "row $row->{ROWNUM} produced no jobs\n";
     468        my $error_code = $row->{error_code};
     469        $error_code =  $PSTAMP_NO_IMAGE_MATCH if !$error_code;
     470        insertFakeJobForRow($row, ++$row->{job_num}, $error_code);
     471    }
     472
    420473    return $num_jobs;
    421474}
     
    447500    }
    448501    my $req_type  = $row->{REQ_TYPE};
    449     $stage        = $row->{IMG_TYPE};
     502    my $stage     = $row->{IMG_TYPE};
    450503    my $id        = $row->{ID};
    451504    my $component = $row->{COMPONENT};
     
    463516    my $image_db   = $proj_hash->{dbname};
    464517    my $camera     = $proj_hash->{camera};
    465     $need_magic    = $proj_hash->{need_magic};
     518    my $need_magic    = $proj_hash->{need_magic};
    466519    # Since user can get unmagicked data "by coordinate" requests can go back in time
    467520    # to dredge unusable data from the "dark days"...
     
    523576    # information required is contained there
    524577
    525     $imageList = locate_images($ipprc, $image_db, \@rowList, $req_type, $stage, $id, $tess_id, $component,
     578    $imageList = locate_images($ipprc, $image_db, $rowList, $req_type, $stage, $id, $tess_id, $component,
    526579                $option_mask, $need_magic, $mjd_min, $mjd_max, $filter, $data_group, $verbose);
    527580
     
    533586    $row->{need_magic} = $need_magic;
    534587
    535     $num_jobs += queueJobs($action, \@rowList, $imageList);
     588    $num_jobs += queueJobs($action, $rowList, $imageList);
    536589
    537590    # if a row slipped through with no jobs add a faulted one
    538     foreach my $row (@rowList) {
     591    foreach my $row (@$rowList) {
    539592        if ($row->{job_num} == 0) {
    540593            print "row $row->{ROWNUM} produced no jobs\n";
     
    675728    my $imageList = shift;
    676729
    677     my $firstRow = $rowList[0];
     730    my $firstRow = $rowList->[0];
    678731    my $stage    = $firstRow->{IMG_TYPE};
    679732    my $job_type = $firstRow->{JOB_TYPE};
     
    10041057    my $r_fault = shift;
    10051058    my $r_dep_id = shift;
     1059
     1060    my $need_magic = 0;
    10061061
    10071062    if ($stage ne 'raw') {
Note: See TracChangeset for help on using the changeset viewer.