IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18985


Ignore:
Timestamp:
Aug 8, 2008, 3:47:34 PM (18 years ago)
Author:
bills
Message:

Major re-work to get image data from the database. Supports
looking up mask, and weight files and getting req_id for all
requests (except for stack imgages) not done yet

File:
1 edited

Legend:

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

    r18743 r18985  
    1111use Sys::Hostname;
    1212use Getopt::Long qw( GetOptions );
     13use PStamp::RequestFile qw( :standard );
     14use PStamp::Job qw( :standard );
    1315
    1416my $verbose;
     
    1921my $out_dir;
    2022my $product;
    21 
    22 # values for COORD_MASK
    23 use constant PSTAMP_CENTER_IN_PIXELS => 1;
    24 use constant PSTAMP_RANGE_IN_PIXELS  => 2;
    25 
    26 # values for OPTION_MASK
    27 use constant PSTAMP_SELECT_IMAGE  => 1;
    28 use constant PSTAMP_SELECT_MASK   => 2;
    29 use constant PSTAMP_SELECT_WEIGHT => 4;
    3023
    3124GetOptions(
     
    4033
    4134die "invalid mode '$mode'" unless ($mode eq "list_uri") or ($mode eq "list_job") or ($mode eq "queue_job");
    42 die "req_id is required"   if (!defined($req_id) && ($mode ne "list_uri"));
    4335die "file is required"     if !defined($request_file_name);
    44 die "out_dir is required"  if !defined($out_dir);
    45 die "product is required"  if !defined($product);
    46 
     36
     37if ($mode ne "list_uri") {
     38    die "req_id is required"   if !$req_id;
     39    die "out_dir is required"  if !$out_dir;
     40    die "product is required"  if !$product;
     41}
    4742
    4843use IPC::Cmd 0.36 qw( can_run run );
     
    5247use PS::IPP::Metadata::List qw( parse_md_list );
    5348
    54 use PS::IPP::Config qw($PS_EXIT_SUCCESS
    55                        $PS_EXIT_UNKNOWN_ERROR
    56                        $PS_EXIT_SYS_ERROR
    57                        $PS_EXIT_CONFIG_ERROR
    58                        $PS_EXIT_PROG_ERROR
    59                        $PS_EXIT_DATA_ERROR
    60                        $PS_EXIT_TIMEOUT_ERROR
    61                        metadataLookupStr
    62                        metadataLookupBool
    63                        caturi
    64                        );
    65 
     49use PS::IPP::Config qw( :standard );
    6650my $ipprc = PS::IPP::Config->new(); # IPP Configuration
    6751
     
    10286die "wrong EXTVER $extver found in $request_file_name" if ($extver ne "1");
    10387
    104 $out_dir .= "/$req_name";
    105 if (! -e $out_dir ) {
    106     mkdir $out_dir or die "cannot create output directory $out_dir";
    107 } elsif (! -d $out_dir ) {
    108     die "output fileset directory $out_dir exists but is not a directory";
    109 }
    110 
    111 {
    112     my $command = "$pstamptool -processedreq -req_id $req_id -name $req_name -outProduct $product";
    113     $command .= " -dbname $dbname";
     88if ($out_dir) {
     89    $out_dir .= "/$req_name";
     90    if (! -e $out_dir ) {
     91        mkdir $out_dir or die "cannot create output directory $out_dir";
     92    } elsif (! -d $out_dir ) {
     93        die "output fileset directory $out_dir exists but is not a directory";
     94    }
     95}
     96
     97if ($req_id) {
     98    my $command = "$pstamptool -processedreq -req_id $req_id  -name $req_name";
     99    $command .= " -outProduct $product";
     100    $command .= " -dbname $dbname" if $dbname;
    114101    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    115102        run(command => $command, verbose => $verbose);
     
    158145    $stamp_name = "" if $stamp_name eq "null";
    159146   
    160 
    161     # XXX: TODO: don't die in this loop. If we encounter an error add a job with the proper fault
    162     # code
    163     # todo this needs some implementation work
     147    # XXX: TODO: sanity check all parameters
     148
     149    # XXX: TODO: We shouldn't just die in this loop.
     150    # If we encounter an error for a particular row
     151    # add a job with the proper fault code. If there is a db or config error we should probably just
     152    # trash the request.
    164153    die "job_type is list_uri but mode is $mode" if ($job_type eq "list_uri") and ($mode ne "list_uri");
    165154
    166     # TODO: sanity check all arguments
    167 
    168     my ($image_db, $lookup_class_id ) = resolve_project($project, $img_type, $class_id);
     155
     156    my ($image_db, $lookup_class_id, $camera, $magic_required ) = resolve_project($project, $img_type, $class_id);
    169157
    170158    my $roi_string;
    171159    # XXX we're depending on other code to insure valid values for roi components
    172     # this is checked in pstamprequest and ppstamp
    173     # I should check here to but not today
     160    # this is checked in and ppstamp but I should check here so that we don't get that far,
     161    # but not today
    174162    if ($x && ($x ne "null") && $y && ($y ne "null") && $w && ($w ne "null") && $h && ($h ne "null")) {
    175         if ($coord_mask & PSTAMP_CENTER_IN_PIXELS) {
     163        if ($coord_mask & $PSTAMP_CENTER_IN_PIXELS) {
    176164            $roi_string = "-pixcenter $x $y";
    177165        } else {
    178166            $roi_string = "-skycenter $x $y";
    179167        }
    180         if ($coord_mask & PSTAMP_RANGE_IN_PIXELS) {
     168        if ($coord_mask & $PSTAMP_RANGE_IN_PIXELS) {
    181169            $roi_string .= " -pixrange $w $h";
    182170        } else {
     
    193181        die "region of interest is required for request type bycoord" if !defined($roi_string) ;
    194182        die "center must be specified in sky coordintes for bycoord"
    195             if ($coord_mask & PSTAMP_CENTER_IN_PIXELS);
    196         # replace the id with center coordinates
    197         $id = "$x $y";
    198     }
    199 
    200     # XXX: replace the invokcation of the hacked locateimages with a new ippTool that finds
    201     # images/runs and prints out the uri and other metadata as a metadata config doc
    202 
    203     my $command = "$locateimages -dbname $image_db -$req_type $img_type $id $lookup_class_id";
    204     $command .= " -mjd_min $mjd_min" if ($mjd_min);
    205     $command .= " -mjd_max $mjd_max" if ($mjd_max);
    206 
    207     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    208             run(command => $command, verbose => $verbose);
    209     unless ($success) {
    210         print STDERR @$stderr_buf;
    211         exit 1;
    212     }
    213     my @uris = split "^", join("", @$stdout_buf);
     183            if ($coord_mask & $PSTAMP_CENTER_IN_PIXELS);
     184    }
     185
     186    # Call PStamp::Job's locate_images routinte to get the parameters for this request specification
     187    my $images = locate_images($ipprc, $image_db, $req_type, $img_type, $id, $lookup_class_id,
     188            $x, $y, $mjd_min, $mjd_max, $filter);
    214189
    215190    if ($mode eq "list_uri") {
    216         foreach my $uri (@uris) {
    217             print $uri;
     191        foreach my $image (@$images) {
     192            print "$image->{image}\n";
    218193        }
    219194    } elsif ($job_type eq "get_image") {
     195        # XXX TODO: Get rid of this block and use the same code as the stamp jobs
     196        # XXX This doesn't work to get the mask and weight images
    220197        my $listfile = "$out_dir/filelist";
    221198
     
    223200            or die "failed to open file list: $listfile while parsing get_image request $req_id";
    224201
    225         # XXX TODO: how do we expand URIS to include wt and mk images
    226         # I've been assuming that ppstamp would just know what to do based on flags and file rules.
    227         # Actually if we change the code that lists images to list outputBase's instead we can
    228         # translate the rules here
    229         foreach my $uri (@uris) {
    230             chomp $uri;
    231             print LISTFILE "$uri|$img_type\n";
     202        foreach my $image (@$images) {
     203            print LISTFILE "$image->{image}|$img_type\n";
    232204        }
    233205        close LISTFILE;
    234         $command = "$pstamptool -dbname $dbname -addjob -req_id $req_id -job_type get_image"
     206        my $command = "$pstamptool -addjob -req_id $req_id -job_type get_image"
    235207                    . " -uri $listfile -outputBase $out_dir -rownum $rownum";
     208        $command .= " -dbname $dbname" if $dbname;
    236209        if ($mode eq "list_job") {
    237210            print "$command\n";
     
    249222        $args .= " -class_id $class_id" if ($class_id and ($class_id ne "null"));
    250223
    251 #        my $numJobs = @uris;
    252         my $num = 0;
    253         foreach my $uri (@uris) {
    254             chomp $uri;
    255 
    256             $num++;
    257             my $output_base = "$out_dir/${rownum}_${num}";
    258             $output_base .= "_${stamp_name}" if $stamp_name;
     224        # sequence number for the the job for a request spec. Not to be confused with job_id
     225        my $job_num = 0;
     226
     227        # XXX for raw and chip level images and class_id "null" if there are multiple images
     228        # use -list instead of -file
     229        foreach my $image (@$images) {
     230            my $uri = $image->{image};
     231
     232            $job_num++;
     233
     234            my $output_base = "$out_dir/${rownum}_${job_num}";
     235
     236            # By commenting out the next line, I hereby drop the use of STAMP_NAME
     237            # $output_base .= "_${stamp_name}" if $stamp_name;
     238
     239            # add astrometry file for raw and chip images if one is available
     240            if (($img_type eq "chip") || ($img_type eq "raw")) {
     241                $args .= " -astrom $image->{astrom}" if $image->{astrom};
     242            }
     243
     244            if ($option_mask & $PSTAMP_SELECT_IMAGE) {
     245                $args .= " -mask $image->{mask}";
     246            }
     247            if ($option_mask & $PSTAMP_SELECT_WEIGHT) {
     248                $args .= " -weight $image->{weight}";
     249            }
     250
     251            # XXX sounds like magic will be handled outside of the postage stamp server
     252            #if ($magic_required) {
     253            #    die "no magic mask available" if ! $image->{magic_mask};
     254            #    $args .= " -magic_mask $image->{magic_mask}"
     255            #}
     256
    259257
    260258            # XXX: TODO: here is where we need to check whether or not the source inputs still exist
    261259            # and if not, queue a regeneration job and set the job state appropriately.
    262             # a simpler but slower option would be to set state to 'staged' and have a new task do
    263             # the checking. This would add latency to the processing when the images are available.
    264             # just share code.
    265 
    266             $command = "$pstamptool -dbname $dbname -addjob -req_id $req_id -job_type $job_type"
     260
     261
     262#            # XXX TEMPORARY HACK won't work in general don't commit this
     263#            if (($img_type eq "chip") && ($image_db eq "gpc1")) {
     264#                my $astrom = $uri;
     265#                $astrom =~ s/.ch.fits/.smf/;
     266#                if ( -e $astrom ) {
     267#                    $astrom_args .= " -astrom $astrom";
     268#                }
     269#            }
     270
     271            my $command = "$pstamptool -addjob -req_id $req_id -job_type $job_type"
    267272                . " -uri $uri -outputBase $output_base -args '$args' -rownum $rownum";
     273            $command .= " -dbname $dbname" if $dbname;
     274
    268275            if ($mode eq "list_job") {
    269276                # this is a debugging mode, just print the pstamptool that would have run
     
    288295exit 0;
    289296
     297
    290298# resolve_project()
    291299# get project specific information
     
    308316    my $ret_dbname;
    309317    my $ret_class_id;
     318    my $ret_inst;
     319    my $ret_magic;
     320    my $ret_camera;
    310321
    311322    if ($project_name eq "megacam-mops") {
    312323        $ret_dbname = "mops";
    313324        $ret_class_id = "null";
     325        $ret_camera = "MEGACAM";
     326        $ret_magic = 0;
    314327    } elsif ($project_name eq "simtest") {
    315328        $ret_dbname = "simtest";
    316329        $ret_class_id = "null";
     330        $ret_camera = "SIMTEST";
     331        $ret_magic = 0;
    317332    } elsif ($project_name eq "gpc1") {
    318333        $ret_dbname = "gpc1";
    319334        $ret_class_id = $class_id;
     335        $ret_camera = "GPC1";
     336        $ret_magic = 0; # switch this to 1 when we're ready
    320337    } else {
    321338        die "unknown project $project_name";
     
    327344    }
    328345
    329     return ($ret_dbname, $ret_class_id);
    330 }
     346    return ($ret_dbname, $ret_class_id, $ret_camera, $ret_magic);
     347}
Note: See TracChangeset for help on using the changeset viewer.