IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 35489


Ignore:
Timestamp:
May 2, 2013, 2:15:28 PM (13 years ago)
Author:
bills
Message:

Merge a whole bunch of changes from recent development.
Areas affected

Postage Stamp Server: support for version 2 of the request interface
ippTools/ippScripts/ippTasks: release tracking, lap groups (for staticsky queuing)
ippTools: integrate a couple of fixes from Heather which she has been running in the ippdvo user's build

Location:
tags/ipp-20130307
Files:
48 edited
38 copied

Legend:

Unmodified
Added
Removed
  • tags/ipp-20130307/DataStoreServer

  • tags/ipp-20130307/PS-IPP-PStamp

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

    r35480 r35489  
    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
    5152my $default_data_groups = "";
     53
     54# old locate_images() function. Still used by dqueryparse
     55# Postage stamp server now uses locate_images_for_row()
    5256
    5357sub locate_images {
    … …  
    5660    my $rowList  = shift;   # required
    5761    my $req_type = shift;   # required
    58     my $img_type = shift;   # required
     62    my $stage = shift;   # required
    5963    my $id       = shift;   # required unless req_type eq bycoord or byskycell
    6064    my $tess_id  = shift;
    … …  
    7882           ($req_type ne "byskycell");
    7983
    80     if (!$default_data_groups) {
     84    if (!$data_group and !$default_data_groups) {
    8185        $default_data_groups = load_data_groups($verbose);
    8286    }
    … …  
    106110        my $x = $row->{CENTER_X};
    107111        my $y = $row->{CENTER_Y};
    108         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);
     112        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);
    109113        return $results;
    110114    }
    111115
    112     if (($req_type eq "byid") and ($img_type eq "diff")) {
     116    if (($req_type eq "byid") and ($stage eq "diff")) {
    113117        # lookups of all of the information for diff images requires a two level lookup to
    114118        # get the exposure information. Switching the req_type allows us to keep that code
    115119        # in one place
    116120        $req_type = "bydiff";
    117         my $results = lookup_diff($ipprc, $rowList, $imagedb, $id, $component, 1, $option_mask, $img_type, $verbose);
     121        my $results = lookup_diff($ipprc, $rowList, $imagedb, $id, $component, 1, $option_mask, $stage, $verbose);
    118122        return $results;
    119123    }
    … …  
    122126        # for bydiff reuqests we go look up the diffRun to obtain exp_id, chip_id, warp_id, stack_id, or
    123127        # the image from the diffRun
    124         my $results = lookup_diff($ipprc, $rowList, $imagedb, $id, $component, 0, $option_mask, $img_type, $verbose);
     128        my $results = lookup_diff($ipprc, $rowList, $imagedb, $id, $component, 0, $option_mask, $stage, $verbose);
    125129        if (!$results) {
    126130            return undef;
    127131        }
    128         if ($img_type eq "diff") {
     132        if ($stage eq "diff") {
    129133            # lookup_diff has done all of the work
    130134            return $results;
    … …  
    132136
    133137        my $image = $results->[0];
    134         if ($img_type eq "raw") {
     138        if ($stage eq "raw") {
    135139            $req_type = "byid";
    136140            $id = $image->{exp_id};
    137141            return undef if !$id;
    138142            # fall through and lookup byid
    139         } elsif ($img_type eq "chip") {
     143        } elsif ($stage eq "chip") {
    140144            $req_type = "byid";
    141145            $id = $image->{chip_id};
    142146            return undef if !$id;
    143147            # fall through and lookup byid
    144         } elsif ($img_type eq "warp") {
     148        } elsif ($stage eq "warp") {
    145149            $req_type = "byid";
    146150            $id = $image->{warp_id};
    … …  
    148152            return undef if !$id;
    149153            # fall through and lookup by warp_id
    150         } elsif ($img_type eq "stack") {
     154        } elsif ($stage eq "stack") {
    151155            $req_type = "byid";
    152156            $id = $image->{stack_id};
    … …  
    155159        } else {
    156160            # This is checked this elsewhere?
    157             print STDERR "Error: $img_type is an unknown image type\n";
     161            print STDERR "Error: $stage is an unknown image type\n";
    158162            return undef;
    159163        }
    160164    } elsif ($req_type eq "byskycell") {
    161         if (($img_type eq "raw") or ($img_type eq "chip")) {
     165        if (($stage eq "raw") or ($stage eq "chip")) {
    162166            print STDERR "REQ_TYPE byskycell not supported for IMG_TYPE raw or chip\n";
    163167            return undef;
    … …  
    169173    }
    170174
    171     my $results = lookup($ipprc, $rowList, $imagedb, $req_type, $img_type, $id, $tess_id, $component,
    172         $need_magic, $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max, $verbose);
     175    my $results = lookup($ipprc, $rowList, $imagedb, $req_type, $stage, $id, $tess_id, $component,
     176        $need_magic, $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max,
     177        0, 0,   # fwhm cuts are not applied here
     178        undef, undef, undef, $verbose);
     179
     180    return $results;
     181}
     182
     183sub locate_images_for_row {
     184    my $ipprc    = shift;
     185    my $imagedb  = shift;
     186    my $camera   = shift;
     187    my $row      = shift;
     188    my $verbose  = shift;
     189
     190    my $req_type  = $row->{REQ_TYPE};
     191
     192    # we die in response to bad data in request files
     193    # The caller is responsible for updating the database
     194    # pstampparse.pl error checks now so this shouldn't happen
     195    &my_die("Unknown req_type: $req_type", $PS_EXIT_PROG_ERROR)
     196        if ($req_type ne "byid") and
     197           ($req_type ne "byexp") and
     198           ($req_type ne "bycoord") and
     199           ($req_type ne "bydiff") and
     200           ($req_type ne "byskycell");
     201
     202    my $stage     = $row->{IMG_TYPE};
     203    my $id        = $row->{ID};
     204    my $component = $row->{COMPONENT};
     205    my $tess_id   = $row->{TESS_ID};
     206
     207    my $filter    = $row->{REQFILT};
     208    my $mjd_min   = $row->{MJD_MIN};
     209    my $mjd_max   = $row->{MJD_MAX};
     210    my $data_group = $row->{DATA_GROUP};
     211    if (isnull($data_group) and !$default_data_groups) {
     212        $default_data_groups = load_data_groups($verbose);
     213    }
     214
     215    my $rownum     = $row->{ROWNUM};
     216    my $job_type   = $row->{JOB_TYPE};
     217    my $option_mask= $row->{OPTION_MASK};
     218
     219    my $dateobs_begin;
     220    my $dateobs_end;
     221    if (!iszero($mjd_min)) {
     222        $dateobs_begin = mjd_to_dateobs($mjd_min);
     223    }
     224    if (!iszero($mjd_max)) {
     225        $dateobs_end = mjd_to_dateobs($mjd_max);
     226    }
     227    if (isnull($tess_id)) {
     228        $tess_id = undef;
     229    }
     230    if (isnull($data_group)) {
     231        $data_group = undef;
     232    }
     233    if (isnull($filter)) {
     234        $filter = undef;
     235    }
     236
     237    if ($req_type eq "bycoord") {
     238        my $x = $row->{CENTER_X};
     239        my $y = $row->{CENTER_Y};
     240        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);
     241        return $results;
     242    }
     243
     244    # for compatability with the lower level functions that haven't been converted to take a single row
     245    my $rowList = [$row];
     246
     247    if (($req_type eq "byid") and ($stage eq "diff")) {
     248        # lookups of all of the information for diff images requires a two level lookup to
     249        # get the exposure information. Switching the req_type allows us to keep that code
     250        # in one place
     251        $req_type = "bydiff";
     252        my $results = lookup_diff($ipprc, $rowList, $imagedb, $id, $component, 1, $option_mask, $stage, $verbose);
     253        return $results;
     254    }
     255
     256    my ($release_name, $survey, $default_tess_id) = get_release_info($row);
     257    if (!$tess_id and $default_tess_id) {
     258        $tess_id = $default_tess_id;
     259    }
     260
     261    if ($req_type eq "bydiff") {
     262        # for bydiff reuqests we go look up the diffRun to obtain exp_id, chip_id, warp_id, stack_id, or
     263        # the image from the diffRun
     264        my $results = lookup_diff($ipprc, $rowList, $imagedb, $id, $component, 0, $option_mask, $stage, $verbose);
     265        if (!$results) {
     266            return undef;
     267        }
     268        if ($stage eq "diff") {
     269            # lookup_diff has done all of the work
     270            return $results;
     271        }
     272
     273        my $image = $results->[0];
     274        if ($stage eq "raw") {
     275            $req_type = "byid";
     276            $id = $image->{exp_id};
     277            return undef if !$id;
     278            # fall through and lookup byid
     279        } elsif ($stage eq "chip") {
     280            $req_type = "byid";
     281            $id = $image->{chip_id};
     282            return undef if !$id;
     283            # fall through and lookup byid
     284        } elsif ($stage eq "warp") {
     285            $req_type = "byid";
     286            $id = $image->{warp_id};
     287            $component = $image->{skycell_id};
     288            return undef if !$id;
     289            # fall through and lookup by warp_id
     290        } elsif ($stage eq "stack") {
     291            $req_type = "byid";
     292            $id = $image->{stack_id};
     293            return undef if !$id;
     294            # fall though and lookup by stack_id
     295        } else {
     296            # This is checked this elsewhere?
     297            print STDERR "Error: $stage is an unknown image type\n";
     298            return undef;
     299        }
     300    } elsif ($req_type eq "byskycell") {
     301        if (($stage eq "raw") or ($stage eq "chip")) {
     302            print STDERR "REQ_TYPE byskycell not supported for IMG_TYPE raw or chip\n";
     303            return undef;
     304        }
     305        if (!$tess_id or !$component) {
     306            print STDERR "component and tess_id are required for REQ_TYPE byskycell\n";
     307            return undef;
     308        }
     309    }
     310
     311    my $results = lookup($ipprc, $rowList, $imagedb, $req_type, $stage, $id, $tess_id, $component,
     312        0, $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max,
     313        getValOrZero($row->{FWHM_MIN}), getValOrZero($row->{FWHM_MAX}),
     314        undef, $release_name, $survey,
     315        $verbose);
    173316
    174317    return $results;
    … …  
    195338    my $mjd_min = shift;
    196339    my $mjd_max = shift;
     340    my $fwhm_min = shift;
     341    my $fwhm_max = shift;
     342    my $selectedAstrom = shift;
     343    my $release_name = shift;
     344    my $survey = shift;
    197345    my $verbose  = shift;
    198346
    … …  
    219367    my $magic_arg = $need_magic ? " -destreaked" : "";
    220368
     369    my $row = $rowList->[0];
     370
    221371    # all rows have the same center type
    222     my $skycenter = ! ($rowList->[0]->{COORD_MASK} & $PSTAMP_CENTER_IN_PIXELS);
     372    my $skycenter = ! ($row->{COORD_MASK} & $PSTAMP_CENTER_IN_PIXELS);
     373
     374    my $use_releasetool = 0;
     375    my $release_args;
     376    if (($req_type eq 'byexp' and $stage ne 'raw') or ($req_type eq 'byskycell' and $stage ne 'diff')) {
     377        if ($release_name or $survey) {
     378            $use_releasetool = 1;
     379            if ($release_name) {
     380                $release_args = " -release_name $release_name";
     381            } else {
     382                $release_args = " -priority_order";
     383            }
     384            $release_args .= " -surveyName $survey" if $survey;
     385        }
     386    }
    223387
    224388    my $component_args;
    … …  
    251415        # use chiptool -processsedimfile. Otherwise use chiptool -listrun and then
    252416        # choose the chips containing the center pixel by calling selectComponets() below
    253         if ($component or $use_imfile_id or !$skycenter) {
    254             $command = "$chiptool -processedimfile -pstamp_order -dbname $imagedb";
    255             if ($component and $component ne 'all') {
    256                 $class_id = $component;
    257                 $component_args = " -class_id $class_id";
    258             }
    259         } else {
    260             $command = "$chiptool -listrun -pstamp_order -dbname $imagedb";
     417        if ($use_releasetool) {
     418            $command = "$releasetool -dbname $imagedb -listrelexp $release_args";
    261419            $choose_components = 1;
    262         }
    263         $id_opt = $use_imfile_id ? "-chip_imfile_id" : "-chip_id";
     420        } else {
     421            $command = "$chiptool -pstamp_order -dbname $imagedb";
     422            if ($component or $use_imfile_id or !$skycenter) {
     423                $command .= " -processedimfile";
     424                if ($component and $component ne 'all') {
     425                    $class_id = $component;
     426                    $component_args = " -class_id $class_id";
     427                }
     428            } else {
     429                $command .= " -listrun";
     430                $choose_components = 1;
     431            }
     432            $id_opt = $use_imfile_id ? "-chip_imfile_id" : "-chip_id";
     433        }
    264434        # XXX: perhaps we should stop resolving images to this level here and do it at job run time.
    265435        # With the mdc file it has all of the information that it needs.
    … …  
    275445        $want_astrom  = 1;
    276446        $set_class_id = 1;
    277     } elsif ($stage eq "warp") {
    278         if ($component or $use_imfile_id or !$skycenter) {
    279             $command = "$warptool -warped -pstamp_order -dbname $imagedb";
    280             if ($component and $component ne 'all') {
    281                 $skycell_id = $component;
    282                 $component_args = " -skycell_id $skycell_id";
    283             }
    284         } else {
    285             $command = "$warptool -listrun -pstamp_order -dbname $imagedb";
     447    } elsif ($stage eq 'warp') {
     448        if ($use_releasetool) {
     449            $command = "$releasetool -dbname $imagedb -listrelexp $release_args";
     450            $skycell_id = $component;
    286451            $choose_components = 1;
    287         }
    288         $id_opt = $use_imfile_id ? "-warp_skyfile_id" : "-warp_id";
     452        } else {
     453            $command = "$warptool -pstamp_order -dbname $imagedb";
     454            if ($component or $use_imfile_id or !$skycenter) {
     455                $command .= " -warped";
     456                if ($component and $component ne 'all') {
     457                    $skycell_id = $component;
     458                    $component_args = " -skycell_id $skycell_id";
     459                }
     460            } else {
     461                $command .= " -listrun";
     462                $choose_components = 1;
     463            }
     464            $id_opt = $use_imfile_id ? "-warp_skyfile_id" : "-warp_id";
     465        }
    289466        $image_name   = "PSWARP.OUTPUT";
    290467        $mask_name    = "PSWARP.OUTPUT.MASK";
    … …  
    294471        $base_name    = "path_base"; # name of the field for the warptool output
    295472    } elsif ($stage eq "diff") {
     473        # XXX: is this path ever used for diff images anymore?
    296474        if ($component or $use_imfile_id or !$skycenter) {
    297475            $command = "$difftool -diffskyfile -pstamp_order -dbname $imagedb";
    … …  
    314492    } elsif ($stage eq "stack") {
    315493        $skycell_id = $component;
    316         $command = "$stacktool -sumskyfile -dbname $imagedb";
    317         # only consider stacks in full state.
    318         $command .= " -state full";
    319         $id_opt = "-stack_id";
     494        if ($use_releasetool) {
     495            $command = "$releasetool -listrelstack -dbname $imagedb $release_args";
     496            $base_name = 'stack_path_base';
     497            my $stack_type = $row->{RUN_TYPE};
     498            if (!isnull($stack_type)) {
     499                if (lc($stack_type) eq 'notnightly') {
     500                    $command .= " -stack_type deep -stack_type reference";
     501                } else {
     502                    $command .= " -stack_type $stack_type";
     503                }
     504            }
     505        } else {
     506            $command = "$stacktool -sumskyfile -dbname $imagedb";
     507            # only consider stacks in full state.
     508            $command .= " -state full";
     509            $id_opt = "-stack_id";
     510            $base_name = 'path_base';
     511        }
    320512        $component_args = " -skycell_id $skycell_id" if $skycell_id and $skycell_id ne  'all';
    321513
    … …  
    331523        # this is wrong but gets the right answer. Need to figure out how to find the
    332524        # rule properly
    333         #$cmf_name    = "PSPHOT.OUTPUT";    # this puts .fpa. in the name
    334525        $cmf_name     = "PSWARP.OUTPUT.SOURCES";
     526        # $cmf_name    = "PSPHOT.OUTPUT";    # this puts .fpa. in the name
    335527        $psf_name    = "PPSTACK.TARGET.PSF";
    336         $base_name   = "path_base";
    337528    } else {
    338         die "Unknown IMG_TYPe supplied: $stage";
     529        die "Unknown IMG_TYPE supplied: $stage";
    339530    }
    340531
    … …  
    371562        $command .= " -dateobs_end $dateobs_end" if $dateobs_end;
    372563    } elsif ($req_type ne "byid") {
    373         $command .= " -mjd_obs_begin $mjd_min" if $mjd_min;
    374         $command .= " -mjd_obs_end $mjd_max" if $mjd_max;
     564        $command .= " -mjd_min $mjd_min" if $mjd_min;
     565        $command .= " -mjd_max $mjd_max" if $mjd_max;
    375566    }
    376567
    … …  
    379570    if (!isnull($data_group)) {
    380571        $command .= " -data_group $data_group";
    381     } elsif ($req_type eq 'byskycell') {
     572    } elsif (!$use_releasetool and $req_type eq 'byskycell') {
     573        # XXX: Why am I using default data_groups only for byskycell requests?
    382574        $command .= $default_data_groups;
     575    }
     576
     577    if ($use_releasetool) {
     578        # fwhm arguments are currently only supported when using releasetool for lookups
     579        $command .= " -fwhm_min $fwhm_min" if $fwhm_min;
     580        $command .= " -fwhm_max $fwhm_max" if $fwhm_max;
    383581    }
    384582
    … …  
    394592        $images = filterRuns($stage, $need_magic, $images, $inverse, $verbose);
    395593    }
     594
    396595    if ($choose_components) {
    397596        # the list of "images" is actually a list of "Runs"
    398597        # match the coords in the rows to the components in the runs
    399598        # returns an actual list of images
    400         $images = selectComponents($ipprc, $imagedb, $req_type, $stage, $rowList, $images, $verbose);
     599        if ($skycenter and $req_type ne 'byskycell') {
     600            $images = selectComponents($ipprc, $imagedb, $req_type, $stage, $rowList, $images, $verbose);
     601        } else {
     602            $images = selectComponentsByName($ipprc, $imagedb, $req_type, $stage, $component, $rowList, $images, $verbose);
     603        }
    401604    } else {
    402         # put index for each of the rows into all of the the images
     605        # put index for each of the rows into all of the the selected images
    403606        setRowRefs($rowList, $images);
    404607    }
    … …  
    464667            # dquery wants these set
    465668            $out->{magicked} = 0;
    466             $out->{data_state} = $out->{state};
     669            if ($use_releasetool) {
     670                if ($image->{skycal_path_base}) {
     671                    $out->{astrom} = $image->{skycal_path_base} . ".cmf";
     672                }
     673                $out->{data_state} = $out->{state} = $out->{stack_state};
     674            } else {
     675                # XXX: Consider looking up skycal results even if we are
     676                # not using releasetool
     677                $out->{data_state} = $out->{state};
     678            }
    467679        }
    468680        $out->{stage_id} = $stage_id;
    … …  
    472684        my $mask_base;
    473685        if ($want_astrom) {
    474             if (! defined $out->{astrom}) {
     686            if ($selectedAstrom) {
     687                $out->{astrom} = $selectedAstrom;
     688                $out->{cam_path_base} = $selectedAstrom;
     689                if ($selectedAstrom =~ /\.smf$/) {
     690                    $out->{cam_path_base} =~ s/\.smf$//;
     691                } elsif ($selectedAstrom =~ /\.cmf$/) {
     692                    $out->{cam_path_base} =~ s/\.cmf$//;
     693                } else {
     694                    die ("ERROR: don't know how to extract cam_path_base from $selectedAstrom\n");
     695                }
     696            } elsif (! defined $out->{astrom}) {
    475697                if (! find_astrometry($ipprc, $imagedb, $out, $verbose)) {
    476698                    print STDERR "failed to find astrometry for $stage $stage_id\n";
    … …  
    507729    my $byid     = shift;
    508730    my $option_mask  = shift;
    509     my $img_type = shift;
     731    my $stage = shift;
    510732    my $verbose = shift;
    511733
    … …  
    558780        }
    559781
     782        # XXX: The logic below is somewhat messed up. See XXX: ... below
     783        #
    560784        # The standard way to do a diff is warp - stack
    561785        # so we interpret the requested image in that way
    … …  
    572796        }
    573797        my $stack_id;
     798        if ($image->{diff_mode} == 2) {
     799            # XXX: .. stack_id wasn't getting set
     800            $stack_id = $stack2;
     801            $image->{stack_id} = $stack_id;
     802        }
    574803        if ($stack1 and $stack2) {
    575804            # we have a stack - stack diff (well it might be stack - warp....)
    576805            # but at any rate we only handle image type diff and stack
    577             if (($img_type ne "diff") and ($img_type ne "stack")) {
    578                 print STDERR "lookup_diff: cannot lookup IMG_TYPE $img_type bydiff from a stack stack diff run\n";
     806            if (($stage ne "diff") and ($stage ne "stack")) {
     807                print STDERR "lookup_diff: cannot lookup IMG_TYPE $stage bydiff from a stack stack diff run\n";
    579808                setErrorCodes($rowList, $PSTAMP_INVALID_REQUEST);
    580809                # all images will be the same so we can stop
    … …  
    627856        }
    628857
    629         if ($img_type eq "diff") {
     858        if ($stage eq "diff") {
    630859            my @imageList = ($image);
    631860
    … …  
    658887sub lookup_bycoord {
    659888    my $ipprc      = shift;
    660     my $rowList    = shift;
     889    my $row        = shift;
    661890    my $imagedb    = shift;
    662     my $img_type   = shift;
     891    my $stage      = shift;
    663892    my $tess_id    = shift;
    664893    my $component  = shift;
    … …  
    666895    my $ra         = shift;
    667896    my $dec        = shift;
    668     my $dateobs_begin  = shift;
     897    my $dateobs_begin  = shift; # these are used for single frame lookups
    669898    my $dateobs_end    = shift;
    670899    my $filter     = shift;
    671900    my $data_group = shift;
    672901    my $option_mask = shift;
    673     my $mjd_min = shift;
    674     my $mjd_max = shift;
     902    my $mjd_min = shift;        # these are used for stack lookups
     903    my $mjd_max = shift;        # these are used for stack lookups
    675904    my $verbose    = shift;
    676905
     906    my $fwhm_min = getValOrZero($row->{FWHM_MIN});
     907    my $fwhm_max = getValOrZero($row->{FWHM_MAX});
     908   
     909
     910    my ($release_name, $survey, $default_tess_id) = get_release_info($row);
     911    if (!$tess_id and $default_tess_id) {
     912        $tess_id = $default_tess_id;
     913    }
     914
     915    my $rowList = [$row];
     916
    677917    my $results = ();
    678     if (($img_type eq "raw") or ($img_type eq "chip")) {
    679 
    680         my $chips = lookup_by_cam_id_and_coords($ipprc, $imagedb, $img_type,
    681             $ra, $dec, $need_magic, $dateobs_begin, $dateobs_end, $filter, $data_group, $verbose);
     918    if (($stage eq "raw") or ($stage eq "chip")) {
     919
     920        my $chips = lookup_by_cam_id_and_coords($ipprc, $imagedb, $stage,
     921            $ra, $dec, $need_magic, $dateobs_begin, $dateobs_end, $filter, $data_group, $verbose,
     922            $release_name, $survey, $fwhm_min, $fwhm_max);
    682923
    683924        if (!$chips or scalar @$chips == 0) {
    … …  
    686927            foreach my $chip (@$chips) {
    687928                next if $component and ($chip->{component} ne $component);
    688                 my $these_results = lookup($ipprc, $rowList, $imagedb, "byid", $img_type, $chip->{id},
     929                my $these_results = lookup($ipprc, $rowList, $imagedb, "byid", $stage, $chip->{id},
    689930                    $tess_id, $chip->{component}, $need_magic,
    690                     $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max, $verbose);
     931                    $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max,
     932                    $fwhm_min, $fwhm_max,
     933                    $chip->{astrom}, undef, undef,
     934                    $verbose);
    691935
    692936                next if !$these_results;
    … …  
    697941    } else {
    698942        # this should have been checked elsewhere
    699         die "unexpected image type $img_type" if ($img_type ne "warp")
    700                                               and ($img_type ne "stack") and ($img_type ne "diff");
     943        die "unexpected image type $stage" if ($stage ne "warp")
     944                                              and ($stage ne "stack") and ($stage ne "diff");
    701945
    702946        my $skycells = lookup_skycell_by_coords($ipprc, $tess_id, $component, $ra, $dec, $verbose);
    … …  
    705949            setErrorCodes($rowList, $PSTAMP_NO_IMAGE_MATCH);
    706950        } else {
     951            # XXX: We are not applying the fwhm cuts
    707952            foreach my $skycell (@$skycells) {
    708                 my $these_results = lookup($ipprc, $rowList, $imagedb, "byskycell", $img_type, undef,
     953                my $these_results = lookup($ipprc, $rowList, $imagedb, "byskycell", $stage, undef,
    709954                    $skycell->{tess_id}, $skycell->{component}, $need_magic,
    710                     $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max, $verbose);
     955                    $dateobs_begin, $dateobs_end, $filter, $data_group, $option_mask, $mjd_min, $mjd_max,
     956                    $fwhm_min, $fwhm_max,
     957                    undef, $release_name, $survey,
     958                    $verbose);
    711959
    712960                next if !$these_results;
    … …  
    724972
    725973sub lookup_by_cam_id_and_coords {
    726     my $ipprc      = shift;
    727     my $imagedb   = shift;
    728     my $img_type   = shift;
    729     my $ra         = shift;
    730     my $dec        = shift;
    731     my $need_magic = shift;
     974    my $ipprc       = shift;
     975    my $imagedb     = shift;
     976    my $stage       = shift;
     977    my $ra          = shift;
     978    my $dec         = shift;
     979    my $need_magic  = shift;
    732980    my $dateobs_begin  = shift;
    733981    my $dateobs_end = shift;
    … …  
    735983    my $data_group = shift;
    736984    my $verbose    = shift;
    737 
    738     my $camruns;
    739 
    740     {
    741         my $search_radius = 1.6; # XXX: this should be camera specific
    742 
     985    my $release_name = shift;
     986    my $survey      = shift;
     987    my $fwhm_min    = shift;
     988    my $fwhm_max    = shift;
     989
     990    my $search_radius = 1.6; # XXX: this should be camera specific
     991
     992    my $command;
     993    my $using_camtool = 0;
     994    if ($release_name or $survey) {
     995        $command = "$releasetool -dbname $imagedb -listrelexp";
     996        if ($survey) {
     997            $command .= " -surveyName $survey";
     998        }
     999        if ($release_name) {
     1000            $command .= " -release_name $release_name";
     1001        } else {
     1002            $command .= " -priority_order";
     1003        }
     1004        if ($fwhm_min != 0) {
     1005            $command .= " -fwhm_min $fwhm_min";
     1006        }
     1007        if ($fwhm_max != 0) {
     1008            $command .= " -fwhm_max $fwhm_max";
     1009        }
     1010    } else {
     1011        $using_camtool = 1;
    7431012        my $command = "$camtool -dbname $imagedb -processedexp -pstamp_order";
    744            $command .= " -ra $ra -decl $dec -radius $search_radius";
    745            $command .= " -dateobs_begin $dateobs_begin" if $dateobs_begin;
    746            $command .= " -dateobs_end   $dateobs_end"   if $dateobs_end  ;
    747            $command .= " -filter $filter" if $filter;
    7481013           # NOTE: we are applying the data_group to the camera run.
    7491014           # If we're looking for chip stage images there is no guarentee that
    … …  
    7571022           }
    7581023           $command .= " -destreaked" if $need_magic;
    759 
    760         # run the tool and parse the output
    761         $camruns = runToolAndParse($command, $verbose);
    762     }
    763     if (!$camruns) {
     1024    }
     1025    $command .= " -ra $ra -decl $dec -radius $search_radius";
     1026    $command .= " -dateobs_begin $dateobs_begin" if $dateobs_begin;
     1027    $command .= " -dateobs_end   $dateobs_end"   if $dateobs_end  ;
     1028    $command .= " -filter $filter" if $filter;
     1029
     1030    # run the tool and parse the output
     1031    my $results = runToolAndParse($command, $verbose);
     1032    if (!$results) {
    7641033        return undef;
    7651034    }
    7661035    my $components;
    7671036    my $last_exp_id = 0;
    768     foreach my $camRun (@$camruns) {
    769         my $cam_id = $camRun->{cam_id};
    770         my $exp_id = $camRun->{exp_id};
    771 
     1037    foreach my $result (@$results) {
     1038        my $cam_id = $result->{cam_id};
     1039        my $exp_id = $result->{exp_id};
     1040
     1041        # go on if we already have a result for this exposure
    7721042        next if $exp_id eq $last_exp_id;
    7731043
    774         next if $camRun->{quality};
    775         next if $camRun->{fault};
    776 
    777         updateCamRunCache($camRun);
     1044        next if $result->{quality};
     1045
     1046        if ($using_camtool) {
     1047            next if $result->{fault};
     1048        } else {
     1049            $result->{path_base} = $result->{cam_path_base};
     1050        }
     1051        updateCamRunCache($result);
    7781052
    7791053        $last_exp_id = $exp_id;
    7801054
    7811055        # XXX Use file rule
    782         my $astrom = $camRun->{path_base} . ".smf";
     1056        my $astrom = $result->{path_base} . ".smf";
    7831057        my $astrom_resolved = $ipprc->file_resolve($astrom);
    7841058        next if !$astrom_resolved;
    … …  
    8341108        }
    8351109
    836         print "cam_id $cam_id exp_id $camRun->{exp_id} chip_id $camRun->{chip_id} $class_id\n";
     1110        print "cam_id $cam_id exp_id $result->{exp_id} chip_id $result->{chip_id} $class_id\n";
    8371111
    8381112        # build the hash to return
    … …  
    8421116        # problem
    8431117        my $comp = {
    844             exp_id    => $camRun->{exp_id},
    845             exp_name  => $camRun->{exp_name},
    846             chip_id   => $camRun->{chip_id},
    847             cam_id    => $camRun->{cam_id},
     1118            exp_id    => $result->{exp_id},
     1119            exp_name  => $result->{exp_name},
     1120            chip_id   => $result->{chip_id},
     1121            cam_id    => $result->{cam_id},
    8481122            class_id  => $class_id,
    849             component => $class_id
     1123            component => $class_id,
     1124            astrom    => $astrom
    8501125        };
    851         if ($img_type eq "chip") {
    852             $comp->{id} = $camRun->{chip_id};
    853             $comp->{state} = $camRun->{chip_state};
    854             $comp->{magicked} = $camRun->{chip_magicked};
    855         } else {
    856             $comp->{id} = $camRun->{exp_id};
     1126        if ($stage eq "chip") {
     1127            $comp->{id} = $result->{chip_id};
     1128            $comp->{state} = $result->{chip_state};
     1129            $comp->{magicked} = 0;
     1130        } else {
     1131            $comp->{id} = $result->{exp_id};
    8571132            $comp->{state} = 'full';
    858             $comp->{magicked} = $camRun->{raw_magicked};
     1133            $comp->{magicked} = $0;
    8591134        }
    8601135        push @$components, $comp;
    … …  
    10721347    my $val = shift;
    10731348    return (!defined($val) or ($val == 0));
     1349}
     1350
     1351sub getValOrZero {
     1352    my $val = shift;
     1353    return iszero($val) ? 0.0 : $val;
    10741354}
    10751355
    … …  
    12831563}
    12841564
     1565sub selectComponentsByName {
     1566    my $ipprc = shift;
     1567    my $imagedb = shift;
     1568    my $req_type = shift;
     1569    my $stage  = shift;
     1570    my $component  = shift;
     1571    my $rowList = shift;
     1572    my $runList = shift;
     1573    my $verbose = shift;
     1574    my $results = [];
     1575
     1576    $component = "" if $component and lc($component) eq 'all';
     1577
     1578    # all runs match all rows so they can share a common row_index
     1579    # XXX: I'm not sure we ever actually get here with more than one
     1580    # row
     1581    my $numRows = scalar @$rowList;
     1582    my $row_index = [];
     1583    for (my $i=0; $i < $numRows; $i++) {
     1584        push @$row_index, $i;
     1585    }
     1586   
     1587    # XXX: Why did I make this restriction? I added byskycell
     1588    if (($req_type eq "byid") or ($req_type eq "byexp") or ($req_type eq 'byskycell')) {
     1589        my ($last_tess_id, $tess_dir_abs, $astrom_file) = ("", "", "");
     1590        foreach my $run (@$runList) {
     1591            # now find the images for this run
     1592            #foreach my $c (keys %components) {
     1593            my $command;
     1594            my $stage_id;
     1595            if ($stage eq 'raw') {
     1596                $stage_id = $run->{exp_id};
     1597                $command = "$regtool -processedimfile -exp_id $stage_id";
     1598                $command .= " -class_id $component" if $component;
     1599            } elsif ($stage eq 'chip') {
     1600                $stage_id = $run->{chip_id};
     1601                $command = "$chiptool -processedimfile -chip_id $stage_id";
     1602                $command .= " -class_id $component" if $component;
     1603            } elsif ($stage eq 'warp') {
     1604                $stage_id = $run->{warp_id};
     1605                $command = "$warptool -warped -warp_id $stage_id";
     1606                $command .= " -skycell_id $component" if $component;
     1607            }
     1608            $command .= " -dbname $imagedb";
     1609            my $images = runToolAndParse($command, $verbose);
     1610            if (!defined $images) {
     1611                print "No  $component found for $stage ${stage}_id $stage_id\n";
     1612                next;
     1613            }
     1614            foreach my $image (@$images) {
     1615                $image->{row_index} = $row_index;
     1616                if (($stage eq "raw") or ($stage eq 'chip')) {
     1617                    $image->{cam_id} = $run->{cam_id};
     1618                    $image->{cam_path_base} = $run->{cam_path_base};
     1619                }
     1620                push @$results, $image;
     1621            }
     1622        }
     1623    } else {
     1624        &my_die ("selectComponentsByName not supported for REQ_TYPE: $req_type\n", $PS_EXIT_PROG_ERROR);
     1625    }
     1626    return $results;
     1627}
     1628
    12851629sub filterRuns {
    12861630    my $stage      = shift;
    … …  
    14091753    $dvoImagesAtCoords = can_run('dvoImagesAtCoords') or (warn "Can't find dvoImagesAtCoords"
    14101754                                                                and $missing_tools = 1);
     1755    $releasetool = can_run('releasetool') or (warn "Can't find releasetool"
     1756                                                                and $missing_tools = 1);
    14111757    $whichimage = can_run('whichimage') or (warn "Can't find whichimage" and $missing_tools = 1);
    14121758    $ppConfigDump = can_run('ppConfigDump') or (warn "Can't find ppConfigDump" and $missing_tools = 1);
    … …  
    14641810}
    14651811
     1812sub get_release_info {
     1813    my $row = shift;
     1814
     1815    my $survey;
     1816    my $release_name = $row->{IPP_RELEASE};
     1817    if (isnull($release_name)) {
     1818        $release_name = "";
     1819        # no release check for survey
     1820        $survey = isnull($row->{SURVEY_NAME}) ? "" : $row->{SURVEY_NAME};
     1821    } else {
     1822        # if release is given leave survey empty
     1823        $survey = "";
     1824    }
     1825
     1826    my $tess_id;
     1827    if ($release_name) {
     1828        # hack to optimize bycoord and byskycell lookups for well known releases
     1829        # XXX: todo query database and return a list for the survey or release
     1830        if ($release_name eq '3PI.PV1') {
     1831            $tess_id = 'RINGS.V3';
     1832        }
     1833    }
     1834
     1835    return ($release_name, $survey, $tess_id);
     1836}
     1837
    14661838sub my_die
    14671839{
  • tags/ipp-20130307/PS-IPP-PStamp/lib/PS/IPP/PStamp/RequestFile.pm

    r34448 r35489  
    4444                    $PSTAMP_DUP_REQUEST
    4545                    $PSTAMP_INVALID_REQUEST
     46                    $PSTAMP_UNKNOWN_PROJECT
    4647                    $PSTAMP_UNKNOWN_PRODUCT
    4748                    $PSTAMP_NO_IMAGE_MATCH
    … …  
    8081our $PSTAMP_USE_IMFILE_ID      = 16384;
    8182our $PSTAMP_NO_WAIT_FOR_UPDATE = 32768;
     83
     84# these bits will be repurposed
    8285our $PSTAMP_REQUEST_UNCENSORED = 0x10000;
    8386our $PSTAMP_REQUIRE_UNCENSORED = 0x20000;
    … …  
    9396our $PSTAMP_DUP_REQUEST      = 20;
    9497our $PSTAMP_INVALID_REQUEST  = 21;
    95 our $PSTAMP_UNKNOWN_PRODUCT  = 22;
     98our $PSTAMP_UNKNOWN_PROJECT  = 22;
     99our $PSTAMP_UNKNOWN_PRODUCT  = 22;  #this error code was mis-named it is left for compatabiliyt
    96100our $PSTAMP_NO_IMAGE_MATCH   = 23;
    97101our $PSTAMP_NOT_DESTREAKED   = 24;
    98102our $PSTAMP_NOT_AVAILABLE    = 25;
    99 our $PSTAMP_GONE             = 26;
     103our $PSTAMP_GONE             = 26;  # this value is used in ippTools
    100104our $PSTAMP_NO_JOBS_QUEUED   = 27;
    101105our $PSTAMP_NO_OVERLAP       = 28;
    … …  
    131135PSTAMP_DUP_REQUEST
    132136PSTAMP_INVALID_REQUEST
    133 PSTAMP_UNKNOWN_PRODUCT
     137PSTAMP_UNKNOWN_PROJECT
    134138PSTAMP_NO_IMAGE_MATCH
    135139PSTAMP_NOT_DESTREAKED
    … …  
    139143PSTAMP_NO_OVERLAP
    140144PSTAMP_NOT_AUTHORIZED
     145PSTAMP_NOT_AUTHORIZED
    141146);
    142147
    … …  
    167172    my $fields_output;
    168173    {
    169         my $command = "echo $request_file_name | $fields -x 0 EXTNAME EXTVER REQ_NAME ACTION USERNAME EMAIL";
     174        my $command = "echo $request_file_name | $fields -x 0 EXTNAME EXTVER REQ_NAME ACTION EMAIL";
    170175        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    171176            run(command => $command, verbose => $verbose);
    … …  
    187192    if ($extver > 1) {
    188193        $header{ACTION} = $action;
    189         $header{USER} = $username;
    190194        $header{EMAIL} = $email;
    191195    } else {
    192196        $header{ACTION} = $action = "PROCESS";
    193         $header{USERNAME} = 'null';
    194197        $header{EMAIL} = 'null';
    195198    }
    196199
    197     if ($action eq "LIST") {
    198         return (\%header, undef);
    199     } elsif ($action ne "PROCESS") {
    200         die "unexpected request ACTION found: $action in $request_file_name";
     200    if ($action ne "PROCESS" and $action ne 'PREVIEW') {
     201        die "\nunexpected request ACTION found: $action in $request_file_name";
    201202    }
    202203
  • tags/ipp-20130307/dbconfig

  • tags/ipp-20130307/dbconfig/changes.txt

    r35293 r35489  
    23882388CREATE TABLE lapGroup  (
    23892389    seq_id  BIGINT,
     2390    tess_id VARCHAR(64),
    23902391    projection_cell VARCHAR(64),
    23912392    state   VARCHAR(16),
     2393    label   VARCHAR(654),
     2394    registered TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
    23922395    fault   SMALLINT,
    23932396    PRIMARY KEY(seq_id, projection_cell),
    … …  
    23972400) ENGINE=innodb DEFAULT CHARSET=latin1;
    23982401
    2399 UPDATE dbversion set schema_version = '1.1.75', updated= CURRENT_TIMESTAMP();
    2400 
    2401 -- new Postage Stamp Request columns (NOTE these changes to not apply to gpc1
    2402 -- because the pstamp tables have been dropped from that database
     2402-- new Postage Stamp Request columns
     2403-- Note: These do not aply to the gpc1 database because the pstamp tables were
     2404-- deleted from that database.
    24032405ALTER TABLE pstampRequest ADD COLUMN username VARCHAR(255) AFTER outdir;
    24042406ALTER TABLE pstampRequest ADD COLUMN proj_id BIGINT AFTER username;
    2405 ALTER TABLE pstampRequest ADD COLUMN registered TIMESTAMP DEFAULT CURRENT_TIMESTAMP AFTER proj_id;
    2406 
    2407 -- default to the gpc1 project (or is it ps1?)
     2407ALTER TABLE pstampRequest ADD COLUMN registered DATETIME AFTER proj_id;
     2408
     2409-- default to the gpc1 project
    24082410UPDATE pstampRequest SET proj_id = 1;
    24092411
    2410 
    2411 
     2412-- unique keys for the release tables
     2413
     2414alter table relStack  add unique key (rel_id, tess_id, skycell_id, filter, stack_type, mjd_obs)
     2415alter table relExp add UNIQUE KEY(rel_id, exp_id);
     2416alter table ippRelease add unique key (surveyID, release_name);
     2417
     2418UPDATE dbversion set schema_version = '1.1.75', updated= CURRENT_TIMESTAMP();
  • tags/ipp-20130307/dbconfig/lap.md

    r35213 r35489  
    3333lapGroup METADATA
    3434    seq_id          S64 0
     35    tess_id         STR 64
    3536    projection_cell STR 64
    3637    state           STR 64
     38    label           STR 64
     39    registered      TAI NULL
    3740    fault           S16 0
    3841end
  • tags/ipp-20130307/ippScripts

  • tags/ipp-20130307/ippScripts/Build.PL

    r35247 r35489  
    130130        scripts/regenerate_background.pl
    131131        scripts/relgroup_exp_list.pl
     132        scripts/queuestaticsky.pl
    132133    )],
    133134    dist_abstract => 'Scripts for running the Pan-STARRS IPP',
  • tags/ipp-20130307/ippScripts/scripts/camera_exp.pl

    r35159 r35489  
    363363    }
    364364    # Construct FPA continuity corrected background images
    365     {
     365    if ($camera =~ /ISP/) {
     366        print "Skipping FPA continuity corrected background images for ISP\n";
     367    } else {
    366368        my $command;
    367369        $command = "$ppImage";
  • tags/ipp-20130307/ippScripts/scripts/mergedvodb_merge.pl

    r33030 r35489  
    156156            $merge_command = "rsync -rvat $minidvodb_path/* $mergedvodb_path";
    157157        } else {
    158             $merge_command = "$dvomerge $minidvodb_path into $mergedvodb_path";
     158            $merge_command = "$dvomerge -parallel $minidvodb_path into $mergedvodb_path";
    159159        }
    160160        print "\n$merge_command\n";
  • tags/ipp-20130307/ippScripts/scripts/minidvodb_premerge.pl

    r33030 r35489  
    1616my $dtime_relphot;
    1717my $dtime_script;
     18my $dtime_delstar;
    1819
    1920use vars qw( $VERSION );
    … …  
    3334my $dvomerge = can_run('dvomerge') or (warn "Can't find dvomerge" and $missing_tools = 1);
    3435my $addtool = can_run('addtool') or (warn "Can't find addtool" and $missing_tools = 1);
     36my $delstar = can_run('delstar') or (warn "Can't find delstar" and $missing_tools = 1);
    3537my $addstar = can_run('addstar') or (warn "Can't find addstar" and $missing_tools = 1);
    3638my $relphot = can_run('relphot') or (warn "Can't find relphot" and $missing_tools = 1);
    3739my $relastro = can_run('relastro') or (warn "Can't find relastro" and $missing_tools = 1);
     40
    3841my $dvoverify = can_run('dvoverify') or (warn "Can't find dvoverify" and $missing_tools = 1);
    3942
    … …  
    8083unless ($no_op) {
    8184   
    82         #this is chopped into several parts: addstar, relphot
     85        #this is chopped into several parts: delstar,addstar, relphot, relastro, dvoverify
     86        #delstar - first step: are there duplicates, if so remove them
     87        {
     88            my $command  = "$delstar -update -dup-images ";
     89            #$command .= " -D CAMERA $camera";
     90            $command .= " -D CATDIR $minidvodb";
     91            my $mjd_delstar_start = DateTime->now->mjd;   # MJD of starting script
     92            print "\n$command\n";
     93            my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     94                run(command => $command, verbose => $verbose);
     95            unless ($success) {
     96                $error_code = (($error_code >> 8) or $PS_EXIT_PROG_ERROR);
     97                &my_die("Unable to perform delstar: $error_code", $minidvodb_id, $error_code);
     98            }
     99            print $full_buf;
     100            $dtime_delstar = 86400.0*(DateTime->now->mjd - $mjd_delstar_start); 
     101            # MJD of starting script
     102            print "delstar time $dtime_delstar\n";
     103        }
     104
     105
     106
    83107        #addstar
    84108        {
    … …  
    94118                &my_die("Unable to perform addstar: $error_code", $minidvodb_id, $error_code);
    95119            }
    96             $dtime_addstar = 86400.0*(DateTime->now->mjd - $mjd_addstar_start);  $dtime_resort = $dtime_addstar;
    97             # MJD of starting script
     120            $dtime_addstar = 86400.0*(DateTime->now->mjd - $mjd_addstar_start); 
     121            # MJD of starting script
    98122            $dtime_resort = $dtime_addstar;
    99123            print "addstar -resort time $dtime_addstar\n";
    … …  
    105129            # relphot only takes lower case gpc1
    106130            my $relphot_camera = lc($camera);
    107             my $command  = "$relphot -averages -update";
    108             $command .= " -D CAMERA $relphot_camera";
    109             $command .= " -D CATDIR $minidvodb";
     131            #my $command  = "$relphot -averages -update";
     132            #$command .= " -D CAMERA $relphot_camera";
     133            #$command .= " -D CATDIR $minidvodb";
     134            #this is a friday hack
     135            my $command = "echo skipping relphot";
    110136            print "$command\n";
    111137            my $mjd_relphot_start = DateTime->now->mjd;   # MJD of starting script
  • tags/ipp-20130307/ippScripts/scripts/relgroup_exp_list.pl

    r35247 r35489  
    1616
    1717
    18 my ($group_id, $group_type, $lap_id, $release_name, $rebuild, $dbname, $no_update, $verbose);
     18my ($group_id, $group_type, $lap_id, $group_name, $release_name, $rebuild, $dbname, $no_update, $verbose);
    1919
    2020GetOptions(
    2121    'group_id=s'    =>      \$group_id,
     22    'group_type=s'  =>      \$group_type,
    2223    'lap_id=s'      =>      \$lap_id,
    23     'group_type=s'  =>      \$group_type,
     24    'group_name=s'  =>      \$group_name,
    2425    'release_name=s' =>     \$release_name,
    2526    'rebuild'       =>      \$rebuild,      # rebuild directory if it exists
    … …  
    3637           -exitval => 3)
    3738        unless $lap_id;
     39    $group_name = "lap_$lap_id";
     40} else {
     41    pod2usage( -msg => "--group_name is required with --group_type $group_type",
     42           -exitval => 3)
     43        unless $group_name;
    3844}
    3945
    … …  
    4854
    4955# XXX: get this from site.config
    50 my $outputBase = "/data/ippc17.0/www/ipp-misc/ps1-data/single-frame/$release_name";
    51 
    52 my $outdir;
    53 if ($group_type eq 'lap') {
    54     $outdir = "$outputBase/lap_$lap_id";
    55     if (-e $outdir) {
    56         if ($rebuild) {
    57             my $rc = system "rm -rf $outdir";
    58             if ($rc) {
    59                 my $status = $rc >> 8;
    60                 my_die("failed to remove existing directory $outdir: $rc $status", $group_id, $PS_EXIT_UNKNOWN_ERROR);
    61             }
    62         } else {
    63             my_die("directory $outdir already exists and --rebuild not supplied", $group_id, $PS_EXIT_UNKNOWN_ERROR);
    64         }
    65     }
    66 } else {
    67     my_die("Not ready to do group_type $group_type\n", $group_id, $PS_EXIT_UNKNOWN_ERROR);
     56my $exposureListRoot = "/data/ippc17.0/www/ipp-misc/ps1-data/single-frame";
     57
     58my $outputBase = "$exposureListRoot/$release_name";
     59
     60if (!-e $outputBase) {
     61    mkdir $outputBase or &my_die("Failed to create $outputBase", $group_id, $PS_EXIT_SYS_ERROR);
     62}
     63
     64my $outdir = "$outputBase/$group_name";
     65if (-e $outdir) {
     66    if ($rebuild) {
     67        my $rc = system "rm -rf $outdir";
     68        if ($rc) {
     69            my $status = $rc >> 8;
     70            my_die("failed to remove existing directory $outdir: $rc $status", $group_id, $PS_EXIT_UNKNOWN_ERROR);
     71        }
     72    } else {
     73        my_die("directory $outdir already exists and --rebuild not supplied", $group_id, $PS_EXIT_UNKNOWN_ERROR);
     74    }
    6875}
    6976
    7077mkdir $outdir or my_die ("failed to create $outdir", $group_id, $PS_EXIT_UNKNOWN_ERROR);
    71 
    72 if (0) {
    73     # XXX: old code from prototype for nightly lists
    74         my $outroot;
    75         my $oh;
    76         my ($year, $month, $day);
    77         if ($outroot) {
    78         die "usage: $0 <year> <month> <day>\n" unless $year and $month and $day;
    79             my $monthdir = sprintf "$outroot/%4d/%02d", $year, $month;
    80             if (! -e $monthdir) {
    81                 die "can't find directory for $year-$month\n";
    82             }
    83             my $daydir = sprintf "$monthdir/%02d", $day;
    84             if (! -e $daydir) {
    85                 mkdir $daydir or die "failed to create $daydir\n";
    86             }
    87             my $outfile = sprintf "$daydir/index.html", $day;
    88             open $oh, ">$outfile" or die "failed to open $outfile";
    89         } else {
    90             $oh = *STDOUT;
    91         }
    92 
    93         my $ticks = timegm(0, 0, 0, $day, $month - 1, $year - 1900);
    94 
    95         my $mjd = 40587 + ($ticks / 86400.);
    96         my $date = sprintf "%04d-%02d-%02d", $year, $month, $day;
    97 }
    9878
    9979my $oh;
    … …  
    10585open $oh2, ">$outfile2" or my_die("failed to open $outfile2", $group_id, $PS_EXIT_UNKNOWN_ERROR);
    10686
    107 my $title = "PS1 Exposure List for $release_name LAP run $lap_id";
     87my $title = "PS1 Exposure List for";
     88if ($group_type eq 'lap') {
     89    $title .= " $release_name LAP run $lap_id";
     90} else {
     91    $title .= " $group_name";
     92}
    10893
    10994my $head = "
    … …  
    125110
    126111
    127 # find all exposures on given day that have a chip run
     112# find all exposures in this relGroup
    128113my $query = "
    129114SELECT
    … …  
    149134$stmt->execute() or my_die("failed to execute query: $stmt->errstr\n", $group_id, $PS_EXIT_UNKNOWN_ERROR);
    150135
    151 printf STDERR "%4d exposures in group for LAP run $lap_id\n", $stmt->rows;
     136printf STDERR "%4d exposures in group for $group_name\n", $stmt->rows;
    152137
    153138# $stmt->dump_results(1000);
  • tags/ipp-20130307/ippScripts/scripts/whichimage

    r32820 r35489  
    9494my $cmd = "dvoImagesAtCoords -chipcoords $coord_file";
    9595$cmd .= " -listchipcoords" if $listchipcoords;
     96
     97$tess_id = uc($tess_id) if $tess_id;
    9698
    9799my $status = 0;
    … …  
    125127            # next if $tess_name eq 'FIXNS';
    126128            # next if $tess_name eq 'ALLSKY';
     129            next if $tess_name eq 'RINGS.V0';
    127130            push @tess_ids_to_check, $tess_name;
    128131        }
  • tags/ipp-20130307/ippTasks

  • tags/ipp-20130307/ippTasks/pstamp.pro

    r35475 r35489  
    965965
    966966        # XXX: have the script set this up this
    967         $MYLOGFILE="/data/ippc17.0/pstamp/work/logs/cleanup.$REQ_ID"
     967        $MYLOGFILE=/data/ippc17.0/pstamp/work/logs/cleanup.$REQ_ID
    968968        stdout $MYLOGFILE
    969969        stderr $MYLOGFILE
  • tags/ipp-20130307/ippTasks/survey.pro

    r34976 r35489  
    1818 book create SURVEY_STATICSKYSINGLE
    1919 book create SURVEY_SKYCAL
     20 book create SURVEY_LAPGROUP
     21 book create SURVEY_RELEXP
    2022 $haveSurveyBooks = TRUE
    2123end
    … …  
    3335$SURVEY_PUBLISH_DB = 0
    3436$SURVEY_SKYCAL_DB = 0
     37$SURVEY_LAPGROUP_DB = 0
     38$SURVEY_RELEXP_DB = 0
    3539$SURVEY_STATICSKYSINGLE_DB = 0
    3640$SURVEY_EXEC = 120
    … …  
    7882    active true
    7983  end
     84  task survey.lapgroup
     85    active true
     86  end
     87  task survey.relexp
     88    active true
     89  end
    8090end
    8191
    … …  
    118128  end
    119129  task survey.skycal
     130    active false
     131  end
     132  task survey.lapgroup
     133    active false
     134  end
     135  task survey.relexp
    120136    active false
    121137  end
    … …  
    494510macro survey.show.skycal
    495511  if ($0 != 1)
    496     echo "USAGE: survey.show.skyacl"
     512    echo "USAGE: survey.show.skycal"
    497513    break
    498514  end
    499515  book listbook SURVEY_SKYCAL
     516end
     517
     518macro survey.add.lapgroup
     519  if ($0 != 3)
     520    echo "USAGE: survey.add.lapgroup (label) (seq_id)"
     521    break
     522  end
     523  book newpage SURVEY_LAPGROUP $1
     524  book setword SURVEY_LAPGROUP $1 LABEL $1
     525  book setword SURVEY_LAPGROUP $1 SEQ_ID $2
     526  book setword SURVEY_LAPGROUP $1 STATE PENDING
     527end
     528
     529macro survey.del.lapgroup
     530  if ($0 != 2)
     531    echo "USAGE: survey.del.lapgroup (label)"
     532    break
     533  end
     534  book delpage SURVEY_LAPGROUP $1
     535end
     536
     537macro survey.show.lapgroup
     538  if ($0 != 1)
     539    echo "USAGE: survey.show.lapgroup"
     540    break
     541  end
     542  book listbook SURVEY_LAPGROUP
     543end
     544
     545macro survey.add.relexp
     546  if ($0 != 3)
     547    echo "USAGE: survey.add.relexp (label) (releasename)"
     548    break
     549  end
     550  book newpage SURVEY_RELEXP $1
     551  book setword SURVEY_RELEXP $1 LABEL $1
     552  book setword SURVEY_RELEXP $1 RELEASE_NAME $2
     553  book setword SURVEY_RELEXP $1 STATE PENDING
     554end
     555
     556macro survey.del.relexp
     557  if ($0 != 2)
     558    echo "USAGE: survey.del.relexp (label)"
     559    break
     560  end
     561  book delpage SURVEY_RELEXP $1
     562end
     563
     564macro survey.show.relexp
     565  if ($0 != 1)
     566    echo "USAGE: survey.show.relexp"
     567    break
     568  end
     569  book listbook SURVEY_RELEXP
    500570end
    501571
    … …  
    15611631  end
    15621632end
     1633
     1634task survey.lapgroup
     1635  host local
     1636 
     1637  periods      -poll $SURVEY_POLL
     1638  periods      -exec $SURVEY_EXEC
     1639  periods      -timeout $SURVEY_TIMEOUT
     1640  npending     1
     1641
     1642  stdout $LOGDIR/survey.lapgroup.log
     1643  stderr $LOGDIR/survey.lapgroup.log
     1644
     1645  task.exec
     1646    book npages SURVEY_LAPGROUP -var N
     1647    if ($N == 0)
     1648#      echo "No labels for processing"
     1649      break
     1650    endif
     1651
     1652    book getpage SURVEY_LAPGROUP 0 -var label -key STATE NEW
     1653    if ("$label" == "NULL")
     1654      # All labels have been done --- reset
     1655#      echo "Resetting labels"
     1656      for i 0 $N
     1657        book getpage SURVEY_LAPGROUP $i -var label
     1658        book setword SURVEY_LAPGROUP $label STATE NEW
     1659      end
     1660      book getpage SURVEY_LAPGROUP 0 -var label -key STATE NEW
     1661
     1662      # Select different database
     1663      $SURVEY_LAPGROUP_DB ++
     1664      if ($SURVEY_LAPGROUP_DB >= $DB:n) set SURVEY_LAPGROUP_DB = 0
     1665    end
     1666
     1667    book setword SURVEY_LAPGROUP $label STATE DONE
     1668    book getword SURVEY_LAPGROUP $label SEQ_ID -var SEQ_ID
     1669
     1670    # For now the list of filters is hardcoded here
     1671    $run = laptool -definegroup -seq_id $SEQ_ID -set_label $label -filter g.00000 -filter r.00000 -filter i.00000 -filter z.00000 -filter y.00000
     1672
     1673    if ($DB:n == 0)
     1674      option DEFAULT
     1675    else
     1676      $run = $run -dbname $DB:$SURVEY_LAPGROUP_DB
     1677      option $DB:$SURVEY_LAPGROUP_DB
     1678    end
     1679   
     1680    # echo $run
     1681    command $run
     1682  end
     1683
     1684  # success
     1685  task.exit    0
     1686#    echo "Success"
     1687  end
     1688
     1689  # locked list
     1690  task.exit    default
     1691    showcommand failure
     1692  end
     1693
     1694  task.exit    crash
     1695    showcommand crash
     1696  end
     1697
     1698  # operation times out?
     1699  task.exit    timeout
     1700    showcommand timeout
     1701  end
     1702end
     1703
     1704task survey.relexp
     1705  host local
     1706 
     1707  periods      -poll $SURVEY_POLL
     1708  periods      -exec $SURVEY_EXEC
     1709  periods      -timeout $SURVEY_TIMEOUT
     1710  npending     1
     1711
     1712  stdout $LOGDIR/survey.relexp.log
     1713  stderr $LOGDIR/survey.relexp.log
     1714
     1715  task.exec
     1716    book npages SURVEY_RELEXP -var N
     1717    if ($N == 0)
     1718#      echo "No labels for processing"
     1719      break
     1720    endif
     1721
     1722    book getpage SURVEY_RELEXP 0 -var label -key STATE NEW
     1723    if ("$label" == "NULL")
     1724      # All labels have been done --- reset
     1725#      echo "Resetting labels"
     1726      for i 0 $N
     1727        book getpage SURVEY_RELEXP $i -var label
     1728        book setword SURVEY_RELEXP $label STATE NEW
     1729      end
     1730      book getpage SURVEY_RELEXP 0 -var label -key STATE NEW
     1731
     1732      # Select different database
     1733      $SURVEY_RELEXP_DB ++
     1734      if ($SURVEY_RELEXP_DB >= $DB:n) set SURVEY_RELEXP_DB = 0
     1735    end
     1736
     1737    book setword SURVEY_RELEXP $label STATE DONE
     1738    book getword SURVEY_RELEXP $label RELEASE_NAME -var RELEASE_NAME
     1739
     1740    $run = releasetool -definerelexp -label $label -release_name $RELEASE_NAME -set_state processed
     1741
     1742    if ($DB:n == 0)
     1743      option DEFAULT
     1744    else
     1745      $run = $run -dbname $DB:$SURVEY_RELEXP_DB
     1746      option $DB:$SURVEY_RELEXP_DB
     1747    end
     1748   
     1749    # echo $run
     1750    command $run
     1751  end
     1752
     1753  # success
     1754  task.exit    0
     1755#    echo "Success"
     1756  end
     1757
     1758  # locked list
     1759  task.exit    default
     1760    showcommand failure
     1761  end
     1762
     1763  task.exit    crash
     1764    showcommand crash
     1765  end
     1766
     1767  # operation times out?
     1768  task.exit    timeout
     1769    showcommand timeout
     1770  end
     1771end
  • tags/ipp-20130307/ippTools

  • tags/ipp-20130307/ippTools/share

  • tags/ipp-20130307/ippTools/share/Makefile.am

    r35214 r35489  
    457457        laptool_WSdiff_check.sql \
    458458        laptool_stacks.sql \
     459        laptool_pendinggroup.sql \
     460        laptool_revertgroup.sql \
     461        laptool_filtersforgroup.sql \
    459462        vptool_find_rawexp.sql \
    460463        vptool_pendingimfile.sql \
    … …  
    470473        releasetool_definerelstack.sql \
    471474        releasetool_definerelstack_with_skycal.sql \
     475        releasetool_listrelstack.sql \
    472476        releasetool_definerelgroup_select_lap.sql \
    473477        releasetool_definerelgroup_select_data_group.sql \
  • tags/ipp-20130307/ippTools/share/addtool_find_processedexp_cam.sql

    r31375 r35489  
    11SELECT
    22    addProcessedExp.*,
    3     addRun.workdir
     3    addRun.label,
     4    addRun.workdir,
     5    camRun.cam_id,
     6    camRun.label as cam_label,
     7    camRun.data_group as cam_data_group,
     8    rawExp.exp_id,
     9    exp_name
    410FROM addProcessedExp
    511JOIN addRun
  • tags/ipp-20130307/ippTools/share/pstamptool_completedreq.sql

    r29563 r35489  
    88        SELECT count(*) FROM pstampJob
    99        WHERE pstampJob.req_id = pstampRequest.req_id
    10                 AND pstampJob.state != 'stop'
     10                AND pstampJob.state != 'stop'
     11                AND pstampJob.state != 'cancel'
    1112        ) = 0
  • tags/ipp-20130307/ippTools/share/pstamptool_getdependent.sql

    r28145 r35489  
    11SELECT DISTINCT pstampDependent.*
    22FROM pstampDependent
    3 WHERE pstampDependent.state = 'new'
     3WHERE (pstampDependent.state = 'new' OR pstampDependent.state = 'hold')
  • tags/ipp-20130307/ippTools/share/pxadmin_create_tables.sql

    r35293 r35489  
    1 CREATE TABLE dbversion (
     1eREATE TABLE dbversion (
    22    schema_version VARCHAR(64),
    33    updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP
    … …  
    21722172    priority    INT,
    21732173    PRIMARY KEY(rel_id),
     2174    UNIQUE KEY(surveyID, release_name),
    21742175    KEY(release_name),
    21752176    KEY(release_state),
    … …  
    21962197    PRIMARY KEY (relexp_id),
    21972198    FOREIGN KEY(rel_id) REFERENCES ippRelease(rel_id),
     2199    UNIQUE KEY(rel_id, exp_id),
    21982200    KEY (state),
    21992201    KEY (fault),
    … …  
    22242226    time_stamp  DATETIME,
    22252227    PRIMARY KEY (relstack_id),
     2228    UNIQUE KEY (rel_id, tess_id, skycell_id, filter, stack_type, mjd_obs),
    22262229    KEY (tess_id, skycell_id),
    2227     KEY (rel_id, tess_id, skycell_id, filter, mjd_obs),
    22282230    KEY (stack_type),
    22292231    KEY (mjd_obs),
    … …  
    22582260CREATE TABLE lapGroup  (
    22592261    seq_id  BIGINT,
     2262    tess_id VARCHAR(64),
    22602263    projection_cell VARCHAR(64),
    22612264    state   VARCHAR(16),
     2265    label   VARCHAR(64),
     2266    registered TIMESTAMP DEFAULT CURRENT_TIMESTAMP, -- time group was registered
    22622267    fault   SMALLINT,
    2263     PRIMARY KEY(seq_id, projection_cell),
     2268    PRIMARY KEY(seq_id, tess_id, projection_cell),
    22642269    KEY(state),
    22652270    KEY(fault),
  • tags/ipp-20130307/ippTools/share/releasetool_definerelgroup_select_exp_lap.sql

    r35213 r35489  
    11SELECT relExp.relexp_id
    2 FROM relGroup JOIN lapRun USING(lap_id)
     2FROM relGroup
     3    JOIN lapRun USING(lap_id)
     4    JOIN lapExp USING(lap_id)
    35    JOIN relExp using(rel_id, exp_id)
    46WHERE relExp.group_id = 0
  • tags/ipp-20130307/ippTools/share/releasetool_definerelstack.sql

    r35196 r35489  
    66    stackRun.tess_id,
    77    stackRun.filter,
    8     0 AS mjd_obs,
     8    stackSumSkyfile.mjd_obs,
    99    0 AS zpt_obs,
    1010    0 AS zpt_stdev
    … …  
    1212FROM ippRelease
    1313JOIN stackRun
    14 LEFT JOIN relStack AS previousRelStack USING(rel_id, tess_id, skycell_id, filter)
    15 
     14JOIN stackSumSkyfile using(stack_id)
     15LEFT JOIN relStack AS previousRelStack
     16    ON previousRelStack.rel_id = ippRelease.rel_id
     17    AND previousRelStack.tess_id = stackRun.tess_id
     18    AND previousRelStack.skycell_id = stackRun.skycell_id
     19    AND previousRelStack.filter = stackRun.filter
     20    -- JOIN hook %s
    1621WHERE previousRelStack.relstack_id IS NULL
     22    AND stackRun.state ='full'
     23    AND stackSumSkyfile.quality = 0
     24    AND stackSumSkyfile.fault = 0
  • tags/ipp-20130307/ippTools/share/releasetool_definerelstack_with_skycal.sql

    r35196 r35489  
    1313JOIN stackRun
    1414JOIN stackSumSkyfile USING(stack_id)
    15 LEFT JOIN relStack AS previousRelStack USING(rel_id, tess_id, skycell_id, filter)
    1615JOIN skycalRun ON skycalRun.stack_id = stackRun.stack_id
    1716JOIN skycalResult ON skycalRun.skycal_id = skycalResult.skycal_id
     17-- LEFT JOIN relStack AS previousRelStack USING(rel_id, tess_id, skycell_id, filter)
     18LEFT JOIN relStack AS previousRelStack
     19    ON ippRelease.rel_id = previousRelStack.rel_id
     20    AND stackRun.tess_id = previousRelStack.tess_id
     21    AND stackRun.skycell_id = previousRelStack.skycell_id
     22    AND stackRun.filter = previousRelStack.filter
     23-- JOIN Hook %s
    1824
    1925WHERE previousRelStack.relstack_id IS NULL
     26    AND skycalRun.state = 'full'
  • tags/ipp-20130307/ippTools/share/releasetool_listrelexp.sql

    r35213 r35489  
    2525    warpRun.warp_id,
    2626    warpRun.state as warp_state,
     27    warpRun.tess_id,
    2728    rawExp.filter,
    2829    rawExp.dateobs,
  • tags/ipp-20130307/ippTools/share/releasetool_pendingrelgroup.sql

    r35214 r35489  
    1 SELECT relGroup.*
     1SELECT
     2    relGroup.*,
     3    ippRelease.release_name
    24FROM relGroup
    35    JOIN ippRelease USING(rel_id)
    46WHERE relGroup.state = 'new'
     7    AND relGroup.fault = 0
  • tags/ipp-20130307/ippTools/src

  • tags/ipp-20130307/ippTools/src/laptool.c

    r34081 r35489  
    3434static bool inactiveexpMode(pxConfig *config);
    3535
     36// Groups
     37static bool definegroupMode(pxConfig *config);
     38static bool pendinggroupMode(pxConfig *config);
     39static bool filtersforgroupMode(pxConfig *config);
     40static bool updategroupMode(pxConfig *config);
     41static bool revertgroupMode(pxConfig *config);
     42static bool listgroupMode(pxConfig *config);
     43
    3644# define MODECASE(caseName, func) \
    3745  case caseName: \
    … …  
    6775   
    6876    MODECASE(LAPTOOL_MODE_INACTIVEEXP,   inactiveexpMode);
     77
     78    MODECASE(LAPTOOL_MODE_DEFINEGROUP,   definegroupMode);
     79    MODECASE(LAPTOOL_MODE_PENDINGGROUP,  pendinggroupMode);
     80    MODECASE(LAPTOOL_MODE_FILTERSFORGROUP, filtersforgroupMode);
     81    MODECASE(LAPTOOL_MODE_UPDATEGROUP,   updategroupMode);
     82    MODECASE(LAPTOOL_MODE_REVERTGROUP,   revertgroupMode);
     83    MODECASE(LAPTOOL_MODE_LISTGROUP,     listgroupMode);
     84
    6985  default:
    7086    psAbort("invalid option (this should not happen)");
    … …  
    900916  return(true);
    901917}
    902 
     918// ---------------------------
     919// Group level (a collection of completed lapRuns for a given lapSequence projection cell and collection of filters
     920
     921static bool definegroupMode(pxConfig *config)
     922{
     923  PS_ASSERT_PTR_NON_NULL(config, false);
     924
     925  PXOPT_LOOKUP_S64(seq_id,          config->args, "-seq_id",    true, false);
     926  PXOPT_LOOKUP_STR(label,           config->args, "-set_label", true, false);
     927
     928  PXOPT_LOOKUP_BOOL(pretend,        config->args, "-pretend",    false);
     929  PXOPT_LOOKUP_BOOL(simple,         config->args, "-simple",    false);
     930  PXOPT_LOOKUP_U64(limit,           config->args, "-limit",     false, false);
     931
     932  // the following insures that the -filter argument has been set up properly (adapted from pxAddLabelSearchArgs)
     933  psMetadataItem *item = psMetadataLookup(config->args, "-filter");
     934  psAssert (item, "-filter argument not found in config->args");
     935  psAssert (item->type == PS_DATA_METADATA_MULTI, "%s should be a multi container", "filter");
     936  psAssert (item->data.list->n, "%s should at least have a place-holder", "filter");
     937  psMetadataItem *entry = (psMetadataItem *)item->data.list->head->data;
     938  psAssert (entry, "%s should at least have a place-holder", "filter");
     939  // end of checking
     940
     941  // Now if the ony entry is the place-holder then the user supplied no -filter arguments
     942  // which are required
     943  if (!entry->data.str) {
     944    psError(PXTOOLS_ERR_ARGUMENTS, true, "at least one -filter is required");
     945    return false;
     946  }
     947
     948  int nFilters = item->data.list->n;
     949
     950  psString query = psStringCopy("SELECT seq_id, tess_id, projection_cell,\n");
     951
     952  // We construct a query joining completed lap runs with the same lapSequence.seq_id,
     953  // tess_id, and projection_cell
     954
     955  // select the lap_ids for the various filters. These are only used for debugging.
     956  psStringAppend(&query, "lap_id_%d", 0);
     957  for (int i = 1; i < nFilters; i++) {
     958    psStringAppend(&query, ", lap_id_%d", i);
     959  }
     960
     961
     962  // sub query for each supplied filter
     963  char * lapRunForFilter = "(\nSELECT seq_id, tess_id, projection_cell, lap_id as 'lap_id_%d'\n"
     964    "FROM lapRun\n"
     965    "WHERE filter LIKE '%s'\n"
     966    "   AND lapRun.seq_id = %"PRId64"\n"
     967    "   AND (lapRun.state = 'done' or lapRun.state = 'full')\n"
     968    " ) as lap_%d\n";
     969
     970  // loop over supplied filters and flesh out the query using the format above
     971  psListIterator *iter = psListIteratorAlloc (item->data.list, PS_LIST_HEAD, true);
     972  psMetadataItem *filterItem = NULL;
     973  int i = -1;
     974  while ((filterItem = psListGetAndIncrement(iter))) {
     975    ++i;
     976    if (i == 0) {
     977      psStringAppend(&query, "\nFROM\n");
     978    } else {
     979      psStringAppend(&query, "\nJOIN\n");
     980    }
     981
     982    psString filter = filterItem->data.str;
     983    psStringAppend(&query, lapRunForFilter, i, filter, seq_id, i);
     984
     985    if (i != 0) {
     986      psStringAppend(&query, "USING (seq_id, tess_id, projection_cell)\n");
     987    }
     988  }
     989  // now join to lapGroup
     990  psStringAppend(&query, "\nLEFT JOIN lapGroup USING(seq_id, tess_id, projection_cell)\n");
     991
     992  // we only want projection cells which do not already of an entry
     993  psStringAppend(&query, "\nWHERE lapGroup.projection_cell IS NULL\n");
     994  psStringAppend(&query, "\nORDER by projection_cell\n");
     995
     996  if (limit) {
     997    psString limitString = psDBGenerateLimitSQL(limit);
     998    psStringAppend(&query, "\n %s", limitString);
     999    psFree(limitString);
     1000  }
     1001
     1002  if (!p_psDBRunQuery(config->dbh, query)) {
     1003      psError(PS_ERR_UNKNOWN, false, "database error");
     1004      psFree(query);
     1005      return false;
     1006  }
     1007  psFree(query);
     1008
     1009  psArray *output = p_psDBFetchResult(config->dbh);
     1010  if (!output) {
     1011      psError(PS_ERR_UNKNOWN, false, "database error");
     1012      return false;
     1013  }
     1014
     1015  if (!psArrayLength(output)) {
     1016      psTrace("laptool", PS_LOG_INFO, "no rows found");
     1017      psFree(output);
     1018      return true;
     1019  }
     1020
     1021  if (pretend) {
     1022    if (!ippdbPrintMetadatas(stdout, output, "new_lapGroups", !simple)) {
     1023        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1024        psFree(output);
     1025        return false;
     1026    }
     1027    psFree(output);
     1028    return true;
     1029  }
     1030
     1031  if (!psDBTransaction(config->dbh)) {
     1032    psError(PS_ERR_UNKNOWN, false, "database error");
     1033    return false;
     1034  }
     1035
     1036  psTime *now = psTimeGetNow(PS_TIME_TAI);
     1037
     1038  psString last_projection_cell = NULL;
     1039  for (long i = 0; i < psArrayLength(output); i++) {
     1040    psMetadata *row = output->data[i];
     1041
     1042    psString tess_id = psMetadataLookupStr(NULL, row, "tess_id");
     1043    psString projection_cell = psMetadataLookupStr(NULL, row, "projection_cell");
     1044    if (last_projection_cell && !strcmp(last_projection_cell, projection_cell)) {
     1045        // duplicate lap runs for a filter will generate multiple rows
     1046        // Since we care about projection_cells not lapRuns per se this is not problem.
     1047        // Skip any duplicates.
     1048        continue;
     1049    }
     1050    last_projection_cell = projection_cell;
     1051
     1052    lapGroupRow *group = lapGroupRowAlloc(
     1053                                  seq_id,
     1054                                  tess_id,
     1055                                  projection_cell,
     1056                                  "new",  // state
     1057                                  label,
     1058                                  now,    // registered
     1059                                  0       // fault
     1060                                  );
     1061    if (!group) {
     1062      psError(PS_ERR_UNKNOWN, false, "failed to alloc lapGroup object");
     1063      psFree(output);
     1064      psFree(now);
     1065      return(false);
     1066    }
     1067
     1068
     1069    if (!lapGroupInsertObject(config->dbh, group)) {
     1070      if (!psDBRollback(config->dbh)) {
     1071        psError(PS_ERR_UNKNOWN, false, "database error");
     1072      }
     1073      psError(PS_ERR_UNKNOWN, false, "database error");
     1074      psFree(output);
     1075      return(true);
     1076    }
     1077  }
     1078
     1079  // point of no return
     1080  if (!psDBCommit(config->dbh)) {
     1081    psError(PS_ERR_UNKNOWN, false, "database error");
     1082    return false;
     1083  }
     1084
     1085  psFree(now);
     1086  psFree(output);
     1087
     1088  return(true); 
     1089}
     1090
     1091static bool pendinggroupMode(pxConfig *config)
     1092{
     1093  PS_ASSERT_PTR_NON_NULL(config, false);
     1094
     1095  PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1096  PXOPT_LOOKUP_U64(limit,   config->args, "-limit",  false, false);
     1097 
     1098  psMetadata *where = psMetadataAlloc();
     1099  PXOPT_COPY_S64(config->args, where, "-seq_id", "seq_id", "==");
     1100  pxAddLabelSearchArgs(config, where, "-label", "lapRun.label", "==");
     1101 
     1102  psString query = pxDataGet("laptool_pendinggroup.sql");
     1103  if (!query) {
     1104    psError(PXTOOLS_ERR_SYS, false, "failed to retrieve SQL statement");
     1105    return false;
     1106  }
     1107
     1108  if (psListLength(where->list)) {
     1109    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1110    psStringAppend(&query, " AND %s", whereClause);
     1111    psFree(whereClause);
     1112  }
     1113  if (limit) {
     1114    psString limitString = psDBGenerateLimitSQL(limit);
     1115    psStringAppend(&query, "\n %s", limitString);
     1116    psFree(limitString);
     1117  }
     1118 
     1119  if (!p_psDBRunQuery(config->dbh, query)) {
     1120    psError(PS_ERR_UNKNOWN, false, "database error");
     1121    psFree(query);
     1122    return false;
     1123  }
     1124  psFree(query);
     1125
     1126  psArray *output = p_psDBFetchResult(config->dbh);
     1127  if (!output) {
     1128    psErrorCode err = psErrorCodeLast();
     1129    switch (err) {
     1130    case PS_ERR_DB_CLIENT:
     1131      psError(PXTOOLS_ERR_SYS, false, "database error");
     1132    case PS_ERR_DB_SERVER:
     1133      psError(PXTOOLS_ERR_PROG, false, "database error");
     1134    default:
     1135      psError(PXTOOLS_ERR_PROG, false, "unknown error");
     1136    }
     1137
     1138    return false;
     1139  }
     1140  if (!psArrayLength(output)) {
     1141    psTrace("laptool", PS_LOG_INFO, "no rows found");
     1142    psFree(output);
     1143    return true;
     1144  }
     1145
     1146  if (psArrayLength(output)) {
     1147    if (!ippdbPrintMetadatas(stdout, output, "lapGroup", !simple)) {
     1148      psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1149      psFree(output);
     1150      return false;
     1151    }
     1152  }
     1153
     1154  psFree(output);
     1155
     1156  return true;
     1157}
     1158static bool filtersforgroupMode(pxConfig *config)
     1159{
     1160  PS_ASSERT_PTR_NON_NULL(config, false);
     1161
     1162  PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1163 
     1164  psMetadata *where = psMetadataAlloc();
     1165  PXOPT_COPY_S64(config->args, where, "-seq_id", "seq_id", "==");
     1166  PXOPT_COPY_STR(config->args, where, "-tess_id", "tess_id", "==");
     1167  PXOPT_COPY_STR(config->args, where, "-projection_cell", "projection_cell", "==");
     1168 
     1169  psString query = pxDataGet("laptool_filtersforgroup.sql");
     1170  if (!query) {
     1171    psError(PXTOOLS_ERR_SYS, false, "failed to retrieve SQL statement");
     1172    return false;
     1173  }
     1174
     1175  psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1176  psStringAppend(&query, " WHERE %s", whereClause);
     1177  psFree(whereClause);
     1178
     1179  if (!p_psDBRunQuery(config->dbh, query)) {
     1180    psError(PS_ERR_UNKNOWN, false, "database error");
     1181    psFree(query);
     1182    return false;
     1183  }
     1184  psFree(query);
     1185
     1186  psArray *output = p_psDBFetchResult(config->dbh);
     1187  if (!output) {
     1188    psErrorCode err = psErrorCodeLast();
     1189    switch (err) {
     1190    case PS_ERR_DB_CLIENT:
     1191      psError(PXTOOLS_ERR_SYS, false, "database error");
     1192    case PS_ERR_DB_SERVER:
     1193      psError(PXTOOLS_ERR_PROG, false, "database error");
     1194    default:
     1195      psError(PXTOOLS_ERR_PROG, false, "unknown error");
     1196    }
     1197
     1198    return false;
     1199  }
     1200  if (!psArrayLength(output)) {
     1201    psTrace("laptool", PS_LOG_INFO, "no rows found");
     1202    psFree(output);
     1203    return true;
     1204  }
     1205
     1206  if (psArrayLength(output)) {
     1207    if (!ippdbPrintMetadatas(stdout, output, "filters", !simple)) {
     1208      psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1209      psFree(output);
     1210      return false;
     1211    }
     1212  }
     1213
     1214  psFree(output);
     1215
     1216  return true;
     1217}
     1218
     1219static bool updategroupMode(pxConfig *config)
     1220{
     1221  PS_ASSERT_PTR_NON_NULL(config, false);
     1222
     1223  // check that all of the keys that define a lapGroup are supplied
     1224  PXOPT_LOOKUP_S64(seq_id, config->args, "-seq_id", true, false);
     1225  PXOPT_LOOKUP_STR(tess_id, config->args, "-tess_id", true, false);
     1226  PXOPT_LOOKUP_STR(projection_cell, config->args, "-projection_cell", true, false);
     1227
     1228  psMetadata *where = psMetadataAlloc();
     1229  PXOPT_COPY_S64(config->args, where, "-seq_id", "seq_id", "==");
     1230  PXOPT_COPY_STR(config->args, where, "-tess_id", "tess_id", "==");
     1231  PXOPT_COPY_STR(config->args, where, "-projection_cell", "projection_cell", "==");
     1232
     1233  psMetadata *values = psMetadataAlloc();
     1234  PXOPT_COPY_STR(config->args, values, "-set_state", "state", "==");
     1235  PXOPT_COPY_STR(config->args, values, "-set_label", "label", "==");
     1236  PXOPT_COPY_S16(config->args, values, "-set_fault", "fault", "==");
     1237
     1238  if (!psListLength(values->list)) {
     1239    psFree(values);
     1240    psFree(where);
     1241    psError(PXTOOLS_ERR_ARGUMENTS, true, "must set at least one column");
     1242    return false;
     1243  }
     1244
     1245  long rows = psDBUpdateRows(config->dbh, "lapGroup", where, values);
     1246  if (rows < 1) {
     1247    psFree(values);
     1248    psError(PXTOOLS_ERR_SYS, true, "failed to update lapGroup for %" PRId64 " %s %s", seq_id, tess_id, projection_cell);
     1249    return false;
     1250  }
     1251  psFree(values);
     1252
     1253  return(true);
     1254}
     1255
     1256static bool revertgroupMode(pxConfig *config)
     1257{
     1258  PS_ASSERT_PTR_NON_NULL(config, false);
     1259
     1260  psMetadata *where = psMetadataAlloc();
     1261  pxAddLabelSearchArgs (config, where, "-label", "label", "==");
     1262  PXOPT_COPY_S64(config->args, where, "-seq_id", "seq_id", "==");
     1263  PXOPT_COPY_STR(config->args, where, "-tess_id", "tess_id", "==");
     1264  PXOPT_COPY_STR(config->args, where, "-projection_cell", "projection_cell", "==");
     1265
     1266  if (!psListLength(where->list)) {
     1267    psFree(where);
     1268    psError(PXTOOLS_ERR_CONFIG, false, "search arguments are required");
     1269    return false;
     1270  }
     1271
     1272  psString query = pxDataGet("laptool_revertgroup.sql");
     1273  psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1274  psStringAppend(&query, " AND %s", whereClause);
     1275  psFree(whereClause);
     1276  psFree(where);
     1277  if (!p_psDBRunQuery(config->dbh, query)) {
     1278    psError(PS_ERR_UNKNOWN, false, "database error");
     1279    psFree(query);
     1280    return false;
     1281  }
     1282  psFree(query);
     1283
     1284  psU64 affected = psDBAffectedRows(config->dbh);
     1285  psLogMsg("laptool", PS_LOG_INFO, "Updated %" PRIu64 " lapGroups", affected);
     1286
     1287  return true;
     1288}
     1289
     1290static bool listgroupMode(pxConfig *config)
     1291{
     1292  PS_ASSERT_PTR_NON_NULL(config, false);
     1293
     1294  psError(PXTOOLS_ERR_SYS, true, "not yet implemented");
     1295  return false;
     1296
     1297  PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1298  PXOPT_LOOKUP_U64(limit,   config->args, "-limit",  false, false);
     1299 
     1300  psMetadata *where = psMetadataAlloc();
     1301  PXOPT_COPY_S64(config->args, where, "-seq_id", "seq_id", "==");
     1302  PXOPT_COPY_STR(config->args, where, "-seq_name",   "name",   "LIKE");
     1303
     1304  psString query = pxDataGet("laptool_listsequence.sql");
     1305  if (!query) {
     1306    psError(PXTOOLS_ERR_SYS, false, "failed to retrieve SQL statement");
     1307    return false;
     1308  }
     1309  if (psListLength(where->list)) {
     1310    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1311    psStringAppend(&query, " WHERE %s", whereClause);
     1312    psFree(whereClause);
     1313  }
     1314
     1315  if (limit) {
     1316    psString limitString = psDBGenerateLimitSQL(limit);
     1317    psStringAppend(&query, " %s", limitString);
     1318    psFree(limitString);
     1319  }
     1320  if (!p_psDBRunQuery(config->dbh, query)) {
     1321    psError(PS_ERR_UNKNOWN, false, "database error");
     1322    psFree(query);
     1323    return false;
     1324  }
     1325  psFree(query);
     1326
     1327  psArray *output = p_psDBFetchResult(config->dbh);
     1328  if (!output) {
     1329    psErrorCode err = psErrorCodeLast();
     1330    switch (err) {
     1331    case PS_ERR_DB_CLIENT:
     1332      psError(PXTOOLS_ERR_SYS, false, "database error");
     1333    case PS_ERR_DB_SERVER:
     1334      psError(PXTOOLS_ERR_PROG, false, "database error");
     1335    default:
     1336      psError(PXTOOLS_ERR_PROG, false, "unknown error");
     1337    }
     1338
     1339    return false;
     1340  }
     1341  if (!psArrayLength(output)) {
     1342    psTrace("laptool", PS_LOG_INFO, "no rows found");
     1343    psFree(output);
     1344    return true;
     1345  }
     1346
     1347  if (psArrayLength(output)) {
     1348    if (!ippdbPrintMetadatas(stdout, output, "lapSequence", !simple)) {
     1349      psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1350      psFree(output);
     1351      return false;
     1352    }
     1353  }
     1354
     1355  psFree(output);
     1356
     1357  return true;
     1358}
  • tags/ipp-20130307/ippTools/src/laptool.h

    r32422 r35489  
    2020  LAPTOOL_MODE_UPDATEEXP,
    2121  LAPTOOL_MODE_DIFFCHECK,
    22   LAPTOOL_MODE_INACTIVEEXP
     22  LAPTOOL_MODE_INACTIVEEXP,
     23  LAPTOOL_MODE_DEFINEGROUP,
     24  LAPTOOL_MODE_PENDINGGROUP,
     25  LAPTOOL_MODE_FILTERSFORGROUP,
     26  LAPTOOL_MODE_UPDATEGROUP,
     27  LAPTOOL_MODE_REVERTGROUP,
     28  LAPTOOL_MODE_LISTGROUP,
    2329} laptoolMode;
    2430
  • tags/ipp-20130307/ippTools/src/laptoolConfig.c

    r33343 r35489  
    9797  ADD_OPT(S64, updaterunArgs, "-set_quick_sass_id",           "set quick stack sass_id", 0);
    9898  ADD_OPT(S64, updaterunArgs, "-set_final_sass_id",           "set final stack sass_id", 0);
    99  
    10099 
    101100  // -pendingexp
    … …  
    150149  ADD_OPT(U64, inactiveexpArgs, "-limit",                     "limit result set to N items", 0);
    151150 
     151  // -definegroup
     152  psMetadata *definegroupArgs = psMetadataAlloc();
     153  ADD_OPT(S64, definegroupArgs, "-seq_id",                    "search by lap sequence ID (required)", 0);
     154  ADD_OPT(Str, definegroupArgs, "-set_label",                 "set label (required)", 0);
     155
     156  psMetadataAddStr(definegroupArgs,  PS_LIST_TAIL,
     157                                "-filter", PS_META_DUPLICATE_OK,
     158                                                              "search by filter (LIKE comparison, multiple OK)", NULL);
     159  ADD_OPT(Bool,definegroupArgs, "-pretend",                   "do not actuallym modify the database", false);
     160  ADD_OPT(Bool,definegroupArgs, "-simple",                    "use the simple output format", false);
     161  ADD_OPT(U64, definegroupArgs, "-limit",                     "limit result set to N items", 0);
     162
     163  // -pendinggroup
     164  psMetadata *pendinggroupArgs = psMetadataAlloc();
     165  psMetadataAddStr(pendinggroupArgs,  PS_LIST_TAIL,
     166                                "-label", PS_META_DUPLICATE_OK,
     167                                                              "search by label (multiple OK)", NULL);
     168  ADD_OPT(S64, pendinggroupArgs, "-seq_id",                    "search by lap sequence ID (required)", 0);
     169
     170  ADD_OPT(Bool,pendinggroupArgs, "-simple",                    "use the simple output format", false);
     171  ADD_OPT(U64, pendinggroupArgs, "-limit",                     "limit result set to N items", 0);
     172
     173  // -updategroup
     174  psMetadata *updategroupArgs = psMetadataAlloc();
     175  ADD_OPT(S64, updategroupArgs, "-seq_id",                    "search by lap sequence ID (required)", 0);
     176  ADD_OPT(Str, updategroupArgs, "-tess_id",                   "search by tess_id (required)", 0);
     177  ADD_OPT(Str, updategroupArgs, "-projection_cell",           "search by projection_cell (required)", 0);
     178  ADD_OPT(Str, updategroupArgs, "-set_state",                 "set state", 0);
     179  ADD_OPT(S16, updategroupArgs, "-set_fault",                 "set fault code", INT16_MAX);
     180  ADD_OPT(Str, updategroupArgs, "-set_label",                 "set label", 0);
     181
     182  // -revertgroup
     183  psMetadata *revertgroupArgs = psMetadataAlloc();
     184  psMetadataAddStr(revertgroupArgs,  PS_LIST_TAIL,
     185                                "-label", PS_META_DUPLICATE_OK,
     186                                                              "search by label (multiple OK)", NULL);
     187  ADD_OPT(S64, revertgroupArgs, "-seq_id",                    "search by lap sequence ID", 0);
     188  ADD_OPT(Str, revertgroupArgs, "-tess_id",                   "search by tess_id", 0);
     189  ADD_OPT(Str, revertgroupArgs, "-projection_cell",           "search by projection_cell", 0);
     190  ADD_OPT(S16, revertgroupArgs, "-fault",                     "fault code", INT16_MAX);
     191
     192  // -filtersforgroup
     193  psMetadata *filtersforgroupArgs = psMetadataAlloc();
     194  ADD_OPT(S64, filtersforgroupArgs, "-seq_id",                    "search by lap sequence ID (required)", 0);
     195  ADD_OPT(Str, filtersforgroupArgs, "-tess_id",                   "search by tess_id (required)", 0);
     196  ADD_OPT(Str, filtersforgroupArgs, "-projection_cell",           "search by projection_cell (required)", 0);
     197  ADD_OPT(Bool,filtersforgroupArgs, "-simple",                    "use the simple output format", false);
     198
    152199 
    153200  psMetadata *argSets = psMetadataAlloc();
    … …  
    166213  PXOPT_ADD_MODE("-diffcheck",               "", LAPTOOL_MODE_DIFFCHECK,        diffcheckArgs);
    167214  PXOPT_ADD_MODE("-inactiveexp",             "", LAPTOOL_MODE_INACTIVEEXP,      inactiveexpArgs);
     215  PXOPT_ADD_MODE("-definegroup",             "", LAPTOOL_MODE_DEFINEGROUP,      definegroupArgs);
     216  PXOPT_ADD_MODE("-pendinggroup",            "", LAPTOOL_MODE_PENDINGGROUP,     pendinggroupArgs);
     217  PXOPT_ADD_MODE("-filtersforgroup",         "", LAPTOOL_MODE_FILTERSFORGROUP,  filtersforgroupArgs);
     218  PXOPT_ADD_MODE("-updategroup",             "", LAPTOOL_MODE_UPDATEGROUP,      updategroupArgs);
     219  PXOPT_ADD_MODE("-revertgroup",             "", LAPTOOL_MODE_REVERTGROUP,      revertgroupArgs);
    168220 
    169221  if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) {
  • tags/ipp-20130307/ippTools/src/pstamptool.c

    r35293 r35489  
    4949static bool revertjobMode(pxConfig *config);
    5050
    51 # if (1)
    52 // these are unused functions -- since they are 'static', this raises an warning
    53 // XXX: They actually are used
    5451static bool addprojectMode(pxConfig *config);
    5552static bool projectMode(pxConfig *config);
    … …  
    6360static bool listfileMode(pxConfig *config);
    6461static bool deletefileMode(pxConfig *config);
    65 # endif
    6662
    6763# define MODECASE(caseName, func) \
    … …  
    10399        MODECASE(PSTAMPTOOL_MODE_STOPDEPENDENTJOB, stopdependentjobMode);
    104100        MODECASE(PSTAMPTOOL_MODE_REVERTJOB, revertjobMode);
    105 # if (1)
    106101        MODECASE(PSTAMPTOOL_MODE_ADDPROJECT, addprojectMode);
    107102        MODECASE(PSTAMPTOOL_MODE_MODPROJECT, modprojectMode);
    … …  
    115110        MODECASE(PSTAMPTOOL_MODE_LISTFILE, listfileMode);
    116111        MODECASE(PSTAMPTOOL_MODE_DELETEFILE, deletefileMode);
    117 # endif
     112
    118113        default:
    119114            psAbort("invalid option (this should not happen)");
    … …  
    452447    PXOPT_COPY_S64(config->args, where, "-req_id", "req_id", "==");
    453448    PXOPT_COPY_S64(config->args, where, "-not_req_id", "req_id", "!=");
    454     PXOPT_COPY_STR(config->args, where, "-name", "name", "==");
     449    PXOPT_COPY_STR(config->args, where, "-name", "name", "LIKE");
     450    PXOPT_COPY_STR(config->args, where, "-username", "username", "==");
     451    PXOPT_COPY_STR(config->args, where, "-state", "state", "==");
    455452
    456453    PXOPT_LOOKUP_U64(limit,   config->args, "-limit",  false, false);
    … …  
    458455
    459456    if (!psListLength(where->list)) {
    460         psError(PS_ERR_UNKNOWN, true, "-req_id or -name must be supplied");
     457        psError(PS_ERR_UNKNOWN, true, "search paramters are required");
    461458        return false;
    462459    }
    … …  
    490487    if (!psArrayLength(output)) {
    491488        psTrace("pstamptool", PS_LOG_INFO, "request not found");
    492         // This causes main to exit with PS_EXIT_DATA_ERROR which the script is looking for
     489        // This causes main to exit with PS_EXIT_DATA_ERROR which the pstamp scripts are looking for
    493490        psError(PXTOOLS_ERR_CONFIG, true, "request not found");
    494491        psFree(output);
    495         // we return false so that the caller can determine that a request does not exist
     492        // we return false so that the caller can easily determine that a request does not exist
    496493        return false;
    497494    }
    … …  
    593590    PXOPT_COPY_S32(config->args, where, "-fault",      "fault", "==");
    594591    PXOPT_COPY_STR(config->args, where, "-state",      "state", "==");
    595     PXOPT_COPY_STR(config->args, where, "-reqType",     "reqType", "==");
    596     PXOPT_COPY_STR(config->args, where, "-name",     "name", "LIKE");
     592    PXOPT_COPY_STR(config->args, where, "-reqType",    "reqType", "==");
     593    PXOPT_COPY_STR(config->args, where, "-name",       "name", "LIKE");
     594    PXOPT_COPY_STR(config->args, where, "-username",   "username", "==");
    597595    PXOPT_COPY_TIME(config->args, where, "-timestamp_begin", "timestamp", ">=");
    598596    PXOPT_COPY_TIME(config->args, where, "-timestamp_end", "timestamp", "<=");
    … …  
    621619    if (outdir) {
    622620        psStringAppend(&query, ", outdir = '%s'", outdir);
     621    }
     622    if (username) {
     623        psStringAppend(&query, ", username = '%s'", username);
    623624    }
    624625    if (clearfault) {
    … …  
    12331234    PXOPT_LOOKUP_BOOL(need_magic, config->args, "-need_magic", false);
    12341235    PXOPT_LOOKUP_BOOL(no_create,  config->args, "-no_create", false);
     1236    PXOPT_LOOKUP_BOOL(hold,       config->args, "-hold", false);
    12351237
    12361238    psMetadata *where = psMetadataAlloc();
    … …  
    12401242    PXOPT_COPY_STR(config->args, where, "-component", "component", "==");
    12411243
    1242     // start a transaction eraly so it will contain any row level locks
     1244    // start a transaction early so it will contain any row level locks
    12431245    if (!psDBTransaction(config->dbh)) {
    12441246        psError(PS_ERR_UNKNOWN, false, "database error");
    … …  
    12641266        psError(PS_ERR_UNKNOWN, false, "database error");
    12651267        psFree(query);
     1268        if (!psDBRollback(config->dbh)) {
     1269            psError(PS_ERR_UNKNOWN, false, "database error");
     1270        }
    12661271        return false;
    12671272    }
    … …  
    12711276    if (!output) {
    12721277        psError(PS_ERR_UNKNOWN, false, "database error");
     1278        if (!psDBRollback(config->dbh)) {
     1279            psError(PS_ERR_UNKNOWN, false, "database error");
     1280        }
    12731281        return false;
    12741282    }
    … …  
    12791287            psError(PS_ERR_UNKNOWN, false, "database error");
    12801288            psFree(output);
     1289            if (!psDBRollback(config->dbh)) {
     1290                psError(PS_ERR_UNKNOWN, false, "database error");
     1291            }
    12811292            return false;
    12821293        }
    … …  
    12841295        if (fault > 0) {
    12851296            fprintf(stderr, "existing dependent has fault %d\n", fault);
     1297            if (!psDBRollback(config->dbh)) {
     1298                psError(PS_ERR_UNKNOWN, false, "database error");
     1299            }
     1300            // return the fault to the client. This is used by the postage stamp parser
    12861301            exit (fault);
    12871302        }
     1303        bool commit = false;
     1304        // Check the state of the exisiting dependent. By query it is either
     1305        // new or hold
     1306        psString state = psMetadataLookupStr(NULL, dep, "state");
     1307        if (!hold && !strcmp(state, "hold")) {
     1308            // There is a dependent for this component but it's state is hold.
     1309            // This client needs one that will run.
     1310            // Update the state
     1311            psString updateQuery = NULL;
     1312            psStringAppend(&updateQuery, "UPDATE pstampDependent SET state = 'new' "
     1313                "\nWHERE stage = '%s' AND imagedb = '%s' AND stage_id = %"PRId64 " AND component = '%s'",
     1314                    stage, imagedb, stage_id, component);
     1315
     1316            if (!p_psDBRunQuery(config->dbh, updateQuery)) {
     1317                psError(PS_ERR_UNKNOWN, false, "database error");
     1318                psFree(updateQuery);
     1319                if (!psDBRollback(config->dbh)) {
     1320                    psError(PS_ERR_UNKNOWN, false, "database error");
     1321                }
     1322                return false;
     1323            }
     1324            // set flag to commit this change
     1325            commit = true;
     1326            psFree(updateQuery);
     1327        }
     1328        // print the dep_id for the user
    12881329        printf("%" PRId64 "\n", dep_id);
    12891330        psFree(output);
    1290         if (!psDBRollback(config->dbh)) {
     1331        // now either commit the change or rollback the transaction which releases the lock
     1332        if (commit) {
     1333            if (!psDBCommit(config->dbh)) {
     1334                // rollback
     1335                if (!psDBRollback(config->dbh)) {
     1336                    psError(PS_ERR_UNKNOWN, false, "database error");
     1337                }
    12911338            psError(PS_ERR_UNKNOWN, false, "database error");
     1339            return false;
     1340            }
     1341        } else if (!psDBRollback(config->dbh)) {
     1342            psError(PS_ERR_UNKNOWN, false, "database error");
     1343            return false;
    12921344        }
    12931345        return true;
    … …  
    13071359        config->dbh,
    13081360        0,              // dep_id
    1309         "new",          // state
     1361        hold ? "hold" : "new",          // state
    13101362        stage,
    13111363        stage_id,
  • tags/ipp-20130307/ippTools/src/pstamptoolConfig.c

    r35293 r35489  
    9090    psMetadataAddS64(listreqArgs, PS_LIST_TAIL, "-req_id", 0,            "list by req_id", 0);
    9191    psMetadataAddStr(listreqArgs, PS_LIST_TAIL, "-name", 0,              "list by name", NULL);
     92    psMetadataAddStr(listreqArgs, PS_LIST_TAIL, "-username", 0,          "list by user name", NULL);
     93    psMetadataAddStr(listreqArgs, PS_LIST_TAIL, "-state", 0,              "list by state", NULL);
    9294    psMetadataAddS64(listreqArgs, PS_LIST_TAIL, "-not_req_id", 0,        "req_id to not list", 0);
    9395    psMetadataAddU64(listreqArgs, PS_LIST_TAIL, "-limit",  0,            "limit result set to N items", 0);
    … …  
    107109    psMetadataAddStr(updatereqArgs, PS_LIST_TAIL, "-state", 0,        "search by state", NULL);
    108110    psMetadataAddStr(updatereqArgs, PS_LIST_TAIL, "-reqType", 0,      "search by reqType", NULL);
    109     psMetadataAddStr(updatereqArgs, PS_LIST_TAIL, "-name", 0,      "search by reqType (LIKE comparsion)", NULL);
     111    psMetadataAddStr(updatereqArgs, PS_LIST_TAIL, "-name", 0,         "search by reqType (LIKE comparsion)", NULL);
     112    psMetadataAddStr(updatereqArgs, PS_LIST_TAIL, "-username", 0,     "search by username", NULL);
    110113    psMetadataAddStr(updatereqArgs, PS_LIST_TAIL, "-label", PS_META_DUPLICATE_OK, "search by pstampJob label (LIKE comparision)", NULL);
    111114    psMetadataAddTime(updatereqArgs, PS_LIST_TAIL, "-timestamp_begin", 0, "search by timestamp (>=)", NULL);
    … …  
    220223    psMetadataAddBool(getdependentArgs,PS_LIST_TAIL, "-need_magic", 0, "define need_magic", false);
    221224    psMetadataAddStr(getdependentArgs, PS_LIST_TAIL, "-outdir", 0,    "define output directory for dependent (required)", NULL);
     225    psMetadataAddBool(getdependentArgs,PS_LIST_TAIL, "-hold", 0, "if creating new dependent set it's state to hold", false);
    222226    psMetadataAddBool(getdependentArgs,PS_LIST_TAIL, "-no_create", 0, "if no matching dependent do not create one", false);
    223227
  • tags/ipp-20130307/ippTools/src/releasetool.c

    r35230 r35489  
    702702    PXOPT_COPY_STR(config->args, where, "-cam_data_group",  "camRun.data_group", "LIKE");
    703703    PXOPT_COPY_STR(config->args, where, "-warp_data_group", "warpRun.data_group", "LIKE");
     704    PXOPT_COPY_STR(config->args, where, "-tess_id",      "warpRun.tess_id", "==");
     705    PXOPT_COPY_STR(config->args, where, "-skycell_id",   "warpSkyfile.skycell_id", "==");
     706   
     707    PXOPT_LOOKUP_STR(skycell_id, config->args, "-skycell_id", false, false);
    704708
    705709    PXOPT_COPY_STR(config->args, where, "-surveyName",  "survey.surveyName", "LIKE");
    … …  
    715719        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    716720        return false;
     721    }
     722
     723    if (skycell_id) {
     724        psStringAppend(&query, "\nJOIN warpSkyfile ON warpRun.warp_id = warpSkyfile.warp_id AND warpRun.tess_id = warpSkyfile.tess_id");
    717725    }
    718726
    … …  
    741749
    742750    if (priority_order) {
    743         psStringAppend(&query, "\nAND priority > 0 order by exp_id, priority");
     751        psStringAppend(&query, "\nAND priority > 0 order by exp_id, priority DESC");
    744752    }
    745753
    … …  
    787795    bool includeSkycal = false;
    788796
     797    PXOPT_COPY_STR(config->args, where, "-skycal_label", "skycalRun.label", "==");
     798    PXOPT_COPY_STR(config->args, where, "-skycal_data_group", "skycalRun.data_group", "LIKE");
    789799    PXOPT_COPY_S64(config->args, where, "-skycal_id",  "skycalRun.skycal_id", "==");
    790     PXOPT_COPY_STR(config->args, where, "-skycal_label", "skycalRun.label", "==");
    791     PXOPT_COPY_STR(config->args, where, "-skycal_data_group", "skycalRun.data_group", "==");
    792800    if (psListLength(where->list)) {
    793801        includeSkycal = true;
    … …  
    795803
    796804    PXOPT_COPY_STR(config->args, where, "-label",      "stackRun.label", "==");
    797     PXOPT_COPY_STR(config->args, where, "-data_group", "stackRun.data_group", "==");
     805    PXOPT_COPY_STR(config->args, where, "-data_group", "stackRun.data_group", "LIKE");
    798806    PXOPT_COPY_S64(config->args, where, "-stack_id",   "stackRun.stack_id", "==");
    799807
    … …  
    832840    PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
    833841    PXOPT_LOOKUP_BOOL(simple, config->args,  "-simple", false);
     842    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    834843
    835844    // find the parameters of all the exposures that we want to add to the release
    … …  
    847856    }
    848857
     858    psString joinConditions = psStringCopy("");
     859    // Finish up the selectors for the JOIN to previousRelStack
     860    // join to rows with our stack_type
     861    psStringAppend(&joinConditions, "\nAND previousRelStack.stack_type = '%s'", stack_type);
     862
     863    if (!strcmp(stack_type, "nightly")) {
     864        // detect nightly stack entries that already exist for this day
     865        psStringAppend(&joinConditions, "\nAND previousRelStack.mjd_obs = floor(stackSumSkyfile.mjd_obs)");
     866    }
     867
     868    // Add in the where conditions
    849869    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    850     psStringAppend(&query, " AND %s", whereClause);
     870    psStringAppend(&query, "\nAND %s", whereClause);
    851871    psFree(whereClause);
    852872
     873    if (!strcmp(stack_type, "nightly")) {
     874        // avoid stacks with NAN mjd_obs. These are old skycells that were lost due to system failure
     875        // prior to the time that the mjd_obs was extracted from the headers and added to stackSumSkyfile
     876        psStringAppend(&query, "\nAND stackSumSkyfile.mjd_obs IS NOT NULL");
     877    }
     878
    853879    psFree(where);
    854880
    855     if (!p_psDBRunQuery(config->dbh, query)) {
     881    if (limit) {
     882        psString limitString = psDBGenerateLimitSQL(limit);
     883        psStringAppend(&query, " %s", limitString);
     884        psFree(limitString);
     885    }
     886
     887    if (!p_psDBRunQueryF(config->dbh, query, joinConditions)) {
    856888        psError(PS_ERR_UNKNOWN, false, "database error");
    857889        psFree(query);
     890        psFree(joinConditions);
    858891        return false;
    859892    }
    860893    psFree(query);
     894    psFree(joinConditions);
    861895
    862896    psArray *output = p_psDBFetchResult(config->dbh);
    … …  
    9681002    psMetadata *where = psMetadataAlloc();
    9691003
     1004    PXOPT_COPY_S64(config->args, where, "-relstack_id", "relStack.relstack_id", "==");
     1005    PXOPT_COPY_S64(config->args, where, "-stack_id",    "relStack.stack_id", "==");
     1006    PXOPT_COPY_S64(config->args, where, "-skycal_id",   "relStack.skycal_id", "==");
     1007    PXOPT_COPY_S64(config->args, where, "-relstack_id", "relStack.relstack_id", "==");
    9701008    PXOPT_COPY_STR(config->args, where, "-release_name", "ippRelease.release_name", "LIKE");
    9711009    pxAddLabelSearchArgs(config, where, "-release_state","ippRelease.state", "==");
    972     PXOPT_COPY_STR(config->args, where, "-state",       "relExp.state", "==");
    973     PXOPT_COPY_STR(config->args, where, "-filter",      "rawExp.filter", "LIKE");
    974     PXOPT_COPY_TIME(config->args, where, "-dateobs_begin","rawExp.dateobs", ">=");
    975     PXOPT_COPY_TIME(config->args, where, "-dateobs_end", "rawExp.dateobs", "<=");
    976     PXOPT_COPY_F32(config->args, where, "-fwhm_min",    "skycalResult.fwhm_major", ">=");
    977     PXOPT_COPY_F32(config->args, where, "-fwhm_max",    "skycalresult.fwhm_major", "<=");
    978     PXOPT_COPY_STR(config->args, where, "-exp_name",    "rawExp.exp_ame", "==");
    979     PXOPT_COPY_S64(config->args, where, "-exp_id",      "relExp.exp_id", "==");
    980     PXOPT_COPY_S64(config->args, where, "-chip_id",     "relExp.chip_id", "==");
    981     PXOPT_COPY_S64(config->args, where, "-cam_id",      "relExp.cam_id", "==");
    982     PXOPT_COPY_S64(config->args, where, "-warp_id",     "warpRun.warp_id", "==");
    983     PXOPT_COPY_STR(config->args, where, "-chip_data_group", "chipRun.data_group", "LIKE");
    984     PXOPT_COPY_STR(config->args, where, "-cam_data_group",  "camRun.data_group", "LIKE");
    985     PXOPT_COPY_STR(config->args, where, "-warp_data_group", "warpRun.data_group", "LIKE");
     1010    PXOPT_COPY_STR(config->args, where, "-state",       "relStack.state", "==");
     1011    PXOPT_COPY_STR(config->args, where, "-filter",      "relStack.filter", "LIKE");
     1012    PXOPT_COPY_F32(config->args, where, "-mjd_min",    "stackSumSkyfile.mjd_obs", ">=");
     1013    PXOPT_COPY_F32(config->args, where, "-mjd_max",    "stackSumSkyfile.mjd_obs", "<=");
     1014    PXOPT_COPY_STR(config->args, where, "-tess_id",     "relStack.tess_id", "==");
     1015    PXOPT_COPY_STR(config->args, where, "-skycell_id",  "relStack.skycell_id", "LIKE");
     1016//    PXOPT_COPY_STR(config->args, where, "-stack_type",  "relStack.stack_type", "==");
     1017    PXOPT_COPY_STR(config->args, where, "-stack_data_group",  "stackRun.data_group", "LIKE");
     1018    PXOPT_COPY_STR(config->args, where, "-skycal_data_group", "skycalRun.data_group", "LIKE");
    9861019
    9871020    PXOPT_COPY_STR(config->args, where, "-surveyName",  "survey.surveyName", "LIKE");
    9881021    PXOPT_COPY_S32(config->args, where, "-rel_id",      "relExp.rel_id", "==");
     1022    pxskycellAddWhere(config, where);
     1023
     1024    PXOPT_COPY_F32(config->args, where, "-fwhm_min",    "IFNULL(skycalResult.fwhm_major, 999)", ">=");
     1025    PXOPT_COPY_F32(config->args, where, "-fwhm_max",    "IFNULL(skycalResult.fwhm_major, 0)", "<=");
    9891026
    9901027    PXOPT_LOOKUP_BOOL(priority_order, config->args, "-priority_order", false);
    … …  
    9931030    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    9941031
    995     psString query = pxDataGet("releasetool_listrelexp.sql");
     1032    pxAddLabelSearchArgs (config, where, "-stack_type", "relStack.stack_type", "==");
     1033
     1034    psString query = pxDataGet("releasetool_listrelstack.sql");
    9961035    if (!query) {
    9971036        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    998         return false;
    999     }
    1000 
    1001     psString where2 = NULL;
    1002     if (!pxspaceAddWhere(config, &where2, "rawExp")) {
    1003         psError(psErrorCodeLast(), false, "pxspaceAddWhere failed");
    10041037        return false;
    10051038    }
    … …  
    10091042        psStringAppend(&query, "\nWHERE %s", whereClause);
    10101043        psFree(whereClause);
    1011     } else if (where2) {
    1012         psStringAppend(&query, "\nWHERE ");
    10131044    } else {
    10141045        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required\n");
    … …  
    10171048    }
    10181049
    1019     if (where2) {
    1020         psStringAppend(&query, "\n%s", where2);
    1021         psFree(where2);
    1022     }
    1023 
    10241050    if (priority_order) {
    1025         psStringAppend(&query, "\nAND priority > 0 order by exp_id, priority");
     1051        psStringAppend(&query, "\nAND priority > 0 order by stack_id, priority DESC");
    10261052    }
    10271053
    … …  
    10511077    }
    10521078
    1053     if (!ippdbPrintMetadatas(stdout, output, "relExp", !simple)) {
     1079    if (!ippdbPrintMetadatas(stdout, output, "relStack", !simple)) {
    10541080        psError(PS_ERR_UNKNOWN, false, "failed to print array");
    10551081        psFree(output);
    … …  
    12701296        }
    12711297        if (!psArrayLength(exposures)) {
     1298            fprintf(stderr, "no exposures found for lap_id %" PRId64 "\n", lap_id);
     1299#ifdef notdef
     1300            continue;
    12721301            psFree(now);
    12731302            psFree(output);
    … …  
    12781307            }
    12791308            return false;
     1309#endif
    12801310        }
    12811311
    … …  
    13011331        psFree(exposures);
    13021332
    1303         // set state of relGroup to 'new'
     1333        // update the state of relGroup to 'new'
    13041334        if (!p_psDBRunQueryF(config->dbh, "UPDATE relGroup set state = 'new' WHERE group_id = %d", group_id)) {
    13051335            psError(PS_ERR_UNKNOWN, false, "database error");
    … …  
    13251355static bool updaterelgroupMode(pxConfig *config)
    13261356{
    1327     psError(PS_ERR_UNKNOWN, true, "not yet implemented");
    1328     return false;
     1357    PS_ASSERT_PTR_NON_NULL(config, false);
     1358
     1359    PXOPT_LOOKUP_S32(group_id, config->args,      "-group_id", false, false);
     1360    PXOPT_LOOKUP_STR(group_name, config->args,    "-group_name",  false, false);
     1361    if (!group_id && !group_name) {
     1362        psError(PXTOOLS_ERR_CONFIG, true, "either group_id or group_name is required\n");
     1363        return false;
     1364    }
     1365
     1366    PXOPT_LOOKUP_STR(state,    config->args,    "-set_state",  false, false);
     1367    PXOPT_LOOKUP_STR(exp_list_path, config->args, "-set_exp_list_path", false, false);
     1368    PXOPT_LOOKUP_STR(new_label, config->args,   "-set_label", false, false);
     1369    PXOPT_LOOKUP_S16(fault,    config->args,    "-set_fault",  false, false);
     1370    PXOPT_LOOKUP_BOOL(clearfault, config->args, "-clearfault",  false);
     1371
     1372    if (!state && !exp_list_path && !new_label && !fault && !clearfault) {
     1373        psError(PXTOOLS_ERR_CONFIG, true, "must set at least one column\n");
     1374        return false;
     1375    }
     1376
     1377    if (fault && clearfault) {
     1378        psError(PXTOOLS_ERR_CONFIG, true, "cannot set and clear fault at same time\n");
     1379        return false;
     1380    }
     1381
     1382    psMetadata *where = psMetadataAlloc();
     1383
     1384    PXOPT_COPY_S64(config->args, where, "-group_id", "relGroup.group_id", "==");
     1385    PXOPT_COPY_STR(config->args, where, "-group_name", "relGroup.group_name", "==");
     1386    // XXX TODO if label is enabled (for changing label or state for a block) we should
     1387    // disallow setting some parameters such as exp_list_path
     1388    //    PXOPT_COPY_S64(config->args, where, "-label", "relGroup.label", "==");
     1389    // make sure that we have enough parameters to identify the relGroup to change
     1390    if (!psListLength(where->list)){
     1391        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required\n");
     1392        psFree(where);
     1393        return false;
     1394    }
     1395
     1396    psString sep = "";
     1397    psString comma = ", ";
     1398    psString query = psStringCopy("UPDATE relGroup SET");
     1399    if (state) {
     1400        psStringAppend(&query, "%s relGroup.state = '%s'", sep, state);
     1401        sep = comma;
     1402    }
     1403    if (exp_list_path) {
     1404        psStringAppend(&query, "%s relGroup.exp_list_path = '%s'", sep, exp_list_path);
     1405        sep = comma;
     1406    }
     1407    if (new_label) {
     1408        psStringAppend(&query, "%s relGroup.label = '%s'", sep, new_label);
     1409        sep = comma;
     1410    }
     1411    if (fault) {
     1412        psStringAppend(&query, "%s relGroup.fault = %d", sep, fault);
     1413        sep = comma;
     1414    }
     1415    if (clearfault) {
     1416        psStringAppend(&query, "%s relGroup.fault = 0", sep);
     1417        sep = comma;
     1418    }
     1419
     1420    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1421    psStringAppend(&query, " WHERE %s", whereClause);
     1422    psFree(whereClause);
     1423
     1424    if (!p_psDBRunQuery(config->dbh, query)) {
     1425        psError(PS_ERR_UNKNOWN, false, "database error");
     1426        psFree(query);
     1427        return false;
     1428    }
     1429
     1430    psU64 affected = psDBAffectedRows(config->dbh);
     1431    psLogMsg("releasetool", PS_LOG_INFO, "Updated %" PRIu64 " ippReleases", affected);
     1432
     1433
     1434    psFree(query);
     1435
     1436    return true;
    13291437}
    13301438
    … …  
    14101518    PXOPT_COPY_TIME(config->args, where, "-dateobs_end", "rawExp.dateobs", "<=");
    14111519    PXOPT_COPY_F32(config->args, where, "-fwhm_min",    "skycalResult.fwhm_major", ">=");
    1412     PXOPT_COPY_F32(config->args, where, "-fwhm_max",    "skycalresult.fwhm_major", "<=");
     1520    PXOPT_COPY_F32(config->args, where, "-fwhm_max",    "skycalResult.fwhm_major", "<=");
    14131521    PXOPT_COPY_STR(config->args, where, "-exp_name",    "rawExp.exp_ame", "==");
    14141522    PXOPT_COPY_S64(config->args, where, "-exp_id",      "relExp.exp_id", "==");
  • tags/ipp-20130307/ippTools/src/releasetoolConfig.c

    r35227 r35489  
    164164    psMetadataAddStr(listrelexpArgs,  PS_LIST_TAIL, "-cam_data_group", 0, "camRun.data_group (LIKE comparison)", NULL);
    165165    psMetadataAddStr(listrelexpArgs,  PS_LIST_TAIL, "-warp_data_group", 0, "warpRun.data_group (LIKE comparison)", NULL);
     166    psMetadataAddStr(listrelexpArgs,  PS_LIST_TAIL, "-skycell_id", 0, "select by skycell", NULL);
     167    psMetadataAddStr(listrelexpArgs,  PS_LIST_TAIL, "-tess_id", 0,    "warpRun.tess_id", NULL);
    166168
    167169    psMetadataAddStr(listrelexpArgs,  PS_LIST_TAIL, "-surveyName", 0, "select by survey name (LIKE comparision)", NULL);
    … …  
    195197    psMetadataAddF32(definerelstackArgs,  PS_LIST_TAIL, "-set_zpt_stdev", 0,  "define zero point stdev", NAN);
    196198    psMetadataAddF32(definerelstackArgs,  PS_LIST_TAIL, "-set_fwhm_major", 0, "define fwhm_major", NAN);
    197     psMetadataAddStr(definerelstackArgs,  PS_LIST_TAIL, "-set_path_base", 0,  "define state (required)", NULL);
     199    psMetadataAddStr(definerelstackArgs,  PS_LIST_TAIL, "-set_path_base", 0,  "define state", NULL);
    198200    psMetadataAddS16(definerelstackArgs,  PS_LIST_TAIL, "-set_fault", 0,      "define fault", 0);
    199201
    200     psMetadataAddBool(definerelstackArgs, PS_LIST_TAIL, "-pretend",  0, "do not actually modify the database", false);
     202    psMetadataAddBool(definerelstackArgs, PS_LIST_TAIL, "-pretend", 0, "do not actually modify the database", false);
    201203    psMetadataAddBool(definerelstackArgs, PS_LIST_TAIL, "-simple",  0, "use the simple output format", false);
     204    psMetadataAddU64(definerelstackArgs, PS_LIST_TAIL,  "-limit",   0, "limit result set to N items", 0);
     205
     206    // -listrelstack
     207    psMetadata *listrelstackArgs = psMetadataAlloc();
     208    psMetadataAddS64(listrelstackArgs, PS_LIST_TAIL,  "-relstack_id", 0,   "select by released exposure ID", 0);
     209    psMetadataAddS64(listrelstackArgs, PS_LIST_TAIL,  "-stack_id", 0,   "select by stack ID", 0);
     210    psMetadataAddS64(listrelstackArgs, PS_LIST_TAIL,  "-skycal_id", 0,   "select by skycal ID", 0);
     211    psMetadataAddStr(listrelstackArgs,  PS_LIST_TAIL, "-release_name", 0, "select by release name (LIKE comparision)", NULL);
     212    psMetadataAddStr(listrelstackArgs,  PS_LIST_TAIL, "-release_state", PS_META_DUPLICATE_OK, "select by release state", NULL);
     213    psMetadataAddStr(listrelstackArgs,  PS_LIST_TAIL, "-state", 0,        "select by released stack state", NULL);
     214
     215    psMetadataAddStr(listrelstackArgs,  PS_LIST_TAIL, "-filter", 0,       "select by filter name (LIKE comparison)", NULL);
     216    // psMetadataAddTime(listrelstackArgs, PS_LIST_TAIL, "-dateobs_begin", 0,"search for exposures by time (>=)", NULL);
     217    // psMetadataAddTime(listrelstackArgs, PS_LIST_TAIL, "-dateobs_end", 0,  "search for exposures by time (<=)", NULL);
     218
     219    pxskycellAddArguments(listrelstackArgs);
     220
     221    psMetadataAddF32(listrelstackArgs,  PS_LIST_TAIL, "-fwhm_min", 0, "search by measured seeing (>=)", NAN);
     222    psMetadataAddF32(listrelstackArgs,  PS_LIST_TAIL, "-fwhm_max", 0, "search by seeing (<=)", NAN);
     223
     224    psMetadataAddF32(listrelstackArgs,  PS_LIST_TAIL, "-mjd_min", 0, "search by MJD seeing (>=)", NAN);
     225    psMetadataAddF32(listrelstackArgs,  PS_LIST_TAIL, "-mjd_max", 0, "search by MJD (<=)", NAN);
     226
     227    psMetadataAddStr(listrelstackArgs,  PS_LIST_TAIL, "-tess_id", 0, "select by tess_id", NULL);
     228    psMetadataAddStr(listrelstackArgs,  PS_LIST_TAIL, "-skycell_id", 0, "select by skycell_id (LIKE comparision)", NULL);
     229    psMetadataAddStr(listrelstackArgs,  PS_LIST_TAIL, "-stack_type", PS_META_DUPLICATE_OK, "select by stack_type", NULL);
     230
     231    psMetadataAddStr(listrelstackArgs,  PS_LIST_TAIL, "-stack_data_group", 0, "select by stackRun.data_group (LIKE comparison)", NULL);
     232    psMetadataAddStr(listrelstackArgs,  PS_LIST_TAIL, "-skycal_data_group", 0, "select by skycalRun.data_group (LIKE comparison)", NULL);
     233
     234    psMetadataAddStr(listrelstackArgs,  PS_LIST_TAIL, "-surveyName", 0, "select by survey name (LIKE comparision)", NULL);
     235    psMetadataAddS64(listrelstackArgs,  PS_LIST_TAIL, "-rel_id", 0, "select by release ID", 0);
     236
     237    psMetadataAddBool(listrelstackArgs, PS_LIST_TAIL, "-priority_order",   0, "order by release priority", false);
     238
     239    psMetadataAddU64(listrelstackArgs,  PS_LIST_TAIL, "-limit",       0, "limit result set to N items", 0);
     240    psMetadataAddBool(listrelstackArgs, PS_LIST_TAIL, "-simple",      0, "use the simple output format", false);
     241
    202242
    203243    // -definerelgroup
    … …  
    217257        // parameters of the relGroup
    218258    psMetadataAddStr(definerelgroupArgs, PS_LIST_TAIL, "-set_group_type", 0,  "define group_type (required)", NULL);
    219     psMetadataAddStr(definerelgroupArgs, PS_LIST_TAIL, "-set_group_name", 0,  "define group_name (required)", NULL);
     259    psMetadataAddStr(definerelgroupArgs, PS_LIST_TAIL, "-set_group_name", 0,  "define group_name", NULL);
    220260    psMetadataAddStr(definerelgroupArgs, PS_LIST_TAIL, "-set_label", 0, "define relgroup label (required)", NULL);
    221261    psMetadataAddStr(definerelgroupArgs,  PS_LIST_TAIL, "-set_state", 0,      "define state", NULL);
    … …  
    240280    psMetadata *updaterelgroupArgs = psMetadataAlloc();
    241281
    242         // set the target release
    243     psMetadataAddS32(updaterelgroupArgs,  PS_LIST_TAIL, "-group_id", 0,   "select by group ID (required)", 0);
     282    psMetadataAddS32(updaterelgroupArgs,  PS_LIST_TAIL, "-group_id", 0,   "select by group ID",  0);
     283    psMetadataAddStr(updaterelgroupArgs,  PS_LIST_TAIL, "-group_name", 0, "select by group name", 0);
    244284
    245285        // parameters of the relGroup
    … …  
    273313
    274314    PXOPT_ADD_MODE("-definerelstack",     "define a released stack",    RELEASETOOL_MODE_DEFINERELSTACK,  definerelstackArgs);
     315    PXOPT_ADD_MODE("-listrelstack",       "list released stacks",      RELEASETOOL_MODE_LISTRELSTACK,    listrelstackArgs);
    275316
    276317    PXOPT_ADD_MODE("-definerelgroup",     "define a group of exposures", RELEASETOOL_MODE_DEFINERELGROUP,  definerelgroupArgs);
  • tags/ipp-20130307/pstamp

  • tags/ipp-20130307/pstamp/scripts

  • tags/ipp-20130307/pstamp/scripts/psmkreq

    r34611 r35489  
    11#!/bin/env perl
    22###
    3 ### pstamprequest
     3### psmkreq
    44###
    5 ###     Program to make a postage stamp request table for a set of coordinates
     5###     Program to make a postage stamp request table for a set of coordinates using supplied command
     6###     line options and defaults
    67###
    78
    … …  
    2829my ($ra, $dec, $x, $y, $list, $output, $req_name, $req_name_base);
    2930
    30 my ($image, $mask, $variance, $cmf, $psf, $backmdl, $inverse);
    31 my ($unconvolved, $use_imfile_id, $no_wait);
     31my ($image, $mask, $variance, $jpeg, $cmf, $psf, $backmdl, $inverse);
     32my ($convolved, $unconvolved, $uncompressed, $use_imfile_id, $no_wait);
     33
     34# new header keywords for version 2
     35my $action = 'PROCESS';
     36my $email = 'null';
    3237
    3338my $default_size = 100;
    … …  
    5257my $comment;
    5358
     59# new request specification columns for version 2
     60my $survey_name ='null';
     61my $release_name = 'null';
     62my $run_type ='null';
     63my $fwhm_min = 0;
     64my $fwhm_max = 0;
     65
     66
    5467my $missing_tools;
    5568my $pstamp_request_file  = can_run('pstamp_request_file')  or (warn "Can't find required program pstamp_request_file"  and $missing_tools = 1);
    … …  
    6275GetOptions(
    6376    'list=s'            => \$list,          # list of coordinates if undef ra and dec or x and y are required
    64     'ra=s'              => \$ra,            #
     77    'ra=s'              => \$ra,
    6578    'dec=s'             => \$dec,
    6679    'x=s'               => \$x,
    … …  
    87100    'comment=s'         => \$comment,
    88101
     102    'survey=s'          => \$survey_name,
     103    'release=s'         => \$release_name,
     104    'run_type=s'        => \$run_type,
     105    'fwhm_min=s'        => \$fwhm_min,
     106    'fwhm_max=s'        => \$fwhm_max,
     107
    89108    'option_mask=i'     => \$option_mask,
    90109    'image'             => \$image,
    91110    'mask'              => \$mask,
     111    'jpeg'              => \$jpeg,
    92112    'variance'          => \$variance,
    93113    'cmf'               => \$cmf,
    … …  
    96116    'inverse'           => \$inverse,
    97117    'unconvolved'       => \$unconvolved,
     118    'convolved'         => \$convolved,
     119    'uncompressed'      => \$uncompressed,
    98120    'use_imfile_id'     => \$use_imfile_id,
    99121    'do_not_wait'       => \$no_wait,
     122
     123    'action=s'          => \$action,
     124    'email=s'           => \$email,
    100125
    101126    'verbose'           => \$verbose,
    … …  
    156181}
    157182
     183if ($stage eq 'stack') {
     184    # default is to do convolved stack
     185    unless (defined $option_mask || $convolved) {
     186        $unconvolved = 1;
     187    }
     188}
     189
    158190checkFilter($filter, 'null', $filter)  if $filter;
    159191checkMJD($mjd_min, 0, "") if $mjd_min;
    … …  
    167199        $option_mask |= $PSTAMP_SELECT_MASK     if $mask;
    168200        $option_mask |= $PSTAMP_SELECT_VARIANCE if $variance;
     201        $option_mask |= $PSTAMP_SELECT_JPEG     if $jpeg;
     202
     203        # if no image was requested make a stamp of the image
    169204        $option_mask = $PSTAMP_SELECT_IMAGE    if $option_mask == 0;
    170205
    171         # if no image was requested make a stamp of the image
    172206
    173207        $option_mask |= $PSTAMP_SELECT_CMF      if $cmf;
    … …  
    207241} else {
    208242    $rows = [];
    209     push @$rows, buildRow("", $comment, $x, $y, $filter, $mjd_min, $mjd_max);
     243    push @$rows, buildRow("", $comment, 1, $x, $y, $filter, $mjd_min, $mjd_max);
    210244}
    211245
    212246my ($tdf, $table_def_name) = tempfile ("/tmp/tabledef.XXXX", UNLINK => !$save_temps);
    213 print $tdf "$req_name 1\n";
     247my $line = "$req_name 2 $action $email";
     248print "$line\n" if $verbose;
     249print $tdf "$line\n";
    214250my $rownum = 0;
    215251foreach my $row (@$rows) {
    216252    $rownum++;
    217253    my $line = "$rownum $row->{ra}\t$row->{dec}\t$width $height"
    218         . " $coord_mask $job_type $option_mask $project $req_type"
     254        . " $coord_mask $job_type $option_mask $project $survey_name $release_name $req_type"
    219255        . " $stage $id $tess_id $component $data_group"
    220         . " $row->{filter} $row->{mjd_min} $row->{mjd_max}";
     256        . " $row->{filter} $row->{mjd_min} $row->{mjd_max} $run_type $fwhm_min $fwhm_max";
    221257
    222258    if ($row->{comment} and $row->{comment} ne '') {
    … …  
    235271    $command .= " --output $output" if $output;
    236272    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    237         run(command => $command, verbose => 0);
     273        run(command => $command, verbose => $verbose);
    238274    unless ($success) {
    239275        print STDERR @$stderr_buf;
    … …  
    274310
    275311    my $row = {};
    276     $row->{ra}      = checkRA($vals[0], $linenumber);
    277     $row->{dec}     = checkDEC($vals[1], $linenumber);
    278     $row->{filter}  = checkFilter($vals[2], $filter, $linenumber);
    279     $row->{mjd_min} = checkMJD($vals[3], $mjd_min, $linenumber);;
    280     $row->{mjd_max} = checkMJD($vals[4], $mjd_max, $linenumber);;
     312    $row->{rownum}  = checkRownum($vals[0], $linenumber);
     313    $row->{ra}      = checkRA($vals[1], $linenumber);
     314    $row->{dec}     = checkDEC($vals[2], $linenumber);
     315    $row->{filter}  = checkFilter($vals[3], $filter, $linenumber);
     316    $row->{mjd_min} = checkMJD($vals[4], $mjd_min, $linenumber);;
     317    $row->{mjd_max} = checkMJD($vals[5], $mjd_max, $linenumber);;
    281318    $row->{comment} = $comment;
    282319
    … …  
    305342    my $linenumber = shift;
    306343
    307     my $result;
     344   my $result;
    308345    if ($c =~ /\:/) {
    309346        # sexagesmial format not valid for pixel coordinates
    … …  
    329366}
    330367
     368sub checkRownum {
     369    my $rownum = shift;
     370    my $linenumber = shift;
     371    die "rownum can not be null at $linenumber\n" unless defined $rownum;
     372
     373    # XXX: For now just check that rownum is defined and a single word
     374    # extend this. Should we require a number?
     375    my @words = split " ", $rownum;
     376    die "$rownum is not a vaild rownum at $linenumber\n" unless (scalar @words) == 1;
     377}
     378
    331379sub checkRA {
    332380    my $ra = shift;
    … …  
    335383
    336384    if ($ra =~ /\:/) {
     385        # assume RA is in hours:minutes:seconds
    337386        return $checked * 360. / 24.;
    338387    } else {
  • tags/ipp-20130307/pstamp/scripts/pstamp_finish.pl

    r34447 r35489  
    107107    my ($header, $rows) = read_request_file($req_file);
    108108
    109     my $action = $header->{ACTION};
    110 
    111     if (!$header or (($action eq 'PROCESS') and !$rows)) {
     109    if (!$header or !$rows) {
    112110        # Since a request got queued, the request file must have been readable at some point
    113111        my_die("failed to read request file $req_file", $req_id, $PS_EXIT_CONFIG_ERROR);
    … …  
    128126
    129127    my $request_fault = 0;
    130     if ($action eq 'PROCESS') {
     128    {
    131129        # The results table definition file
    132130        my ($tdf, $table_def_name) = tempfile ("$outdir/tabledef.XXXX", UNLINK => !$save_temps);
    … …  
    238236                } else {
    239237                    my_die("No reglist for successful job: $job_id", $req_id, $PS_EXIT_PROG_ERROR)
    240                         if $fault eq $PSTAMP_SUCCESS;
     238                        if $job->{state} eq 'stop' and $fault eq $PSTAMP_SUCCESS;
    241239                    print STDERR "no reglist file for job $job_id\n" if $verbose;
    242240                    print $tdf "$rownum|$fault|$error_string|0|$job_id|";
    … …  
    273271            }
    274272        }
    275     } elsif ($action ne 'LIST') {
    276         my_die("Unexpected action $action found", $req_id, $PS_EXIT_PROG_ERROR);
    277     } else {
    278         # pstampparse did all of the work
    279273    }
    280274
  • tags/ipp-20130307/pstamp/scripts/pstamp_job_run.pl

    r33512 r35489  
    113113
    114114    if ($stage eq "raw") {
     115        # zap options that don't apply to raw stage
    115116        $options &= ~($PSTAMP_SELECT_MASK | $PSTAMP_SELECT_VARIANCE);
    116117    }
    … …  
    136137        $argString .= " -astrom $params->{astrom}";
    137138        push @file_list, $params->{astrom};
     139    }
     140
     141    if ($options & $PSTAMP_SELECT_SOURCES) {
     142        # Extract sources from astrometry file if provided. This will be the smf for chip stage
     143        # or the skycal cmf for stacks
     144        if ($params->{astrom}) {
     145            $argString .= " -write_cmf";
     146            if ($stage eq 'stack') {
     147                # Set psphot recipe to STACKPHOT so that the extended source paramters will
     148                # be copied from the cmf file.
     149                $argString .= " -recipe PSPHOT STACKPHOT"
     150            }
     151        } elsif ($params->{cmf}) {
     152            $argString .= " -write_cmf";
     153            push @file_list, $params->{cmf};
     154        } else {
     155            print "Could not find suitable sources file will not write cmf\n";
     156        }
    138157    }
    139158
    … …  
    254273                           $PSTAMP_SELECT_MASK     => "mk.fits",
    255274                           $PSTAMP_SELECT_VARIANCE => "wt.fits",
     275                           $PSTAMP_SELECT_SOURCES  => "cmf",
    256276                           $PSTAMP_SELECT_JPEG     => "jpg");
    257277
    258         my $output_mask = $options & ($PSTAMP_SELECT_IMAGE | $PSTAMP_SELECT_MASK | $PSTAMP_SELECT_VARIANCE | $PSTAMP_SELECT_JPEG);
     278        my $output_mask = $options & ($PSTAMP_SELECT_IMAGE | $PSTAMP_SELECT_MASK | $PSTAMP_SELECT_VARIANCE | $PSTAMP_SELECT_JPEG | $PSTAMP_SELECT_SOURCES);
    259279
    260280        foreach my $key (keys (%extensions)) {
    … …  
    400420        my $pattern_file = $params->{pattern} if ($options & $PSTAMP_SELECT_BACKMDL);
    401421        my $cmf_file;
    402         if ($stage ne 'chip') {
    403             # we don't ship chip stage cmf files because they may not be censored
    404             $cmf_file = $params->{cmf} if ($options & $PSTAMP_SELECT_CMF);
    405         }
     422#        if ($stage ne 'chip') {
     423#            # we don't ship chip stage cmf files because they may not be censored
     424#            $cmf_file = $params->{cmf} if ($options & $PSTAMP_SELECT_CMF);
     425#        }
    406426
    407427        my $outdir = dirname($output_base);
  • tags/ipp-20130307/pstamp/scripts/pstamp_parser_run.pl

    r34232 r35489  
    158158my $request_fault = $PSTAMP_INVALID_REQUEST;
    159159
     160# default action is to process the request after parsing. This can be overridden by
     161# PREVIEW mode for pstamp requests
     162my $action = 'PROCESS';
     163
    160164if (-r $uri) {
    161165    # run the appropriate parse command to parse the queue the jobs for this request
    162166    # first check the extension header to find the EXTNAME
    163     $request_type = find_request_type($uri);
     167    $request_type = find_request_type($uri, \$action);
    164168
    165169    if ($request_type) {
    … …  
    240244
    241245    if ($success) {
    242         $newState = 'run';
     246        # XXX: This bit of the postage stamp request API has slipped in here because we need to control
     247        # the new state of the request
     248        if ($action eq 'PROCESS') {
     249            $newState = 'run';
     250        } elsif ($action eq 'PREVIEW') {
     251            $newState = 'parsed';
     252        } else {
     253            print STDERR "WARNING Ignoring unexpected value for ACTION found in request header: $action\n";
     254        }
    243255    } else {
    244256        $fault = $error_code >> 8;
    … …  
    275287    # find the EXTNAME in the input fits table
    276288    my $file_name = shift;
    277     my $out = `echo $file_name | fields -x 0 EXTNAME`;
     289    my $r_action = shift;
     290
     291    my $out = `echo $file_name | fields -x 0 EXTNAME ACTION`;
    278292
    279293    if ($out) {
    280294        # output from fields is filename value
    281         my ($dummy, $extname) = split " ", $out;
     295        my ($dummy, $extname, $action) = split " ", $out;
     296
     297        # Set the action if it is defined in the request header
     298        # XXX:consider doing this only if extname is PS1_PS_REQUSET
     299        $$r_action = $action if ($action);
    282300
    283301        return $extname;
  • tags/ipp-20130307/pstamp/scripts/pstamp_request_file

    r34447 r35489  
    1818     $output,                   # Name of output table
    1919     $req_name,
     20     $email,
    2021     $help
    2122     );
    … …  
    2526           'output|o=s'   => \$output,
    2627           'req_name|r=s' => \$req_name,
    27            'help|h'         => \$help,
     28           'email=s'      => \$email,
     29           'help|h'       => \$help,
    2830) or pod2usage( 2 );
    2931
    … …  
    5456                    value => undef
    5557        },
    56         { name => 'USERNAME',
    57                     writetype => TSTRING,
    58                     comment => 'username for request (optional)',
    59                     value => undef
    60         },
     58#        { name => 'USERNAME',
     59#                    writetype => TSTRING,
     60#                    comment => 'username for request (optional)',
     61#                    value => undef
     62#        },
    6163        { name => 'EMAIL',
    6264                    writetype => TSTRING,
    … …  
    6567        },
    6668];
     69
     70my $email_column_num = 3;
    6771
    6872# Specification of columns to write
    … …  
    97101        { name => 'MJD_MIN',    type => 'D',   writetype => TDOUBLE },
    98102        { name => 'MJD_MAX',    type => 'D',   writetype => TDOUBLE },
     103        # new in version 2
    99104        { name => 'RUN_TYPE',   type => '16A', writetype => TSTRING },
     105        { name => 'FWHM_MIN',   type => 'D',   writetype => TDOUBLE },
     106        { name => 'FWHM_MAX',   type => 'D',   writetype => TDOUBLE },
    100107
    101108        { name => 'COMMENT ',   type => '64A', writetype => TSTRING },
    … …  
    162169    $req_name = $header->[0]->{value};
    163170}
     171if ($email) {
     172    $header->[$email_column_num]->{value} = $email;
     173}
     174
    164175
    165176die "no request name defined" unless defined $req_name;
    … …  
    299310
    300311            $$r_extver = $vals[1];
    301             if ($extver > 1) {
     312            if ($$r_extver > 1) {
    302313                die "number of header columns in input $nvals does not equal expected number of header words $nhead"
    303314                    if (@vals != @$header);
    … …  
    323334    if ($$r_extver == 1) {
    324335        # pop off the colData arrays to account for the unused columns
     336        pop @colData;
     337        pop @colData;
    325338        pop @colData;
    326339        pop @colData;
    … …  
    346359        }
    347360        # trim leading whitespace from comment
    348         $comment =~ s/^\s+//;
     361        $comment =~ s/^\s+// if $comment;
    349362        if ($comment) {
    350363            if ($comment =~ /#/) {
  • tags/ipp-20130307/pstamp/scripts/pstamp_webrequest.pl

    r35485 r35489  
    7171}
    7272
    73 # make a request file
     73# make the request file in a sub directory of the current directory
    7474my $cur_dir = getcwd();
    7575
    7676#print STDERR "cur_dir is $cur_dir\n";
    7777
     78# put file in directory for the current date
    7879my $datestr = strftime "%Y/%m/%d", gmtime;
    7980my $datedir = "$cur_dir/webreq/$datestr";
  • tags/ipp-20130307/pstamp/scripts/pstampparse.pl

    r34447 r35489  
    2727my $outdir;
    2828my $product;
    29 my $label;
     29my $label = "";
    3030my $save_temps;
    3131my $no_update;
    … …  
    5757    die "outdir is required"  if !$outdir;
    5858    die "product is required"  if !$product;
     59} else {
     60    $req_id = 0;
     61    $outdir = "nowhere";
     62    $product = "dummy";
    5963}
    6064
    … …  
    8387$pstamptool .= " -dbserver $dbserver" if $dbserver;
    8488
    85 # list_job is a deugging mode
    86 $no_update = 1 if $mode eq "list_job";
     89# If $mode is not queue_job we are using a debugging mode
     90# do not update the database
     91$no_update = 1 if $mode ne "queue_job";
    8792
    8893my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    8994
    9095#
    91 # get the data from the extension header
     96# Read the keywords from the extension header
    9297#
    9398my $fields_output;
    9499{
    95     my $command = "echo $request_file_name | $fields -x 0 EXTNAME EXTVER REQ_NAME ACTION USER EMAIL";
     100    my $command = "echo $request_file_name | $fields -x 0 EXTNAME EXTVER REQ_NAME ACTION EMAIL";
    96101    my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    97102        run(command => $command, verbose => $verbose);
    98     # fields doesn't return zero when it succeeds
    99     #unless ($success) {
    100     #    print STDERR @$stderr_buf;
    101     #}
     103
     104    # note fields doesn't return zero when it succeeds.
    102105    $fields_output = join "", @$stdout_buf;
    103106}
    104 my (undef, $extname, $extver, $req_name, $action, $username, $email) = split " ", $fields_output;
     107my (undef, $extname, $extver, $req_name, $action, $email) = split " ", $fields_output;
    105108
    106109# make sure the file contains what we are expecting
    107 # This program shouldn't have been run if the request file is bogus.
    108 # No need to notify the client
    109 my_die("$request_file_name is not a PS1_PS_REQEST", $PS_EXIT_PROG_ERROR) if $extname ne "PS1_PS_REQUEST";
    110 my_die("REQ_NAME not found in $request_file_name", $PS_EXIT_PROG_ERROR)  if (!$req_name);
    111 my_die("wrong EXTVER $extver found in $request_file_name", $PS_EXIT_PROG_ERROR) if ($extver ne "1" and $extver ne "2");
    112 
     110# pstamp_parser_run.pl would not have run this program unless the request file was ok
     111my_die("$request_file_name does not contain EXTNAME\n", $PS_EXIT_PROG_ERROR) if !$extname;
     112my_die("$request_file_name is not a PS1_PS_REQUEST\n", $PS_EXIT_PROG_ERROR) if $extname ne "PS1_PS_REQUEST";
     113my_die("REQ_NAME not found in $request_file_name\n", $PS_EXIT_PROG_ERROR)  if (!$req_name);
     114my_die("wrong EXTVER $extver found in $request_file_name\n", $PS_EXIT_PROG_ERROR) if ($extver ne "1" and $extver ne "2");
     115
     116if ($extver >= 2) {
     117    # We have a version 2 file. Require that the new keywords be supplied.
     118    my_die("action not supplied in version $extver request file $request_file_name\n", $PSTAMP_INVALID_REQUEST) unless defined $action;
     119
     120    my_die("invalid action: $action supplied in version $extver request file $request_file_name\n", $PSTAMP_INVALID_REQUEST) unless (uc($action) eq 'PROCESS' or uc($action) eq 'PREVIEW');
     121
     122    my_die("email not supplied in version $extver request file $request_file_name\n", $PSTAMP_INVALID_REQUEST) unless $email;
     123    # XXX check for "valid" $email
     124} else {
     125    # for version 1 file the action is process and email is not used
     126    $action = 'PROCESS';
     127    $email = 'null';
     128}
     129
     130print "Request Header Keywords EXTVER: $extver REQ_NAME: $req_name ACTION: $action EMAIL: $email\n";
    113131
    114132# check for duplicate request name
    … …  
    161179    # the output data store's product name
    162180    my $command = "$pstamptool -updatereq -req_id $req_id  -set_name $req_name";
     181    $command .= " -set_username $email" if $email ne 'null';
    163182    $command .= " -set_outProduct $product";
    164183    $command .= " -set_label $label" if $label_changed;
    … …  
    174193
    175194#
    176 # now convert the request table to an array of metadata config docs
     195# now convert the request table to an array of metadatas
    177196#
    178197
    … …  
    191210    my $dtime_request_file = gettimeofday() - $start_request_file;
    192211    print "Time to read and parse request file: $dtime_request_file\n";
    193 
    194 }
    195 
    196 #
    197 # Loop over rows in the request file collecting consecutive rows that have the "same images of interest"
    198 # in the sense that their selection parameters will yield the same "Runs".
    199 # Process the groups of rows together to reduce lookup time and to potentially make multiple
    200 # stamps from the same ppstamp process.
    201 #
    202 my @rowList;
     212}
     213
     214my $nRows = scalar @$rows;
     215print "\n$nRows rows read from request file\n";
     216
     217
    203218my $num_jobs = 0;
    204219my $imageList;
    205220my $stage;
    206 my $need_magic;
    207221foreach my $row (@$rows) {
    208     # santiy check the paramaters
     222
     223    if ($label eq 'WEB.UP' and ($nRows > 500 or $num_jobs > 500) and $req_id and !$no_update) {
     224        # this is a big request and it came from the upload page and doesn't have a specific label assigned
     225        # change it to the generic one that has lower with lower priority
     226        $label = 'WEB.BIG';
     227        print "\nChanging label for big WEB.UP request to $label\n";
     228
     229        my $command = "$pstamptool -updatereq -req_id $req_id  -set_label $label";
     230        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     231            run(command => $command, verbose => $verbose);
     232        unless ($success) {
     233            my_die("$command failed", $PS_EXIT_UNKNOWN_ERROR);
     234        }
     235    }
     236
     237    # validate the paramaters
    209238    if (!checkRow($row)) {
    210239        # when it enconters an error checkRow adds a fake job with an appropriate error code to the database
    … …  
    216245    $row->{error_code} = 0;
    217246
    218     if (scalar @rowList == 0) {
    219         push @rowList, $row;
    220         next;
    221     }
    222 
    223     my $firstRow = $rowList[0];
    224     if (same_images_of_interest($firstRow, $row)) {
    225         # add this row to the list and move on
    226         push @rowList, $row;
    227         next;
    228     }
    229 
    230     # the images of interest for this new row doesn't match the list.
    231     # process the list ...
    232     $num_jobs += processRows($action, \@rowList);
    233 
    234     # and reset the list to contain just the new row
    235     @rowList = ($row);
    236 }
    237 
    238 # out of rows process the list
    239 if (scalar @rowList > 0) {
    240     $num_jobs += processRows($action, \@rowList);
     247    $num_jobs += processRow($action, $row);
    241248}
    242249
    … …  
    252259    my $row = shift;
    253260
     261    # check validity of the paramters in a request specification
    254262    # If we encounter an error for a particular row add a job with the proper fault code.
     263    # also adjust some paramterers like filter and set defaults for some others
    255264
    256265    my $stage = $row->{IMG_TYPE};
    … …  
    284293    }
    285294
    286 
    287295    my $component = $row->{COMPONENT};
    288296    if (!defined $component or (lc($component) eq "null") or (lc($component) eq "all")) {
    … …  
    314322        return 0;
    315323    }
     324
     325    my $fwhm_min = $row->{FWHM_MIN};
     326    if (!defined $fwhm_min) {
     327        $row->{FWHM_MIN} = 0;
     328    } elsif (!validNumber($fwhm_min)) {
     329        print STDERR "$fwhm_min is not a valid FWHM_MIN\n";
     330        insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
     331        return 0;
     332    }
     333    my $fwhm_max = $row->{FWHM_MAX};
     334    if (!defined $fwhm_max) {
     335        $row->{FWHM_MAX} = 0;
     336    } elsif (!validNumber($fwhm_max)) {
     337        print STDERR "$fwhm_max is not a valid FWHM_MAX\n";
     338        insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
     339        return 0;
     340    }
     341
    316342    my $data_group = $row->{DATA_GROUP};
    317343    if (!defined $data_group) {
    … …  
    334360
    335361    my $wholefile = 0;
    336     if (!$skycenter && $row->{CENTER_X} == 0 && $row->{CENTER_Y} == 0) {
     362    if (($row->{WIDTH} == 0 && $row->{HEIGHT} == 0) ||
     363       (!$skycenter && $row->{CENTER_X} == 0 && $row->{CENTER_Y} == 0)) {
    337364        # Secret code for returning the whole file
    338365        $wholefile = 1;
    … …  
    362389        return 0;
    363390    }
    364 
    365     # $mode list_uri is a debugging mode (it may used by the http interface)
    366     # if this happens just croak
    367    # my_die("job_type is list_uri but mode is $mode", $PS_EXIT_PROG_ERROR) if ($job_type eq "list_uri") and ($mode ne "list_uri");
    368 
    369391
    370392    if ($req_type eq "bycoord") {
    … …  
    384406    }
    385407
     408
    386409    return 1;
    387410}
    … …  
    392415
    393416    $num_jobs = 1;
     417    return $num_jobs;
     418}
     419
     420sub processRow {
     421    my $action  = shift;
     422    my $row     = shift;
     423
     424    my $num_jobs = 0;
     425
     426    my $project  = $row->{PROJECT};
     427
     428    # note: resolve_project avoids running pstamptool every time by remembering the
     429    # last project resolved
     430    my $proj_hash = resolve_project($ipprc, $project, $dbname, $dbserver);
     431    if (!$proj_hash) {
     432        insertFakeJobForRow($row, 1, $PSTAMP_UNKNOWN_PROJECT);
     433        $num_jobs++;
     434        return $num_jobs;
     435    }
     436    my $image_db   = $proj_hash->{dbname};
     437    my $camera     = $proj_hash->{camera};
     438
     439    my $req_type    = $row->{REQ_TYPE};
     440    my $rownum      = $row->{ROWNUM};
     441
     442    # Since user can get unmagicked data "by coordinate" requests can go back in time
     443    # to dredge unusable data from the "dark days"...
     444    if ($req_type eq 'bycoord' and $row->{IMG_TYPE} ne 'stack' and $row->{MJD_MIN} == 0) {
     445        # ... so unless the user sets mjd_min clamp it to 2009-04-01
     446        # XXX: This value should live in the pstampProject table not be hardcoded here
     447        $row->{MJD_MIN} = 54922;
     448    }
     449
     450    if (($req_type eq 'byskycell') or ($req_type eq 'bycoord')) {
     451        # avoid error from print below if $id isn't needed
     452        $row->{ID} = "" if !$row->{ID};
     453    }
     454   
     455    # Call PS::IPP::PStamp::Job locate_images subroutine to get the images for this
     456    # request specification. An array reference is returned.
     457    my $start_locate = gettimeofday();
     458
     459    print "\nCalling new_locate_images for row: $rownum\n";
     460
     461    $imageList = locate_images_for_row($ipprc, $image_db, $camera, $row, $verbose);
     462
     463    my $dtime_locate = gettimeofday() - $start_locate;
     464    print "Time to locate_images for row $rownum $dtime_locate\n";
     465
     466    my @rowList = ($row);
     467    $num_jobs += queueJobs($action, \@rowList, $imageList);
     468
     469    # if this row slipped through without a job being added add one.
     470    if ($row->{job_num} == 0) {
     471        print "row $row->{ROWNUM} produced no jobs\n";
     472        print STDERR "row $row->{ROWNUM} produced no jobs\n";
     473        my $error_code = $row->{error_code};
     474        $error_code =  $PSTAMP_NO_IMAGE_MATCH if !$error_code;
     475        insertFakeJobForRow($row, ++$row->{job_num}, $error_code);
     476    }
     477
    394478    return $num_jobs;
    395479}
    … …  
    401485
    402486    if ($action eq 'LIST') {
     487        # LIST is not allowed by caller. Can't get here.
    403488        return list_targets($rowList);
    404489    }
    … …  
    420505    }
    421506    my $req_type  = $row->{REQ_TYPE};
    422     $stage        = $row->{IMG_TYPE};
     507    my $stage     = $row->{IMG_TYPE};
    423508    my $id        = $row->{ID};
    424509    my $component = $row->{COMPONENT};
    … …  
    436521    my $image_db   = $proj_hash->{dbname};
    437522    my $camera     = $proj_hash->{camera};
    438     $need_magic    = $proj_hash->{need_magic};
     523    my $need_magic    = $proj_hash->{need_magic};
    439524    # Since user can get unmagicked data "by coordinate" requests can go back in time
    440525    # to dredge unusable data from the "dark days"...
    … …  
    496581    # information required is contained there
    497582
    498     $imageList = locate_images($ipprc, $image_db, \@rowList, $req_type, $stage, $id, $tess_id, $component,
     583    $imageList = locate_images($ipprc, $image_db, $rowList, $req_type, $stage, $id, $tess_id, $component,
    499584                $option_mask, $need_magic, $mjd_min, $mjd_max, $filter, $data_group, $verbose);
    500585
    … …  
    506591    $row->{need_magic} = $need_magic;
    507592
    508     $num_jobs += queueJobs($mode, \@rowList, $imageList);
     593    $num_jobs += queueJobs($action, $rowList, $imageList);
    509594
    510595    # if a row slipped through with no jobs add a faulted one
    511     foreach my $row (@rowList) {
     596    foreach my $row (@$rowList) {
    512597        if ($row->{job_num} == 0) {
    513598            print "row $row->{ROWNUM} produced no jobs\n";
    … …  
    528613    my $image = shift;
    529614    my $need_magic = shift;
    530     my $mode = shift;
     615    my $action = shift;
    531616
    532617    my $rownum = $row->{ROWNUM};
    … …  
    544629    my $h = $row->{HEIGHT};
    545630    my $coord_mask = $row->{COORD_MASK};
     631
    546632    my $wholeFile = 0;
    547     if ($coord_mask & $PSTAMP_CENTER_IN_PIXELS) {
    548         # Center of 0, 0 in pixel coordinates is interpreted to mean
    549         # return the entire file
    550         if ($x == 0 && $y == 0) {
    551             $roi_string = "-wholefile";
    552             $wholeFile = 1;
     633    # For historical reasons there are two ways to specify that the entire file be returned
     634    # rather than a postage stamp ...
     635    if ($w == 0 and $h == 0) {
     636        # ... The right way: width and height both zero ...
     637        $wholeFile = 1;
     638    } else {
     639        if ($coord_mask & $PSTAMP_CENTER_IN_PIXELS) {
     640            if ($x == 0 && $y == 0) {
     641                # ... and pixel coordinate center of 0, 0
     642                # I made this one up without thinking through the API clearly.
     643                # allowing width and height to do it works much better
     644                $wholeFile = 1;
     645            } else {
     646                $roi_string = "-pixcenter $x $y";
     647            }
    553648        } else {
    554             $roi_string = "-pixcenter $x $y";
    555         }
     649            $roi_string = "-skycenter $x $y";
     650        }
     651    }
     652
     653    if ($wholeFile) {
     654        $roi_string = "-wholefile";
     655    } elsif ($coord_mask & $PSTAMP_RANGE_IN_PIXELS) {
     656            $roi_string .= " -pixrange $w $h";
    556657    } else {
    557         $roi_string = "-skycenter $x $y";
    558     }
    559     if (!$wholeFile) {
    560         if ($coord_mask & $PSTAMP_RANGE_IN_PIXELS) {
    561             $roi_string .= " -pixrange $w $h";
    562         } else {
    563658            $roi_string .= " -arcrange $w $h";
    564         }
    565659    }
    566660
    … …  
    611705    write_params($output_base, $image);
    612706
    613     my $newState = "run";
     707    my $newState = $action eq 'PROCESS' ? "run" : "parsed";
    614708    my $fault = 0;
    615709    my $dep_id;
    616710
    617     queueUpdatesIfNeeded($stage, $image, $option_mask, \$newState, \$fault, \$dep_id);
     711    queueUpdatesIfNeeded($action, $stage, $image, $option_mask, \$newState, \$fault, \$dep_id);
    618712
    619713    my $command = "$pstamptool -addjob  -req_id $req_id -job_type $row->{JOB_TYPE}"
    … …  
    644738sub queueJobs
    645739{
    646     my $mode = shift;
     740    my $action = shift;
    647741    my $rowList = shift;
    648742    my $imageList = shift;
    649743
    650     my $firstRow = $rowList[0];
     744    my $firstRow = $rowList->[0];
    651745    my $stage    = $firstRow->{IMG_TYPE};
    652746    my $job_type = $firstRow->{JOB_TYPE};
    … …  
    656750
    657751    if ($mode eq "list_uri") {
     752        $num_jobs = $imageList ? scalar @$imageList : 0;
     753        print "List of $num_jobs Images selected for row: $firstRow->{ROWNUM}\n";
    658754        foreach my $image (@$imageList) {
    659755            print "$image->{image}\n";
     756            ++$firstRow->{job_num};
    660757        }
    661758    } elsif ($job_type eq "get_image") {
    … …  
    664761        my_die( "error: unexpected number of rows for get_image request: $n", $PS_EXIT_PROG_ERROR) if $n != 1;
    665762
    666         $num_jobs = queueGetImageJobs($firstRow, $imageList, $stage, $need_magic, $mode);
     763        $num_jobs = queueGetImageJobs($firstRow, $imageList, $stage, $need_magic, $action);
    667764
    668765    } else {
    … …  
    692789                my $row = $rowList->[$i];
    693790
    694                 $num_jobs += queueJobForImage($row, $stage, $image, $need_magic, $mode);
     791                $num_jobs += queueJobForImage($row, $stage, $image, $need_magic, $action);
    695792            }
    696793        }
    … …  
    706803    my $stage = shift;
    707804    my $need_magic = shift;
    708     my $mode = shift;
     805    my $action = shift;
    709806
    710807    my $num_jobs = 0;
    … …  
    753850        write_params($output_base, $image);
    754851
    755         my $newState = "run";
     852        my $newState = $action eq 'PROCESS' ? "run" : "parsed";
    756853        my $fault = 0;
    757854        my $dep_id;
    758855
    759         queueUpdatesIfNeeded($stage, $image, $option_mask, \$newState, \$fault, \$dep_id);
     856        queueUpdatesIfNeeded($action, $stage, $image, $option_mask, \$newState, \$fault, \$dep_id);
    760857
    761858        $num_jobs++;
    … …  
    899996sub get_dependent
    900997{
    901     my ($r_jobState, $r_fault, $r_dep_id, $imagedb, $state, $stage, $stage_id, $component, $need_magic) = @_;
     998    my ($action, $r_jobState, $r_fault, $r_dep_id, $imagedb, $state, $stage, $stage_id, $component, $need_magic) = @_;
    902999
    9031000    # chipRun's can be in full state if destreaking is necessary
    … …  
    9181015    my $command = "$pstamptool -getdependent -stage $stage -stage_id $stage_id -imagedb $imagedb -component $component -outdir $outdir";
    9191016    $command .= " -need_magic" if $need_magic;
    920 
    921     # compute rlabel for the run.
    922     # XXX: This bit of policy shouldn't be buried so deeply in the code
    923     # For now use one that implies 'postage stamp server' 'update' 'request_label"
    924     my $rlabel = "ps_ud_" . $label if $label;
    925     $command .= " -rlabel $rlabel" if $rlabel;
     1017    $command .= ' -hold' if $action eq 'PREVIEW';
     1018
     1019    if ($label) {
     1020        # compute rlabel for the run.
     1021        # XXX: This bit of policy shouldn't be buried so deeply in the code
     1022        # For now use one that implies 'postage stamp server' 'update' 'request_label"
     1023        my $rlabel = "ps_ud_" . $label;
     1024        $command .= " -rlabel $rlabel";
     1025    }
    9261026
    9271027    if (!$no_update) {
    … …  
    9311031            my $fault = $error_code >> 8;
    9321032            print STDERR "$command failed with fault $fault\n";
    933             if ($fault < 10) {
     1033            if ($fault < $PSTAMP_FIRST_ERROR_CODE) {
    9341034                # pstamptool returns an error if an existing depenent is faulted
    935                 # Set the object to not available even if the fault < 10
     1035                # Set the object to not available even if the fault < $PSTAMP_FIRST_ERROR_CODE
    9361036                # which is nominally a recoverable error in order to keep
    9371037                # the request from faulting (which can be very expensive if
    … …  
    9391039                $fault = $PSTAMP_NOT_AVAILABLE
    9401040            }
    941             if ($fault >= 10) {
     1041            if ($fault >= $PSTAMP_FIRST_ERROR_CODE) {
    9421042                $$r_dep_id = 0;
    9431043                $$r_fault = $fault;
    … …  
    9671067
    9681068sub queueUpdatesIfNeeded {
     1069    my $action = shift;
    9691070    my $stage = shift;
    9701071    my $image = shift;
    … …  
    9731074    my $r_fault = shift;
    9741075    my $r_dep_id = shift;
     1076
     1077    my $need_magic = 0;
    9751078
    9761079    if ($stage ne 'raw') {
    … …  
    10161119                    # set up to queue an update run
    10171120                    my $require_magic = ($need_magic or $image->{magicked});
    1018                     get_dependent(\$$r_newState, \$$r_fault, $r_dep_id, $image->{imagedb},
     1121                    get_dependent($action, \$$r_newState, \$$r_fault, $r_dep_id, $image->{imagedb},
    10191122                        $run_state, $stage, $image->{stage_id}, $image->{component}, $require_magic );
    10201123                }
    … …  
    10701173    my $fault = shift;
    10711174
    1072     carp $msg;
     1175    print STDERR $msg;
    10731176
    10741177    # we don't fault the request here pstamp_parser_run.pl handles that if necessary
  • tags/ipp-20130307/pstamp/src/ppstampParseCamera.c

    r34596 r35489  
    9595    }
    9696       
    97 
    98     // XXX: create a filerule for PPSTAMP.ASTROM
    9997    pmFPAfile *astrom = pmFPAfileDefineFromArgs(&status, config, "PSWARP.ASTROM", "ASTROM");
    10098    if (!status) {
    … …  
    103101    }
    104102    if (astrom) {
    105         psLogMsg ("ppstamp", 3, "using supplied astrometry\n");
     103        psLogMsg ("ppstamp", 3, "Using supplied astrometry.\n");
    106104    } else {
    107         psLogMsg ("ppstamp", 3, "using header astrometry\n");
     105        psLogMsg ("ppstamp", 3, "Using header astrometry.\n");
    108106    }
    109 
    110 #ifdef notyet
    111     // add recipe options supplied on command line
    112     psMetadata *recipe  = psMetadataLookupPtr (&status, config->recipes, RECIPE_NAME);
    113 #endif
    114107
    115108    // Set up the output target
    … …  
    138131            }
    139132        } else {
    140             psLogMsg ("ppstamp", PS_LOG_INFO, "output sources file requested but no input supplied. Will try the supplied astrometry file.\n");
     133            psLogMsg ("ppstamp", PS_LOG_INFO, "Output sources file requested but no -sources supplied.\n");
     134            psLogMsg ("ppstamp", PS_LOG_INFO, "Will use the sources in the supplied astrometry file.\n");
    141135        }
    142136       
  • tags/ipp-20130307/pstamp/src/pstampdump.c

    r27259 r35489  
    9494        if (!strcmp(extname, "PS1_PS_REQUEST")) {
    9595            psString extver = psMetadataLookupStr(NULL, header, "EXTVER");
     96            psString action = psMetadataLookupStr(NULL, header, "ACTION");
     97            psString email = psMetadataLookupStr(NULL, header, "EMAIL");
    9698            if (!extver) {
    9799                // work around bug in MOPS request files
    … …  
    105107                }
    106108            }
    107             printf("%s %s %s\n", extname, extver, req_name);
     109            if (!strcmp(extver, "1")) {
     110                printf("%s %s %s\n", extname, extver, req_name);
     111            } else {
     112                if (!action) {
     113                    psErrorStackPrint(stderr, "failed to find action in fits header of: %s\n", fileName);
     114                    return PS_EXIT_DATA_ERROR;
     115                }
     116                if (!email) {
     117                    psErrorStackPrint(stderr, "failed to find action in fits header of: %s\n", email);
     118                    return PS_EXIT_DATA_ERROR;
     119                }
     120                printf("%s %s %s %s %s\n", extname, extver, req_name, action, email);
     121            }
    108122        } else if (!strcmp(extname, "PS1_PS_RESULTS")) {
    109123            psS64 req_id = psMetadataLookupS64(NULL, header, "REQ_ID");
Note: See TracChangeset for help on using the changeset viewer.