IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 35384


Ignore:
Timestamp:
Apr 9, 2013, 2:08:27 PM (13 years ago)
Author:
bills
Message:

beginning rework of the postage stamp parser

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm

    r35315 r35384  
    1515our @EXPORT_OK = qw(
    1616                    locate_images
     17                    new_locate_images
    1718                    resolve_project
    1819                    getCamRunByCamID
     
    4647my $last_project = "";
    4748
    48 my ($regtool, $chiptool, $camtool, $warptool, $stacktool, $difftool);
     49my ($regtool, $chiptool, $camtool, $warptool, $stacktool, $difftool, $releasetool);
    4950my ($pstamptool, $dvoImagesAtCoords, $whichimage, $ppConfigDump);
    5051
     
    5657    my $rowList  = shift;   # required
    5758    my $req_type = shift;   # required
    58     my $img_type = shift;   # required
     59    my $stage = shift;   # required
    5960    my $id       = shift;   # required unless req_type eq bycoord or byskycell
    6061    my $tess_id  = shift;
     
    7879           ($req_type ne "byskycell");
    7980
    80     $default_data_groups = load_data_groups($verbose);
     81    if (!$default_data_groups) {
     82        $default_data_groups = load_data_groups($verbose);
     83    }
    8184
    8285    my $dateobs_begin;
     
    104107        my $x = $row->{CENTER_X};
    105108        my $y = $row->{CENTER_Y};
    106         my $results = lookup_bycoord($ipprc, $rowList, $imagedb, $img_type, $tess_id, $component, $need_magic, $x, $y, $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max, $verbose);
     109        my $results = lookup_bycoord($ipprc, $row, $imagedb, $stage, $tess_id, $component, $need_magic, $x, $y, $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max, $verbose);
    107110        return $results;
    108111    }
    109112
    110     if (($req_type eq "byid") and ($img_type eq "diff")) {
     113    if (($req_type eq "byid") and ($stage eq "diff")) {
    111114        # lookups of all of the information for diff images requires a two level lookup to
    112115        # get the exposure information. Switching the req_type allows us to keep that code
    113116        # in one place
    114117        $req_type = "bydiff";
    115         my $results = lookup_diff($ipprc, $rowList, $imagedb, $id, $component, 1, $option_mask, $img_type, $verbose);
     118        my $results = lookup_diff($ipprc, $rowList, $imagedb, $id, $component, 1, $option_mask, $stage, $verbose);
    116119        return $results;
    117120    }
     
    120123        # for bydiff reuqests we go look up the diffRun to obtain exp_id, chip_id, warp_id, stack_id, or
    121124        # the image from the diffRun
    122         my $results = lookup_diff($ipprc, $rowList, $imagedb, $id, $component, 0, $option_mask, $img_type, $verbose);
     125        my $results = lookup_diff($ipprc, $rowList, $imagedb, $id, $component, 0, $option_mask, $stage, $verbose);
    123126        if (!$results) {
    124127            return undef;
    125128        }
    126         if ($img_type eq "diff") {
     129        if ($stage eq "diff") {
    127130            # lookup_diff has done all of the work
    128131            return $results;
     
    130133
    131134        my $image = $results->[0];
    132         if ($img_type eq "raw") {
     135        if ($stage eq "raw") {
    133136            $req_type = "byid";
    134137            $id = $image->{exp_id};
    135138            return undef if !$id;
    136139            # fall through and lookup byid
    137         } elsif ($img_type eq "chip") {
     140        } elsif ($stage eq "chip") {
    138141            $req_type = "byid";
    139142            $id = $image->{chip_id};
    140143            return undef if !$id;
    141144            # fall through and lookup byid
    142         } elsif ($img_type eq "warp") {
     145        } elsif ($stage eq "warp") {
    143146            $req_type = "byid";
    144147            $id = $image->{warp_id};
     
    146149            return undef if !$id;
    147150            # fall through and lookup by warp_id
    148         } elsif ($img_type eq "stack") {
     151        } elsif ($stage eq "stack") {
    149152            $req_type = "byid";
    150153            $id = $image->{stack_id};
     
    153156        } else {
    154157            # This is checked this elsewhere?
    155             print STDERR "Error: $img_type is an unknown image type\n";
     158            print STDERR "Error: $stage is an unknown image type\n";
    156159            return undef;
    157160        }
    158161    } elsif ($req_type eq "byskycell") {
    159         if (($img_type eq "raw") or ($img_type eq "chip")) {
     162        if (($stage eq "raw") or ($stage eq "chip")) {
    160163            print STDERR "REQ_TYPE byskycell not supported for IMG_TYPE raw or chip\n";
    161164            return undef;
     
    167170    }
    168171
    169     my $results = lookup($ipprc, $rowList, $imagedb, $req_type, $img_type, $id, $tess_id, $component,
     172    my $results = lookup($ipprc, $rowList, $imagedb, $req_type, $stage, $id, $tess_id, $component,
    170173        $need_magic, $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max, $verbose);
     174
     175    return $results;
     176}
     177
     178sub new_locate_images {
     179    my $ipprc    = shift;
     180    my $imagedb  = shift;
     181    my $camera   = shift;
     182    my $row      = shift;
     183    my $verbose  = shift;
     184
     185    my $req_type  = $row->{REQ_TYPE};
     186
     187    # we die in response to bad data in request files
     188    # The caller is responsible for updating the database
     189    # pstampparse.pl error checks now so this shouldn't happen
     190    &my_die("Unknown req_type: $req_type", $PS_EXIT_PROG_ERROR)
     191        if ($req_type ne "byid") and
     192           ($req_type ne "byexp") and
     193           ($req_type ne "bycoord") and
     194           ($req_type ne "bydiff") and
     195           ($req_type ne "byskycell");
     196
     197    if (!$default_data_groups) {
     198        $default_data_groups = load_data_groups($verbose);
     199    }
     200
     201    my $stage     = $row->{IMG_TYPE};
     202    my $id        = $row->{ID};
     203    my $component = $row->{COMPONENT};
     204    my $tess_id   = $row->{TESS_ID};
     205
     206    my $filter    = $row->{REQFILT};
     207    my $mjd_min   = $row->{MJD_MIN};
     208    my $mjd_max   = $row->{MJD_MAX};
     209    my $data_group = $row->{DATA_GROUP};
     210
     211    my $rownum     = $row->{ROWNUM};
     212    my $job_type   = $row->{JOB_TYPE};
     213    my $option_mask= $row->{OPTION_MASK};
     214
     215    my $dateobs_begin;
     216    my $dateobs_end;
     217    if (!iszero($mjd_min)) {
     218        $dateobs_begin = mjd_to_dateobs($mjd_min);
     219    }
     220    if (!iszero($mjd_max)) {
     221        $dateobs_end = mjd_to_dateobs($mjd_max);
     222    }
     223    if (isnull($tess_id)) {
     224        $tess_id = undef;
     225    }
     226    if (isnull($data_group)) {
     227        $data_group = undef;
     228    }
     229    if (isnull($filter)) {
     230        $filter = undef;
     231    }
     232
     233
     234
     235    if ($req_type eq "bycoord") {
     236        my $x = $row->{CENTER_X};
     237        my $y = $row->{CENTER_Y};
     238        my $results = lookup_bycoord($ipprc, $row, $imagedb, $stage, $tess_id, $component, 0, $x, $y, $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max, $verbose);
     239        return $results;
     240    }
     241
     242    # for compatability with the lower level functions
     243    my $rowList = [$row];
     244
     245    if (($req_type eq "byid") and ($stage eq "diff")) {
     246        # lookups of all of the information for diff images requires a two level lookup to
     247        # get the exposure information. Switching the req_type allows us to keep that code
     248        # in one place
     249        $req_type = "bydiff";
     250        my $results = lookup_diff($ipprc, $rowList, $imagedb, $id, $component, 1, $option_mask, $stage, $verbose);
     251        return $results;
     252    }
     253
     254    if ($req_type eq "bydiff") {
     255        # for bydiff reuqests we go look up the diffRun to obtain exp_id, chip_id, warp_id, stack_id, or
     256        # the image from the diffRun
     257        my $results = lookup_diff($ipprc, $rowList, $imagedb, $id, $component, 0, $option_mask, $stage, $verbose);
     258        if (!$results) {
     259            return undef;
     260        }
     261        if ($stage eq "diff") {
     262            # lookup_diff has done all of the work
     263            return $results;
     264        }
     265
     266        my $image = $results->[0];
     267        if ($stage eq "raw") {
     268            $req_type = "byid";
     269            $id = $image->{exp_id};
     270            return undef if !$id;
     271            # fall through and lookup byid
     272        } elsif ($stage eq "chip") {
     273            $req_type = "byid";
     274            $id = $image->{chip_id};
     275            return undef if !$id;
     276            # fall through and lookup byid
     277        } elsif ($stage eq "warp") {
     278            $req_type = "byid";
     279            $id = $image->{warp_id};
     280            $component = $image->{skycell_id};
     281            return undef if !$id;
     282            # fall through and lookup by warp_id
     283        } elsif ($stage eq "stack") {
     284            $req_type = "byid";
     285            $id = $image->{stack_id};
     286            return undef if !$id;
     287            # fall though and lookup by stack_id
     288        } else {
     289            # This is checked this elsewhere?
     290            print STDERR "Error: $stage is an unknown image type\n";
     291            return undef;
     292        }
     293    } elsif ($req_type eq "byskycell") {
     294        if (($stage eq "raw") or ($stage eq "chip")) {
     295            print STDERR "REQ_TYPE byskycell not supported for IMG_TYPE raw or chip\n";
     296            return undef;
     297        }
     298        if (!$tess_id or !$component) {
     299            print STDERR "component and tess_id are required for REQ_TYPE byskycell\n";
     300            return undef;
     301        }
     302    }
     303
     304    my $results = lookup($ipprc, $rowList, $imagedb, $req_type, $stage, $id, $tess_id, $component,
     305        0, $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max, $verbose);
    171306
    172307    return $results;
     
    505640    my $byid     = shift;
    506641    my $option_mask  = shift;
    507     my $img_type = shift;
     642    my $stage = shift;
    508643    my $verbose = shift;
    509644
     
    573708            # we have a stack - stack diff (well it might be stack - warp....)
    574709            # but at any rate we only handle image type diff and stack
    575             if (($img_type ne "diff") and ($img_type ne "stack")) {
    576                 print STDERR "lookup_diff: cannot lookup IMG_TYPE $img_type bydiff from a stack stack diff run\n";
     710            if (($stage ne "diff") and ($stage ne "stack")) {
     711                print STDERR "lookup_diff: cannot lookup IMG_TYPE $stage bydiff from a stack stack diff run\n";
    577712                setErrorCodes($rowList, $PSTAMP_INVALID_REQUEST);
    578713                # all images will be the same so we can stop
     
    625760        }
    626761
    627         if ($img_type eq "diff") {
     762        if ($stage eq "diff") {
    628763            my @imageList = ($image);
    629764
     
    656791sub lookup_bycoord {
    657792    my $ipprc      = shift;
    658     my $rowList    = shift;
     793    my $row        = shift;
    659794    my $imagedb    = shift;
    660     my $img_type   = shift;
     795    my $stage      = shift;
    661796    my $tess_id    = shift;
    662797    my $component  = shift;
     
    673808    my $verbose    = shift;
    674809
     810    my ($release_name, $survey) = get_release($row);
     811
     812    my $rowList = [$row];
     813
    675814    my $results = ();
    676     if (($img_type eq "raw") or ($img_type eq "chip")) {
    677 
    678         my $chips = lookup_by_cam_id_and_coords($ipprc, $imagedb, $img_type,
    679             $ra, $dec, $need_magic, $dateobs_begin, $dateobs_end, $filter, $data_group, $verbose);
     815    if (($stage eq "raw") or ($stage eq "chip")) {
     816
     817        my $chips = lookup_by_cam_id_and_coords($ipprc, $imagedb, $stage,
     818            $ra, $dec, $need_magic, $dateobs_begin, $dateobs_end, $filter, $data_group, $verbose, $release_name, $survey, $row->{FWHM_MIN}, $row->{FWHM_MAX});
    680819
    681820        if (!$chips or scalar @$chips == 0) {
     
    684823            foreach my $chip (@$chips) {
    685824                next if $component and ($chip->{component} ne $component);
    686                 my $these_results = lookup($ipprc, $rowList, $imagedb, "byid", $img_type, $chip->{id},
     825                my $these_results = lookup($ipprc, $rowList, $imagedb, "byid", $stage, $chip->{id},
    687826                    $tess_id, $chip->{component}, $need_magic,
    688827                    $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max, $verbose);
     
    695834    } else {
    696835        # this should have been checked elsewhere
    697         die "unexpected image type $img_type" if ($img_type ne "warp")
    698                                               and ($img_type ne "stack") and ($img_type ne "diff");
     836        die "unexpected image type $stage" if ($stage ne "warp")
     837                                              and ($stage ne "stack") and ($stage ne "diff");
    699838
    700839        my $skycells = lookup_skycell_by_coords($ipprc, $tess_id, $component, $ra, $dec, $verbose);
     
    704843        } else {
    705844            foreach my $skycell (@$skycells) {
    706                 my $these_results = lookup($ipprc, $rowList, $imagedb, "byskycell", $img_type, undef,
     845                my $these_results = lookup($ipprc, $rowList, $imagedb, "byskycell", $stage, undef,
    707846                    $skycell->{tess_id}, $skycell->{component}, $need_magic,
    708847                    $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max, $verbose);
     
    722861
    723862sub lookup_by_cam_id_and_coords {
    724     my $ipprc      = shift;
    725     my $imagedb   = shift;
    726     my $img_type   = shift;
    727     my $ra         = shift;
    728     my $dec        = shift;
    729     my $need_magic = shift;
     863    my $ipprc       = shift;
     864    my $imagedb     = shift;
     865    my $stage       = shift;
     866    my $ra          = shift;
     867    my $dec         = shift;
     868    my $need_magic  = shift;
    730869    my $dateobs_begin  = shift;
    731870    my $dateobs_end = shift;
     
    733872    my $data_group = shift;
    734873    my $verbose    = shift;
    735 
    736     my $camruns;
    737 
    738     {
    739         my $search_radius = 1.6; # XXX: this should be camera specific
    740 
     874    my $release_name = shift;
     875    my $survey      = shift;
     876    my $fwhm_min    = shift;
     877    my $fwhm_max    = shift;
     878
     879    my $search_radius = 1.6; # XXX: this should be camera specific
     880
     881    my $command;
     882    my $using_camtool = 0;
     883    if ($release_name or $survey) {
     884        my $command = "$releasetool -dbname $imagedb -listrelexp";
     885        if ($survey) {
     886            $command .= " -survey_name $survey";
     887        }
     888        if ($release_name) {
     889            $command .= " -release_name $release_name";
     890        } else {
     891            $command .= " -priority_order";
     892        }
     893        if ($fwhm_min != 0) {
     894            $command .= " -fwhm_min $fwhm_min";
     895        }
     896        if ($fwhm_max != 0) {
     897            $command .= " -fwhm_max $fwhm_max";
     898        }
     899    } else {
     900        $using_camtool = 1;
    741901        my $command = "$camtool -dbname $imagedb -processedexp -pstamp_order";
    742            $command .= " -ra $ra -decl $dec -radius $search_radius";
    743            $command .= " -dateobs_begin $dateobs_begin" if $dateobs_begin;
    744            $command .= " -dateobs_end   $dateobs_end"   if $dateobs_end  ;
    745            $command .= " -filter $filter" if $filter;
    746902           # NOTE: we are applying the data_group to the camera run.
    747903           # If we're looking for chip stage images there is no guarentee that
     
    755911           }
    756912           $command .= " -destreaked" if $need_magic;
    757 
    758         # run the tool and parse the output
    759         $camruns = runToolAndParse($command, $verbose);
    760     }
    761     if (!$camruns) {
     913    }
     914    $command .= " -ra $ra -decl $dec -radius $search_radius";
     915    $command .= " -dateobs_begin $dateobs_begin" if $dateobs_begin;
     916    $command .= " -dateobs_end   $dateobs_end"   if $dateobs_end  ;
     917    $command .= " -filter $filter" if $filter;
     918
     919    # run the tool and parse the output
     920    my $results = runToolAndParse($command, $verbose);
     921    if (!$results) {
    762922        return undef;
    763923    }
    764924    my $components;
    765925    my $last_exp_id = 0;
    766     foreach my $camRun (@$camruns) {
    767         my $cam_id = $camRun->{cam_id};
    768         my $exp_id = $camRun->{exp_id};
    769 
     926    foreach my $result (@$results) {
     927        my $cam_id = $result->{cam_id};
     928        my $exp_id = $result->{exp_id};
     929
     930        # go on if we already have a result for this exposure
    770931        next if $exp_id eq $last_exp_id;
    771932
    772         next if $camRun->{quality};
    773         next if $camRun->{fault};
    774 
    775         updateCamRunCache($camRun);
     933        next if $result->{quality};
     934
     935        if ($using_camtool) {
     936            next if $result->{fault};
     937            updateCamRunCache($result);
     938        }
    776939
    777940        $last_exp_id = $exp_id;
    778941
    779942        # XXX Use file rule
    780         my $astrom = $camRun->{path_base} . ".smf";
     943        my $astrom = $result->{path_base} . ".smf";
    781944        my $astrom_resolved = $ipprc->file_resolve($astrom);
    782945        next if !$astrom_resolved;
     
    832995        }
    833996
    834         print "cam_id $cam_id exp_id $camRun->{exp_id} chip_id $camRun->{chip_id} $class_id\n";
     997        print "cam_id $cam_id exp_id $result->{exp_id} chip_id $result->{chip_id} $class_id\n";
    835998
    836999        # build the hash to return
     
    8401003        # problem
    8411004        my $comp = {
    842             exp_id    => $camRun->{exp_id},
    843             exp_name  => $camRun->{exp_name},
    844             chip_id   => $camRun->{chip_id},
    845             cam_id    => $camRun->{cam_id},
     1005            exp_id    => $result->{exp_id},
     1006            exp_name  => $result->{exp_name},
     1007            chip_id   => $result->{chip_id},
     1008            cam_id    => $result->{cam_id},
    8461009            class_id  => $class_id,
    8471010            component => $class_id
    8481011        };
    849         if ($img_type eq "chip") {
    850             $comp->{id} = $camRun->{chip_id};
    851             $comp->{state} = $camRun->{chip_state};
    852             $comp->{magicked} = $camRun->{chip_magicked};
    853         } else {
    854             $comp->{id} = $camRun->{exp_id};
     1012        if ($stage eq "chip") {
     1013            $comp->{id} = $result->{chip_id};
     1014            $comp->{state} = $result->{chip_state};
     1015            $comp->{magicked} = 0;
     1016        } else {
     1017            $comp->{id} = $result->{exp_id};
    8551018            $comp->{state} = 'full';
    856             $comp->{magicked} = $camRun->{raw_magicked};
     1019            $comp->{magicked} = $0;
    8571020        }
    8581021        push @$components, $comp;
     
    14071570    $dvoImagesAtCoords = can_run('dvoImagesAtCoords') or (warn "Can't find dvoImagesAtCoords"
    14081571                                                                and $missing_tools = 1);
     1572    $releasetool = can_run('releasetool') or (warn "Can't find releasetool"
     1573                                                                and $missing_tools = 1);
    14091574    $whichimage = can_run('whichimage') or (warn "Can't find whichimage" and $missing_tools = 1);
    14101575    $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
     
    14621627}
    14631628
     1629sub get_release {
     1630    my $row = shift;
     1631
     1632    my $survey;
     1633    my $release_name = $row->{IPP_RELEASE};
     1634    if (!isnull($release_name)) {
     1635        # no release check for survey
     1636        $survey = $row->{SURVEY_NAME};
     1637    }
     1638
     1639    return ($release_name, $survey);
     1640}
     1641
    14641642sub my_die
    14651643{
  • trunk/PS-IPP-PStamp/lib/PS/IPP/PStamp/RequestFile.pm

    r35364 r35384  
    5252                    $PSTAMP_NO_OVERLAP
    5353                    $PSTAMP_NOT_AUTHORIZED
     54                    $PSTAMP_UNKNOWN_PROJECT
    5455                    );
    5556our %EXPORT_TAGS = (standard => [@EXPORT_OK]);
     
    101102our $PSTAMP_NO_OVERLAP       = 28;
    102103our $PSTAMP_NOT_AUTHORIZED   = 29;
     104our $PSTAMP_UNKNOWN_PROJECT  = 22;
    103105
    104106
  • trunk/pstamp/scripts/pstampparse.pl

    r35380 r35384  
    211211print "\n$nRows rows read from request file\n";
    212212
    213 # If this is a big request and it came from the upload page and doesn't have a specific label assigned
    214 # change it to the generic one that has lower with lower priority
    215 
    216 #
    217 # Loop over rows in the request file collecting consecutive rows that have the "same images of interest"
    218 # in the sense that their selection parameters will yield the same target "Runs".
    219 # Process the groups of rows together to reduce lookup time and to potentially make multiple
    220 # stamps from the same ppstamp process.
    221 
    222 my @rowList;
     213
    223214my $num_jobs = 0;
    224215my $imageList;
    225216my $stage;
    226 my $need_magic;
    227217foreach my $row (@$rows) {
     218
    228219    if ($label eq 'WEB.UP' and ($nRows > 500 or $num_jobs > 500) and $req_id and !$no_update) {
     220        # this is a big request and it came from the upload page and doesn't have a specific label assigned
     221        # change it to the generic one that has lower with lower priority
    229222        $label = 'WEB.BIG';
    230223        print "\nChanging label for big WEB.UP request to $label\n";
     
    237230        }
    238231    }
    239     # sanity check the paramaters
     232
     233    # validate the paramaters
    240234    if (!checkRow($row)) {
    241235        # when it enconters an error checkRow adds a fake job with an appropriate error code to the database
     
    247241    $row->{error_code} = 0;
    248242
    249     if (scalar @rowList == 0) {
    250         push @rowList, $row;
    251         next;
    252     }
    253 
    254     my $firstRow = $rowList[0];
    255     if (same_images_of_interest($firstRow, $row)) {
    256         # add this row to the list and move on
    257         push @rowList, $row;
    258         next;
    259     }
    260 
    261     # the images of interest for this new row doesn't match the list.
    262     # process the list ...
    263     $num_jobs += processRows($action, \@rowList);
    264 
    265     # and reset the list to contain just the new row
    266     @rowList = ($row);
    267 }
    268 
    269 # out of rows process the list
    270 if (scalar @rowList > 0) {
    271     $num_jobs += processRows($action, \@rowList);
     243    $num_jobs += processRow($action, $row);
    272244}
    273245
     
    283255    my $row = shift;
    284256
     257    # check validity of the paramters in a request specification
    285258    # If we encounter an error for a particular row add a job with the proper fault code.
     259    # also adjust some paramterers like filter and set defaults for some others
    286260
    287261    my $stage = $row->{IMG_TYPE};
     
    315289    }
    316290
    317 
    318291    my $component = $row->{COMPONENT};
    319292    if (!defined $component or (lc($component) eq "null") or (lc($component) eq "all")) {
     
    345318        return 0;
    346319    }
     320
     321    my $fwhm_min = $row->{FWHM_MIN};
     322    if (!defined $fwhm_min) {
     323        $row->{FWHM_MIN} = 0;
     324    } elsif (!validNumber($fwhm_min)) {
     325        print STDERR "$fwhm_min is not a valid FWHM_MIN\n";
     326        insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
     327        return 0;
     328    }
     329    my $fwhm_max = $row->{FWHM_MAX};
     330    if (!defined $fwhm_max) {
     331        $row->{FWHM_MAX} = 0;
     332    } elsif (!validNumber($fwhm_max)) {
     333        print STDERR "$fwhm_max is not a valid FWHM_MAX\n";
     334        insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
     335        return 0;
     336    }
     337
    347338    my $data_group = $row->{DATA_GROUP};
    348339    if (!defined $data_group) {
     
    410401    }
    411402
     403
    412404    return 1;
    413405}
     
    418410
    419411    $num_jobs = 1;
     412    return $num_jobs;
     413}
     414
     415sub processRow {
     416    my $action  = shift;
     417    my $row     = shift;
     418
     419    my $num_jobs = 0;
     420
     421    my $project  = $row->{PROJECT};
     422
     423    # note: resolve_project avoids running pstamptool every time by remembering the
     424    # last project resolved
     425    my $proj_hash = resolve_project($ipprc, $project, $dbname, $dbserver);
     426    if (!$proj_hash) {
     427        insertFakeJobForRow($row, 1, $PSTAMP_UNKNOWN_PROJECT);
     428        $num_jobs++;
     429        return $num_jobs;
     430    }
     431    my $image_db   = $proj_hash->{dbname};
     432    my $camera     = $proj_hash->{camera};
     433
     434    my $req_type    = $row->{REQ_TYPE};
     435    my $rownum      = $row->{ROWNUM};
     436
     437    # Since user can get unmagicked data "by coordinate" requests can go back in time
     438    # to dredge unusable data from the "dark days"...
     439    if ($req_type eq 'bycoord' and $row->{MJD_MIN} == 0) {
     440        # ... so unless the user sets mjd_min clamp it to 2009-04-01
     441        # XXX: This value should live in the pstampProject table not be hardcoded here
     442        $row->{MJD_MIN} = 54922;
     443    }
     444
     445    if (($req_type eq 'byskycell') or ($req_type eq 'bycoord')) {
     446        # avoid error from print below if $id isn't needed
     447        $row->{ID} = "" if !$row->{ID};
     448    }
     449   
     450    # Call PS::IPP::PStamp::Job locate_images subroutine to get the images for this
     451    # request specification. An array reference is returned.
     452    my $start_locate = gettimeofday();
     453
     454    print "\nCalling new_locate_images for row: $rownum\n";
     455
     456    $imageList = new_locate_images($ipprc, $image_db, $camera, $row, $verbose);
     457
     458    my $dtime_locate = gettimeofday() - $start_locate;
     459    print "Time to locate_images for row $rownum $dtime_locate\n";
     460
     461    my @rowList = ($row);
     462    $num_jobs += queueJobs($action, \@rowList, $imageList);
     463
     464    # if this row slipped through without a job being added add one.
     465    if ($row->{job_num} == 0) {
     466        print "row $row->{ROWNUM} produced no jobs\n";
     467        print STDERR "row $row->{ROWNUM} produced no jobs\n";
     468        my $error_code = $row->{error_code};
     469        $error_code =  $PSTAMP_NO_IMAGE_MATCH if !$error_code;
     470        insertFakeJobForRow($row, ++$row->{job_num}, $error_code);
     471    }
     472
    420473    return $num_jobs;
    421474}
     
    447500    }
    448501    my $req_type  = $row->{REQ_TYPE};
    449     $stage        = $row->{IMG_TYPE};
     502    my $stage     = $row->{IMG_TYPE};
    450503    my $id        = $row->{ID};
    451504    my $component = $row->{COMPONENT};
     
    463516    my $image_db   = $proj_hash->{dbname};
    464517    my $camera     = $proj_hash->{camera};
    465     $need_magic    = $proj_hash->{need_magic};
     518    my $need_magic    = $proj_hash->{need_magic};
    466519    # Since user can get unmagicked data "by coordinate" requests can go back in time
    467520    # to dredge unusable data from the "dark days"...
     
    523576    # information required is contained there
    524577
    525     $imageList = locate_images($ipprc, $image_db, \@rowList, $req_type, $stage, $id, $tess_id, $component,
     578    $imageList = locate_images($ipprc, $image_db, $rowList, $req_type, $stage, $id, $tess_id, $component,
    526579                $option_mask, $need_magic, $mjd_min, $mjd_max, $filter, $data_group, $verbose);
    527580
     
    533586    $row->{need_magic} = $need_magic;
    534587
    535     $num_jobs += queueJobs($action, \@rowList, $imageList);
     588    $num_jobs += queueJobs($action, $rowList, $imageList);
    536589
    537590    # if a row slipped through with no jobs add a faulted one
    538     foreach my $row (@rowList) {
     591    foreach my $row (@$rowList) {
    539592        if ($row->{job_num} == 0) {
    540593            print "row $row->{ROWNUM} produced no jobs\n";
     
    675728    my $imageList = shift;
    676729
    677     my $firstRow = $rowList[0];
     730    my $firstRow = $rowList->[0];
    678731    my $stage    = $firstRow->{IMG_TYPE};
    679732    my $job_type = $firstRow->{JOB_TYPE};
     
    10041057    my $r_fault = shift;
    10051058    my $r_dep_id = shift;
     1059
     1060    my $need_magic = 0;
    10061061
    10071062    if ($stage ne 'raw') {
Note: See TracChangeset for help on using the changeset viewer.