IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 24921


Ignore:
Timestamp:
Jul 24, 2009, 2:45:59 PM (17 years ago)
Author:
bills
Message:

when parsing postage stamp request files run dvoImagesAtCoords to
narrow down the images that contain the center pixel. This prevents
queuing many many failing jobs

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/getstar/src/dvoImagesAtCoords.c

    r24914 r24921  
    104104  for (i = 0; i < Nmatches; i++) {
    105105    int N = matches[i];
    106     fprintf (stdout, "%d (%lf, %lf)  :  %s\n", id, ra, dec, dbImages[N].name);
     106
     107    char *name;
     108    // output of lookup is filename[class_id.hdr] for astrometry files
     109    char *left_bracket = rindex(dbImages[N].name, '[');
     110    if (left_bracket) {
     111        name = strdup(left_bracket + 1);
     112        // zap the .hdr]
     113        char *dot = index(name, '.');
     114        if (dot) {
     115            *dot = 0;
     116        }
     117    } else {
     118        name = dbImages[N].name;
     119    }
     120    fprintf (stdout, "%d %lf %lf %s\n", id, ra, dec, name);
    107121  }
    108122 
  • trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm

    r24831 r24921  
    2424use PS::IPP::Metadata::List qw( parse_md_list );
    2525use PS::IPP::Config qw( :standard );
     26use Carp;
    2627
    2728### my @images = locate_images($image_db, $req_type, $img_type, $id, $component,
     
    121122    my $command;
    122123    my $id_opt;     # option for the lookup
     124    my $image_name;
    123125    my $mask_name;
    124126    my $weight_name;
     
    130132
    131133    # special class_id value "null" means ignore
    132     if ($component eq "null") {
     134    if ($component and ($component eq "null")) {
    133135        $component = undef;
    134136    }
     
    146148        $command .= " -class_id $class_id" if $class_id;
    147149        $id_opt = "-chip_id";
     150        $image_name   = "PPIMAGE.CHIP";
    148151        $mask_name    = "PPIMAGE.CHIP.MASK";
    149152        $weight_name  = "PPIMAGE.CHIP.VARIANCE";
     
    156159        $command .= " -skycell_id $skycell_id" if $skycell_id;
    157160        $id_opt = "-warp_id";
     161        $image_name   = "PSWARP.OUTPUT";
    158162        $mask_name    = "PSWARP.OUTPUT.MASK";
    159163        $weight_name  = "PSWARP.OUTPUT.VARIANCE";
     
    164168        $command .= " -skycell_id $skycell_id" if $skycell_id;
    165169        $id_opt = "-diff_id";
     170        $image_name  = "PPSUB.OUTPUT";
    166171        $mask_name   = "PPSUB.OUTPUT.MASK";
    167172        $weight_name = "PPSUB.OUTPUT.VARIANCE";
     
    171176        $id_opt = "-stack_id";
    172177
     178        $image_name  = "PPSTACK.OUTPUT";
    173179        $mask_name   = "PPSTACK.OUTPUT.MASK";
    174180        $weight_name = "PPSTACK.OUTPUT.VARIANCE";
     
    225231            $ipprc->define_camera($camera);
    226232        }
    227         my $out = {};
    228         $out->{exp_id} = $image->{exp_id};
    229         $out->{exp_name} = $image->{exp_name};
     233        my $out = $image;
     234        # if uri is nil this will get overridded below
    230235        $out->{image}  = $image->{uri};
    231         $out->{state}  = $image->{state}; # state is undef for rawExp, but that's ok
    232         if ($set_class_id) {
    233             $class_id = $image->{class_id};
    234             $out->{class_id} = $class_id;
    235         }
     236#        $out->{exp_id} = $image->{exp_id};
     237#        $out->{exp_name} = $image->{exp_name};
     238#        $out->{state}  = $image->{state}; # state is undef for rawExp, but that's ok
     239#        if ($set_class_id) {
     240#            $class_id = $image->{class_id};
     241#            $out->{class_id} = $class_id;
     242#        }
    236243
    237244        # find the mask and weight images
    238245        if ($base) {
     246            $out->{image}  = $ipprc->filename($image_name,   $base, $class_id) if $image_name;
    239247            $out->{mask}   = $ipprc->filename($mask_name,   $base, $class_id) if $mask_name;
    240248            $out->{weight} = $ipprc->filename($weight_name, $base, $class_id) if $weight_name;
    241249        }
    242         $out->{camera} = $camera;
     250#        $out->{camera} = $camera;
    243251
    244252        $out->{astrom} = find_astrometry($ipprc, $image_db, $image, $verbose) if $want_astrom;
     
    539547# resolve_project()
    540548# get project specific information
     549my $last_project = "";
    541550sub resolve_project {
    542551    my $ipprc = shift;
    543552    my $project_name = shift;
     553
     554    if (!$project_name) {
     555        carp ("project is not defined");
     556        return undef;
     557    }
     558
     559    if ($project_name eq $last_project) {
     560        return $last_project;
     561    }
     562
    544563    my $dbname = shift;
    545564    my $dbserver = shift;
    546     die "project is not defined" if !$project_name;
    547565
    548566    my $verbose = 0;
     
    575593    my $proj_hash = parse_md_fast($mdcParser, $output);
    576594
    577     return $proj_hash->[0];
     595    $last_project = $proj_hash->[0];
     596
     597    return $last_project;
    578598}
    5795991;
  • trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/RequestFile.pm

    r23266 r24921  
    2626
    2727
     28# these values need to match the ones in pstamp/src/pstamp.h
    2829our $PSTAMP_CENTER_IN_PIXELS = 1;
    2930our $PSTAMP_RANGE_IN_PIXELS  = 2;
  • trunk/pstamp/scripts/pstampparse.pl

    r24855 r24921  
    1313use PS::IPP::PStamp::RequestFile qw( :standard );
    1414use PS::IPP::PStamp::Job qw( :standard );
     15use File::Temp qw(tempfile);
    1516
    1617my $verbose;
     
    2223my $out_dir;
    2324my $product;
     25my $save_temps;
     26my $no_update;
    2427
    2528GetOptions(
     
    3235    'dbserver=s'=>  \$dbserver,
    3336    'verbose'   =>  \$verbose,
     37    'save-temps'=>  \$save_temps,
     38    'no-update' =>  \$no_update,
    3439);
    3540
     
    5661my $pstamptool  = can_run('pstamptool')  or (warn "Can't find pstamptool"  and $missing_tools = 1);
    5762my $pstampdump  = can_run('pstampdump') or (warn "Can't find pstampdump" and $missing_tools = 1);
     63my $dvoImagesAtCoords  = can_run('dvoImagesAtCoords') or (warn "Can't find dvoImagesAtCoords" and $missing_tools = 1);
    5864my $fields  = can_run('fields') or (warn "Can't find fields" and $missing_tools = 1);
    5965
     
    6268    exit ($PS_EXIT_CONFIG_ERROR);
    6369}
     70
     71$no_update = 1 if $mode eq "list_job";
    6472
    6573my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
     
    8795die "wrong EXTVER $extver found in $request_file_name" if ($extver ne "1");
    8896
    89 if ($req_id) {
     97if ($req_id and !$no_update) {
    9098    my $command = "$pstamptool -updatereq -req_id $req_id  -name $req_name";
    9199    $command .= " -outProduct $product";
     
    117125}
    118126
     127my @rowList;
    119128my $num_jobs = 0;
     129my $imageList;
     130my $stage;
     131my $need_magic;
    120132foreach my $row (@$rows) {
    121     my $rownum   = $row->{ROWNUM};
    122     my $job_type = $row->{JOB_TYPE};
    123     my $project  = $row->{PROJECT};
    124     my $req_type = $row->{REQ_TYPE};
    125     my $img_type = $row->{IMG_TYPE};
    126     my $id       = $row->{ID};
    127     my $class_id = $row->{CLASS_ID};
    128     my $filter   = $row->{REQFILT};
    129     my $mjd_min = $row->{MJD_MIN};
    130     my $mjd_max = $row->{MJD_MAX};
    131     my $x = $row->{CENTER_X};
    132     my $y = $row->{CENTER_Y};
    133     my $w = $row->{WIDTH};
    134     my $h = $row->{HEIGHT};
    135     my $coord_mask = $row->{COORD_MASK};
    136     my $option_mask= $row->{OPTION_MASK};
    137 
    138     $class_id = "" if ($class_id eq "null" or $class_id eq "all");
    139    
    140133    # XXX: TODO: sanity check all parameters
    141134
     
    144137    # add a job with the proper fault code. If there is a db or config error we should probably just
    145138    # trash the request.
     139
     140    my $rownum   = $row->{ROWNUM};
     141    my $job_type = $row->{JOB_TYPE};
     142   
     143    # parameters that select the images of interest
     144    my $project  = $row->{PROJECT};
     145    my $req_type = $row->{REQ_TYPE};
     146    $stage = $row->{IMG_TYPE};
     147    my $id       = $row->{ID};
     148    my $class_id = $row->{CLASS_ID};
     149    my $component = $row->{COMPONENT};
     150    my $filter   = $row->{REQFILT};
     151    my $mjd_min = $row->{MJD_MIN};
     152    my $mjd_max = $row->{MJD_MAX};
     153    my $option_mask= $row->{OPTION_MASK};
     154
     155    die "region of interest is required to make postage stamps"
     156        if (($job_type eq "stamp") and ! validROI($row));
     157
     158    my $skycenter = $row->{skycenter} = ! ($row->{COORD_MASK} & $PSTAMP_CENTER_IN_PIXELS);
     159    $class_id = "" if (defined($class_id) and ($class_id eq "null" or $class_id eq "all"));
     160    $component = "" if (defined($component) and ($component eq "null" or $component eq "all"));
     161   
    146162    die "job_type is list_uri but mode is $mode" if ($job_type eq "list_uri") and ($mode ne "list_uri");
    147163
     164
     165    # note: resolve_project remembers the last project returned so avoids running
     166    # pstamptool every time
    148167    my $proj_hash = resolve_project($ipprc, $project, $dbname, $dbserver);
    149168    die "project $project not found\n" unless $proj_hash;
    150169
    151     my $image_db = $proj_hash->{dbname};
    152     my $camera = $proj_hash->{camera};
    153     my $need_magic = $proj_hash->{need_magic};
    154 
    155     my $roi_string;
    156     # XXX we're depending on other code to insure valid values for roi components
    157     # this is checked in and ppstamp but I should check here so that we don't get that far,
    158     # but not today
    159     if ($x && ($x ne "null") && $y && ($y ne "null") && $w && ($w ne "null") && $h && ($h ne "null")) {
    160         if ($coord_mask & $PSTAMP_CENTER_IN_PIXELS) {
    161             $roi_string = "-pixcenter $x $y";
     170    my $image_db   = $proj_hash->{dbname};
     171    my $camera     = $proj_hash->{camera};
     172    $need_magic = $proj_hash->{need_magic};
     173
     174    # collect rows with the same images of interest in a list so that they
     175    # can be processed optimially
     176    if (@rowList) {
     177        my $firstRow = $rowList[0];
     178        if ($skycenter and same_images_of_interest($row, $firstRow)) {
     179            push @rowList, $row;
     180            # On to the next row
     181            next;
    162182        } else {
    163             $roi_string = "-skycenter $x $y";
    164         }
    165         if ($coord_mask & $PSTAMP_RANGE_IN_PIXELS) {
    166             $roi_string .= " -pixrange $w $h";
    167         } else {
    168             $roi_string .= " -arcrange $w $h";
    169         }
    170     }
    171 
    172     die "region of interest is required to make postage stamps"
    173         if (($job_type eq "stamp") && !defined($roi_string));
    174 
    175     # find the uris for this request
     183            # Process the jobs for this set of rows
     184            $num_jobs += makeJobs($mode, $stage, $need_magic, \@rowList, $imageList);
     185            @rowList = ();
     186        }
     187    }
    176188
    177189    if ($req_type eq "bycoord") {
    178         die "region of interest is required for request type bycoord" if !defined($roi_string) ;
    179         die "center must be specified in sky coordintes for bycoord"
    180             if ($coord_mask & $PSTAMP_CENTER_IN_PIXELS);
    181     }
    182 
    183     # Call PS::IPP::PStamp::Job's locate_images routine to get the parameters for this request specification
    184     my $images = locate_images($ipprc, $image_db, $req_type, $img_type, $id, $class_id,
    185             $x, $y, $mjd_min, $mjd_max, $filter, $verbose);
    186 
    187     if (!$images) {
     190        die "center must be specified in sky coordintes for bycoord" if ( ! $skycenter);
     191        die "lookup bycoord is not yet implemented";
     192    } else {
     193
     194        # Call PS::IPP::PStamp::Job's locate_images routine to get the parameters for this
     195        # request specification. An array reference is returned
     196        my ($x, $y);
     197        $imageList = locate_images($ipprc, $image_db, $req_type, $stage, $id, $class_id, $skycenter,
     198                $x, $y, $mjd_min, $mjd_max, $filter, $verbose);
     199    }
     200
     201    if (!$imageList or !@$imageList) {
    188202        print STDERR "no matching images found for row $rownum\n";
    189203        next;
    190204    }
    191     if ($mode eq "list_uri") {
    192         foreach my $image (@$images) {
    193             print "$image->{image}\n";
    194         }
    195     } elsif ($job_type eq "get_image") {
    196         # XXX TODO: Get rid of this block and use the same code as the stamp jobs
    197         # XXX This doesn't work to get the mask and weight images
    198         my $listfile = "$out_dir/filelist";
    199 
    200 
    201         # map our img_type to the Data Store file types.
    202         my %filelist_img_types = ( "raw" => "chip",
    203                                    "chip" => "chipproc",
    204                                    "warp" => "warp",
    205                                    "stack"=>"stack",
    206                                    "diff" => "diff");
    207 
    208         my $filelist_img_type = $filelist_img_types{$img_type};
    209 
    210         open LISTFILE, ">$listfile"
    211             or die "failed to open file list: $listfile while parsing get_image request $req_id";
    212 
    213         foreach my $image (@$images) {
    214             my $class_id = $image->{class_id} ? $image->{class_id} : "";
    215             print LISTFILE "$image->{image}|$filelist_img_type|$class_id|\n";
    216         }
    217         close LISTFILE;
    218         $num_jobs++;
    219         my $command = "$pstamptool -addjob -req_id $req_id -job_type get_image"
    220                     . " -uri $listfile -outputBase $out_dir -rownum $rownum";
    221         $command .= " -dbname $dbname" if $dbname;
    222         $command .= " -dbserver $dbserver" if $dbserver;
    223         if ($mode eq "list_job") {
    224             print "$command\n";
    225         } else {
    226             my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    227                 run(command => $command, verbose => $verbose);
    228             unless ($success) {
    229                 print STDERR @$stderr_buf;
    230                 # XXX TODO: now what? Should we mark the error state for the request?
    231                 die "failed to queue job for request $req_id: rownum: $rownum";
    232             }
    233         }
    234     } else {
    235         # sequence number for the the job for a request spec. Not to be confused with job_id
    236         my $job_num = 0;
    237 
    238         # XXX TODO: for raw and chip level images and class_id "null" if there are multiple images
    239         # use -list instead of -file
    240         foreach my $image (@$images) {
    241             my $uri = $image->{image};
    242             if (($img_type ne "stack") and ($need_magic and !$image->{magicked})) {
    243                 print STDERR "skippping non-magicked image $uri\n" if $verbose;
    244                 next;
    245             }
    246             my $exp_id = $image->{exp_id};
    247            
    248             my $args = $roi_string ? $roi_string : "";
    249             $args .= " -class_id $class_id" if $class_id;
    250 
    251             $job_num++;
    252 
    253             my $output_base = "$out_dir/${rownum}_${job_num}";
    254 
    255             # add astrometry file for raw and chip images if one is available
    256             if (($img_type eq "chip") || ($img_type eq "raw")) {
    257                 $args .= " -astrom $image->{astrom}" if $image->{astrom};
    258             }
    259 
    260             if (($option_mask & $PSTAMP_SELECT_MASK) &&  $image->{mask} ) {
    261                 $args .= " -mask $image->{mask}";
    262             }
    263             if (($option_mask & $PSTAMP_SELECT_WEIGHT) and $image->{weight} ) {
    264                 $args .= " -weight $image->{weight}";
    265             }
    266 
    267             # XXX: TODO: here is where we need to check whether or not the source inputs still exist
    268             # and if not, queue an update job and set the job state appropriately.
    269 
    270             my $newState = "run";
    271 
    272             $num_jobs++;
    273             my $command = "$pstamptool -addjob -req_id $req_id -job_type $job_type"
    274                 . " -uri $uri -outputBase $output_base -args '$args' -rownum $rownum"
    275                 . " -state $newState";
    276             $command .= " -exp_id $exp_id" if $exp_id;
    277             $command .= " -dbname $dbname" if $dbname;
    278             $command .= " -dbserver $dbserver" if $dbserver;
    279 
    280             if ($mode eq "list_job") {
    281                 # this is a debugging mode, just print the pstamptool that would have run
    282                 # this is sort of like the mode -noupdate that some other tools support
    283                 print "$command\n";
    284             } else {
    285                 # mode eq "queue_job"
    286                 my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    287                     run(command => $command, verbose => $verbose);
    288                 unless ($success) {
    289                     print STDERR @$stderr_buf;
    290                     # XXX TODO: now what? Should we mark the error state for the request?
    291                     # should we keep going for other uris? If so how do we report that some
    292                     # of the work that the request wanted isn't going to get done
    293                     die "failed to queue job for request $req_id";
    294                 }
    295             }
    296         }
    297     }
     205    push @rowList, $row;
     206}
     207
     208if (@rowList) {
     209    $num_jobs += makeJobs($mode, $stage, $need_magic, \@rowList, $imageList);
    298210}
    299211
     
    309221    exit 0;
    310222}
     223
     224
     225sub makeJobsForRow
     226{
     227    my $row = shift;
     228    my $imageList = shift;
     229    my $have_skycells = shift;
     230    my $need_magic = shift;
     231
     232    # loop over images
     233    my $job_num = 0;
     234    foreach my $image (@$imageList) {
     235        my $component;
     236        my $class_id;   # get rid of this use componet
     237        if ($have_skycells) {
     238            $component = $image->{skycell_id};
     239        } else {
     240            $component = $image->{class_id};
     241            $class_id = $component;
     242        }
     243
     244        # skip this component if it is not in the list for this row
     245        next if !$row->{components}->{$component};
     246
     247        my $rownum = $row->{ROWNUM};
     248
     249        my $roi_string;
     250
     251        # XXX we're depending on other code to insure valid values for roi components
     252        # this is checked in and ppstamp but I should check here so that we don't get that far,
     253        # but not today
     254        my $x = $row->{CENTER_X};
     255        my $y = $row->{CENTER_Y};
     256        my $w = $row->{WIDTH};
     257        my $h = $row->{HEIGHT};
     258        my $coord_mask = $row->{COORD_MASK};
     259        if ($x && ($x ne "null") && $y && ($y ne "null") && $w && ($w ne "null") && $h && ($h ne "null")) {
     260            if ($coord_mask & $PSTAMP_CENTER_IN_PIXELS) {
     261                $roi_string = "-pixcenter $x $y";
     262            } else {
     263                $roi_string = "-skycenter $x $y";
     264            }
     265            if ($coord_mask & $PSTAMP_RANGE_IN_PIXELS) {
     266                $roi_string .= " -pixrange $w $h";
     267            } else {
     268                $roi_string .= " -arcrange $w $h";
     269            }
     270        }
     271
     272        my $uri = $image->{image};
     273        if (($stage ne "stack") and ($need_magic and !$image->{magicked})) {
     274            print STDERR "skippping non-magicked image $uri\n" if $verbose;
     275            next;
     276        }
     277        my $exp_id = $image->{exp_id};
     278           
     279        my $args = $roi_string ? $roi_string : "";
     280        $args .= " -class_id $class_id" if $class_id;
     281
     282        $job_num++;
     283
     284        my $output_base = "$out_dir/${rownum}_${job_num}";
     285
     286        # add astrometry file for raw and chip images if one is available
     287        if (($stage eq "chip") || ($stage eq "raw")) {
     288            $args .= " -astrom $image->{astrom}" if $image->{astrom};
     289        }
     290
     291        if (($row->{OPTION_MASK} & $PSTAMP_SELECT_MASK) &&  $image->{mask} ) {
     292            $args .= " -mask $image->{mask}";
     293        }
     294        if (($row->{OPTION_MASK} & $PSTAMP_SELECT_WEIGHT) and $image->{weight} ) {
     295            $args .= " -weight $image->{weight}";
     296        }
     297
     298        # XXX: TODO: here is where we need to check whether or not the source inputs still exist
     299        # and if not, queue an update job and set the job state appropriately.
     300
     301        my $newState = "run";
     302
     303        $num_jobs++;
     304        my $command = "$pstamptool -addjob -req_id $req_id -job_type $row->{JOB_TYPE}"
     305            . " -uri $uri -outputBase $output_base -args '$args' -rownum $rownum"
     306            . " -state $newState";
     307        $command .= " -exp_id $exp_id" if $exp_id;
     308        $command .= " -dbname $dbname" if $dbname;
     309        $command .= " -dbserver $dbserver" if $dbserver;
     310
     311        if ($mode eq "list_job") {
     312            # this is a debugging mode, just print the pstamptool that would have run
     313            # this is sort of like the mode -noupdate that some other tools support
     314            print "$command\n";
     315        } else {
     316            # mode eq "queue_job"
     317            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     318                run(command => $command, verbose => $verbose);
     319            unless ($success) {
     320                print STDERR @$stderr_buf;
     321                # XXX TODO: now what? Should we mark the error state for the request?
     322                # should we keep going for other uris? If so how do we report that some
     323                # of the work that the request wanted isn't going to get done
     324                die "failed to queue job for request $req_id";
     325            }
     326        }
     327    }
     328    return $num_jobs;
     329}
     330
     331sub makeJobs
     332{
     333    my $mode = shift;
     334    my $stage = shift;
     335    my $need_magic = shift;
     336    my $rowList = shift;
     337    my $imageList = shift;
     338
     339    my $firstRow = $rowList[0];
     340    my $job_type = $firstRow->{JOB_TYPE};
     341
     342    my $num_jobs = 0;
     343
     344    if ($mode eq "list_uri") {
     345        foreach my $image (@$imageList) {
     346            print "$image->{image}\n";
     347        }
     348    } elsif ($job_type eq "get_image") {
     349        die "get_image jobs not implemented yet";
     350    } else {
     351        my $thisRun;
     352
     353        my ($pointsList, $pointsListName) = tempfile ("/tmp/pointsList.XXXX", UNLINK => !$save_temps);
     354        foreach my $row (@$rowList) {
     355            print $pointsList "$row->{ROWNUM} $row->{CENTER_X} $row->{CENTER_Y}\n";
     356            $row->{components} = {};
     357        }
     358        close $pointsList;
     359
     360        my $have_skycells;
     361        if (($stage eq "raw") or ($stage eq "chip")) {
     362            $have_skycells = 0;
     363        } else {
     364            $have_skycells = 1;
     365        }
     366       
     367        my $tess_dir_abs;
     368        my $last_tess_id = "";
     369        while ($thisRun = getOneRun($stage, $imageList)) {
     370            {
     371                my $command = "$dvoImagesAtCoords $pointsListName";
     372                if ($have_skycells) {
     373                    my $tess_id = $thisRun->[0]->{tess_id};
     374                    if ($tess_id ne $last_tess_id) {
     375                        $tess_dir_abs = $ipprc->tessellation_catdir( $tess_id );
     376                        $tess_dir_abs = $ipprc->convert_filename_absolute( $tess_dir_abs );
     377                        $last_tess_id = $tess_id;
     378                    }
     379                    $command .= " -D CATDIR $tess_dir_abs";
     380                } else {
     381                    my $astrom = $thisRun->[0]->{astrom};
     382                    die "no astrometry file found" if !$astrom;
     383                    $command .= " -astrom $astrom";
     384                }
     385                my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     386                    run(command => $command, verbose => $verbose);
     387                unless ($success) {
     388                    print STDERR @$stderr_buf;
     389                    my $rc = $error_code >> 8;
     390                    die "dvoImagesAtCoords failed: $rc";
     391                }
     392                # now we have a list of row numbers and components
     393                # eventually we might want to multiple stamp requests for the same image
     394                # into the same ppstamp job but not yet. For now we will queue a new
     395                my @lines = split "\n", join "", @$stdout_buf;
     396                foreach my $line (@lines) {
     397                    # parse the line, ignoring the ra and dec
     398                    my ($rownum, undef, undef, $component) = split " ", $line;
     399
     400                    # I guess since we need this function we should be useing a hash for rowList
     401                    my $row = findRow($rownum, $rowList);
     402                    $row->{components}->{$component} = 1;
     403                }
     404            }
     405           
     406
     407                # XXX TODO: for raw and chip level images and class_id "null" if there are multiple images
     408                # use -list instead of -file
     409            foreach my $row (@$rowList) {
     410                $num_jobs += makeJobsForRow($row, $thisRun, $have_skycells, $need_magic);
     411            }
     412        }
     413    }
     414    return $num_jobs;
     415}
     416
     417sub get_run_id
     418{
     419    my $stage = shift;
     420    my $image = shift;
     421
     422    if ($stage eq "raw") {
     423        return $image->{exp_id};
     424    } elsif ($stage eq "chip") {
     425        return $image->{chip_id};
     426    } elsif ($stage eq "warp") {
     427        return $image->{warp_id};
     428    } elsif ($stage eq "stack") {
     429        return $image->{stack_id};
     430    } elsif ($stage eq "diff") {
     431        return $image->{diff_id};
     432    } else {
     433        die "unenexpected stage: $stage found";
     434    }
     435}
     436
     437# extract components from the imageList that have the same run id and return the list
     438sub getOneRun {
     439    my $stage = shift;
     440    my $imageList = shift;
     441
     442    # return if array is empty
     443    return undef if ! @$imageList;
     444
     445    my $last_run_id = 0;
     446    my @runList;
     447    while ($imageList->[0]) {
     448        my $run_id = get_run_id($stage, $imageList->[0]);
     449
     450        last if ($last_run_id and ($run_id ne $last_run_id));
     451
     452        my $image = shift @$imageList;
     453        push @runList, $image;
     454        $last_run_id = $run_id;
     455    }
     456    return \@runList;
     457}
     458
     459sub same_images_of_interest {
     460    my $r1 = shift;
     461    my $r2 = shift;
     462
     463    return 0 if ($r1->{project} ne $r2->{project});
     464    return 0 if ($r1->{job_type} ne $r2->{job_type});
     465    return 0 if ($r1->{req_type} ne $r2->{req_type});
     466    return 0 if ($r1->{img_type} ne $r2->{img_type});
     467    return 0 if ($r1->{id} ne $r2->{id});
     468#    XXX: turn this on when we change the request file format to change class_id into component
     469#    return false if ($r1->{component} ne $r2->{component});
     470
     471    return 1;
     472}
     473
     474sub validROI
     475{
     476    my $row = shift;
     477    return 0 if !defined $row->{CENTER_X};
     478    return 0 if !defined $row->{CENTER_Y};
     479    return 0 if !defined $row->{WIDTH};
     480    return 0 if !defined $row->{HEIGHT};
     481
     482    return 1;
     483}
     484
     485sub findRow
     486{
     487    my $rownum = shift;
     488    my $rowList = shift;
     489
     490    foreach my $row (@$rowList) {
     491        return $row if $row->{ROWNUM} eq $rownum;
     492    }
     493    return undef;
     494}
Note: See TracChangeset for help on using the changeset viewer.