IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 19265


Ignore:
Timestamp:
Aug 28, 2008, 2:06:45 PM (18 years ago)
Author:
bills
Message:

remove reference to obsolete program

Location:
trunk/pstamp/scripts
Files:
4 edited

Legend:

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

    r19221 r19265  
    99use Pod::Usage qw( pod2usage );
    1010
     11use Time::Local;
    1112use Sys::Hostname;
    1213use IPC::Cmd 0.36 qw( can_run run );
     
    8283    }
    8384
    84 
    85                         # this function is PStamp::RequestFile::read_request_file
     85    if (! -e $req_file ) {
     86        print STDERR "request file $req_file is missing\n";
     87        stop_request($req_id, $PS_EXIT_CONFIG_ERROR, $dbname);
     88        exit  $PS_EXIT_CONFIG_ERROR;
     89    }
     90
     91    # this function is PStamp::RequestFile::read_request_file
    8692    my ($header, $rows) = read_request_file($req_file);
    8793
    88     die "failed to read request_file $req_file" if !$header or !$rows;
     94    if (!$header or !$rows) {
     95        # Since a request got queued, the request file must have been readable at some
     96        # point
     97        print STDERR "failed to read request_file $req_file"
     98        stop_request($req_id, $PS_EXIT_CONFIG_ERROR, $dbname);
     99        exit  $PS_EXIT_CONFIG_ERROR;
     100    }
    89101
    90102    # at this point we need to find out what kind of request type it is and
     
    144156        my $rownum = $job->{rownum};
    145157        my $fault = $job->{fault};
    146 
    147         my $row_info = get_request_info($rows, $rownum);
    148         # rownum fault img_name job_id
     158        my $exp_id = $job->{exp_id};
     159
     160        # XXX: get the image_db from a table in the database, or maybe save it in the job
     161        my $image_db = "ps_simtest";     
     162        my $exp_info = get_exposure_info($image_db, $exp_id);
     163
     164        # unless $exp_id is null (e.g. stack images) get the metadata for this exposure
     165        my ($row, $req_info) = get_request_info($rows, $rownum) if $exp_id;
     166
    149167        if (($job_type eq "stamp") || ($job_type eq "get_image")) {
    150168            my $jreglist = "$out_dir/reglist$job_id";
     
    158176                    my ($img_name, undef) = split '\|', $line;
    159177
    160                     # XXX TODO: need to get these from somewhere. Maybe the stamp.
    161                     #
    162                     # ra_deg and dec_deg are the coordinates of center of the stamp
    163                     # the rest of the metadata come from the original FPA.
    164                     # we could get these out of the rawExp table in the database....
    165                     #
    166                     # Much of those data do not apply to stamps from Stack images.
    167                     my ($ra_deg, $dec_deg, $mjd_obs, $ra_obs, $dec_obs, $filter, $exp_time, $fpa_id) =
    168                         (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
    169 
    170178                    # add line to the table definition file
    171179                    print $tdf "$rownum|$fault|$img_name|$job_id|";
    172                     print $tdf "$ra_deg|$dec_deg|$mjd_obs|$ra_obs|$dec_obs|$filter|$exp_time|$fpa_id|";
    173                     print $tdf "$row_info";
     180
     181                    # ra_deg and dec_deg are the coordinates of center of the stamp
     182                    #
     183                    # XXX  we need to get the center coordinate of the stamp.
     184                    # if request used -skycenter then we have it in the request info
     185
     186                    print $tdf "0.0|0.0|";
     187                    print $tdf "$exp_info|";
     188                    print $tdf "$req_info|";
    174189                    print $tdf "\n";
    175190                }
     
    178193                print STDERR "no reglist file for job $job_id\n" if $verbose;
    179194                print $tdf "$rownum|$fault|0|$job_id|";
    180                 print $tdf "0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|\n";
     195                print $tdf "0|0|";       # center of (non-existent) stamp
     196                print $tdf "$exp_info|";
     197                print $tdf "$req_info|";
    181198            }
    182199        } else {
    183200            # XXX do list jobs
     201            # we can probably arange things to use the code as above and skip the fileset registration
    184202            print STDERR "Unknown jobType: $job_type";
    185203            next;
     
    226244    }
    227245}
     246
    228247sub stop_request {
    229248    my $req_id = shift;
     
    252271    $rowinfo   .= "$row->{ID}|$row->{CLASS_ID}|$row->{OPTION_MASK}|$row->{MJD_MIN}|$row->{MJD_MAX}|";
    253272    $rowinfo   .= "$row->{REQFILT}|$row->{COORD_MASK}|$row->{CENTER_X}|$row->{CENTER_Y}|";
    254     $rowinfo   .= "$row->{WIDTH}|$row->{HEIGHT}|";
    255 
    256     return $rowinfo;
    257 }
     273    $rowinfo   .= "$row->{WIDTH}|$row->{HEIGHT}";
     274
     275    return ($row, $rowinfo);
     276}
     277
     278sub get_exposure_info {
     279    my $image_db= shift;
     280    my $exp_id = shift;
     281
     282    if (!$exp_id) {
     283        # no exposure id just return zeros
     284        # XXX: we could put a value in for filter, but we don't have a good place to find it
     285
     286        #"$mjd_obs|$ra_obs|$dec_obs|$filter|$exp_time|$fpa_id";
     287        return "0|0|0|0|0|0";
     288    }
     289
     290    my $regtool = can_run('regtool') or (warn "Can't find regtool" and $missing_tools = 1);
     291    if ($missing_tools) {
     292        warn("Can't find required tools.");
     293        exit ($PS_EXIT_CONFIG_ERROR);
     294    }
     295
     296    my $command = "$regtool -processedexp -dbname $image_db -exp_id $exp_id";
     297
     298    # run the tool and parse the output
     299    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     300                run(command => $command, verbose => $verbose);
     301    unless ($success) {
     302        # not sure if we should die here
     303        die "cannot get exposure information for $exp_id from image database $image_db";
     304    }
     305    my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     306
     307    my $output = join "", @$stdout_buf;
     308    if (!$output) {
     309        print STDERR "no output returned from $command\n" if $verbose;
     310        return undef;
     311    }
     312    my $metadata = $mdcParser->parse($output) or die("Unable to parse metdata config doc");
     313
     314    my $exposures = parse_md_list($metadata);
     315    my $numExp = @$exposures;
     316
     317    die "unexpected number of exposures $numExp found for exp_id: $exp_id in DB: $image_db" if $numExp != 1;
     318   
     319    my $exp = $exposures->[0];
     320
     321    #my $info = "$mjd_obs|$ra_obs|$dec_obs|$filter|$exp_time|$fpa_id";
     322
     323    use constant RADIANS_TO_DEGREES => 90. / atan2(1, 0);
     324    my $ra_deg   = $exp->{ra} * RADIANS_TO_DEGREES;
     325    my $decl_deg = $exp->{decl} * RADIANS_TO_DEGREES;
     326    my $mjd_obs = dateobs_to_mjd($exp->{dateobs}, $exp->{exp_time});
     327
     328    my $info = "$mjd_obs|$ra_deg|$decl_deg|$exp->{filter}|$exp->{exp_time}|$exp->{exp_name}";
     329           
     330    return $info;
     331}
     332
     333sub dateobs_to_mjd {
     334    my $dateobs = shift;
     335    my $exp_time = shift;
     336
     337    # dateobs is in format: 1970-01-01T00:00:00
     338
     339    my ($date, $time) = split "T", $dateobs;
     340    my ($year, $mon, $day) = split "-", $date;
     341    my ($hr, $min, $sec) = split ":", $time;
     342
     343    my $ticks = timegm($sec, $min, $hr, $day, $mon-1, $year-1900);
     344
     345    $ticks += $exp_time / 2.0;
     346
     347    return 40587.0 + ($ticks/86400.);
     348}
  • trunk/pstamp/scripts/pstamp_parser_run.pl

    r19221 r19265  
    33### pstampparser_run.pl
    44###     Run the request parser for a given request id
     5### This script should be called request_parser.pl since it handles more than postage
     6### stamp requests
    57###
    6 
    7 #XXX see notes about error handling
    88
    99use warnings;
     
    172172    if (! -d $outProductDir);
    173173
    174 
    175 # run the appropriate parse command to parse the queue the jobs for this request
    176 # first check the extension header to find the EXTNAME
    177 my $request_type = find_request_type($uri);
    178 
    179 print STDERR "request_type for $req_id is $request_type\n" if $verbose;
    180 
    181174my $parse_cmd;
     175my $request_type;
    182176my $reqType;    # for the database
    183 if ($request_type eq "PS1_PS_REQUEST") {
    184     $reqType = 'pstamp';
    185     $parse_cmd = $pstampparse;
    186 } elsif ($request_type eq "MOPS_DETECTABILITY_QUERY") {
    187     $reqType = 'dquery';
    188     $parse_cmd = $dqueryparse;
     177
     178if (-r $uri) {
     179    # run the appropriate parse command to parse the queue the jobs for this request
     180    # first check the extension header to find the EXTNAME
     181    $request_type = find_request_type($uri);
     182
     183    if ($request_type) {
     184        print STDERR "request_type for $req_id is $request_type\n" if $verbose;
     185        if ($request_type eq "PS1_PS_REQUEST") {
     186            $reqType = 'pstamp';
     187            $parse_cmd = $pstampparse;
     188        } elsif ($request_type eq "MOPS_DETECTABILITY_QUERY") {
     189            $reqType = 'dquery';
     190            $parse_cmd = $dqueryparse;
     191        } else {
     192            print STDERR "Unknown request type $request_type found in $uri";
     193        }
     194    } else {
     195        print STDERR "No EXTNAME found keyword in $uri";
     196    }
     197} else {
     198    if (-e $uri) {
     199        print STDERR "Request file $uri is not readable";
     200    } else {
     201        print STDERR "Request file $uri does not exist";
     202    }
    189203}
    190204
    191205if (!$parse_cmd) {
    192     print STDERR "No EXTNAME found in $uri" if !$request_type;
    193     print STDERR "Unknown request type $request_type found in $uri";
     206    # can't go any farther, set fault and set request state to run
     207    # request_finish.pl will clean up, perhaps notifiying the operator of the input data store
     208    # that they sent us a request file that we don't understand
    194209
    195210    my $command = "$pstamptool -updatereq -req_id $req_id -state run";
     
    211226{
    212227    my $error_file_name = "$workdir/parse_error.txt";
    213     # get rid of any error file from previous run
     228    # get rid of any error file from previous attempt to parse this request
    214229    unlink $error_file_name if (-e $error_file_name);
    215230
     
    219234
    220235    # save the contents of stderr (if any) to a file. This is relevant if
    221     # the file parsed properl but one of the rows in the request file generated an error
     236    # the file was parseable but one or more of the rows in the request file generated an error
    222237    my $errbuf = join "", @$stderr_buf;
    223238    if ($errbuf) {
     
    258273exit 0;
    259274
     275
    260276sub find_request_type {
    261277    # find the EXTNAME in the input fits table
    262     # TODO: do this right handling errors etc.
    263278    my $file_name = shift;
    264279    my $out = `echo $file_name | fields -x 0 EXTNAME`;
    265280
    266     # output from fields is filename value
    267     my ($dummy, $extname) = split " ", $out;
    268 
    269     return $extname;
    270 }
     281    if ($out) {
     282        # output from fields is filename value
     283        my ($dummy, $extname) = split " ", $out;
     284
     285        return $extname;
     286    } else {
     287        return undef;
     288    }
     289}
  • trunk/pstamp/scripts/pstamp_queue_requests.pl

    r18623 r19265  
    2222    'verbose'       =>  \$verbose,
    2323    'dbname=s'      =>  \$dbname,
    24     'limit=s'       =>  \$limit,
     24    'limit=i'       =>  \$limit,
    2525);
    2626
     
    119119        my $out_buf = join("", @$stdout_buf);
    120120        # split raw output into lines
    121         # XXX: why do I think that i need the map?
    122         #my @lines = map {split "\n"} $raw_output;
    123121        @lines = split /^/, $out_buf;
    124122    }
     
    127125    # each line contains a fileset
    128126    #
    129     # XXX: we probably should set a limit on the number of these we process
    130     # otherwise this could take a long time and the task could time out
     127
     128    # number that we've processed
     129    my $numFilesets = 0;
    131130    foreach my $line (@lines) {
    132131        # parse the line into fields split by whitespace
    133132        my ($uri, $fs_name, $date, $type) = split " ", $line;
    134133
     134        # skip comment lines
    135135        next if ( $uri =~ /^#.*/);
     136
     137        $numFilesets++;
    136138
    137139        my @files;
     
    163165                my $command = "$pstamptool -addreq -uri $req_uri -ds_id $ds_id";
    164166                $command .= " -dbname $dbname" if $dbname;
     167
    165168                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    166169                        run(command => $command, verbose => $verbose);
    167                     unless ($success) {
    168                         # XXX: what do we do now?
    169                         die("Unable to perform $command: $error_code");
    170                     }
     170
     171                unless ($success) {
     172                    die("Unable to perform $command: $error_code");
     173                }
    171174            }
    172             $lastFileset = $fs_name;
    173175        }
     176        $lastFileset = $fs_name;
     177        last if ($numFilesets >= $limit);
    174178    }
    175179
    176180    ## now update the last_fileset column in pstampDataStore
    177     ## XXX: we should probably do this before we process the fileset. Otherwise
    178     ## if we get an error from pstamptool we'll get stuck processing it over and over.
     181    ## XXX: we should perhaps do this while processing each fileset so that if a later
     182    ## one has an error we don't get repeats.
     183
    179184    if ($lastFileset) {
    180185        # print "last fileset: $lastFileset\n";
  • trunk/pstamp/scripts/pstampparse.pl

    r19224 r19265  
    5353
    5454my $pstamptool  = can_run('pstamptool')  or (warn "Can't find pstamptool"  and $missing_tools = 1);
    55 my $locateimages = can_run('locateimages') or (warn "Can't find locateimages" and $missing_tools = 1);
    5655my $pstampdump  = can_run('pstampdump') or (warn "Can't find pstampdump" and $missing_tools = 1);
    5756my $fields  = can_run('fields') or (warn "Can't find fields" and $missing_tools = 1);
Note: See TracChangeset for help on using the changeset viewer.