IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 36122


Ignore:
Timestamp:
Sep 17, 2013, 11:22:17 AM (13 years ago)
Author:
bills
Message:

Support for creating postage stamp jobs for stack_summary stage.
The results are not actually postage stamps but the (relatively small)
full images.
Define bits in option mask for selecting exp and num images from stacks
and stack_summary stage, as well as jpegs for them.

Location:
tags/ipp-20130712
Files:
36 edited
23 copied

Legend:

Unmodified
Added
Removed
  • tags/ipp-20130712/Ohana/src/getstar/src/dvoImagesAtCoords.c

    r33658 r36122  
    99static int makePoint(double ra, double dec, Point **pointsOut);
    1010static int ListImagesAtCoords (Image *dbImages, Point *points, int Npoints);
     11static int readPointFromFile(FILE *f, Point *pt);
    1112
    1213int main (int argc, char **argv) {
     
    1516  int status;
    1617  Image *dbImages;
    17   int Npoints;
    1818  FITS_DB db;
    1919
     
    2323 
    2424  Point *points;
     25  int readStdin = 0;
     26  int Npoints = 0;
    2527  if (coordsFile) {
    26       Npoints = readPoints(coordsFile, &points);
     28      if (strcmp(coordsFile, "-") == 0) {
     29        readStdin = 1;
     30      } else {
     31        Npoints = readPoints(coordsFile, &points);
     32      }
    2733  } else {
    2834      Npoints = makePoint(cmd_line_ra, cmd_line_dec, &points);
    2935  }
    30   if (!Npoints) {
     36  if (!Npoints && !readStdin) {
    3137    exit(1);
    3238  }
     
    6167  }
    6268 
    63   if (MatchCoords (dbImages, NdbImages, points, Npoints)) {
    64     ListImagesAtCoords(dbImages, points, Npoints);
    65     exit(0);
     69  if (readStdin) {
     70    Point pt;
     71    memset(&pt, 0, sizeof(pt));
     72    pt.Nmatches = 0;
     73    ALLOCATE(pt.matches, Match, 20);
     74    pt.arrayLength = 20;
     75
     76    int status;
     77    while ((status = readPointFromFile(stdin, &pt))) {
     78      if (status < 0) {
     79        fprintf(stdout, "ERROR malformed input line\n");
     80        exit(1);
     81      }
     82      if (MatchCoords (dbImages, NdbImages, &pt, 1)) {
     83        ListImagesAtCoords(dbImages, &pt, 1);
     84      }
     85      fprintf(stdout, "DONE\n");
     86      fflush(stdout);
     87      pt.Nmatches = 0;
     88    }
    6689  } else {
    67     exit(PSTAMP_NO_OVERLAP);
    68   }
     90    if (MatchCoords (dbImages, NdbImages, points, Npoints)) {
     91      ListImagesAtCoords(dbImages, points, Npoints);
     92    } else {
     93      exit(PSTAMP_NO_OVERLAP);
     94    }
     95  }
     96  exit(0);
     97}
     98
     99static int readPointFromFile(FILE *f, Point *pt) {
     100    char buf[80];
     101    char *good = fgets(buf, 80, f);
     102    if (!good) {
     103        return 0;
     104    }
     105    // fprintf(stderr, "READ: %s\n", buf);
     106    int Nread = sscanf(buf, "%d %lf %lf\n", &pt->id, &pt->ra, &pt->dec);
     107    if (Nread == 3) {
     108        // got one
     109        return 1;
     110    } else if (Nread == -1) {
     111        // all done time to go
     112        return 0;
     113    } else {
     114        // fprintf(stderr, "malformed input line: %d\n", Nread);
     115        return -1;
     116    }
    69117}
    70118
  • tags/ipp-20130712/PS-IPP-PStamp

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

    r35909 r36122  
    3434use POSIX;
    3535use Time::HiRes qw(gettimeofday);
     36use IO::Handle;
    3637
    3738my $dvo_verbose = 0;
     
    244245    if (isnull($filter)) {
    245246        $filter = undef;
     247    }
     248
     249    if ($stage eq 'stack_summary') {
     250        # stack_summary jobs are so different from others that we lookup in a specialized function
     251        return lookup_stack_summary($ipprc, $row, $imagedb, $tess_id, $component, $filter, $data_group, $option_mask, $mjd_min, $mjd_max, $verbose);
    246252    }
    247253
     
    736742}
    737743
     744sub lookup_stack_summary {
     745    my ($ipprc, $row, $imagedb, $tess_id, $component, $filter, $data_group, $option_mask, $mjd_min, $mjd_max, $verbose) = @_;
     746
     747    $row->{error_code} = $PSTAMP_NO_IMAGE_MATCH;
     748
     749    $component = '' if $component eq 'all';
     750
     751    my $req_type = $row->{REQ_TYPE};
     752    my $results;
     753    if ($req_type eq 'byid') {
     754        my $sass_id = $row->{ID};
     755        my $command = "$stacktool -dbname $imagedb -summary -sass_id $sass_id";
     756        $results = runToolAndParse($command, $verbose);
     757    } else {
     758        my ($release_name, $survey, $default_tess_id) = get_release_info($row);
     759        if (!$tess_id and $default_tess_id) {
     760            $tess_id = $default_tess_id;
     761        }
     762
     763        my $skycells;
     764        if ($req_type eq 'bycoord') {
     765            my $ra = $row->{CENTER_X};
     766            my $dec = $row->{CENTER_Y};
     767            $skycells = lookup_skycell_by_coords($ipprc, $tess_id, $component, $ra, $dec, $verbose);
     768        } elsif ($req_type eq 'byskycell') {
     769            if (!defined $tess_id or !defined $component) {
     770                print STDERR "Error: TESS_ID and  COMPONENT are required for REQ_TYPE byskycell\n";
     771                $row->{error_code} = $PSTAMP_INVALID_REQUEST;
     772            }
     773            my $skycell = {
     774                tess_id    => $tess_id,
     775                component => $component
     776            };
     777            push @$skycells, $skycell
     778        } else {
     779            print STDERR "Error: $req_type is not a valid REQ_TYPE for IMG_TYPE stack_summary\n";
     780            $row->{error_code} = $PSTAMP_INVALID_REQUEST;
     781            return undef;
     782        }
     783
     784        if ($skycells) {
     785            # We have a list of skycells. Find matching projection cells.
     786            # and then matching rows in stackSummary
     787
     788            my %projection_cells_found;
     789            foreach my $skycell (@$skycells) {
     790                my $tess_id = $skycell->{tess_id};
     791                my $skycell_id = $skycell->{component};
     792
     793                my $projection_cell = skycell_id_to_projection_cell($skycell_id);
     794
     795                # only need to include a projection cell once
     796                next if $projection_cells_found{$projection_cell};
     797
     798                $projection_cells_found{$projection_cell} = 1;
     799
     800                # print "$tess_id $skycell_id $projection_cell\n";
     801
     802                my $command;
     803                if ($release_name or $survey) {
     804                    $command = "$releasetool -dbname $imagedb";
     805                    if ($release_name) {
     806                        $command .= " -release_name $release_name";
     807                    } else {
     808                        $command .= " -priority_order";
     809                    }
     810                    $command .= " -surveyName $survey";
     811                } else {
     812                    $command = "$stacktool -dbname $imagedb";
     813                }
     814                $command .= " -summary -tess_id $tess_id";
     815                $command .= " -projection_cell $projection_cell";
     816
     817                $command .= " -filter $filter" if $filter;
     818                $command .= " -data_group $data_group" if $data_group;
     819
     820                my $these_results = runToolAndParse($command, $verbose);
     821                push @$results, @$these_results if $these_results;
     822            }
     823        }
     824    }
     825
     826    if ($results) {
     827        foreach my $summary (@$results) {
     828            my $path_base = $summary->{path_base};
     829            my $projection_cell = $summary->{projection_cell};
     830
     831            # we need to flesh out the hashes returned with values that the parser expects
     832            $summary->{stage} = 'stack_summary';
     833            $summary->{component} = $projection_cell;
     834            $summary->{stage_id} = $summary->{sass_id};
     835            $summary->{path_base} = "$path_base.$projection_cell";
     836
     837            # The stack_summary stage doesn't follow the usual ipp conventions for file rules
     838            # and path_base. We leave it up to the program that runs the job to handle this.
     839            # However, the parser uses the image parameter to set the job's outputBase (by removing the .fits)
     840            # so we need to set it. Just use the new path_base.
     841            $summary->{image} = $summary->{path_base};
     842            $summary->{state} = 'full';
     843            $summary->{data_state} = 'full';
     844            $summary->{fault} = 0;
     845            $summary->{imagedb} = $imagedb;
     846            $summary->{row_index} = [];
     847            push @{$summary->{row_index}}, 0;
     848
     849            # XXX: Are there any other required parameters?
     850            # TODO: create a function to validate the components returned
     851            # and make sure that any required elements are there.
     852        }
     853    }
     854
     855    return $results;
     856}
     857
    738858sub lookup_diff {
    739859    my $ipprc    = shift;
     
    11691289
    11701290    my @lines;
    1171     {
     1291    my $looked_up_fast;
     1292    if ($requested_tess_id) {
     1293        # try using the last method first
     1294        $looked_up_fast = lookup_skycells_fast($ipprc, \@lines, $requested_tess_id, $ra, $dec, $verbose);
     1295    }
     1296   
     1297    if (!$looked_up_fast) {
    11721298        my $command = "$whichimage $ra $dec";
    11731299        $command .= " --tess_id $requested_tess_id" if $requested_tess_id;
     
    18782004    return $diff_mode;
    18792005}
     2006
     2007sub setErrorCodesForRows {
     2008    my $rowList = shift;
     2009    my $error_code = shift;
     2010
     2011    foreach my $row (@$rowList) {
     2012        $row->{error_code} = $error_code;
     2013    }
     2014
     2015}
     2016
     2017# Convert from skycell_id to projection_cell
     2018# This code is not particularly elegant but I think that it matches the SQL used
     2019# to create stackAssocations does.
     2020
     2021sub skycell_id_to_projection_cell {
     2022    my $skycell_id = shift;
     2023
     2024    # split skycell_id into '.' separated components
     2025    my @strs = split '\.', $skycell_id;
     2026
     2027    my $num = scalar @strs;
     2028
     2029    # projection_cell is 'skycell_id' plus all .num values except the last one
     2030    my $projection_cell = $strs[0];
     2031    for (my $i=1; $i < $num - 1; $i++) {
     2032        $projection_cell .= ".$strs[$i]";
     2033    }
     2034
     2035    return $projection_cell;
     2036}
     2037
     2038# lookup_skycells_fast()
     2039# Lookup using a "skycell server" process which is implemented by running dvoImagesAtCoords in "server" mode.
     2040# Repeated calls to this function will reuse an existing process. This avoids having to loading the
     2041# tessellation over and over again for each skycell lookup.
     2042# When this parse process exists, the pipes are closed which causes the skycell server to exit.
     2043
     2044my $scs_tess_id;    # tess_id for existing scs (skycell server) (if any)
     2045my $scs_out;        # reference filehandle for sending data to the scs
     2046my $scs_in;         # filehandle for response from scs
     2047
     2048sub lookup_skycells_fast {
     2049    my ($ipprc, $results, $tess_id, $ra, $dec, $verbose) = @_;
     2050
     2051    # see if we need to start the scs (skycell server)
     2052
     2053    my $very_verbose = 0;
     2054
     2055    if (!$scs_tess_id or ($scs_tess_id ne $tess_id)) {
     2056        if ($scs_tess_id) {
     2057            # tess_id has changed, close down existing scs
     2058            close $scs_out;
     2059            $scs_out = undef;
     2060            close $scs_in;
     2061            $scs_in = undef;
     2062            $scs_tess_id = undef;
     2063        }
     2064
     2065        # convert tess_id to a directory name
     2066        my $tess_dir = $ipprc->tessellation_catdir( $tess_id );
     2067        unless ($tess_dir) {
     2068            print STDERR "Unrecognized tess_id: $tess_id\n";
     2069            return 0;
     2070        }
     2071
     2072        # convert tess_dir to an absolute directory name
     2073        my $tess_dir_resolved = $ipprc->convert_filename_absolute( $tess_dir );
     2074        unless ($tess_dir_resolved and -d $tess_dir_resolved) {
     2075            print STDERR "failed to resolve tessellation directory for $tess_id\n";
     2076            return 0;
     2077        }
     2078
     2079        # start an scs
     2080        print "Starting skycell server for $tess_dir_resolved.\n";
     2081
     2082        # create pipes for communicating with the server
     2083        pipe $scs_in, SERVER_WRITER;
     2084        pipe SERVER_READER, $scs_out;
     2085
     2086        # set our output to be unbuffered
     2087        $scs_out->autoflush(1);
     2088
     2089        # FORK
     2090        my $scs_pid = fork();
     2091
     2092        if (!$scs_pid) {
     2093            unless (defined $scs_pid) {
     2094                # This is still in parent process. No joy.
     2095                print STDERR "fork of skycell server failed: $!";
     2096                return 0;
     2097            }
     2098
     2099            # This code is running in the child process - the skycell server
     2100            # Close file handles for the parent's ends of the pipes
     2101            close $scs_in;
     2102            close $scs_out;
     2103            # close stdio filehandles. we are about to redirect them
     2104            # (STDERR stays open pointing to the parser log)
     2105            close STDIN;
     2106            close STDOUT;
     2107
     2108            # redirect our stdio file handles to the proper end of the pipes
     2109            open (STDIN,  "<&SERVER_READER")   or die "\nSCS: failed to redirect stdin";
     2110            open (STDOUT, ">>&SERVER_WRITER")  or die "\nSCS: failed to redirect stdout";
     2111
     2112            # All set. Now exec dvoImagesAtCoords
     2113
     2114            my $command = "$dvoImagesAtCoords -D CATDIR $tess_dir_resolved -coords -";
     2115
     2116            print STDERR "SCS: execing $command\n" if $very_verbose;
     2117
     2118            unless(exec $command) {
     2119                # note parent will notice that we are gone due to the pipes getting broken
     2120                # when this child dies.
     2121                die "SCS: failed to exec $command";
     2122            }
     2123        }
     2124
     2125        # This code is running in the parent process (the parser).
     2126        # We have succesfully launched the scs process.
     2127        # Close file handles for the scs' end of the pipes.
     2128        close SERVER_WRITER;
     2129        close SERVER_READER;
     2130
     2131        # remember the tess_id
     2132        $scs_tess_id = $tess_id;
     2133    }
     2134
     2135    # send coordinates to the skycell server and wait for the results
     2136    # (which come nearly instantly which is the point of doing this)
     2137
     2138    # If pipes to the skycell server die, don't abort.
     2139    # Our reads and writes detect errors and act sensibly.
     2140    local $SIG{PIPE} = 'IGNORE';
     2141
     2142    # write the coordinates to the pipe
     2143    my $write_ok = print $scs_out "1 $ra $dec\n";
     2144    if (!$write_ok) {
     2145        # server process probably didn't start properly or died. Fail.
     2146        # Caller will attempt to use the conventional method.
     2147        print STDERR "write to skycell server failed. Error is $!\n";
     2148        return 0;
     2149    }
     2150
     2151    print STDERR "  sent coordinates to skycell server\n" if $very_verbose;
     2152
     2153    my $received_done = 0;
     2154
     2155    # Wait for response. If pipe breaks the read returns with no data.
     2156    while (my $line = <$scs_in>) {
     2157        chomp $line;
     2158        if ($line eq 'DONE') {
     2159            # No more results for these coordinates.
     2160            $received_done = 1;
     2161            print STDERR "    received DONE\n" if $very_verbose;
     2162            last;
     2163        }
     2164        print STDERR "    received $line\n" if $very_verbose;
     2165
     2166        # The caller expects the output to be in the format used by whichimage
     2167        # which omits the point number and includes the tess_id.
     2168        my ($ptnum, $raout, $decout, $skycell_id) = split " ", $line;
     2169
     2170        my $out = "$raout $decout $tess_id $skycell_id";
     2171
     2172        # print the result to the log
     2173        print "$out\n" if $verbose;
     2174
     2175        push @$results, $out;
     2176    }
     2177
     2178    print STDERR "Out of wait for responses loop\n" if $very_verbose;
     2179
     2180    if (!$received_done) {
     2181        # something has gone wrong.
     2182        print STDERR "Read loop exited without receiving DONE.\n";
     2183
     2184        die "BAILING out" if $very_verbose;
     2185
     2186        # forget about the existing server instance
     2187        $scs_tess_id = undef;
     2188        close $scs_out;
     2189        close $scs_in;
     2190
     2191        # drop any results received so far
     2192        @$results = ();
     2193        return 0;
     2194    }
     2195
     2196    return 1;
     2197}
     2198
    18802199       
    18812200
  • tags/ipp-20130712/PS-IPP-PStamp/lib/PS/IPP/PStamp/RequestFile.pm

    r35466 r36122  
    2929                    $PSTAMP_SELECT_BACKMDL
    3030                    $PSTAMP_SELECT_JPEG
     31                    $PSTAMP_SELECT_EXP
     32                    $PSTAMP_SELECT_NUM
    3133                    $PSTAMP_SELECT_UNCOMPRESSED
    3234                    $PSTAMP_SELECT_INVERSE
     
    3537                    $PSTAMP_USE_IMFILE_ID
    3638                    $PSTAMP_NO_WAIT_FOR_UPDATE
    37                     $PSTAMP_REQUEST_UNCENSORED
    38                     $PSTAMP_REQUIRE_UNCENSORED
     39                    $PSTAMP_SELECT_EXPJPEG
     40                    $PSTAMP_SELECT_NUMJPEG
    3941                    $PSTAMP_SUCCESS
    4042                    $PSTAMP_FIRST_ERROR_CODE
     
    7173our $PSTAMP_SELECT_BACKMDL   = 32;
    7274our $PSTAMP_SELECT_JPEG      = 64;
    73 # unused 128
    74 # unused 256
     75our $PSTAMP_SELECT_EXP       = 128;
     76our $PSTAMP_SELECT_NUM       = 256;
    7577our $PSTAMP_SELECT_UNCOMPRESSED = 512;
    7678our $PSTAMP_SELECT_INVERSE      = 1024;
     
    8284our $PSTAMP_NO_WAIT_FOR_UPDATE = 32768;
    8385
    84 # these bits will be repurposed
    85 our $PSTAMP_REQUEST_UNCENSORED = 0x10000;
    86 our $PSTAMP_REQUIRE_UNCENSORED = 0x20000;
     86our $PSTAMP_SELECT_EXPJPEG     = 0x10000;
     87our $PSTAMP_SELECT_NUMJPEG     = 0x20000;
     88
     89# these bits have been repurposed. They were only exposed to MOPS and IFA and they have adapted.
     90#our $PSTAMP_REQUEST_UNCENSORED = 0x10000;
     91#our $PSTAMP_REQUIRE_UNCENSORED = 0x20000;
    8792
    8893# job and result codes
     
    97102our $PSTAMP_INVALID_REQUEST  = 21;
    98103our $PSTAMP_UNKNOWN_PROJECT  = 22;
    99 our $PSTAMP_UNKNOWN_PRODUCT  = 22;  #this error code was mis-named it is left for compatabiliyt
     104our $PSTAMP_UNKNOWN_PRODUCT  = 22;  #this error code was a typo it is left for compatabiliy
    100105our $PSTAMP_NO_IMAGE_MATCH   = 23;
    101106our $PSTAMP_NOT_DESTREAKED   = 24;
    102107our $PSTAMP_NOT_AVAILABLE    = 25;
    103 our $PSTAMP_GONE             = 26;  # this value is used in ippTools
     108our $PSTAMP_GONE             = 26;  # this value is also used in ippTools
    104109our $PSTAMP_NO_JOBS_QUEUED   = 27;
    105110our $PSTAMP_NO_OVERLAP       = 28;
    106111our $PSTAMP_NOT_AUTHORIZED   = 29;
     112our $PSTAMP_NO_VALID_PIXELS  = 30;
    107113
    108114
     
    143149PSTAMP_NO_OVERLAP
    144150PSTAMP_NOT_AUTHORIZED
    145 PSTAMP_NOT_AUTHORIZED
     151PSTAMP_NO_VALID_PIXELS
    146152);
    147153
  • tags/ipp-20130712/ippTools

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

    r35799 r36122  
    193193        disttool_definebyquery_sky.sql \
    194194        disttool_definebyquery_sky_singlefilter.sql \
     195        disttool_definebyquery_skycal.sql \
    195196        disttool_definebyquery_stack.sql \
    196197        disttool_definebyquery_warp.sql \
     
    207208        disttool_pending_raw.sql \
    208209        disttool_pending_sky.sql \
     210        disttool_pending_skycal.sql \
    209211        disttool_pending_stack.sql \
    210212        disttool_pending_warp.sql \
     
    398400        stacktool_tosummary.sql \
    399401        stacktool_addsummary.sql \
     402        stacktool_summary.sql \
    400403        staticskytool_definebyquery_select.sql \
    401404        staticskytool_definebyquery_select_by_dg.sql \
     
    408411        staticskytool_export_input.sql \
    409412        staticskytool_export_result.sql \
     413        staticskytool_export_skycalrun.sql \
     414        staticskytool_export_skycalresult.sql \
    410415        staticskytool_inputs.sql \
    411416        staticskytool_todo.sql \
     
    476481        releasetool_definerelstack_with_skycal.sql \
    477482        releasetool_listrelstack.sql \
     483        releasetool_summary.sql \
    478484        releasetool_definerelgroup_select_lap.sql \
    479485        releasetool_definerelgroup_select_data_group.sql \
    480486        releasetool_definerelgroup_select_exp_data_group.sql \
    481487        releasetool_definerelgroup_select_exp_lap.sql \
     488        releasetool_stacksummary.sql \
    482489        releasetool_pendingrelgroup.sql
    483490
  • tags/ipp-20130712/ippTools/share/camtool_pendingexp.sql

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • tags/ipp-20130712/ippTools/share/disttool_definebyquery_sky.sql

    r32696 r36122  
    33    staticskyRun.sky_id AS stage_id,
    44    CAST(0 AS SIGNED) AS magicked,
    5     -- run tag in the form 'sky.$skycell_id.$stack_id'
     5    -- run tag in the form 'sky.$skycell_id.$sky_id'
    66    CONCAT_WS('.', 'sky', stackRun.skycell_id, convert(staticskyRun.sky_id, CHAR)) as run_tag,
    77    staticskyRun.label,
  • tags/ipp-20130712/ippTools/share/disttool_toadvance.sql

    r32710 r36122  
    262262        AND distComponent.fault = 0
    263263UNION
     264-- skycal stage
     265-- NOTE this assumes that there is only one component per skycalRun
     266-- (one skycell)
     267SELECT
     268    distRun.dist_id,
     269    stage,
     270    stage_id,
     271    outroot,
     272    label,
     273    clean
     274    FROM distRun
     275    JOIN skycalResult on stage_id = skycal_id
     276    LEFT JOIN distComponent
     277        ON distRun.dist_id = distComponent.dist_id
     278    WHERE
     279        distRun.state = 'new'
     280        AND distRun.fault = 0
     281        AND distRun.stage = 'skycal'
     282        AND distComponent.component IS NOT NULL
     283        AND distComponent.fault = 0
     284UNION
    264285-- SSdiff stage
    265286SELECT
  • tags/ipp-20130712/ippTools/share/releasetool_listrelexp.sql

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • tags/ipp-20130712/ippTools/share/stacktool_tosummary.sql

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • tags/ipp-20130712/ippTools/share/staticskytool_skycalresult.sql

    r34975 r36122  
    22    skycalResult.*,
    33    skycalRun.stack_id,
     4    skycalRun.workdir,
    45    stackRun.filter,
    56    skycalRun.state,
    67    skycalRun.label,
    78    skycalRun.data_group,
     9    skycalRun.dist_group,
    810    skycalRun.sky_id,
    911    skycell.*
  • tags/ipp-20130712/ippTools/share/warptool_warped.sql

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • tags/ipp-20130712/ippTools/src

  • tags/ipp-20130712/ippTools/src/difftool.c

    • Property svn:mergeinfo deleted
  • tags/ipp-20130712/ippTools/src/disttool.c

    r35193 r36122  
    375375        }
    376376        if (dist_group) {
    377             psStringAppend(&query, " AND (sticskyRun.dist_group = '%s')", dist_group);
     377            psStringAppend(&query, " AND (staticskyRun.dist_group = '%s')", dist_group);
    378378        }
    379379        // (static)sky stage doesn't require magic
     380        magic = false;
     381    } else if (!strcmp(stage, "skycal")) {
     382        query = pxDataGet("disttool_definebyquery_skycal.sql");
     383        if (!query) {
     384            psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     385            psFree(where);
     386            return false;
     387        }
     388
     389        if (label) {
     390            psStringAppend(&query, " AND (skycalRun.label = '%s')", label);
     391        }
     392        if (dist_group) {
     393            psStringAppend(&query, " AND (skycalRun.dist_group = '%s')", dist_group);
     394        }
     395        // skycal stage doesn't require magic
    380396        magic = false;
    381397    } else if (!strcmp(stage, "SSdiff")) {
  • tags/ipp-20130712/ippTools/src/pstamptool.c

    r35673 r36122  
    14281428    psFree(where);
    14291429
    1430     psStringAppend(&query, " ORDER BY priority DESC, req_id, dep_id");
     1430    psStringAppend(&query, " GROUP BY dep_id ORDER BY priority DESC, MIN(req_id), dep_id");
    14311431
    14321432    // treat limit == 0 as "no limit"
  • tags/ipp-20130712/ippTools/src/releasetool.c

    • Property svn:mergeinfo deleted
    r35909 r36122  
    4747static bool updaterelstackMode(pxConfig *config);
    4848static bool listrelstackMode(pxConfig *config);
     49static bool summaryMode(pxConfig *config);
    4950static bool definerelgroupMode(pxConfig *config);
    5051static bool pendingrelgroupMode(pxConfig *config);
     
    8485        MODECASE(RELEASETOOL_MODE_UPDATERELSTACK,   updaterelstackMode);
    8586        MODECASE(RELEASETOOL_MODE_LISTRELSTACK,     listrelstackMode);
     87        MODECASE(RELEASETOOL_MODE_SUMMARY,          summaryMode);
    8688
    8789        MODECASE(RELEASETOOL_MODE_DEFINERELGROUP,   definerelgroupMode);
     
    10801082
    10811083    if (priority_order) {
    1082         psStringAppend(&query, "\nAND priority > 0 order by stack_id, priority DESC");
     1084        psStringAppend(&query, "\nAND priority > 0 order by priority DESC, stack_id");
     1085    }
     1086
     1087    if (limit) {
     1088        psString limitString = psDBGenerateLimitSQL(limit);
     1089        psStringAppend(&query, " %s", limitString);
     1090        psFree(limitString);
     1091    }
     1092
     1093    if (!p_psDBRunQuery(config->dbh, query)) {
     1094        psError(PS_ERR_UNKNOWN, false, "database error");
     1095        psFree(query);
     1096        return false;
     1097    }
     1098    psFree(query);
     1099
     1100    psArray *output = p_psDBFetchResult(config->dbh);
     1101    if (!output) {
     1102        psError(PS_ERR_UNKNOWN, false, "database error");
     1103        return false;
     1104    }
     1105
     1106    if (!psArrayLength(output)) {
     1107        psTrace("releasetool", PS_LOG_INFO, "no rows found");
     1108        psFree(output);
     1109        return true;
     1110    }
     1111
     1112    if (!ippdbPrintMetadatas(stdout, output, "relStack", !simple)) {
     1113        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1114        psFree(output);
     1115        return false;
     1116    }
     1117
     1118    psFree(output);
     1119
     1120    return true;
     1121}
     1122static bool summaryMode(pxConfig *config)
     1123{
     1124    PS_ASSERT_PTR_NON_NULL(config, NULL);
     1125
     1126    psMetadata *where = psMetadataAlloc();
     1127
     1128    PXOPT_COPY_S64(config->args, where, "-sass_id",     "stackAssociation.sass_id", "==");
     1129    PXOPT_COPY_S64(config->args, where, "-relstack_id", "relStack.relstack_id", "==");
     1130    PXOPT_COPY_S64(config->args, where, "-stack_id",    "relStack.stack_id", "==");
     1131//    PXOPT_COPY_S64(config->args, where, "-skycal_id",   "relStack.skycal_id", "==");
     1132    PXOPT_COPY_S64(config->args, where, "-relstack_id", "relStack.relstack_id", "==");
     1133    PXOPT_COPY_STR(config->args, where, "-release_name", "ippRelease.release_name", "LIKE");
     1134    pxAddLabelSearchArgs(config, where, "-release_state","ippRelease.state", "==");
     1135//    PXOPT_COPY_STR(config->args, where, "-state",       "relStack.state", "==");
     1136    PXOPT_COPY_STR(config->args, where, "-filter",      "relStack.filter", "LIKE");
     1137//    PXOPT_COPY_F32(config->args, where, "-mjd_min",    "stackSumSkyfile.mjd_obs", ">=");
     1138//    PXOPT_COPY_F32(config->args, where, "-mjd_max",    "stackSumSkyfile.mjd_obs", "<=");
     1139    PXOPT_COPY_STR(config->args, where, "-tess_id",     "relStack.tess_id", "==");
     1140    PXOPT_COPY_STR(config->args, where, "-skycell_id",  "relStack.skycell_id", "LIKE");
     1141    PXOPT_COPY_STR(config->args, where, "-projection_cell",  "stackAssociation.projection_cell", "LIKE");
     1142    PXOPT_COPY_STR(config->args, where, "-stack_data_group",  "stackRun.data_group", "LIKE");
     1143    PXOPT_COPY_STR(config->args, where, "-data_group",  "stackAssociation.data_group", "LIKE");
     1144//    PXOPT_COPY_STR(config->args, where, "-skycal_data_group", "skycalRun.data_group", "LIKE");
     1145
     1146    PXOPT_COPY_STR(config->args, where, "-surveyName",  "survey.surveyName", "LIKE");
     1147    PXOPT_COPY_S32(config->args, where, "-rel_id",      "relExp.rel_id", "==");
     1148    pxskycellAddWhere(config, where);
     1149
     1150//    PXOPT_COPY_F32(config->args, where, "-fwhm_min",    "IFNULL(skycalResult.fwhm_major, 999)", ">=");
     1151//    PXOPT_COPY_F32(config->args, where, "-fwhm_max",    "IFNULL(skycalResult.fwhm_major, 0)", "<=");
     1152
     1153    PXOPT_LOOKUP_BOOL(priority_order, config->args, "-priority_order", false);
     1154
     1155    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     1156    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1157
     1158    pxAddLabelSearchArgs (config, where, "-stack_type", "relStack.stack_type", "==");
     1159
     1160    psString query = pxDataGet("releasetool_summary.sql");
     1161    if (!query) {
     1162        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     1163        return false;
     1164    }
     1165
     1166    if (psListLength(where->list)) {
     1167        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1168        psStringAppend(&query, "\nWHERE %s", whereClause);
     1169        psFree(whereClause);
     1170    } else {
     1171        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required\n");
     1172        psFree(where);
     1173        return false;
     1174    }
     1175
     1176    if (priority_order) {
     1177        psStringAppend(&query, "\nAND priority > 0 order by priority DESC, stack_id");
    10831178    }
    10841179
  • tags/ipp-20130712/ippTools/src/releasetool.h

    r35213 r36122  
    3838    RELEASETOOL_MODE_TOCALIBSTACK,
    3939    RELEASETOOL_MODE_LISTRELSTACK,
     40    RELEASETOOL_MODE_SUMMARY,
    4041    RELEASETOOL_MODE_DEFINERELGROUP,
    4142    RELEASETOOL_MODE_PENDINGRELGROUP,
  • tags/ipp-20130712/ippTools/src/releasetoolConfig.c

    • Property svn:mergeinfo deleted
    r35898 r36122  
    248248    psMetadataAddBool(listrelstackArgs, PS_LIST_TAIL, "-simple",      0, "use the simple output format", false);
    249249
     250    // -summary
     251    psMetadata *summaryArgs = psMetadataAlloc();
     252    psMetadataAddS64(summaryArgs, PS_LIST_TAIL,  "-sass_id", 0,   "select by released SASS ID", 0);
     253    psMetadataAddS64(summaryArgs, PS_LIST_TAIL,  "-relstack_id", 0,   "select by released exposure ID", 0);
     254    psMetadataAddS64(summaryArgs, PS_LIST_TAIL,  "-stack_id", 0,   "select by stack ID", 0);
     255//    psMetadataAddS64(summaryArgs, PS_LIST_TAIL,  "-skycal_id", 0,   "select by skycal ID", 0);
     256    psMetadataAddStr(summaryArgs,  PS_LIST_TAIL, "-release_name", 0, "select by release name (LIKE comparision)", NULL);
     257    psMetadataAddStr(summaryArgs,  PS_LIST_TAIL, "-release_state", PS_META_DUPLICATE_OK, "select by release state", NULL);
     258//    psMetadataAddStr(summaryArgs,  PS_LIST_TAIL, "-state", 0,        "select by released stack state", NULL);
     259
     260    psMetadataAddStr(summaryArgs,  PS_LIST_TAIL, "-filter", 0,       "select by filter name (LIKE comparison)", NULL);
     261
     262    pxskycellAddArguments(summaryArgs);
     263
     264    psMetadataAddStr(summaryArgs,  PS_LIST_TAIL, "-tess_id", 0, "select by tess_id", NULL);
     265    psMetadataAddStr(summaryArgs,  PS_LIST_TAIL, "-skycell_id", 0, "select by skycell_id (LIKE comparision)", NULL);
     266    psMetadataAddStr(summaryArgs,  PS_LIST_TAIL, "-projection_cell", 0, "select by projection_cell (LIKE comparision)", NULL);
     267    psMetadataAddStr(summaryArgs,  PS_LIST_TAIL, "-stack_type", PS_META_DUPLICATE_OK, "select by stack_type", NULL);
     268
     269    psMetadataAddStr(summaryArgs,  PS_LIST_TAIL, "-stack_data_group", 0, "select by stackRun.data_group (LIKE comparison)", NULL);
     270    psMetadataAddStr(summaryArgs,  PS_LIST_TAIL, "-data_group", 0, "select by stackAsociation.data_group (LIKE comparison)", NULL);
     271
     272    psMetadataAddStr(summaryArgs,  PS_LIST_TAIL, "-surveyName", 0, "select by survey name (LIKE comparision)", NULL);
     273    psMetadataAddS64(summaryArgs,  PS_LIST_TAIL, "-rel_id", 0, "select by release ID", 0);
     274
     275    psMetadataAddBool(summaryArgs, PS_LIST_TAIL, "-priority_order",   0, "order by release priority", false);
     276
     277    psMetadataAddU64(summaryArgs,  PS_LIST_TAIL, "-limit",       0, "limit result set to N items", 0);
     278    psMetadataAddBool(summaryArgs, PS_LIST_TAIL, "-simple",      0, "use the simple output format", false);
    250279
    251280    // -definerelgroup
     
    322351    PXOPT_ADD_MODE("-definerelstack",     "define a released stack",    RELEASETOOL_MODE_DEFINERELSTACK,  definerelstackArgs);
    323352    PXOPT_ADD_MODE("-listrelstack",       "list released stacks",      RELEASETOOL_MODE_LISTRELSTACK,    listrelstackArgs);
     353    PXOPT_ADD_MODE("-summary",            "list stackSummaryes for released stacks", RELEASETOOL_MODE_SUMMARY,    summaryArgs);
    324354
    325355    PXOPT_ADD_MODE("-definerelgroup",     "define a group of exposures", RELEASETOOL_MODE_DEFINERELGROUP,  definerelgroupArgs);
  • tags/ipp-20130712/ippTools/src/stacktool.c

    • Property svn:mergeinfo deleted
    r35857 r36122  
    4444static bool tosummaryMode(pxConfig *config);
    4545static bool addsummaryMode(pxConfig *config);
     46static bool summaryMode(pxConfig *config);
    4647static bool pendingcleanuprunMode(pxConfig *config);
    4748static bool pendingcleanupskyfileMode(pxConfig *config);
     
    8485        MODECASE(STACKTOOL_MODE_TOSUMMARY,             tosummaryMode);
    8586        MODECASE(STACKTOOL_MODE_ADDSUMMARY,            addsummaryMode);
     87        MODECASE(STACKTOOL_MODE_SUMMARY,               summaryMode);
    8688        MODECASE(STACKTOOL_MODE_PENDINGCLEANUPRUN,     pendingcleanuprunMode);
    8789        MODECASE(STACKTOOL_MODE_PENDINGCLEANUPSKYFILE, pendingcleanupskyfileMode);
     
    748750    PXOPT_COPY_S64(config->args, where, "-stack_id",  "stackRun.stack_id",   "==");
    749751    PXOPT_COPY_STR(config->args, where, "-label",     "stackRun.label",     "==");
     752    PXOPT_COPY_STR(config->args, where, "-data_group", "stackRun.data_group", "==");
    750753    PXOPT_COPY_STR(config->args, where, "-state",     "stackRun.state",     "==");
    751754    PXOPT_COPY_S64(config->args, where, "-sass_id",   "stackAssociationMap.sass_id",  "==");
     
    15671570}
    15681571
     1572static bool summaryMode(pxConfig *config)
     1573{
     1574    PS_ASSERT_PTR_NON_NULL(config, false);
     1575
     1576    psMetadata *where = psMetadataAlloc();
     1577    PXOPT_COPY_S64(config->args, where, "-sass_id", "stackSummary.sass_id", "==");
     1578    PXOPT_COPY_STR(config->args, where, "-projection_cell", "stackAssociation.projection_cell", "==");
     1579    PXOPT_COPY_STR(config->args, where, "-tess_id", "stackAssociation.tess_id", "LIKE");
     1580    PXOPT_COPY_STR(config->args, where, "-filter", "stackAssociation.filter", "LIKE");
     1581    PXOPT_COPY_S64(config->args, where, "-stack_id", "stackSumSkyfile.stack_id", "==");
     1582    pxAddLabelSearchArgs(config, where, "-data_group", "stackAssociation.data_group", "LIKE");
     1583    PXOPT_COPY_STR(config->args, where, "-skycell_id", "stackRun.skycell_id", "LIKE");
     1584//    PXOPT_COPY_STR(config->args, where, "-state", "stackRun.state", "==");
     1585    pxAddLabelSearchArgs(config, where, "-label", "stackRun.label", "LIKE");
     1586//    PXOPT_COPY_S16(config->args, where, "-fault", "stackSumSkyfile.fault", "==");
     1587//    PXOPT_COPY_F64(config->args, where, "-mjd_obs_begin", "stackSumSkyfile.mjd_obs", ">=");
     1588//    PXOPT_COPY_F64(config->args, where, "-mjd_obs_end", "stackSumSkyfile.mjd_obs", "<=");
     1589//    PXOPT_COPY_S16(config->args, where, "-background_model","stackSumSkyfile.background_model", "==");
     1590
     1591//    PXOPT_LOOKUP_BOOL(all, config->args, "-all", false);
     1592
     1593    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     1594    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1595
     1596    psString query = pxDataGet("stacktool_summary.sql");
     1597    if (!query) {
     1598        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     1599        return false;
     1600    }
     1601
     1602    if (psListLength(where->list)) {
     1603        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1604        psStringAppend(&query, " WHERE %s", whereClause);
     1605        psFree(whereClause);
     1606    } else {
     1607        psError(PXTOOLS_ERR_CONFIG, true, "search parameters are required");
     1608        return false;
     1609    }
     1610
     1611    psFree(where);
     1612
     1613    // treat limit == 0 as "no limit"
     1614    if (limit) {
     1615        psString limitString = psDBGenerateLimitSQL(limit);
     1616        psStringAppend(&query, " %s", limitString);
     1617        psFree(limitString);
     1618    }
     1619
     1620    if (!p_psDBRunQuery(config->dbh, query)) {
     1621        psError(PS_ERR_UNKNOWN, false, "database error");
     1622        psFree(query);
     1623        return false;
     1624    }
     1625    psFree(query);
     1626
     1627    psArray *output = p_psDBFetchResult(config->dbh);
     1628    if (!output) {
     1629        psErrorCode err = psErrorCodeLast();
     1630        switch (err) {
     1631            case PS_ERR_DB_CLIENT:
     1632                psError(PXTOOLS_ERR_SYS, false, "database error");
     1633            case PS_ERR_DB_SERVER:
     1634                psError(PXTOOLS_ERR_PROG, false, "database error");
     1635            default:
     1636                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     1637        }
     1638
     1639        return false;
     1640    }
     1641    if (!psArrayLength(output)) {
     1642        psTrace("stacktool", PS_LOG_INFO, "no rows found");
     1643        psFree(output);
     1644        return true;
     1645    }
     1646
     1647    if (psArrayLength(output)) {
     1648        if (!ippdbPrintMetadatas(stdout, output, "stackSummary", !simple)) {
     1649            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1650            psFree(output);
     1651            return false;
     1652        }
     1653    }
     1654
     1655    psFree(output);
     1656
     1657    return true;
     1658}
     1659
    15691660static bool pendingcleanuprunMode(pxConfig *config)
    15701661{
  • tags/ipp-20130712/ippTools/src/stacktool.h

    r34800 r36122  
    3838    STACKTOOL_MODE_TOSUMMARY,
    3939    STACKTOOL_MODE_ADDSUMMARY,
     40    STACKTOOL_MODE_SUMMARY,
    4041    STACKTOOL_MODE_PENDINGCLEANUPRUN,
    4142    STACKTOOL_MODE_PENDINGCLEANUPSKYFILE,
  • tags/ipp-20130712/ippTools/src/stacktoolConfig.c

    r35122 r36122  
    121121    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-state", 0,            "search by state", NULL);
    122122    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-label", 0,            "search by label", 0);
     123    psMetadataAddStr(updaterunArgs, PS_LIST_TAIL, "-data_group", 0,       "search by data_group", 0);
    123124    psMetadataAddS16(updaterunArgs, PS_LIST_TAIL, "-fault",  0,           "search by fault code", 0);
    124125    psMetadataAddS64(updaterunArgs, PS_LIST_TAIL, "-sass_id", 0,          "search by stack association ID", 0);
     
    264265    psMetadataAddStr(addsummaryArgs, PS_LIST_TAIL, "-path_base", 0,     "set summary path base", NULL);
    265266
     267    // -summary
     268    psMetadata *summaryArgs = psMetadataAlloc();
     269    psMetadataAddS64(summaryArgs, PS_LIST_TAIL, "-sass_id", 0,  "search by stack association ID", 0);
     270    psMetadataAddS64(summaryArgs, PS_LIST_TAIL, "-stack_id", 0,  "search by stack ID", 0);
     271    psMetadataAddStr(summaryArgs, PS_LIST_TAIL, "-tess_id", 0,   "search by tessellation ID", NULL);
     272    psMetadataAddStr(summaryArgs, PS_LIST_TAIL, "-projection_cell", 0,   "search by projection cell ID", NULL);
     273//    psMetadataAddStr(summaryArgs, PS_LIST_TAIL, "-state", 0,     "search by state", NULL);
     274    psMetadataAddStr(summaryArgs, PS_LIST_TAIL, "-filter", 0,    "search by filter (LIKE comparison)", NULL);
     275    psMetadataAddStr(summaryArgs, PS_LIST_TAIL, "-label", PS_META_DUPLICATE_OK, "search by stackRun label (LIKE comparison)", NULL);
     276    psMetadataAddStr(summaryArgs, PS_LIST_TAIL, "-data_group", PS_META_DUPLICATE_OK, "search by stackAssociation data_group (LIKE comparison)", NULL);
     277    psMetadataAddStr(summaryArgs, PS_LIST_TAIL, "-skycell_id", 0,   "search by skycell ID", NULL);
     278//     psMetadataAddStr(summaryArgs, PS_LIST_TAIL, "-dist_group", PS_META_DUPLICATE_OK, "search by stackRun dist_group (LIKE comparison)", NULL);
     279
     280//    psMetadataAddBool(summaryArgs, PS_LIST_TAIL, "-all",  0,             "search without arguments", false);
     281    psMetadataAddU64(summaryArgs, PS_LIST_TAIL,  "-limit",  0,            "limit result set to N items", 0);
     282    psMetadataAddBool(summaryArgs, PS_LIST_TAIL, "-simple",  0,          "use the simple output format", false);
     283
    266284    // -pendingcleanuprun
    267285    psMetadata *pendingcleanuprunArgs = psMetadataAlloc();
     
    324342    PXOPT_ADD_MODE("-updatesumskyfile",      "update fault code for sumskyfile",     STACKTOOL_MODE_UPDATESUMSKYFILE,          updatesumskyfileArgs);
    325343    PXOPT_ADD_MODE("-tosummary",            "show runs that can be summarized", STACKTOOL_MODE_TOSUMMARY, tosummaryArgs);
     344    PXOPT_ADD_MODE("-summary",              "show runs that have been summarized", STACKTOOL_MODE_SUMMARY, summaryArgs);
    326345    PXOPT_ADD_MODE("-addsummary",           "add entry to the summary table", STACKTOOL_MODE_ADDSUMMARY, addsummaryArgs);
    327346    PXOPT_ADD_MODE("-exportrun",            "export run for import on other database", STACKTOOL_MODE_EXPORTRUN, exportrunArgs);
  • tags/ipp-20130712/ippTools/src/staticskytool.c

    r35194 r36122  
    5050static bool revertskycalresultMode(pxConfig *config);
    5151static bool updateskycalresultMode(pxConfig *config);
     52static bool exportskycalrunMode(pxConfig *config);
     53static bool importskycalrunMode(pxConfig *config);
    5254
    5355static bool setstaticskyRunState(pxConfig *config, psS64 sky_id, const char *state);
     
    8890        MODECASE(STATICSKYTOOL_MODE_REVERTSKYCALRESULT,revertskycalresultMode);
    8991        MODECASE(STATICSKYTOOL_MODE_SKYCALRESULT,      skycalresultMode);
     92        MODECASE(STATICSKYTOOL_MODE_EXPORTSKYCALRUN,   exportskycalrunMode);
     93        MODECASE(STATICSKYTOOL_MODE_IMPORTSKYCALRUN,   importskycalrunMode);
    9094        default:
    9195            psAbort("invalid option (this should not happen)");
     
    895899bool importrunMode(pxConfig *config)
    896900{
    897 # if (0)
    898   unsigned int nFail;
    899 
    900   int numImportTables = 2;
    901 
    902   char tables[2] [80] = {"stackInputSkyfile", "stackSumSkyfile"};
     901  return false;
     902}
     903
     904bool exportskycalrunMode(pxConfig *config)
     905{
     906  typedef struct ExportTable {
     907    char tableName[80];
     908    char sqlFilename[80];
     909  } ExportTable;
     910
     911  int numExportTables = 2;
    903912
    904913  PS_ASSERT_PTR_NON_NULL(config, NULL);
    905914
    906   PXOPT_LOOKUP_STR(infile, config->args, "-infile", true,  false);
    907 
    908   psMetadata *input = psMetadataConfigRead (NULL, &nFail, infile, false);
    909 
    910 #ifdef notdef
    911   fprintf (stderr, "---- input ----\n");
    912   psMetadataPrint (stderr, input, 1);
    913 #endif
    914 
    915   if (!pxCheckImportVersion(config, input)) {
    916       psError(PS_ERR_UNKNOWN, false, "pxCheckImportVersion failed");
     915  // XXX unused PXOPT_LOOKUP_S64(det_id, config->args, "-sky_id", true,  false);
     916  PXOPT_LOOKUP_STR(outfile, config->args, "-outfile", true,  false);
     917  PXOPT_LOOKUP_BOOL(clean, config->args, "-clean", false);
     918  PXOPT_LOOKUP_U64(limit,   config->args, "-limit",   false, false);
     919
     920  FILE *f = fopen (outfile, "w");
     921  if (f == NULL) {
     922      psError(PS_ERR_UNKNOWN, false, "failed to open output file");
    917923      return false;
    918924  }
    919   psMetadataItem *item = psMetadataLookup (input, "stackRun");
    920   psAssert (item, "entry not in input?");
    921   psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?");
    922 
    923   psMetadataItem *entry = psListGet (item->data.list, 0);
    924   assert (entry);
    925   assert (entry->type == PS_DATA_METADATA);
    926   stackRunRow *stackRun = stackRunObjectFromMetadata (entry->data.md);
    927   stackRunInsertObject (config->dbh, stackRun);
    928 
    929   // fprintf (stdout, "---- stack run ----\n");
    930   // psMetadataPrint (stderr, entry->data.md, 1);
    931 
    932   for (int i = 0; i < numImportTables; i++) {
    933     psMetadataItem *item = psMetadataLookup (input, tables[i]);
    934     psAssert (item, "entry not in input?");
    935     psAssert (item->type == PS_DATA_METADATA_MULTI, "entry not multi?");
    936 
    937     switch (i) {
    938       case 0:
    939         for (int i = 0; i < item->data.list->n; i++) {
    940           entry = psListGet (item->data.list, i);
    941           assert (entry);
    942           assert (entry->type == PS_DATA_METADATA);
    943           stackInputSkyfileRow *stackInputSkyfile = stackInputSkyfileObjectFromMetadata (entry->data.md);
    944           stackInputSkyfileInsertObject (config->dbh, stackInputSkyfile);
    945 
    946           // fprintf (stdout, "---- row %d ----\n", i);
    947           // psMetadataPrint (stderr, entry->data.md, 1);
    948         }
    949         break;
    950 
    951       case 1:
    952         for (int i = 0; i < item->data.list->n; i++) {
    953           entry = psListGet (item->data.list, i);
    954           assert (entry);
    955           assert (entry->type == PS_DATA_METADATA);
    956           stackSumSkyfileRow *stackSumSkyfile = stackSumSkyfileObjectFromMetadata (entry->data.md);
    957           stackSumSkyfileInsertObject (config->dbh, stackSumSkyfile);
    958 
    959           // fprintf (stdout, "---- row %d ----\n", i);
    960           // psMetadataPrint (stderr, entry->data.md, 1);
    961         }
    962         break;
    963     }
     925
     926  if (!pxExportVersion(config, f)) {
     927    psError(PS_ERR_UNKNOWN, false, "failed to write dbversion output file");
     928    return false;
    964929  }
    965 
    966 # endif
    967   return true;
     930  psMetadata *where = psMetadataAlloc();
     931  PXOPT_COPY_S64(config->args, where, "-skycal_id", "skycal_id", "==");
     932
     933  ExportTable tables [] = {
     934    {"skycalRun", "staticskytool_export_skycalrun.sql"},
     935    {"skycalResult", "staticskytool_export_skycalresult.sql"},
     936  };
     937
     938  for (int i=0; i < numExportTables; i++) {
     939    psString query = pxDataGet(tables[i].sqlFilename);
     940    if (!query) {
     941      psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     942      return false;
     943    }
     944
     945    if (where && psListLength(where->list)) {
     946      psString whereClause = psDBGenerateWhereSQL(where, NULL);
     947      psStringAppend(&query, " %s", whereClause);
     948      psFree(whereClause);
     949    }
     950
     951    // treat limit == 0 as "no limit"
     952    if (limit) {
     953      psString limitString = psDBGenerateLimitSQL(limit);
     954      psStringAppend(&query, " %s", limitString);
     955      psFree(limitString);
     956    }
     957
     958    if (!p_psDBRunQuery(config->dbh, query)) {
     959      psError(PS_ERR_UNKNOWN, false, "database error");
     960      psFree(query);
     961      return false;
     962    }
     963    psFree(query);
     964
     965    psArray *output = p_psDBFetchResult(config->dbh);
     966    if (!output) {
     967      psError(PS_ERR_UNKNOWN, false, "database error");
     968      return false;
     969    }
     970    if (!psArrayLength(output)) {
     971      psError(PS_ERR_UNKNOWN, true, "no rows found");
     972      psFree(output);
     973      return false;
     974    }
     975
     976    if (clean) {
     977        if (!strcmp(tables[i].tableName, "skycalRun")) {
     978            if (!pxSetStateCleaned("skycalRun", "state", output)) {
     979                psFree(output);
     980                psError(PS_ERR_UNKNOWN, false, "pxSetStateClean failed for table %s",  tables[i].tableName);
     981                return false;
     982            }
     983        }
     984    }
     985
     986      // we must write the export table in non-simple (true) format
     987    if (!ippdbPrintMetadatas(f, output, tables[i].tableName, true)) {
     988        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     989        psFree(output);
     990        return false;
     991    }
     992
     993    psFree(output);
     994  }
     995
     996    fclose (f);
     997
     998    return true;
     999}
     1000
     1001bool importskycalrunMode(pxConfig *config)
     1002{
     1003  return false;
    9681004}
    9691005
     
    9861022
    9871023}
    988 
    989 # if (0)
    990         // now we need to loop over all requested filters and check that each is found
    991         // XXX is this needed?  haven't we required that we only match the requested filters
    992         // and that N unique filters are found?
    993 
    994         psVector *found = psVectorAlloc(inputs->n, PS_TYPE_U8);
    995         psVectorInit (found, 0);
    996 
    997         psMetadataItem *filter = NULL;
    998         psListIterator *iter = psListIteratorAlloc (filters->data.list, PS_LIST_HEAD, false);
    999         while ((filter = psListGetAndIncrement(iter))) {
    1000 
    1001             bool foundOne = false;
    1002 
    1003             psAssert (filter->type == PS_DATA_STR, "filter is not a string?");
    1004             for (int j = 0; !foundOne && (j < inputs->n); j++) {
    1005                 if (found->data.U8[j]) continue;
    1006                 psMetadata *inputRow = inputs->data[j]; // Row from select
    1007 
    1008                 // pull out the skycell_id, tess_id, filter
    1009                 psString inFilter = psMetadataLookupStr(&status, row, "filter");
    1010                 psAssert (status);
    1011 
    1012                 found->data.U8[j] = true;
    1013                 foundOne = true;
    1014             }
    1015             if (!foundOne) {
    1016                 // this required filter was not found in the inputs, skip the entry
    1017                 skip();
    1018             }
    1019         }           
    1020 # endif
    10211024
    10221025static bool defineskycalrunMode(pxConfig *config)
  • tags/ipp-20130712/ippTools/src/staticskytool.h

    r32960 r36122  
    4343    STATICSKYTOOL_MODE_SKYCALRESULT,
    4444    STATICSKYTOOL_MODE_REVERTSKYCALRESULT,
     45    STATICSKYTOOL_MODE_EXPORTSKYCALRUN,
     46    STATICSKYTOOL_MODE_IMPORTSKYCALRUN,
    4547} staticskytoolMode;
    4648
  • tags/ipp-20130712/ippTools/src/staticskytoolConfig.c

    r35197 r36122  
    269269    psMetadataAddBool(skycalresultArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false);
    270270
     271    // -exportskycalrun
     272    psMetadata *exportskycalrunArgs = psMetadataAlloc();
     273    psMetadataAddS64(exportskycalrunArgs, PS_LIST_TAIL, "-skycal_id", 0, "export this skycal ID (required)", 0);
     274    psMetadataAddStr(exportskycalrunArgs, PS_LIST_TAIL, "-outfile", 0, "export to this file (required)", NULL);
     275    psMetadataAddU64(exportskycalrunArgs, PS_LIST_TAIL, "-limit", 0, "limit result set to N items", 0);
     276    psMetadataAddBool(exportskycalrunArgs, PS_LIST_TAIL, "-clean", 0, "mark tables as cleaned", false);
     277
     278    // -importrun
     279    psMetadata *importskycalrunArgs = psMetadataAlloc();
     280    psMetadataAddStr(importskycalrunArgs, PS_LIST_TAIL, "-infile", 0, "import from this file (required)", NULL);
     281 
     282
    271283    psFree(now);
    272284
     
    291303    PXOPT_ADD_MODE("-updateskycal",  "revert faulted skycal run", STATICSKYTOOL_MODE_UPDATESKYCALRESULT, updateskycalresultArgs);
    292304    PXOPT_ADD_MODE("-skycalresult",  "Get result of skycal run",  STATICSKYTOOL_MODE_SKYCALRESULT, skycalresultArgs);
     305    PXOPT_ADD_MODE("-exportskycalrun",     "Export skycal run",   STATICSKYTOOL_MODE_EXPORTSKYCALRUN, exportskycalrunArgs);
     306    PXOPT_ADD_MODE("-importskycalrun",     "Import skycal run",   STATICSKYTOOL_MODE_IMPORTSKYCALRUN, importskycalrunArgs);
    293307
    294308    if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) {
  • tags/ipp-20130712/pstamp

  • tags/ipp-20130712/pstamp/scripts

  • tags/ipp-20130712/pstamp/scripts/psgetcalibinfo

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • tags/ipp-20130712/pstamp/scripts/pstamp_get_image_job.pl

    r33015 r36122  
    6565my $mdcParser = PS::IPP::Metadata::Config->new; # Parser for metadata config files
    6666
    67 my $data = $mdcParser->parse(join "", (<INPUT>)) or my_die("failed to parse metadata config doc", $PS_EXIT_UNKNOWN_ERROR);
     67my $data = $mdcParser->parse(join "", (<INPUT>))
     68    or my_die("failed to parse metadata config doc", $PS_EXIT_UNKNOWN_ERROR);
     69
    6870my $components = parse_md_list($data);
    6971my $n = scalar @$components;
     
    8385    print STDERR "stage_id is $stage_id\n";
    8486    print STDERR "path_base is $path_base\n";
    85     print STDERR "path_base is $path_base\n";
    8687    print STDERR "CAMERA is $camera\n";
    8788    print STDERR "magicked is " . (defined $magicked ? $magicked : "undefined") . "\n";
     
    8990
    9091if (!$camera or !$path_base or !$component or !$stage_id or !$stage) {
    91        my_die("failed to parse params from: $params_file", $PS_EXIT_UNKNOWN_ERROR);
     92       my_die("One or more parameters are missing in: $params_file", $PS_EXIT_UNKNOWN_ERROR);
    9293}
    9394
  • tags/ipp-20130712/pstamp/scripts/pstamp_job_run.pl

    r35909 r36122  
    5757my_die("output_base is required", $job_id, $PS_EXIT_PROG_ERROR) if !$outputBase;
    5858
    59 $options = 1 if !$options;
    60 
    61 # We don't need to muggle anymore. Ignore those options
    62 $options &=  ~($PSTAMP_REQUEST_UNCENSORED | $PSTAMP_REQUIRE_UNCENSORED);
     59# ppstamp requires an input file
     60$options = $PSTAMP_SELECT_IMAGE if !$options;
    6361
    6462my $ipprc = PS::IPP::Config->new(); # IPP Configuration
     
    9593    my $argString;
    9694    $argString = $params->{job_args};
     95   
     96    my_die("argument list is empty", $job_id, $PS_EXIT_DATA_ERROR) if !$argString;
     97
    9798    my $stage = $params->{stage};
    98 
    99     # XXX: should we do any other sanity checking?
    100     my_die("argument list is empty", $job_id, $PS_EXIT_DATA_ERROR) if !$argString;
     99    my_die("stage is not defined", $job_id, $PS_EXIT_DATA_ERROR) if !$stage;
     100
     101    if ($stage eq 'stack_summary') {
     102
     103        # remove options not supported by stack summary
     104        $options &= ~($PSTAMP_SELECT_SOURCES | $PSTAMP_SELECT_BACKMDL | $PSTAMP_SELECT_INVERSE
     105            | $PSTAMP_RESTORE_BACKGROUND);
     106
     107        # stackSummary outputs do not follow the usual IPP conventions for file names.
     108        # The parser (actually Job.pm) has deferred handling this until here
     109        update_stack_summary_filenames($params);
     110
     111    } elsif ($stage ne 'stack') {
     112        # ignore options only supported by stack and stack_summary
     113        $options &= ~($PSTAMP_SELECT_EXP | $PSTAMP_SELECT_NUM);
     114    }
     115   
    101116
    102117    if ($stage eq "raw") {
     
    181196    }
    182197
    183     # my ($tmpImage, $tmpMask, $tmpVariance, $tmproot);
    184 
    185     my $command = "$ppstamp $outputBase $argString $fileArgs";
    186     $command .= " -write_jpeg" if ($options & $PSTAMP_SELECT_JPEG);
    187     $command .= " -nocompress" if ($options & $PSTAMP_SELECT_UNCOMPRESSED);
    188     $command .= " -stage $stage";
    189     $command .= " -forheader $calibfile" if $calibfile;
    190     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    191         run(command => $command, verbose => $verbose);
     198    # unless the stage is stack_summary we use ppstamp to make postage stamps (including -wholefile)
     199    # otherwise we make copies of the input files to the outputs
     200    my $use_ppstamp = ($stage ne 'stack_summary');
    192201
    193202    my $exitStatus;
    194     if (WIFEXITED($error_code)) {
    195         $exitStatus = WEXITSTATUS($error_code);
    196     } else {
    197         print STDERR "ppstamp failed error_code: $error_code\n";
    198         $exitStatus = $PS_EXIT_SYS_ERROR;
     203    if ($use_ppstamp) {
     204        my $command = "$ppstamp $outputBase $argString $fileArgs";
     205        $command .= " -write_jpeg" if ($options & $PSTAMP_SELECT_JPEG);
     206        $command .= " -nocompress" if ($options & $PSTAMP_SELECT_UNCOMPRESSED);
     207        $command .= " -stage $stage";
     208        $command .= " -forheader $calibfile" if $calibfile;
     209        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     210            run(command => $command, verbose => $verbose);
     211
     212        if (WIFEXITED($error_code)) {
     213            $exitStatus = WEXITSTATUS($error_code);
     214        } else {
     215            print STDERR "ppstamp failed error_code: $error_code\n";
     216            $exitStatus = $PS_EXIT_SYS_ERROR;
     217        }
     218        # XXX: if stage is stack deal with EXP and NUM images if selected
     219    } else {
     220        $exitStatus = justCopyFiles($outputBase, \$options, $params);
    199221    }
    200222
     
    208230
    209231        # Note: we are assuming the contents of the PSTAMP filerules here.
    210         my %extensions = ( $PSTAMP_SELECT_IMAGE    => "fits",
    211                            $PSTAMP_SELECT_MASK     => "mk.fits",
    212                            $PSTAMP_SELECT_VARIANCE => "wt.fits",
    213                            $PSTAMP_SELECT_SOURCES  => "cmf",
    214                            $PSTAMP_SELECT_JPEG     => "jpg");
    215 
    216         my $output_mask = $options & ($PSTAMP_SELECT_IMAGE | $PSTAMP_SELECT_MASK | $PSTAMP_SELECT_VARIANCE | $PSTAMP_SELECT_JPEG | $PSTAMP_SELECT_SOURCES);
     232        my %extensions = ( $PSTAMP_SELECT_IMAGE    => 'fits',
     233                           $PSTAMP_SELECT_MASK     => 'mk.fits',
     234                           $PSTAMP_SELECT_VARIANCE => 'wt.fits',
     235                           $PSTAMP_SELECT_SOURCES  => 'cmf',
     236                           $PSTAMP_SELECT_JPEG     => 'jpg',
     237                           $PSTAMP_SELECT_EXP      => 'exp.fits',
     238                           $PSTAMP_SELECT_NUM      => 'num.fits',
     239                           $PSTAMP_SELECT_EXPJPEG  => 'exp.jpg',
     240                           $PSTAMP_SELECT_NUMJPEG  => 'num.jpg');
     241
     242        my $output_mask = $options & ($PSTAMP_SELECT_IMAGE | $PSTAMP_SELECT_MASK | $PSTAMP_SELECT_VARIANCE
     243            | $PSTAMP_SELECT_JPEG | $PSTAMP_SELECT_SOURCES
     244            | $PSTAMP_SELECT_EXP | $PSTAMP_SELECT_NUM
     245            | $PSTAMP_SELECT_EXPJPEG | $PSTAMP_SELECT_NUMJPEG);
     246
    217247
    218248        foreach my $key (keys (%extensions)) {
     
    534564}
    535565
     566# stack_summary stage does not currently use proper file rules.
     567# The parser defers handlint this to us..
     568
     569sub update_stack_summary_filenames {
     570    my $params  = shift;
     571
     572    my $path_base = $params->{path_base};
     573
     574    $params->{image}  = $path_base . ".image.b1.fits";
     575    $params->{mask}   = $path_base . ".mask.b1.fits";
     576    $params->{weight} = $path_base . ".variance.b1.fits";
     577    $params->{jpeg}   = $path_base . ".image.0.b1.jpeg";
     578    $params->{exp}    = $path_base . ".exp.b1.fits";
     579    $params->{num}    = $path_base . ".num.b1.fits";
     580    $params->{expjpeg} = $path_base . ".exp.0.b1.jpeg";
     581    $params->{numjpeg} = $path_base . ".num.0.b1.jpeg";
     582}
     583
     584sub myCopy {
     585    my ($dest, $src, $type, $dieOnFail) = @_;
     586
     587    my $result;
     588    my $resolved = $ipprc->file_resolve($src);
     589    if ($resolved and $ipprc->file_exists($resolved)) {
     590        print "Copying $src to $dest\n" if $verbose;;
     591        $result = copy($resolved, $dest);
     592    } else {
     593        my $msg = "Specified source $type image $src not found.";
     594        if ($dieOnFail) {
     595            $msg .= "\n";
     596        } else {
     597            $msg .= " ignoring\n";
     598        }
     599        carp $msg;
     600        $result = 0;
     601    }
     602   
     603    if (!$result and $dieOnFail) {
     604        &my_die("Unable to copy $type image", $job_id, $PS_EXIT_SYS_ERROR, 'run');
     605    }
     606    return $result;
     607}
     608
     609sub justCopyFiles {
     610    my ($outputBase, $r_options, $params) = @_;
     611
     612    print "Just copying files for $job_id.\n";
     613
     614    my $options = $$r_options;
     615    if ($options & $PSTAMP_SELECT_IMAGE) {
     616        myCopy("$outputBase.fits", $params->{image}, 'image', 1);
     617    }
     618    if ($options & $PSTAMP_SELECT_MASK) {
     619        if (!myCopy("$outputBase.mk.fits", $params->{mask}, 'mask', 0)) {
     620            $options &= ~$PSTAMP_SELECT_MASK;
     621        }
     622    }
     623    if ($options & $PSTAMP_SELECT_VARIANCE) {
     624        if (!myCopy("$outputBase.wt.fits", $params->{weight}, 'variance', 0)) {
     625            $options =  ~$PSTAMP_SELECT_VARIANCE;
     626        }
     627    }
     628    if ($options & $PSTAMP_SELECT_JPEG) {
     629        if (!myCopy("$outputBase.jpg", $params->{jpeg}, 'jpeg', 0)) {
     630            $options &= ~$PSTAMP_SELECT_JPEG;
     631        }
     632    }
     633    if ($options & $PSTAMP_SELECT_EXP) {
     634        if (!myCopy("$outputBase.exp.fits", $params->{exp}, 'exp', 0)) {
     635            $options &= ~$PSTAMP_SELECT_EXP;
     636        }
     637    }
     638    if ($options & $PSTAMP_SELECT_NUM) {
     639        if (!myCopy("$outputBase.num.fits", $params->{num}, 'num', 0)) {
     640            $options &= ~$PSTAMP_SELECT_NUM;
     641        }
     642    }
     643    if ($options & $PSTAMP_SELECT_EXPJPEG) {
     644        if (!myCopy("$outputBase.exp.jpg", $params->{expjpeg}, 'exp', 0)) {
     645            $options &= ~$PSTAMP_SELECT_EXPJPEG;
     646        }
     647    }
     648    if ($options & $PSTAMP_SELECT_NUMJPEG) {
     649        if (!myCopy("$outputBase.num.jpg", $params->{numjpeg}, 'num', 0)) {
     650            $options &= ~$PSTAMP_SELECT_NUMJPEG;
     651        }
     652    }
     653
     654    $$r_options = $options;
     655
     656    print "Done with copy.\n";
     657
     658    return 0;
     659}
     660
    536661sub my_die
    537662{
  • tags/ipp-20130712/pstamp/scripts/pstampparse.pl

    r36056 r36122  
    5151
    5252die "invalid mode '$mode'" unless ($mode eq "list_uri") or ($mode eq "queue_job");
    53 die "--file is required"     if !defined($request_file_name);
     53die "--file is required"   unless defined($request_file_name);
    5454
    5555if ($mode ne "list_uri") {
    56     die "req_id is required"   if !$req_id;
     56    die "req_id is required"  if !$req_id;
    5757    die "outdir is required"  if !$outdir;
    58     die "product is required"  if !$product;
     58    die "product is required" if !$product;
    5959} else {
    60     $req_id = 0;
    61     $outdir = "nowhere";
     60    # mode eq 'list_uri' (used for parser testing)
     61    # these values won't be used for anything but should be defined to avoid errors
     62    $req_id  = 0;
     63    $outdir  = "nowhere";
    6264    $product = "dummy";
    6365}
     
    7678my $pstamptool  = can_run('pstamptool')  or (warn "Can't find pstamptool"  and $missing_tools = 1);
    7779my $pstampdump  = can_run('pstampdump') or (warn "Can't find pstampdump" and $missing_tools = 1);
    78 my $fields  = can_run('fields') or (warn "Can't find fields" and $missing_tools = 1);
     80my $fields      = can_run('fields') or (warn "Can't find fields" and $missing_tools = 1);
    7981
    8082if ($missing_tools) {
     
    116118if ($extver >= 2) {
    117119    # 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;
     120    my_die("action not supplied in version $extver request file $request_file_name\n", $PSTAMP_INVALID_REQUEST)
     121        unless defined $action;
     122
     123    my_die("invalid action: $action supplied in version $extver request file $request_file_name\n",
     124        $PSTAMP_INVALID_REQUEST)
     125        unless (uc($action) eq 'PROCESS' or uc($action) eq 'PREVIEW');
     126
     127    my_die("email not supplied in version $extver request file $request_file_name\n", $PSTAMP_INVALID_REQUEST)
     128        unless $email;
     129
    123130    # XXX check for "valid" $email
    124131} else {
    125132    # for version 1 file the action is process and email is not used
    126133    $action = 'PROCESS';
    127     $email = 'null';
     134    $email  = 'null';
    128135}
    129136
     
    175182
    176183
    177 if ($req_id and !$no_update) {
     184{
    178185    # update the database with the request name. This will be used as the
    179     # the output data store's product name
     186    # the fileset name in the output data store
    180187    my $command = "$pstamptool -updatereq -req_id $req_id  -set_name $req_name";
    181188    $command .= " -set_username $email" if $email ne 'null';
    182189    $command .= " -set_outProduct $product";
    183190    $command .= " -set_label $label" if $label_changed;
    184     my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
    185         run(command => $command, verbose => $verbose);
    186     unless ($success) {
    187         my_die("$command failed", $PS_EXIT_UNKNOWN_ERROR);
    188     }
    189 }
     191    unless ($no_update) {
     192        my ( $success, $error_code, $full_buf, $stdout_buf, $stderr_buf ) =
     193            run(command => $command, verbose => $verbose);
     194        unless ($success) {
     195            my_die("$command failed", $PS_EXIT_UNKNOWN_ERROR);
     196        }
     197    } else {
     198        print "skipping $command\n";
     199    }
     200}
     201
    190202if ($duplicate_req_name) {
    191203    exit 0;
     
    212224}
    213225
    214 if (!$rows) {
    215     # we got called so a valid pstamp request header was found so we can only assume
    216     # that the file is invalid
    217     print STDERR "Invalid request file\n";
     226my $nRows = $rows ? scalar @$rows : 0;
     227print "\n$nRows rows read from request file\n";
     228
     229unless ($nRows) {
     230    # pstamp_job_run was invoked so the request file must have contained a valid header
     231    # a request file with no rows is invalid.
     232    # The print above will let the log file know a bit more.
     233    # Insert a faulted fake job and exit this program successfully.
     234    print STDERR "Invalid request file.\n";
    218235    insertFakeJobForRow(undef, 0, $PSTAMP_INVALID_REQUEST);
    219236    exit 0;
    220237}
    221238
    222 my $nRows = scalar @$rows;
    223 print "\n$nRows rows read from request file\n";
    224239
    225240
     
    227242my $imageList;
    228243my $stage;
     244my $big_limit = 100;    # XXX: this should be in a configuration file some where
    229245foreach my $row (@$rows) {
    230246
    231247    if (!($label =~ /BIG/) and ($label =~ /PSI/ or $label =~ /WEB/)  and
    232248        ($nRows > 200 or $num_jobs > 200) and $req_id and !$no_update) {
    233 
    234         # this is a big request and it came from one of the "high priority" channels
    235         # change the label to one that runs with lower priority
     249        # This is a "big" request and it came from one of the "high priority"
     250        # channels and doesn't have a specific label assigned.
     251        # Change the label to a value that its jobs run with lower priority.
    236252        my $old_label = $label;
    237253
     254        print "\nChanging label for big request from $old_label to $label\n";
    238255        $label = ($label =~ /WEB/) ? 'WEB.BIG' : 'PSI.BIG';
    239         print "\nChanging label for big request from $old_label to $label\n";
    240256
    241257        my $command = "$pstamptool -updatereq -req_id $req_id  -set_label $label";
     
    261277
    262278if (($action eq 'LIST' or $mode eq "queue_job") and ($num_jobs eq 0)) {
    263     print STDERR "no jobs created for $req_name\n" if $verbose;
    264     insertFakeJobForRow(undef, 0, $PSTAMP_INVALID_REQUEST);
     279    # this should not happen. The function above is required to insert a fake job for any
     280    # rows that did not yield any jobs.
     281    print STDERR "ERROR: zero jobs created for $req_name\n";
     282    insertFakeJobForRow(undef, 0, $PS_EXIT_PROG_ERROR);
    265283}
    266284
     
    298316    }
    299317    if ($job_type eq 'get_image') {
    300         unless ($req_type eq 'byid' or $req_type eq 'byexp' or ($req_type eq 'byskycell' and $stage eq 'stack')) {
    301             print STDERR "REQ_TYPE must be 'byid' or 'byexp' or byskcyell for stacks for JOB_TYPE 'get_image'\n";
     318        # get_image jobs are quite expensive in terms of space so we are currently restricting them
     319        unless ($req_type eq 'byid' or $req_type eq 'byexp'
     320            or ($req_type eq 'byskycell' and $stage eq 'stack')
     321            or ($stage eq 'stack_summary')) {
     322            print STDERR "REQ_TYPE must be 'byid' or 'byexp' JOB_TYPE 'get_image' for IMG_TYPE $stage\n";
    302323            insertFakeJobForRow($row, 1, $PSTAMP_INVALID_REQUEST);
    303324            return 0;
     
    307328    my $component = $row->{COMPONENT};
    308329    if (!defined $component or (lc($component) eq "null") or (lc($component) eq "all")) {
    309         if ($job_type eq 'get_image') {
     330        if ($job_type eq 'get_image' and ! ($stage eq 'stack' or $stage eq 'stack_summary')) {
    310331            $row->{COMPONENT} = 'all';
    311332        } else {
     
    396417    }
    397418
    398     if (($req_type eq "byexp") and ($stage eq "stack")) {
    399         print STDERR "byexp not implemented for stack stage. row: $rownum\n";
     419    if (($req_type eq "byexp") and ($stage eq "stack" or $stage eq 'stack_summary')) {
     420        print STDERR "byexp not implemented for $stage stage. row: $rownum\n";
    400421        insertFakeJobForRow($row, 1, $PSTAMP_NOT_IMPLEMENTED);
    401422        return 0;
     
    469490    my $start_locate = gettimeofday();
    470491
    471     print "\nCalling new_locate_images for row: $rownum\n";
     492    print "\nCalling locate_images_for_row for row: $rownum\n";
    472493
    473494    $imageList = locate_images_for_row($ipprc, $image_db, $camera, $row, $verbose);
     
    533554    my $image_db   = $proj_hash->{dbname};
    534555    my $camera     = $proj_hash->{camera};
    535     my $need_magic    = $proj_hash->{need_magic};
     556    my $need_magic = $proj_hash->{need_magic};
    536557    # Since user can get unmagicked data "by coordinate" requests can go back in time
    537558    # to dredge unusable data from the "dark days"...
     
    544565    $need_magic = 0 if $stage eq 'stack';
    545566
    546     if ($need_magic) {
    547 
    548         # this project requires that postage stamps be extracted from destreaked images
    549 
    550         if ($option_mask & ($PSTAMP_REQUEST_UNCENSORED | $PSTAMP_REQUIRE_UNCENSORED)) {
    551             # The user has requested uncensored stamps
    552 
    553             if (!$dest_requires_magic) {
    554                 # and this user's data store destination is allowed uncensored stamps, so accept the request
    555                 $need_magic = 0;
    556             } else {
    557                 print STDERR "Error row $rownum: User not authorized to to request uncensored stamps.\n";
    558                 if ($option_mask & $PSTAMP_REQUIRE_UNCENSORED) {
    559                     # user required uncensored stamps. Can't do it so fail.
    560                     foreach my $r (@$rowList) {
    561                         insertFakeJobForRow($r, 1, $PSTAMP_NOT_AUTHORIZED);
    562                         $num_jobs++;
    563                     }
    564                     return $num_jobs;
    565                 }
    566 
    567                 # user will accept censored stamps. alter OPTION_MASK and continue
    568 
    569                 print STDERR "    Will attempt to make destreaked stamps\n";
    570                 # zap the offending bit in the option mask
    571                 $option_mask = $option_mask ^ ($PSTAMP_REQUEST_UNCENSORED);
    572                 foreach my $r (@$rowList) {
    573                     $r->{OPTION_MASK} = $option_mask;
    574                 }
    575             }
    576         }
    577     }
    578    
     567    # XXX: magic is dead
     568    $need_magic = 0;
     569
    579570    my $numRows = scalar @$rowList;
    580571
     
    713704    }
    714705    $base =~ s/.fits$//;
     706
     707    my $filter = $image->{filter};
     708    if (!$filter) {
     709        if ($stage eq 'diff') {
     710            $filter = $image->{filter_1};
     711        }
     712        if (!$filter) {
     713            # XXX: perhaps this should be a programming error...
     714            print STDERR "missing filter using 'X'\n";
     715            $filter = 'X';
     716        }
     717    }
     718    # use first character of filter
     719    $filter = substr($filter, 0, 1);
    715720           
    716     my $output_base = "$outdir/${rownum}_${job_num}_${base}";
     721    my $output_base = "$outdir/${rownum}_${job_num}_${filter}_${base}";
    717722    write_params($output_base, $image);
    718723
     
    11751180    }
    11761181    if (($img_type eq "raw") or ($img_type eq "chip") or ($img_type eq "warp") or
    1177         ($img_type eq "stack") or ($img_type eq "diff")) {
     1182        ($img_type eq "stack") or ($img_type eq 'stack_summary') or ($img_type eq "diff")) {
    11781183        return 1;
    11791184    } else {
  • tags/ipp-20130712/pstamp/src/Makefile.am

    r34089 r36122  
    1 bin_PROGRAMS = ppstamp pstamprequest pstampdump
     1bin_PROGRAMS = ppstamp pstampdump
    22
    33include_HEADERS = \
  • tags/ipp-20130712/pstamp/src/ppstampMakeStamp.c

    r35909 r36122  
    2020static bool setMaskedToNAN(pmConfig *config, psImage *image, psImage *mask, psImage *variance);
    2121static bool copySources(pmReadout *outputReadout, pmReadout *inputReadout, pmReadout *astromReadout, psRegion extractRegion);
     22static bool imageHasValidPixels(psImage *image);
    2223
    2324// convert the input chip's transforms to the output
     
    337338            status = false;
    338339            break;
     340        }
     341        if (!imageHasValidPixels(outReadout->image)) {
     342            return PSTAMP_NO_VALID_PIXELS;
    339343        }
    340344        if (readout->variance) {
     
    885889    return true;
    886890}
     891
     892static bool
     893imageHasValidPixels(psImage *image) {
     894    // check F32 image and return true if any pixel is finite
     895    if (image->type.type != PS_TYPE_F32) {
     896        return true;
     897    }
     898    for (int y=0; y<image->numRows; y++) {
     899        for (int x=0; x<image->numCols; x++) {
     900            psF32 pixel = image->data.F32[y][x];
     901            if (isfinite(pixel)) {
     902                return true;
     903            }
     904        }
     905    }
     906    return false;
     907}
  • tags/ipp-20130712/pstamp/src/pstamp.h

    r34596 r36122  
    1515        PSTAMP_DUP_REQUEST      = 20,
    1616        PSTAMP_INVALID_REQUEST  = 21,
    17         PSTAMP_UNKNOWN_PRODUCT  = 22,
     17        PSTAMP_UNKNOWN_PROJECT  = 22,
    1818        PSTAMP_NO_IMAGE_MATCH   = 23,
    1919        PSTAMP_NOT_DESTREAKED   = 24,
     
    2121        PSTAMP_GONE             = 26,
    2222        PSTAMP_NO_JOBS_QUEUED   = 27,
    23         PSTAMP_NO_OVERLAP       = 28
     23        PSTAMP_NO_OVERLAP       = 28,
     24        PSTAMP_NOT_AUTHORIZED   = 29,
     25        PSTAMP_NO_VALID_PIXELS  = 30,
    2426} pstampJobErrors;
    2527
     
    3436#define PSTAMP_SELECT_BACKMDL       32
    3537#define PSTAMP_SELECT_JPEG          64
    36 // unused                           128
    37 // unused                           256
     38#define PSTAMP_SELECT_EXP           128
     39#define PSTAMP_SELECT_NUM           256
    3840#define PSTAMP_SELECT_UNCOMPRESSED  512
    3941#define PSTAMP_SELECT_INVERSE       1024
     
    4446
    4547#define PSTAMP_NO_WAIT_FOR_UPDATE   32768
     48#ifdef notdef
    4649#define PSTAMP_REQUEST_UNCENSORED  0x10000
    4750#define PSTAMP_REQUIRE_UNCENSORED  0x20000
     51#endif
    4852
    4953#define PSTAMP_CENTER_IN_PIXELS 1
  • tags/ipp-20130712/pstamp/test/gpc1/stacksummary.bycoord.txt

    r36049 r36122  
    44CHANGEME 2 PROCESS null
    55#  ROWNUM CENTER_X CENTER_Y WIDTH HEIGHT COORD_MASK JOB_TYPE OPTION_MASK PROJECT SURVEY_NAME IPP_RELEASE REQ_TYPE IMG_TYPE ID TESS_ID COMPONENT DATA_GROUP REQFILT MJD_MIN MJD_MAX RUN_TYPE FWHM_MIN FWHM_MAX | COMMENT
    6 1     359.767   -30.2009     100    100   2      stamp      455         gpc1      3PI         null     bycoord   stack_summary  null RINGS.V3 null   LAP.ThreePI.20130717%      r        0      0        null      0        0    |
     61     359.767   -30.2009     100    100   2      stamp      1        gpc1      3PI         null     bycoord   stack_summary  null RINGS.V3 null   LAP.ThreePI.20130717%      r        0      0        null      0        0    |
  • tags/ipp-20130712/pstamp/test/maketestreq

    r35574 r36122  
    4848    'label=s'           => \$label,
    4949    'email=s'           => \$email,
     50    'username=s'        => \$email, # I always forget what the option is
    5051
    5152    'dbname=s'           => \$dbname,
Note: See TracChangeset for help on using the changeset viewer.