IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 21, 2014, 5:42:34 AM (12 years ago)
Author:
eugene
Message:

merge changes from trunk

Location:
branches/eam_branches/ps2-tc3-20130727
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ps2-tc3-20130727

  • branches/eam_branches/ps2-tc3-20130727/pstamp/scripts

    • Property svn:mergeinfo deleted
  • branches/eam_branches/ps2-tc3-20130727/pstamp/scripts/pstampparse.pl

    r35828 r36680  
    3131my $no_update;
    3232my $dest_requires_magic;
     33my $dump_params = 0;
    3334
    3435# set this to true to disable update processing
     
    4849    'save-temps'=>  \$save_temps,
    4950    'no-update' =>  \$no_update,
     51    'dump-params' => \$dump_params,
    5052);
    5153
    5254die "invalid mode '$mode'" unless ($mode eq "list_uri") or ($mode eq "queue_job");
    53 die "--file is required"     if !defined($request_file_name);
     55die "--file is required"   unless defined($request_file_name);
    5456
    5557if ($mode ne "list_uri") {
    56     die "req_id is required"   if !$req_id;
     58    die "req_id is required"  if !$req_id;
    5759    die "outdir is required"  if !$outdir;
    58     die "product is required"  if !$product;
     60    die "product is required" if !$product;
    5961} else {
    60     $req_id = 0;
    61     $outdir = "nowhere";
     62    # mode eq 'list_uri' (used for parser testing)
     63    # these values won't be used for anything but should be defined to avoid errors
     64    $req_id  = 0;
     65    $outdir  = "nowhere";
    6266    $product = "dummy";
    6367}
     
    7680my $pstamptool  = can_run('pstamptool')  or (warn "Can't find pstamptool"  and $missing_tools = 1);
    7781my $pstampdump  = can_run('pstampdump') or (warn "Can't find pstampdump" and $missing_tools = 1);
    78 my $fields  = can_run('fields') or (warn "Can't find fields" and $missing_tools = 1);
     82my $fields      = can_run('fields') or (warn "Can't find fields" and $missing_tools = 1);
    7983
    8084if ($missing_tools) {
     
    116120if ($extver >= 2) {
    117121    # We have a version 2 file. Require that the new keywords be supplied.
    118     my_die("action not supplied in version $extver request file $request_file_name\n", $PSTAMP_INVALID_REQUEST) unless defined $action;
    119 
    120     my_die("invalid action: $action supplied in version $extver request file $request_file_name\n", $PSTAMP_INVALID_REQUEST) unless (uc($action) eq 'PROCESS' or uc($action) eq 'PREVIEW');
    121 
    122     my_die("email not supplied in version $extver request file $request_file_name\n", $PSTAMP_INVALID_REQUEST) unless $email;
     122    my_die("action not supplied in version $extver request file $request_file_name\n", $PSTAMP_INVALID_REQUEST)
     123        unless defined $action;
     124
     125    my_die("invalid action: $action supplied in version $extver request file $request_file_name\n",
     126        $PSTAMP_INVALID_REQUEST)
     127        unless (uc($action) eq 'PROCESS' or uc($action) eq 'PREVIEW');
     128
     129    my_die("email not supplied in version $extver request file $request_file_name\n", $PSTAMP_INVALID_REQUEST)
     130        unless $email;
     131
    123132    # XXX check for "valid" $email
    124133} else {
    125134    # for version 1 file the action is process and email is not used
    126135    $action = 'PROCESS';
    127     $email = 'null';
     136    $email  = 'null';
    128137}
    129138
     
    175184
    176185
    177 if ($req_id and !$no_update) {
     186{
    178187    # update the database with the request name. This will be used as the
    179     # the output data store's product name
     188    # the fileset name in the output data store
    180189    my $command = "$pstamptool -updatereq -req_id $req_id  -set_name $req_name";
    181190    $command .= " -set_username $email" if $email ne 'null';
    182191    $command .= " -set_outProduct $product";
    183192    $command .= " -set_label $label" if $label_changed;
    184     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    185         run(command => $command, verbose => $verbose);
    186     unless ($success) {
    187         my_die("$command failed", $PS_EXIT_UNKNOWN_ERROR);
    188     }
    189 }
     193    unless ($no_update) {
     194        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     195            run(command => $command, verbose => $verbose);
     196        unless ($success) {
     197            my_die("$command failed", $PS_EXIT_UNKNOWN_ERROR);
     198        }
     199    } else {
     200        print "skipping $command\n";
     201    }
     202}
     203
    190204if ($duplicate_req_name) {
    191205    exit 0;
     
    212226}
    213227
    214 my $nRows = scalar @$rows;
     228my $nRows = $rows ? scalar @$rows : 0;
    215229print "\n$nRows rows read from request file\n";
    216230
     231unless ($nRows) {
     232    # pstamp_job_run was invoked so the request file must have contained a valid header
     233    # a request file with no rows is invalid.
     234    # The print above will let the log file know a bit more.
     235    # Insert a faulted fake job and exit this program successfully.
     236    print STDERR "Invalid request file.\n";
     237    insertFakeJobForRow(undef, 0, $PSTAMP_INVALID_REQUEST);
     238    exit 0;
     239}
     240
     241
     242# if label is for one of the high priority channels, watch for big requests
     243my $watch_for_big_requests = (!($label =~ /BIG/) and ($label =~ /PSI/ or $label =~ /WEB/));
     244
     245# XXX: these should be in a configuration file somewhere not hard coded
     246my $big_limit = 100;
     247my $job_big_limit = 400;
     248
     249if ($watch_for_big_requests and $nRows > $big_limit) {
     250    $label = change_to_lower_priority_label($label);
     251    $watch_for_big_requests = 0;
     252}
    217253
    218254my $num_jobs = 0;
    219 my $imageList;
    220 my $stage;
     255
    221256foreach my $row (@$rows) {
    222 
    223     if ($label eq 'WEB.UP' and ($nRows > 500 or $num_jobs > 500) and $req_id and !$no_update) {
    224         # this is a big request and it came from the upload page and doesn't have a specific label assigned
    225         # change it to the generic one that has lower with lower priority
    226         $label = 'WEB.BIG';
    227         print "\nChanging label for big WEB.UP request to $label\n";
    228 
    229         my $command = "$pstamptool -updatereq -req_id $req_id  -set_label $label";
    230         my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    231             run(command => $command, verbose => $verbose);
    232         unless ($success) {
    233             my_die("$command failed", $PS_EXIT_UNKNOWN_ERROR);
    234         }
    235     }
    236257
    237258    # validate the paramaters
     
    246267
    247268    $num_jobs += processRow($action, $row);
     269
     270    # see whether number of jobs limit for high priority request was exceeded
     271    if ($watch_for_big_requests and $num_jobs > $job_big_limit) {
     272        $label = change_to_lower_priority_label($label);
     273        $watch_for_big_requests = 0;
     274    }
    248275}
    249276
    250277if (($action eq 'LIST' or $mode eq "queue_job") and ($num_jobs eq 0)) {
    251     print STDERR "no jobs created for $req_name\n" if $verbose;
    252     insertFakeJobForRow(undef, 0, $PSTAMP_INVALID_REQUEST);
     278    # this should not happen. The function above is required to insert a fake job for any
     279    # rows that did not yield any jobs.
     280    print STDERR "ERROR: zero jobs created for $req_name\n";
     281    insertFakeJobForRow(undef, 0, $PS_EXIT_PROG_ERROR);
    253282}
    254283
    255284exit 0;
     285
     286# end of main function
     287
     288sub change_to_lower_priority_label {
     289    my $label = shift;
     290    my $old_label = $label;
     291    $label = ($label =~ /WEB/) ? 'WEB.BIG' : 'PSI.BIG';
     292    print "\nChanging label for big $old_label request to $label\n";
     293
     294    my $command = "$pstamptool -updatereq -req_id $req_id  -set_label $label";
     295    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     296        run(command => $command, verbose => $verbose);
     297    unless ($success) {
     298        my_die("$command failed", $PS_EXIT_UNKNOWN_ERROR);
     299    }
     300    return $label;
     301}
    256302
    257303sub checkRow {
     
    267313    my $rownum   = $row->{ROWNUM};
    268314    if (!validID($rownum)) {
     315        $rownum = 'NULL' if !defined $rownum;
    269316        print STDERR "$rownum is not a valid ROWNUM\n";
    270317        insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
     
    272319    }
    273320    my $job_type = $row->{JOB_TYPE};
    274     if (($job_type ne "stamp") and ($job_type ne "get_image")) {
     321    if (!defined $job_type || (($job_type ne "stamp") and ($job_type ne "get_image"))) {
     322        $job_type = 'NULL' if !defined $job_type;
    275323        print STDERR "$job_type is not a valid JOB_TYPE\n";
    276324        insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
     
    281329    if (($req_type ne "byid") and ($req_type ne "bycoord") and ($req_type ne "byexp") and
    282330        ($req_type ne "byskycell") and ($req_type ne "bydiff")) {
     331        $req_type = 'NULL' if !defined $req_type;
    283332        print STDERR "$req_type is not a valid REQ_TYPE\n";
    284333        insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
     
    286335    }
    287336    if ($job_type eq 'get_image') {
    288         unless ($req_type eq 'byid' or $req_type eq 'byexp' or ($req_type eq 'byskycell' and $stage eq 'stack')) {
    289             print STDERR "REQ_TYPE must be 'byid' or 'byexp' or byskcyell for stacks for JOB_TYPE 'get_image'\n";
     337        # get_image jobs are quite expensive in terms of space so we are currently restricting them
     338        unless ($req_type eq 'byid' or $req_type eq 'byexp'
     339            or ($req_type eq 'byskycell' and $stage eq 'stack')
     340            or ($stage eq 'stack_summary')) {
     341            print STDERR "REQ_TYPE must be 'byid' or 'byexp' JOB_TYPE 'get_image' for IMG_TYPE $stage\n";
    290342            insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
    291343            return 0;
     
    295347    my $component = $row->{COMPONENT};
    296348    if (!defined $component or (lc($component) eq "null") or (lc($component) eq "all")) {
    297         if ($job_type eq 'get_image') {
     349        if ($job_type eq 'get_image' and ! ($stage eq 'stack' or $stage eq 'stack_summary')) {
    298350            $row->{COMPONENT} = 'all';
    299351        } else {
     
    384436    }
    385437
    386     if (($req_type eq "byexp") and ($stage eq "stack")) {
    387         print STDERR "byexp not implemented for stack stage. row: $rownum\n";
     438    if (($req_type eq "byexp") and ($stage eq "stack" or $stage eq 'stack_summary')) {
     439        print STDERR "byexp not implemented for $stage stage. row: $rownum\n";
    388440        insertFakeJobForRow($row, 1, $PSTAMP_NOT_IMPLEMENTED);
    389441        return 0;
     
    457509    my $start_locate = gettimeofday();
    458510
    459     print "\nCalling new_locate_images for row: $rownum\n";
    460 
    461     $imageList = locate_images_for_row($ipprc, $image_db, $camera, $row, $verbose);
     511    print "\nCalling locate_images_for_row for row: $rownum\n";
     512
     513    my $imageList = locate_images_for_row($ipprc, $image_db, $camera, $row, $verbose);
    462514
    463515    my $dtime_locate = gettimeofday() - $start_locate;
     
    521573    my $image_db   = $proj_hash->{dbname};
    522574    my $camera     = $proj_hash->{camera};
    523     my $need_magic    = $proj_hash->{need_magic};
     575    my $need_magic = $proj_hash->{need_magic};
    524576    # Since user can get unmagicked data "by coordinate" requests can go back in time
    525577    # to dredge unusable data from the "dark days"...
     
    532584    $need_magic = 0 if $stage eq 'stack';
    533585
    534     if ($need_magic) {
    535 
    536         # this project requires that postage stamps be extracted from destreaked images
    537 
    538         if ($option_mask & ($PSTAMP_REQUEST_UNCENSORED | $PSTAMP_REQUIRE_UNCENSORED)) {
    539             # The user has requested uncensored stamps
    540 
    541             if (!$dest_requires_magic) {
    542                 # and this user's data store destination is allowed uncensored stamps, so accept the request
    543                 $need_magic = 0;
    544             } else {
    545                 print STDERR "Error row $rownum: User not authorized to to request uncensored stamps.\n";
    546                 if ($option_mask & $PSTAMP_REQUIRE_UNCENSORED) {
    547                     # user required uncensored stamps. Can't do it so fail.
    548                     foreach my $r (@$rowList) {
    549                         insertFakeJobForRow($r, 1, $PSTAMP_NOT_AUTHORIZED);
    550                         $num_jobs++;
    551                     }
    552                     return $num_jobs;
    553                 }
    554 
    555                 # user will accept censored stamps. alter OPTION_MASK and continue
    556 
    557                 print STDERR "    Will attempt to make destreaked stamps\n";
    558                 # zap the offending bit in the option mask
    559                 $option_mask = $option_mask ^ ($PSTAMP_REQUEST_UNCENSORED);
    560                 foreach my $r (@$rowList) {
    561                     $r->{OPTION_MASK} = $option_mask;
    562                 }
    563             }
    564         }
    565     }
    566    
     586    # XXX: magic is dead
     587    $need_magic = 0;
     588
    567589    my $numRows = scalar @$rowList;
    568590
     
    581603    # information required is contained there
    582604
    583     $imageList = locate_images($ipprc, $image_db, $rowList, $req_type, $stage, $id, $tess_id, $component,
     605    my $imageList = locate_images($ipprc, $image_db, $rowList, $req_type, $stage, $id, $tess_id, $component,
    584606                $option_mask, $need_magic, $mjd_min, $mjd_max, $filter, $data_group, $verbose);
    585607
     
    701723    }
    702724    $base =~ s/.fits$//;
     725
     726    my $filter = $image->{filter};
     727    if (!$filter) {
     728        if ($stage eq 'diff') {
     729            $filter = $image->{filter_1};
     730        }
     731        if (!$filter) {
     732            # XXX: perhaps this should be a programming error...
     733            print STDERR "missing filter using 'X'\n";
     734            $filter = 'X';
     735        }
     736    }
     737    # use first character of filter
     738    $filter = substr($filter, 0, 1);
    703739           
    704     my $output_base = "$outdir/${rownum}_${job_num}_${base}";
     740    my $output_base = "$outdir/${rownum}_${job_num}_${filter}_${base}";
    705741    write_params($output_base, $image);
    706742
     
    758794            print "$image->{image}\n";
    759795            ++$firstRow->{job_num};
     796            if ($dump_params) {
     797                my $rownum = $firstRow->{ROWNUM};
     798                my $jobnum = $firstRow->{job_num};
     799                my $filter = substr $image->{filter}, 0, 1;
     800                my $output_base = "${rownum}_${jobnum}_${filter}";
     801                write_params($output_base, $image);
     802            }
    760803        }
    761804    } elsif ($job_type eq "get_image") {
     
    11631206    }
    11641207    if (($img_type eq "raw") or ($img_type eq "chip") or ($img_type eq "warp") or
    1165         ($img_type eq "stack") or ($img_type eq "diff")) {
     1208        ($img_type eq "stack") or ($img_type eq 'stack_summary') or ($img_type eq "diff")) {
    11661209        return 1;
    11671210    } else {
Note: See TracChangeset for help on using the changeset viewer.