IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

merged from trunk

Location:
branches/eam_branches/ipp-20130307
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20130307

  • branches/eam_branches/ipp-20130307/PS-IPP-PStamp/lib/PS/IPP/PStamp/Job.pm

    r35350 r35413  
    1515our @EXPORT_OK = qw(
    1616                    locate_images
     17                    locate_images_for_row
    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 (!$data_group and !$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,
    170         $need_magic, $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max, $verbose);
     172    my $results = lookup($ipprc, $rowList, $imagedb, $req_type, $stage, $id, $tess_id, $component,
     173        $need_magic, $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max,
     174        undef, undef, undef, $verbose);
     175
     176    return $results;
     177}
     178
     179sub locate_images_for_row {
     180    my $ipprc    = shift;
     181    my $imagedb  = shift;
     182    my $camera   = shift;
     183    my $row      = shift;
     184    my $verbose  = shift;
     185
     186    my $req_type  = $row->{REQ_TYPE};
     187
     188    # we die in response to bad data in request files
     189    # The caller is responsible for updating the database
     190    # pstampparse.pl error checks now so this shouldn't happen
     191    &my_die("Unknown req_type: $req_type", $PS_EXIT_PROG_ERROR)
     192        if ($req_type ne "byid") and
     193           ($req_type ne "byexp") and
     194           ($req_type ne "bycoord") and
     195           ($req_type ne "bydiff") and
     196           ($req_type ne "byskycell");
     197
     198    my $stage     = $row->{IMG_TYPE};
     199    my $id        = $row->{ID};
     200    my $component = $row->{COMPONENT};
     201    my $tess_id   = $row->{TESS_ID};
     202
     203    my $filter    = $row->{REQFILT};
     204    my $mjd_min   = $row->{MJD_MIN};
     205    my $mjd_max   = $row->{MJD_MAX};
     206    my $data_group = $row->{DATA_GROUP};
     207    if (isnull($data_group) and !$default_data_groups) {
     208        $default_data_groups = load_data_groups($verbose);
     209    }
     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    if ($req_type eq "bycoord") {
     234        my $x = $row->{CENTER_X};
     235        my $y = $row->{CENTER_Y};
     236        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);
     237        return $results;
     238    }
     239
     240    # for compatability with the lower level functions that haven't been converted to take a single row
     241    my $rowList = [$row];
     242
     243    if (($req_type eq "byid") and ($stage eq "diff")) {
     244        # lookups of all of the information for diff images requires a two level lookup to
     245        # get the exposure information. Switching the req_type allows us to keep that code
     246        # in one place
     247        $req_type = "bydiff";
     248        my $results = lookup_diff($ipprc, $rowList, $imagedb, $id, $component, 1, $option_mask, $stage, $verbose);
     249        return $results;
     250    }
     251
     252    my ($release_name, $survey) = get_release_info($row);
     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,
     306        undef, $release_name, $survey,
     307        $verbose);
    171308
    172309    return $results;
     
    193330    my $mjd_min = shift;
    194331    my $mjd_max = shift;
     332    my $selectedAstrom = shift;
     333    my $release_name = shift;
     334    my $survey = shift;
    195335    my $verbose  = shift;
    196336
     
    217357    my $magic_arg = $need_magic ? " -destreaked" : "";
    218358
     359    my $row = $rowList->[0];
     360
    219361    # all rows have the same center type
    220     my $skycenter = ! ($rowList->[0]->{COORD_MASK} & $PSTAMP_CENTER_IN_PIXELS);
     362    my $skycenter = ! ($row->{COORD_MASK} & $PSTAMP_CENTER_IN_PIXELS);
     363
     364    my $use_releasetool = 0;
     365    my $release_args;
     366    if (($req_type eq 'byexp' and $stage ne 'raw') or ($req_type eq 'byskycell' and $stage ne 'diff')) {
     367        unless (isnull($release_name) and isnull($survey)) {
     368            $use_releasetool = 1;
     369            $release_args = " -release_name $release_name" if $release_name;
     370            $release_args .= " -surveyName $survey" if $survey;
     371        }
     372    }
    221373
    222374    my $component_args;
     
    249401        # use chiptool -processsedimfile. Otherwise use chiptool -listrun and then
    250402        # choose the chips containing the center pixel by calling selectComponets() below
    251         if ($component or $use_imfile_id or !$skycenter) {
    252             $command = "$chiptool -processedimfile -pstamp_order -dbname $imagedb";
    253             if ($component and $component ne 'all') {
    254                 $class_id = $component;
    255                 $component_args = " -class_id $class_id";
    256             }
    257         } else {
    258             $command = "$chiptool -listrun -pstamp_order -dbname $imagedb";
     403        if ($use_releasetool) {
     404            $command = "$releasetool -dbname $imagedb -priority_order -listrelexp $release_args";
    259405            $choose_components = 1;
    260         }
    261         $id_opt = $use_imfile_id ? "-chip_imfile_id" : "-chip_id";
     406        } else {
     407            $command = "$chiptool -pstamp_order -dbname $imagedb";
     408            if ($component or $use_imfile_id or !$skycenter) {
     409                $command .= " -processedimfile";
     410                if ($component and $component ne 'all') {
     411                    $class_id = $component;
     412                    $component_args = " -class_id $class_id";
     413                }
     414            } else {
     415                $command .= " -listrun";
     416                $choose_components = 1;
     417            }
     418            $id_opt = $use_imfile_id ? "-chip_imfile_id" : "-chip_id";
     419        }
    262420        # XXX: perhaps we should stop resolving images to this level here and do it at job run time.
    263421        # With the mdc file it has all of the information that it needs.
     
    273431        $want_astrom  = 1;
    274432        $set_class_id = 1;
    275     } elsif ($stage eq "warp") {
    276         if ($component or $use_imfile_id or !$skycenter) {
    277             $command = "$warptool -warped -pstamp_order -dbname $imagedb";
    278             if ($component and $component ne 'all') {
    279                 $skycell_id = $component;
    280                 $component_args = " -skycell_id $skycell_id";
    281             }
    282         } else {
    283             $command = "$warptool -listrun -pstamp_order -dbname $imagedb";
     433    } elsif ($stage eq 'warp') {
     434        if ($use_releasetool) {
     435            $command = "$releasetool -dbname $imagedb -priority_order -listrelexp $release_args";
    284436            $choose_components = 1;
    285         }
    286         $id_opt = $use_imfile_id ? "-warp_skyfile_id" : "-warp_id";
     437        } else {
     438            $command = "$warptool -pstamp_order -dbname $imagedb";
     439            if ($component or $use_imfile_id or !$skycenter) {
     440                $command .= " -warped";
     441                if ($component and $component ne 'all') {
     442                    $skycell_id = $component;
     443                    $component_args = " -skycell_id $skycell_id";
     444                }
     445            } else {
     446                $command = " -listrun";
     447                $choose_components = 1;
     448            }
     449            $id_opt = $use_imfile_id ? "-warp_skyfile_id" : "-warp_id";
     450        }
    287451        $image_name   = "PSWARP.OUTPUT";
    288452        $mask_name    = "PSWARP.OUTPUT.MASK";
     
    292456        $base_name    = "path_base"; # name of the field for the warptool output
    293457    } elsif ($stage eq "diff") {
     458        # XXX: is this path ever used for diff images anymore?
    294459        if ($component or $use_imfile_id or !$skycenter) {
    295460            $command = "$difftool -diffskyfile -pstamp_order -dbname $imagedb";
     
    312477    } elsif ($stage eq "stack") {
    313478        $skycell_id = $component;
    314         $command = "$stacktool -sumskyfile -dbname $imagedb";
    315         # only consider stacks in full state.
    316         $command .= " -state full";
    317         $id_opt = "-stack_id";
     479        if ($use_releasetool) {
     480            $command = "$releasetool -listrelstack -dbname $imagedb $release_args";
     481            $base_name = 'stack_path_base';
     482        } else {
     483            $command = "$stacktool -sumskyfile -dbname $imagedb";
     484            # only consider stacks in full state.
     485            $command .= " -state full";
     486            $id_opt = "-stack_id";
     487            $base_name = 'path_base';
     488        }
    318489        $component_args = " -skycell_id $skycell_id" if $skycell_id and $skycell_id ne  'all';
    319490
     
    329500        # this is wrong but gets the right answer. Need to figure out how to find the
    330501        # rule properly
    331         #$cmf_name    = "PSPHOT.OUTPUT";    # this puts .fpa. in the name
    332502        $cmf_name     = "PSWARP.OUTPUT.SOURCES";
     503        # $cmf_name    = "PSPHOT.OUTPUT";    # this puts .fpa. in the name
    333504        $psf_name    = "PPSTACK.TARGET.PSF";
    334         $base_name   = "path_base";
    335505    } else {
    336         die "Unknown IMG_TYPe supplied: $stage";
     506        die "Unknown IMG_TYPE supplied: $stage";
    337507    }
    338508
     
    377547    if (!isnull($data_group)) {
    378548        $command .= " -data_group $data_group";
    379     } elsif ($req_type eq 'byskycell') {
     549    } elsif (!$use_releasetool and $req_type eq 'byskycell') {
     550        # XXX: Why am I using default data_groups only for byskycell requests?
    380551        $command .= $default_data_groups;
    381552    }
     
    392563        $images = filterRuns($stage, $need_magic, $images, $inverse, $verbose);
    393564    }
     565
    394566    if ($choose_components) {
    395567        # the list of "images" is actually a list of "Runs"
    396568        # match the coords in the rows to the components in the runs
    397569        # returns an actual list of images
    398         $images = selectComponents($ipprc, $imagedb, $req_type, $stage, $rowList, $images, $verbose);
     570        if ($skycenter) {
     571            $images = selectComponents($ipprc, $imagedb, $req_type, $stage, $rowList, $images, $verbose);
     572        } else {
     573            $images = selectComponentsByName($ipprc, $imagedb, $req_type, $stage, $component, $rowList, $images, $verbose);
     574        }
    399575    } else {
    400         # put index for each of the rows into all of the the images
     576        # put index for each of the rows into all of the the selected images
    401577        setRowRefs($rowList, $images);
    402578    }
     
    462638            # dquery wants these set
    463639            $out->{magicked} = 0;
    464             $out->{data_state} = $out->{state};
     640            if ($use_releasetool) {
     641                if ($image->{skycal_path_base}) {
     642                    $out->{astrom} = $image->{skycal_path_base} . ".cmf";
     643                }
     644                $out->{data_state} = $out->{state} = $out->{stack_state};
     645            } else {
     646                $out->{data_state} = $out->{state};
     647            }
    465648        }
    466649        $out->{stage_id} = $stage_id;
     
    470653        my $mask_base;
    471654        if ($want_astrom) {
    472             if (! defined $out->{astrom}) {
     655            if ($selectedAstrom) {
     656                $out->{astrom} = $selectedAstrom;
     657                $out->{cam_path_base} = basename($selectedAstrom);
     658            } elsif (! defined $out->{astrom}) {
    473659                if (! find_astrometry($ipprc, $imagedb, $out, $verbose)) {
    474660                    print STDERR "failed to find astrometry for $stage $stage_id\n";
     
    505691    my $byid     = shift;
    506692    my $option_mask  = shift;
    507     my $img_type = shift;
     693    my $stage = shift;
    508694    my $verbose = shift;
    509695
     
    573759            # we have a stack - stack diff (well it might be stack - warp....)
    574760            # 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";
     761            if (($stage ne "diff") and ($stage ne "stack")) {
     762                print STDERR "lookup_diff: cannot lookup IMG_TYPE $stage bydiff from a stack stack diff run\n";
    577763                setErrorCodes($rowList, $PSTAMP_INVALID_REQUEST);
    578764                # all images will be the same so we can stop
     
    625811        }
    626812
    627         if ($img_type eq "diff") {
     813        if ($stage eq "diff") {
    628814            my @imageList = ($image);
    629815
     
    656842sub lookup_bycoord {
    657843    my $ipprc      = shift;
    658     my $rowList    = shift;
     844    my $row        = shift;
    659845    my $imagedb    = shift;
    660     my $img_type   = shift;
     846    my $stage      = shift;
    661847    my $tess_id    = shift;
    662848    my $component  = shift;
     
    671857    my $mjd_min = shift;
    672858    my $mjd_max = shift;
     859    my $astrom = shift;
    673860    my $verbose    = shift;
    674861
     862    my ($release_name, $survey) = get_release_info($row);
     863
     864    my $rowList = [$row];
     865
    675866    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);
     867    if (($stage eq "raw") or ($stage eq "chip")) {
     868
     869        my $chips = lookup_by_cam_id_and_coords($ipprc, $imagedb, $stage,
     870            $ra, $dec, $need_magic, $dateobs_begin, $dateobs_end, $filter, $data_group, $verbose, $release_name, $survey, $row->{FWHM_MIN}, $row->{FWHM_MAX});
    680871
    681872        if (!$chips or scalar @$chips == 0) {
     
    684875            foreach my $chip (@$chips) {
    685876                next if $component and ($chip->{component} ne $component);
    686                 my $these_results = lookup($ipprc, $rowList, $imagedb, "byid", $img_type, $chip->{id},
     877                my $these_results = lookup($ipprc, $rowList, $imagedb, "byid", $stage, $chip->{id},
    687878                    $tess_id, $chip->{component}, $need_magic,
    688                     $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max, $verbose);
     879                    $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max,
     880                    $chip->{astrom}, undef, undef,
     881                    $verbose);
    689882
    690883                next if !$these_results;
     
    695888    } else {
    696889        # 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");
     890        die "unexpected image type $stage" if ($stage ne "warp")
     891                                              and ($stage ne "stack") and ($stage ne "diff");
    699892
    700893        my $skycells = lookup_skycell_by_coords($ipprc, $tess_id, $component, $ra, $dec, $verbose);
     
    704897        } else {
    705898            foreach my $skycell (@$skycells) {
    706                 my $these_results = lookup($ipprc, $rowList, $imagedb, "byskycell", $img_type, undef,
     899                my $these_results = lookup($ipprc, $rowList, $imagedb, "byskycell", $stage, undef,
    707900                    $skycell->{tess_id}, $skycell->{component}, $need_magic,
    708                     $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max, $verbose);
     901                    $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max,
     902                    undef, $release_name, $survey,
     903                    $verbose);
    709904
    710905                next if !$these_results;
     
    722917
    723918sub 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;
     919    my $ipprc       = shift;
     920    my $imagedb     = shift;
     921    my $stage       = shift;
     922    my $ra          = shift;
     923    my $dec         = shift;
     924    my $need_magic  = shift;
    730925    my $dateobs_begin  = shift;
    731926    my $dateobs_end = shift;
     
    733928    my $data_group = shift;
    734929    my $verbose    = shift;
    735 
    736     my $camruns;
    737 
    738     {
    739         my $search_radius = 1.6; # XXX: this should be camera specific
    740 
     930    my $release_name = shift;
     931    my $survey      = shift;
     932    my $fwhm_min    = shift;
     933    my $fwhm_max    = shift;
     934
     935    my $search_radius = 1.6; # XXX: this should be camera specific
     936
     937    my $command;
     938    my $using_camtool = 0;
     939    if ($release_name or $survey) {
     940        $command = "$releasetool -dbname $imagedb -listrelexp";
     941        if (!isnull($survey)) {
     942            $command .= " -survey_name $survey";
     943        }
     944        if (!isnull($release_name)) {
     945            $command .= " -release_name $release_name";
     946        } else {
     947            $command .= " -priority_order";
     948        }
     949        if ($fwhm_min != 0) {
     950            $command .= " -fwhm_min $fwhm_min";
     951        }
     952        if ($fwhm_max != 0) {
     953            $command .= " -fwhm_max $fwhm_max";
     954        }
     955    } else {
     956        $using_camtool = 1;
    741957        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;
    746958           # NOTE: we are applying the data_group to the camera run.
    747959           # If we're looking for chip stage images there is no guarentee that
     
    755967           }
    756968           $command .= " -destreaked" if $need_magic;
    757 
    758         # run the tool and parse the output
    759         $camruns = runToolAndParse($command, $verbose);
    760     }
    761     if (!$camruns) {
     969    }
     970    $command .= " -ra $ra -decl $dec -radius $search_radius";
     971    $command .= " -dateobs_begin $dateobs_begin" if $dateobs_begin;
     972    $command .= " -dateobs_end   $dateobs_end"   if $dateobs_end  ;
     973    $command .= " -filter $filter" if $filter;
     974
     975    # run the tool and parse the output
     976    my $results = runToolAndParse($command, $verbose);
     977    if (!$results) {
    762978        return undef;
    763979    }
    764980    my $components;
    765981    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 
     982    foreach my $result (@$results) {
     983        my $cam_id = $result->{cam_id};
     984        my $exp_id = $result->{exp_id};
     985
     986        # go on if we already have a result for this exposure
    770987        next if $exp_id eq $last_exp_id;
    771988
    772         next if $camRun->{quality};
    773         next if $camRun->{fault};
    774 
    775         updateCamRunCache($camRun);
     989        next if $result->{quality};
     990
     991        if ($using_camtool) {
     992            next if $result->{fault};
     993        } else {
     994            $result->{path_base} = $result->{cam_path_base};
     995        }
     996        updateCamRunCache($result);
    776997
    777998        $last_exp_id = $exp_id;
    778999
    7791000        # XXX Use file rule
    780         my $astrom = $camRun->{path_base} . ".smf";
     1001        my $astrom = $result->{path_base} . ".smf";
    7811002        my $astrom_resolved = $ipprc->file_resolve($astrom);
    7821003        next if !$astrom_resolved;
     
    8321053        }
    8331054
    834         print "cam_id $cam_id exp_id $camRun->{exp_id} chip_id $camRun->{chip_id} $class_id\n";
     1055        print "cam_id $cam_id exp_id $result->{exp_id} chip_id $result->{chip_id} $class_id\n";
    8351056
    8361057        # build the hash to return
     
    8401061        # problem
    8411062        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},
     1063            exp_id    => $result->{exp_id},
     1064            exp_name  => $result->{exp_name},
     1065            chip_id   => $result->{chip_id},
     1066            cam_id    => $result->{cam_id},
    8461067            class_id  => $class_id,
    847             component => $class_id
     1068            component => $class_id,
     1069            astrom    => $astrom
    8481070        };
    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};
     1071        if ($stage eq "chip") {
     1072            $comp->{id} = $result->{chip_id};
     1073            $comp->{state} = $result->{chip_state};
     1074            $comp->{magicked} = 0;
     1075        } else {
     1076            $comp->{id} = $result->{exp_id};
    8551077            $comp->{state} = 'full';
    856             $comp->{magicked} = $camRun->{raw_magicked};
     1078            $comp->{magicked} = $0;
    8571079        }
    8581080        push @$components, $comp;
     
    12811503}
    12821504
     1505sub selectComponentsByName {
     1506    my $ipprc = shift;
     1507    my $imagedb = shift;
     1508    my $req_type = shift;
     1509    my $stage  = shift;
     1510    my $component  = shift;
     1511    my $rowList = shift;
     1512    my $runList = shift;
     1513    my $verbose = shift;
     1514    my $results = [];
     1515
     1516    $component = "" if $component and lc($component) eq 'all';
     1517
     1518    # all runs match all rows so they can share a common row_index
     1519    # XXX: I'm not sure we ever actually get here with more than one
     1520    # row
     1521    my $numRows = scalar @$rowList;
     1522    my $row_index = [];
     1523    for (my $i=0; $i < $numRows; $i++) {
     1524        push @$row_index, $i;
     1525    }
     1526   
     1527    if (($req_type eq "byid") or ($req_type eq "byexp")) {
     1528        my ($last_tess_id, $tess_dir_abs, $astrom_file) = ("", "", "");
     1529        foreach my $run (@$runList) {
     1530            # now find the images for this run
     1531            #foreach my $c (keys %components) {
     1532            my $command;
     1533            my $stage_id;
     1534            if ($stage eq 'raw') {
     1535                $stage_id = $run->{exp_id};
     1536                $command = "$regtool -processedimfile -exp_id $stage_id";
     1537                $command .= " -class_id $component" if $component;
     1538            } elsif ($stage eq 'chip') {
     1539                $stage_id = $run->{chip_id};
     1540                $command = "$chiptool -processedimfile -chip_id $stage_id";
     1541                $command .= " -class_id $component" if $component;
     1542            } elsif ($stage eq 'warp') {
     1543                $stage_id = $run->{warp_id};
     1544                $command = "$warptool -warped -warp_id $stage_id";
     1545                $command .= " -skycell_id $component" if $component;
     1546            }
     1547            $command .= " -dbname $imagedb";
     1548            my $images = runToolAndParse($command, $verbose);
     1549            if (!defined $images) {
     1550                print "No  $component found for $stage ${stage}_id $stage_id\n";
     1551                next;
     1552            }
     1553            foreach my $image (@$images) {
     1554                $image->{row_index} = $row_index;
     1555                if (($stage eq "raw") or ($stage eq 'chip')) {
     1556                    $image->{cam_id} = $run->{cam_id};
     1557                    $image->{cam_path_base} = $run->{cam_path_base};
     1558                }
     1559                push @$results, $image;
     1560            }
     1561        }
     1562    } else {
     1563        &my_die ("selectComponentsByName not supported for REQ_TYPE: $req_type\n", $PS_EXIT_PROG_ERROR);
     1564    }
     1565    return $results;
     1566}
     1567
    12831568sub filterRuns {
    12841569    my $stage      = shift;
     
    14071692    $dvoImagesAtCoords = can_run('dvoImagesAtCoords') or (warn "Can't find dvoImagesAtCoords"
    14081693                                                                and $missing_tools = 1);
     1694    $releasetool = can_run('releasetool') or (warn "Can't find releasetool"
     1695                                                                and $missing_tools = 1);
    14091696    $whichimage = can_run('whichimage') or (warn "Can't find whichimage" and $missing_tools = 1);
    14101697    $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
     
    14621749}
    14631750
     1751sub get_release_info {
     1752    my $row = shift;
     1753
     1754    my $survey;
     1755    my $release_name = $row->{IPP_RELEASE};
     1756    if (isnull($release_name)) {
     1757        $release_name = "";
     1758        # no release check for survey
     1759        $survey = $row->{SURVEY_NAME};
     1760    } else {
     1761        $survey = "";
     1762    }
     1763
     1764    return ($release_name, $survey);
     1765}
     1766
    14641767sub my_die
    14651768{
Note: See TracChangeset for help on using the changeset viewer.