IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 19, 2013, 3:39:39 PM (13 years ago)
Author:
eugene
Message:

merged from trunk

Location:
branches/eam_branches/ipp-20130307/pstamp/scripts
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20130307/pstamp/scripts

  • branches/eam_branches/ipp-20130307/pstamp/scripts/psmkreq

    r34611 r35412  
    2828my ($ra, $dec, $x, $y, $list, $output, $req_name, $req_name_base);
    2929
    30 my ($image, $mask, $variance, $cmf, $psf, $backmdl, $inverse);
    31 my ($unconvolved, $use_imfile_id, $no_wait);
     30my ($image, $mask, $variance, $jpeg, $cmf, $psf, $backmdl, $inverse);
     31my ($convolved, $unconvolved, $uncompressed, $use_imfile_id, $no_wait);
     32
     33# new header keywords for version 2
     34my $action = 'PROCESS';
     35my $email = 'null';
    3236
    3337my $default_size = 100;
     
    5256my $comment;
    5357
     58# new request specification columns for version 2
     59my $survey_name ='null';
     60my $release_name = 'null';
     61my $run_type ='null';
     62my $fwhm_min = 0;
     63my $fwhm_max = 0;
     64
     65
    5466my $missing_tools;
    5567my $pstamp_request_file  = can_run('pstamp_request_file')  or (warn "Can't find required program pstamp_request_file"  and $missing_tools = 1);
     
    6274GetOptions(
    6375    'list=s'            => \$list,          # list of coordinates if undef ra and dec or x and y are required
    64     'ra=s'              => \$ra,            #
     76    'ra=s'              => \$ra,
    6577    'dec=s'             => \$dec,
    6678    'x=s'               => \$x,
     
    8799    'comment=s'         => \$comment,
    88100
     101    'survey=s'          => \$survey_name,
     102    'release=s'         => \$release_name,
     103    'run_type=s'        => \$run_type,
     104    'fwhm_min=s'        => \$fwhm_min,
     105    'fwhm_max=s'        => \$fwhm_max,
     106
    89107    'option_mask=i'     => \$option_mask,
    90108    'image'             => \$image,
    91109    'mask'              => \$mask,
     110    'jpeg'              => \$jpeg,
    92111    'variance'          => \$variance,
    93112    'cmf'               => \$cmf,
     
    96115    'inverse'           => \$inverse,
    97116    'unconvolved'       => \$unconvolved,
     117    'convolved'         => \$convolved,
     118    'uncompressed'      => \$uncompressed,
    98119    'use_imfile_id'     => \$use_imfile_id,
    99120    'do_not_wait'       => \$no_wait,
     121
     122    'action=s'          => \$action,
     123    'email=s'           => \$email,
    100124
    101125    'verbose'           => \$verbose,
     
    156180}
    157181
     182if ($stage eq 'stack') {
     183    # default is to do convolved stack
     184    unless (defined $option_mask || $convolved) {
     185        $unconvolved = 1;
     186    }
     187}
     188
    158189checkFilter($filter, 'null', $filter)  if $filter;
    159190checkMJD($mjd_min, 0, "") if $mjd_min;
     
    167198        $option_mask |= $PSTAMP_SELECT_MASK     if $mask;
    168199        $option_mask |= $PSTAMP_SELECT_VARIANCE if $variance;
     200        $option_mask |= $PSTAMP_SELECT_JPEG     if $jpeg;
     201
     202        # if no image was requested make a stamp of the image
    169203        $option_mask = $PSTAMP_SELECT_IMAGE    if $option_mask == 0;
    170204
    171         # if no image was requested make a stamp of the image
    172205
    173206        $option_mask |= $PSTAMP_SELECT_CMF      if $cmf;
     
    207240} else {
    208241    $rows = [];
    209     push @$rows, buildRow("", $comment, $x, $y, $filter, $mjd_min, $mjd_max);
     242    push @$rows, buildRow("", $comment, 1, $x, $y, $filter, $mjd_min, $mjd_max);
    210243}
    211244
    212245my ($tdf, $table_def_name) = tempfile ("/tmp/tabledef.XXXX", UNLINK => !$save_temps);
    213 print $tdf "$req_name 1\n";
     246my $line = "$req_name 2 $action $email";
     247print "$line\n" if $verbose;
     248print $tdf "$line\n";
    214249my $rownum = 0;
    215250foreach my $row (@$rows) {
    216251    $rownum++;
    217252    my $line = "$rownum $row->{ra}\t$row->{dec}\t$width $height"
    218         . " $coord_mask $job_type $option_mask $project $req_type"
     253        . " $coord_mask $job_type $option_mask $project $survey_name $release_name $req_type"
    219254        . " $stage $id $tess_id $component $data_group"
    220         . " $row->{filter} $row->{mjd_min} $row->{mjd_max}";
     255        . " $row->{filter} $row->{mjd_min} $row->{mjd_max} $run_type $fwhm_min $fwhm_max";
    221256
    222257    if ($row->{comment} and $row->{comment} ne '') {
     
    235270    $command .= " --output $output" if $output;
    236271    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    237         run(command => $command, verbose => 0);
     272        run(command => $command, verbose => $verbose);
    238273    unless ($success) {
    239274        print STDERR @$stderr_buf;
     
    274309
    275310    my $row = {};
    276     $row->{ra}      = checkRA($vals[0], $linenumber);
    277     $row->{dec}     = checkDEC($vals[1], $linenumber);
    278     $row->{filter}  = checkFilter($vals[2], $filter, $linenumber);
    279     $row->{mjd_min} = checkMJD($vals[3], $mjd_min, $linenumber);;
    280     $row->{mjd_max} = checkMJD($vals[4], $mjd_max, $linenumber);;
     311    $row->{rownum}  = checkRownum($vals[0], $linenumber);
     312    $row->{ra}      = checkRA($vals[1], $linenumber);
     313    $row->{dec}     = checkDEC($vals[2], $linenumber);
     314    $row->{filter}  = checkFilter($vals[3], $filter, $linenumber);
     315    $row->{mjd_min} = checkMJD($vals[4], $mjd_min, $linenumber);;
     316    $row->{mjd_max} = checkMJD($vals[5], $mjd_max, $linenumber);;
    281317    $row->{comment} = $comment;
    282318
     
    305341    my $linenumber = shift;
    306342
    307     my $result;
     343   my $result;
    308344    if ($c =~ /\:/) {
    309345        # sexagesmial format not valid for pixel coordinates
     
    329365}
    330366
     367sub checkRownum {
     368    my $rownum = shift;
     369    my $linenumber = shift;
     370    die "rownum can not be null at $linenumber\n" unless defined $rownum;
     371
     372    # XXX: For now just check that rownum is defined and a single word
     373    # extend this. Should we require a number?
     374    my @words = split " ", $rownum;
     375    die "$rownum is not a vaild rownum at $linenumber\n" unless (scalar @words) == 1;
     376}
     377
    331378sub checkRA {
    332379    my $ra = shift;
     
    335382
    336383    if ($ra =~ /\:/) {
     384        # assume RA is in hours:minutes:seconds
    337385        return $checked * 360. / 24.;
    338386    } else {
  • branches/eam_branches/ipp-20130307/pstamp/scripts/psstatus

    r30692 r35412  
    6868    IFNULL(depcount, 0) AS 'Image updates'
    6969    , timestamp AS 'last state change (UTC)'
     70    , registered AS 'Submit time (UTC)'
    7071FROM (
    7172    SELECT
     
    7778        pstampRequest.fault,
    7879        timestamp,
     80        registered,
    7981        IFNULL(priority,10000) AS priority
    8082FROM pstampRequest
    8183LEFT JOIN Label USING(label)
    8284    WHERE pstampRequest.state = 'run' or pstampRequest.state ='new'
     85        OR pstampRequest.state = 'parsed'
    8386   --     OR pstampRequest.state = 'run.wait'
    8487) as unfinishedReq
     
    8992FROM pstampRequest JOIN pstampJob USING(req_id)
    9093    WHERE (pstampRequest.state = 'run' or pstampRequest.state = 'new'
    91         OR pstampRequest.state = 'run.wait')
     94        OR pstampRequest.state = 'run.wait'
     95        OR pstampRequest.state = 'parsed')
    9296    GROUP BY req_id
    9397) as rowCounts
     
    101105    JOIN pstampDependent USING(dep_id)
    102106    WHERE (pstampRequest.state = 'run' or pstampRequest.state = 'new'
     107            OR pstampRequest.state = 'parsed'
    103108            OR pstampRequest.state = 'run.wait')
    104109        AND dep_id > 0
     
    178183    IFNULL(faulted,0) AS 'Faulted Jobs',
    179184    IFNULL(depcount, 0) AS 'Image updates completed',
    180     timestamp AS 'Completion Time (UTC)'
     185    timestamp AS 'Completion Time (UTC)',
     186    registered AS 'Submit Time (UTC)'
    181187FROM (
    182188    SELECT
     
    187193--    pstampRequest.state,
    188194--    pstampRequest.fault,
    189     timestamp
     195    timestamp,
     196    registered
    190197FROM pstampRequest
    191198    WHERE pstampRequest.state = 'stop'
  • branches/eam_branches/ipp-20130307/pstamp/scripts/pstamp_cleanup.pl

    r34231 r35412  
    183183    }
    184184
    185     my $command = "rm -r $dir";
     185    # do an ls of the directory before starting
     186#    print "directory listing for $dir\n";
     187#    system "ls $dir";
     188
     189    my $command = "rm -rf $dir";
    186190    unless ($no_update) {
    187191        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    188192            run(command => $command, verbose => $verbose);
    189193        unless ($success) {
    190             my $rc = $error_code >> 8;
    191             my_die("Unable to perform $command return status: $rc", $req_id, $rc);
     194            if (-e $dir) {
     195                my $rc = $error_code >> 8;
     196                my_die("Unable to perform $command return status: $rc", $req_id, $rc);
     197            } else {
     198                print STDERR "rm claimed to fail but directory no longer exists\n";
     199            }
    192200        }
    193201    } else {
  • branches/eam_branches/ipp-20130307/pstamp/scripts/pstamp_finish.pl

    r34447 r35412  
    107107    my ($header, $rows) = read_request_file($req_file);
    108108
    109     my $action = $header->{ACTION};
    110 
    111     if (!$header or (($action eq 'PROCESS') and !$rows)) {
     109    if (!$header or !$rows) {
    112110        # Since a request got queued, the request file must have been readable at some point
    113111        my_die("failed to read request file $req_file", $req_id, $PS_EXIT_CONFIG_ERROR);
     
    128126
    129127    my $request_fault = 0;
    130     if ($action eq 'PROCESS') {
     128    {
    131129        # The results table definition file
    132130        my ($tdf, $table_def_name) = tempfile ("$outdir/tabledef.XXXX", UNLINK => !$save_temps);
     
    238236                } else {
    239237                    my_die("No reglist for successful job: $job_id", $req_id, $PS_EXIT_PROG_ERROR)
    240                         if $fault eq $PSTAMP_SUCCESS;
     238                        if $job->{state} eq 'stop' and $fault eq $PSTAMP_SUCCESS;
    241239                    print STDERR "no reglist file for job $job_id\n" if $verbose;
    242240                    print $tdf "$rownum|$fault|$error_string|0|$job_id|";
     
    273271            }
    274272        }
    275     } elsif ($action ne 'LIST') {
    276         my_die("Unexpected action $action found", $req_id, $PS_EXIT_PROG_ERROR);
    277     } else {
    278         # pstampparse did all of the work
    279273    }
    280274
  • branches/eam_branches/ipp-20130307/pstamp/scripts/pstamp_job_run.pl

    r33512 r35412  
    113113
    114114    if ($stage eq "raw") {
     115        # zap options that don't apply to raw stage
    115116        $options &= ~($PSTAMP_SELECT_MASK | $PSTAMP_SELECT_VARIANCE);
    116117    }
     
    136137        $argString .= " -astrom $params->{astrom}";
    137138        push @file_list, $params->{astrom};
     139    }
     140
     141    if ($options & $PSTAMP_SELECT_SOURCES) {
     142        # Extract sources from astrometry file if provided. This will be the smf for chip stage
     143        # or the skycal cmf for stacks
     144        if ($params->{astrom}) {
     145            $argString .= " -write_cmf";
     146            if ($stage eq 'stack') {
     147                # Set psphot recipe to STACKPHOT so that the extended source paramters will
     148                # be copied from the cmf file.
     149                $argString .= " -recipe PSPHOT STACKPHOT"
     150            }
     151        } elsif ($params->{cmf}) {
     152            $argString .= " -write_cmf";
     153            push @file_list, $params->{cmf};
     154        } else {
     155            print "Could not find suitable sources file will not write cmf\n";
     156        }
    138157    }
    139158
     
    254273                           $PSTAMP_SELECT_MASK     => "mk.fits",
    255274                           $PSTAMP_SELECT_VARIANCE => "wt.fits",
     275                           $PSTAMP_SELECT_SOURCES  => "cmf",
    256276                           $PSTAMP_SELECT_JPEG     => "jpg");
    257277
    258         my $output_mask = $options & ($PSTAMP_SELECT_IMAGE | $PSTAMP_SELECT_MASK | $PSTAMP_SELECT_VARIANCE | $PSTAMP_SELECT_JPEG);
     278        my $output_mask = $options & ($PSTAMP_SELECT_IMAGE | $PSTAMP_SELECT_MASK | $PSTAMP_SELECT_VARIANCE | $PSTAMP_SELECT_JPEG | $PSTAMP_SELECT_SOURCES);
    259279
    260280        foreach my $key (keys (%extensions)) {
     
    400420        my $pattern_file = $params->{pattern} if ($options & $PSTAMP_SELECT_BACKMDL);
    401421        my $cmf_file;
    402         if ($stage ne 'chip') {
    403             # we don't ship chip stage cmf files because they may not be censored
    404             $cmf_file = $params->{cmf} if ($options & $PSTAMP_SELECT_CMF);
    405         }
     422#        if ($stage ne 'chip') {
     423#            # we don't ship chip stage cmf files because they may not be censored
     424#            $cmf_file = $params->{cmf} if ($options & $PSTAMP_SELECT_CMF);
     425#        }
    406426
    407427        my $outdir = dirname($output_base);
  • branches/eam_branches/ipp-20130307/pstamp/scripts/pstamp_parser_run.pl

    r34232 r35412  
    158158my $request_fault = $PSTAMP_INVALID_REQUEST;
    159159
     160# default action is to process the request after parsing. This can be overridden by
     161# PREVIEW mode for pstamp requests
     162my $action = 'PROCESS';
     163
    160164if (-r $uri) {
    161165    # run the appropriate parse command to parse the queue the jobs for this request
    162166    # first check the extension header to find the EXTNAME
    163     $request_type = find_request_type($uri);
     167    $request_type = find_request_type($uri, \$action);
    164168
    165169    if ($request_type) {
     
    240244
    241245    if ($success) {
    242         $newState = 'run';
     246        # XXX: This bit of the postage stamp request API has slipped in here because we need to control
     247        # the new state of the request
     248        if ($action eq 'PROCESS') {
     249            $newState = 'run';
     250        } elsif ($action eq 'PREVIEW') {
     251            $newState = 'parsed';
     252        } else {
     253            print STDERR "WARNING Ignoring unexpected value for ACTION found in request header: $action\n";
     254        }
    243255    } else {
    244256        $fault = $error_code >> 8;
     
    275287    # find the EXTNAME in the input fits table
    276288    my $file_name = shift;
    277     my $out = `echo $file_name | fields -x 0 EXTNAME`;
     289    my $r_action = shift;
     290
     291    my $out = `echo $file_name | fields -x 0 EXTNAME ACTION`;
    278292
    279293    if ($out) {
    280294        # output from fields is filename value
    281         my ($dummy, $extname) = split " ", $out;
     295        my ($dummy, $extname, $action) = split " ", $out;
     296
     297        # Set the action if it is defined in the request header
     298        # XXX:consider doing this only if extname is PS1_PS_REQUSET
     299        $$r_action = $action if ($action);
    282300
    283301        return $extname;
  • branches/eam_branches/ipp-20130307/pstamp/scripts/pstamp_request_file

    r34447 r35412  
    5454                    value => undef
    5555        },
    56         { name => 'USERNAME',
    57                     writetype => TSTRING,
    58                     comment => 'username for request (optional)',
    59                     value => undef
    60         },
     56#        { name => 'USERNAME',
     57#                    writetype => TSTRING,
     58#                    comment => 'username for request (optional)',
     59#                    value => undef
     60#        },
    6161        { name => 'EMAIL',
    6262                    writetype => TSTRING,
     
    9797        { name => 'MJD_MIN',    type => 'D',   writetype => TDOUBLE },
    9898        { name => 'MJD_MAX',    type => 'D',   writetype => TDOUBLE },
     99        # new in version 2
    99100        { name => 'RUN_TYPE',   type => '16A', writetype => TSTRING },
     101        { name => 'FWHM_MIN',   type => 'D',   writetype => TDOUBLE },
     102        { name => 'FWHM_MAX',   type => 'D',   writetype => TDOUBLE },
    100103
    101104        { name => 'COMMENT ',   type => '64A', writetype => TSTRING },
     
    326329        pop @colData;
    327330        pop @colData;
     331        pop @colData;
     332        pop @colData;
    328333    }
    329334
     
    346351        }
    347352        # trim leading whitespace from comment
    348         $comment =~ s/^\s+//;
     353        $comment =~ s/^\s+// if $comment;
    349354        if ($comment) {
    350355            if ($comment =~ /#/) {
  • branches/eam_branches/ipp-20130307/pstamp/scripts/pstamp_webrequest.pl

    r29383 r35412  
    55#
    66# The arguments are the command line parameters for the program psmkreq
    7 #
    8 # Unless the argument -list is provided the output is the request id for the resulting request
    9 #
    10 # If -list is the first argument, the request file is built and parsed and the
    11 # the selected "input" uris are listed on stdout.
    127#
    138# Note: Despite the name there nothing particularly web specific about this program.
     
    2318
    2419my $host = hostname();
    25 my $verbose = 1;
     20my $verbose = 0;
    2621my $dbname;
    2722my $dbserver;
     23my $pretend;
     24my $label = 'WEB';
     25my $req_name_prefix = 'web';
     26my $username;
    2827
    2928GetOptions(
    3029    'dbname=s'      =>  \$dbname,
    3130    'dbserver=s'    =>  \$dbserver,
    32     'verbose'       => \$verbose,
     31    'label=s'       =>  \$label,
     32    'username=s'    =>  \$username,
     33    'prefix=s'      =>  \$req_name_prefix,
     34    'pretend'       =>  \$pretend,
     35    'verbose'       =>  \$verbose,
    3336);
    3437
     
    3639
    3740if ($verbose) {
    38     print "\n\n";
    39     print "Starting script $0 on $host\n\n";
     41    print STDERR "\n\n";
     42    print STDERR "Starting script $0 on $host\n\n";
    4043}
    4144
     
    7073# make a request file
    7174my $cur_dir = getcwd();
     75
    7276#print STDERR "cur_dir is $cur_dir\n";
    7377
    74 my $datestr = strftime "%Y%m%d", gmtime;
     78my $datestr = strftime "%Y/%m/%d", gmtime;
    7579my $datedir = "$cur_dir/webreq/$datestr";
    7680if (! -e $datedir ) {
    77     if (!  mkdir $datedir ) {
    78         print STDERR  "failed to create working directory $datedir";
     81    my $rc = system "mkdir -p $datedir";
     82    if ($rc) {
     83        my $status = $rc >> 8;
     84        print STDERR  "failed to create working directory $datedir: $rc $status";
    7985        exit $PS_EXIT_CONFIG_ERROR;
    8086    }
    8187}
    8288
    83 my $request_name = "web_" . get_webreq_num();
     89my $request_name = $req_name_prefix . '_' . get_webreq_num();
    8490my $request_file = "$datedir/$request_name.fits";
    8591{
     
    96102# Queue the request
    97103my $req_id = 0;
    98 {
     104unless ($pretend) {
    99105
    100106    my $command = "$pstamptool -addreq -uri $request_file -ds_id 0";
    101     $command .= " -label WEB";
     107    $command .= " -label $label";
     108    $command .= " -username $username" if $username;
    102109    $command .= " -dbname $dbname" if $dbname;
    103110    $command .= " -dbserver $dbserver" if $dbserver;
     
    109116    }
    110117    $req_id = ${$stdout_buf}[0];
     118    chomp $req_id;
    111119}
    112120
  • branches/eam_branches/ipp-20130307/pstamp/scripts/pstampparse.pl

    r34447 r35412  
    2727my $outdir;
    2828my $product;
    29 my $label;
     29my $label = "";
    3030my $save_temps;
    3131my $no_update;
     
    5757    die "outdir is required"  if !$outdir;
    5858    die "product is required"  if !$product;
     59} else {
     60    $req_id = 0;
     61    $outdir = "nowhere";
     62    $product = "dummy";
    5963}
    6064
     
    8387$pstamptool .= " -dbserver $dbserver" if $dbserver;
    8488
    85 # list_job is a deugging mode
    86 $no_update = 1 if $mode eq "list_job";
     89# If $mode is not queue_job we are using a debugging mode
     90# do not update the database
     91$no_update = 1 if $mode ne "queue_job";
    8792
    8893my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    8994
    9095#
    91 # get the data from the extension header
     96# Read the keywords from the extension header
    9297#
    9398my $fields_output;
    9499{
    95     my $command = "echo $request_file_name | $fields -x 0 EXTNAME EXTVER REQ_NAME ACTION USER EMAIL";
     100    my $command = "echo $request_file_name | $fields -x 0 EXTNAME EXTVER REQ_NAME ACTION EMAIL";
    96101    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    97102        run(command => $command, verbose => $verbose);
    98     # fields doesn't return zero when it succeeds
    99     #unless ($success) {
    100     #    print STDERR @$stderr_buf;
    101     #}
     103
     104    # note fields doesn't return zero when it succeeds.
    102105    $fields_output = join "", @$stdout_buf;
    103106}
    104 my (undef, $extname, $extver, $req_name, $action, $username, $email) = split " ", $fields_output;
     107my (undef, $extname, $extver, $req_name, $action, $email) = split " ", $fields_output;
    105108
    106109# make sure the file contains what we are expecting
    107 # This program shouldn't have been run if the request file is bogus.
    108 # No need to notify the client
    109 my_die("$request_file_name is not a PS1_PS_REQEST", $PS_EXIT_PROG_ERROR) if $extname ne "PS1_PS_REQUEST";
    110 my_die("REQ_NAME not found in $request_file_name", $PS_EXIT_PROG_ERROR)  if (!$req_name);
    111 my_die("wrong EXTVER $extver found in $request_file_name", $PS_EXIT_PROG_ERROR) if ($extver ne "1" and $extver ne "2");
    112 
     110# pstamp_parser_run.pl would not have run this program unless the request file was ok
     111my_die("$request_file_name does not contain EXTNAME\n", $PS_EXIT_PROG_ERROR) if !$extname;
     112my_die("$request_file_name is not a PS1_PS_REQUEST\n", $PS_EXIT_PROG_ERROR) if $extname ne "PS1_PS_REQUEST";
     113my_die("REQ_NAME not found in $request_file_name\n", $PS_EXIT_PROG_ERROR)  if (!$req_name);
     114my_die("wrong EXTVER $extver found in $request_file_name\n", $PS_EXIT_PROG_ERROR) if ($extver ne "1" and $extver ne "2");
     115
     116if ($extver >= 2) {
     117    # 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;
     123    # XXX check for "valid" $email
     124} else {
     125    # for version 1 file the action is process and email is not used
     126    $action = 'PROCESS';
     127    $email = 'null';
     128}
     129
     130print "Request Header Keywords EXTVER: $extver REQ_NAME: $req_name ACTION: $action EMAIL: $email\n";
    113131
    114132# check for duplicate request name
     
    161179    # the output data store's product name
    162180    my $command = "$pstamptool -updatereq -req_id $req_id  -set_name $req_name";
     181    $command .= " -set_username $email" if $email ne 'null';
    163182    $command .= " -set_outProduct $product";
    164183    $command .= " -set_label $label" if $label_changed;
     
    174193
    175194#
    176 # now convert the request table to an array of metadata config docs
     195# now convert the request table to an array of metadatas
    177196#
    178197
     
    191210    my $dtime_request_file = gettimeofday() - $start_request_file;
    192211    print "Time to read and parse request file: $dtime_request_file\n";
    193 
    194 }
    195 
    196 #
    197 # Loop over rows in the request file collecting consecutive rows that have the "same images of interest"
    198 # in the sense that their selection parameters will yield the same "Runs".
    199 # Process the groups of rows together to reduce lookup time and to potentially make multiple
    200 # stamps from the same ppstamp process.
    201 #
    202 my @rowList;
     212}
     213
     214my $nRows = scalar @$rows;
     215print "\n$nRows rows read from request file\n";
     216
     217
    203218my $num_jobs = 0;
    204219my $imageList;
    205220my $stage;
    206 my $need_magic;
    207221foreach my $row (@$rows) {
    208     # santiy check the paramaters
     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    }
     236
     237    # validate the paramaters
    209238    if (!checkRow($row)) {
    210239        # when it enconters an error checkRow adds a fake job with an appropriate error code to the database
     
    216245    $row->{error_code} = 0;
    217246
    218     if (scalar @rowList == 0) {
    219         push @rowList, $row;
    220         next;
    221     }
    222 
    223     my $firstRow = $rowList[0];
    224     if (same_images_of_interest($firstRow, $row)) {
    225         # add this row to the list and move on
    226         push @rowList, $row;
    227         next;
    228     }
    229 
    230     # the images of interest for this new row doesn't match the list.
    231     # process the list ...
    232     $num_jobs += processRows($action, \@rowList);
    233 
    234     # and reset the list to contain just the new row
    235     @rowList = ($row);
    236 }
    237 
    238 # out of rows process the list
    239 if (scalar @rowList > 0) {
    240     $num_jobs += processRows($action, \@rowList);
     247    $num_jobs += processRow($action, $row);
    241248}
    242249
     
    252259    my $row = shift;
    253260
     261    # check validity of the paramters in a request specification
    254262    # If we encounter an error for a particular row add a job with the proper fault code.
     263    # also adjust some paramterers like filter and set defaults for some others
    255264
    256265    my $stage = $row->{IMG_TYPE};
     
    284293    }
    285294
    286 
    287295    my $component = $row->{COMPONENT};
    288296    if (!defined $component or (lc($component) eq "null") or (lc($component) eq "all")) {
     
    314322        return 0;
    315323    }
     324
     325    my $fwhm_min = $row->{FWHM_MIN};
     326    if (!defined $fwhm_min) {
     327        $row->{FWHM_MIN} = 0;
     328    } elsif (!validNumber($fwhm_min)) {
     329        print STDERR "$fwhm_min is not a valid FWHM_MIN\n";
     330        insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
     331        return 0;
     332    }
     333    my $fwhm_max = $row->{FWHM_MAX};
     334    if (!defined $fwhm_max) {
     335        $row->{FWHM_MAX} = 0;
     336    } elsif (!validNumber($fwhm_max)) {
     337        print STDERR "$fwhm_max is not a valid FWHM_MAX\n";
     338        insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
     339        return 0;
     340    }
     341
    316342    my $data_group = $row->{DATA_GROUP};
    317343    if (!defined $data_group) {
     
    363389    }
    364390
    365     # $mode list_uri is a debugging mode (it may used by the http interface)
    366     # if this happens just croak
    367    # my_die("job_type is list_uri but mode is $mode", $PS_EXIT_PROG_ERROR) if ($job_type eq "list_uri") and ($mode ne "list_uri");
    368 
    369 
    370391    if ($req_type eq "bycoord") {
    371392        if (!$skycenter) {
     
    384405    }
    385406
     407
    386408    return 1;
    387409}
     
    392414
    393415    $num_jobs = 1;
     416    return $num_jobs;
     417}
     418
     419sub processRow {
     420    my $action  = shift;
     421    my $row     = shift;
     422
     423    my $num_jobs = 0;
     424
     425    my $project  = $row->{PROJECT};
     426
     427    # note: resolve_project avoids running pstamptool every time by remembering the
     428    # last project resolved
     429    my $proj_hash = resolve_project($ipprc, $project, $dbname, $dbserver);
     430    if (!$proj_hash) {
     431        insertFakeJobForRow($row, 1, $PSTAMP_UNKNOWN_PROJECT);
     432        $num_jobs++;
     433        return $num_jobs;
     434    }
     435    my $image_db   = $proj_hash->{dbname};
     436    my $camera     = $proj_hash->{camera};
     437
     438    my $req_type    = $row->{REQ_TYPE};
     439    my $rownum      = $row->{ROWNUM};
     440
     441    # Since user can get unmagicked data "by coordinate" requests can go back in time
     442    # to dredge unusable data from the "dark days"...
     443    if ($req_type eq 'bycoord' and $row->{IMG_TYPE} ne 'stack' and $row->{MJD_MIN} == 0) {
     444        # ... so unless the user sets mjd_min clamp it to 2009-04-01
     445        # XXX: This value should live in the pstampProject table not be hardcoded here
     446        $row->{MJD_MIN} = 54922;
     447    }
     448
     449    if (($req_type eq 'byskycell') or ($req_type eq 'bycoord')) {
     450        # avoid error from print below if $id isn't needed
     451        $row->{ID} = "" if !$row->{ID};
     452    }
     453   
     454    # Call PS::IPP::PStamp::Job locate_images subroutine to get the images for this
     455    # request specification. An array reference is returned.
     456    my $start_locate = gettimeofday();
     457
     458    print "\nCalling new_locate_images for row: $rownum\n";
     459
     460    $imageList = locate_images_for_row($ipprc, $image_db, $camera, $row, $verbose);
     461
     462    my $dtime_locate = gettimeofday() - $start_locate;
     463    print "Time to locate_images for row $rownum $dtime_locate\n";
     464
     465    my @rowList = ($row);
     466    $num_jobs += queueJobs($action, \@rowList, $imageList);
     467
     468    # if this row slipped through without a job being added add one.
     469    if ($row->{job_num} == 0) {
     470        print "row $row->{ROWNUM} produced no jobs\n";
     471        print STDERR "row $row->{ROWNUM} produced no jobs\n";
     472        my $error_code = $row->{error_code};
     473        $error_code =  $PSTAMP_NO_IMAGE_MATCH if !$error_code;
     474        insertFakeJobForRow($row, ++$row->{job_num}, $error_code);
     475    }
     476
    394477    return $num_jobs;
    395478}
     
    401484
    402485    if ($action eq 'LIST') {
     486        # LIST is not allowed by caller. Can't get here.
    403487        return list_targets($rowList);
    404488    }
     
    420504    }
    421505    my $req_type  = $row->{REQ_TYPE};
    422     $stage        = $row->{IMG_TYPE};
     506    my $stage     = $row->{IMG_TYPE};
    423507    my $id        = $row->{ID};
    424508    my $component = $row->{COMPONENT};
     
    436520    my $image_db   = $proj_hash->{dbname};
    437521    my $camera     = $proj_hash->{camera};
    438     $need_magic    = $proj_hash->{need_magic};
     522    my $need_magic    = $proj_hash->{need_magic};
    439523    # Since user can get unmagicked data "by coordinate" requests can go back in time
    440524    # to dredge unusable data from the "dark days"...
     
    496580    # information required is contained there
    497581
    498     $imageList = locate_images($ipprc, $image_db, \@rowList, $req_type, $stage, $id, $tess_id, $component,
     582    $imageList = locate_images($ipprc, $image_db, $rowList, $req_type, $stage, $id, $tess_id, $component,
    499583                $option_mask, $need_magic, $mjd_min, $mjd_max, $filter, $data_group, $verbose);
    500584
     
    506590    $row->{need_magic} = $need_magic;
    507591
    508     $num_jobs += queueJobs($mode, \@rowList, $imageList);
     592    $num_jobs += queueJobs($action, $rowList, $imageList);
    509593
    510594    # if a row slipped through with no jobs add a faulted one
    511     foreach my $row (@rowList) {
     595    foreach my $row (@$rowList) {
    512596        if ($row->{job_num} == 0) {
    513597            print "row $row->{ROWNUM} produced no jobs\n";
     
    528612    my $image = shift;
    529613    my $need_magic = shift;
    530     my $mode = shift;
     614    my $action = shift;
    531615
    532616    my $rownum = $row->{ROWNUM};
     
    611695    write_params($output_base, $image);
    612696
    613     my $newState = "run";
     697    my $newState = $action eq 'PROCESS' ? "run" : "parsed";
    614698    my $fault = 0;
    615699    my $dep_id;
    616700
    617     queueUpdatesIfNeeded($stage, $image, $option_mask, \$newState, \$fault, \$dep_id);
     701    queueUpdatesIfNeeded($action, $stage, $image, $option_mask, \$newState, \$fault, \$dep_id);
    618702
    619703    my $command = "$pstamptool -addjob  -req_id $req_id -job_type $row->{JOB_TYPE}"
     
    644728sub queueJobs
    645729{
    646     my $mode = shift;
     730    my $action = shift;
    647731    my $rowList = shift;
    648732    my $imageList = shift;
    649733
    650     my $firstRow = $rowList[0];
     734    my $firstRow = $rowList->[0];
    651735    my $stage    = $firstRow->{IMG_TYPE};
    652736    my $job_type = $firstRow->{JOB_TYPE};
     
    656740
    657741    if ($mode eq "list_uri") {
     742        $num_jobs = $imageList ? scalar @$imageList : 0;
     743        print "List of $num_jobs Images selected for row: $firstRow->{ROWNUM}\n";
    658744        foreach my $image (@$imageList) {
    659745            print "$image->{image}\n";
     746            ++$firstRow->{job_num};
    660747        }
    661748    } elsif ($job_type eq "get_image") {
     
    664751        my_die( "error: unexpected number of rows for get_image request: $n", $PS_EXIT_PROG_ERROR) if $n != 1;
    665752
    666         $num_jobs = queueGetImageJobs($firstRow, $imageList, $stage, $need_magic, $mode);
     753        $num_jobs = queueGetImageJobs($firstRow, $imageList, $stage, $need_magic, $action);
    667754
    668755    } else {
     
    692779                my $row = $rowList->[$i];
    693780
    694                 $num_jobs += queueJobForImage($row, $stage, $image, $need_magic, $mode);
     781                $num_jobs += queueJobForImage($row, $stage, $image, $need_magic, $action);
    695782            }
    696783        }
     
    706793    my $stage = shift;
    707794    my $need_magic = shift;
    708     my $mode = shift;
     795    my $action = shift;
    709796
    710797    my $num_jobs = 0;
     
    753840        write_params($output_base, $image);
    754841
    755         my $newState = "run";
     842        my $newState = $action eq 'PROCESS' ? "run" : "parsed";
    756843        my $fault = 0;
    757844        my $dep_id;
    758845
    759         queueUpdatesIfNeeded($stage, $image, $option_mask, \$newState, \$fault, \$dep_id);
     846        queueUpdatesIfNeeded($action, $stage, $image, $option_mask, \$newState, \$fault, \$dep_id);
    760847
    761848        $num_jobs++;
     
    899986sub get_dependent
    900987{
    901     my ($r_jobState, $r_fault, $r_dep_id, $imagedb, $state, $stage, $stage_id, $component, $need_magic) = @_;
     988    my ($action, $r_jobState, $r_fault, $r_dep_id, $imagedb, $state, $stage, $stage_id, $component, $need_magic) = @_;
    902989
    903990    # chipRun's can be in full state if destreaking is necessary
     
    9181005    my $command = "$pstamptool -getdependent -stage $stage -stage_id $stage_id -imagedb $imagedb -component $component -outdir $outdir";
    9191006    $command .= " -need_magic" if $need_magic;
    920 
    921     # compute rlabel for the run.
    922     # XXX: This bit of policy shouldn't be buried so deeply in the code
    923     # For now use one that implies 'postage stamp server' 'update' 'request_label"
    924     my $rlabel = "ps_ud_" . $label if $label;
    925     $command .= " -rlabel $rlabel" if $rlabel;
     1007    $command .= ' -hold' if $action eq 'PREVIEW';
     1008
     1009    if ($label) {
     1010        # compute rlabel for the run.
     1011        # XXX: This bit of policy shouldn't be buried so deeply in the code
     1012        # For now use one that implies 'postage stamp server' 'update' 'request_label"
     1013        my $rlabel = "ps_ud_" . $label;
     1014        $command .= " -rlabel $rlabel";
     1015    }
    9261016
    9271017    if (!$no_update) {
     
    9311021            my $fault = $error_code >> 8;
    9321022            print STDERR "$command failed with fault $fault\n";
    933             if ($fault < 10) {
     1023            if ($fault < $PSTAMP_FIRST_ERROR_CODE) {
    9341024                # pstamptool returns an error if an existing depenent is faulted
    935                 # Set the object to not available even if the fault < 10
     1025                # Set the object to not available even if the fault < $PSTAMP_FIRST_ERROR_CODE
    9361026                # which is nominally a recoverable error in order to keep
    9371027                # the request from faulting (which can be very expensive if
     
    9391029                $fault = $PSTAMP_NOT_AVAILABLE
    9401030            }
    941             if ($fault >= 10) {
     1031            if ($fault >= $PSTAMP_FIRST_ERROR_CODE) {
    9421032                $$r_dep_id = 0;
    9431033                $$r_fault = $fault;
     
    9671057
    9681058sub queueUpdatesIfNeeded {
     1059    my $action = shift;
    9691060    my $stage = shift;
    9701061    my $image = shift;
     
    9731064    my $r_fault = shift;
    9741065    my $r_dep_id = shift;
     1066
     1067    my $need_magic = 0;
    9751068
    9761069    if ($stage ne 'raw') {
     
    10161109                    # set up to queue an update run
    10171110                    my $require_magic = ($need_magic or $image->{magicked});
    1018                     get_dependent(\$$r_newState, \$$r_fault, $r_dep_id, $image->{imagedb},
     1111                    get_dependent($action, \$$r_newState, \$$r_fault, $r_dep_id, $image->{imagedb},
    10191112                        $run_state, $stage, $image->{stage_id}, $image->{component}, $require_magic );
    10201113                }
     
    10701163    my $fault = shift;
    10711164
    1072     carp $msg;
     1165    print STDERR $msg;
    10731166
    10741167    # we don't fault the request here pstamp_parser_run.pl handles that if necessary
Note: See TracChangeset for help on using the changeset viewer.