IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 28091


Ignore:
Timestamp:
May 25, 2010, 1:38:50 PM (16 years ago)
Author:
eugene
Message:

updates to staticskytool (now mostly working)

Location:
trunk/ippTools
Files:
5 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/notes.txt

    r19092 r28091  
     1
     22010.05.24 EAM
     3
     4  staticskytool:
     5
     6    definebyquery : choose input stacks that meet a list of
     7                    restrictions.  Require a specific list of filters?
     8                    Require a minimum number of inputs?
     9
     10      eg: sst definebyquery -filterlist g,r,i,z,y [-label md04%] [-ra_min x] [-dec_min x] ...
     11
     12      can we do the filter selects in the database?
    113
    2142008.07.19 EAM
  • trunk/ippTools/share/Makefile.am

    r28043 r28091  
    289289     stacktool_sumskyfile.sql \
    290290     stacktool_tosum.sql \
     291     staticskytool_definebyquery_select.sql \
     292     staticskytool_definebyquery_inputs.sql \
     293     staticskytool_inputs.sql \
     294     staticskytool_todo.sql \
     295     staticskytool_result.sql \
    291296     warptool_change_skyfile_data_state.sql \
    292297     warptool_change_run_state.sql \
  • trunk/ippTools/share/pxadmin_create_tables.sql

    r28089 r28091  
    16171617-- A static sky analysis set
    16181618CREATE TABLE staticskyRun (
    1619       ss_id BIGINT AUTO_INCREMENT, -- unique identifier
     1619      sky_id BIGINT AUTO_INCREMENT, -- unique identifier
    16201620      state VARCHAR(64) NOT NULL,  -- state of run (new, full, etc.)
    16211621      workdir VARCHAR(255) NOT NULL, -- working directory
     
    16261626      note VARCHAR(255),             -- note
    16271627      registered TIMESTAMP DEFAULT CURRENT_TIMESTAMP, -- time run was registered
    1628       PRIMARY KEY(ss_id),
     1628      PRIMARY KEY(sky_id),
    16291629      KEY(state),
    16301630      KEY(label),
     
    16351635-- Inputs for static sky analysis
    16361636CREATE TABLE staticskyInput (
    1637       ss_id BIGINT,             -- static sky identifier
     1637      sky_id BIGINT,             -- static sky identifier
    16381638      stack_id BIGINT,          -- stack identifier
    1639       PRIMARY KEY(ss_id,stack_id),
     1639      PRIMARY KEY(sky_id,stack_id),
    16401640      KEY(stack_id),
    1641       FOREIGN KEY(ss_id) REFERENCES staticskyRun(ss_id),
     1641      FOREIGN KEY(sky_id) REFERENCES staticskyRun(sky_id),
    16421642      FOREIGN KEY(stack_id) REFERENCES stackSumSkyfile(stack_id)
    16431643) ENGINE=innodb DEFAULT CHARSET=latin1;
     
    16451645-- Result of static sky analysis
    16461646CREATE TABLE staticskyResult (
    1647       ss_id BIGINT,             -- static sky identifier
     1647      sky_id BIGINT,             -- static sky identifier
    16481648      path_base VARCHAR(255) NOT NULL, -- root name for outputs
    16491649      dtime_phot FLOAT,                -- elapsed time for photometry
     
    16541654      quality SMALLINT NOT NULL,       -- bad quality flag
    16551655      fault SMALLINT NOT NULL,         -- fault code
    1656       PRIMARY KEY(ss_id),
     1656      PRIMARY KEY(sky_id),
    16571657      KEY(good_frac),
    16581658      KEY(fault),
    16591659      KEY(quality),
    1660       FOREIGN KEY(ss_id) REFERENCES staticskyRun(ss_id)
     1660      FOREIGN KEY(sky_id) REFERENCES staticskyRun(sky_id)
    16611661) ENGINE=innodb DEFAULT CHARSET=latin1;
    16621662
  • trunk/ippTools/share/staticskytool_definebyquery.sql

    r27546 r28091  
    1 SELECT
    2     tess_id,
    3     skycell_id,
    4     COUNT(*) AS num,
    5     COUNT(DISTINCT filter) AS num_filter
    6 FROM stackRun
    7 JOIN stackSumSkyfile USING(stack_id)
    8 WHERE stackRun.state = 'full'
    9     AND stackSumSkyfile.fault = 0
    10     AND stackSumSkyfile.quality = 0
    11 -- WHERE hook %s
    12 GROUP BY
    13     tess_id,
    14     skycell_id
     1SELECT
     2       tess_id,
     3       skycell_id,
     4       num_filter
     5FROM (
     6  SELECT
     7      tess_id,
     8      skycell_id,
     9      COUNT(DISTINCT filter) AS num_filter
     10  FROM stackRun
     11  JOIN stackSumSkyfile USING(stack_id)
     12  WHERE stackRun.state = 'full'
     13      AND stackSumSkyfile.fault = 0
     14      AND stackSumSkyfile.quality = 0
     15  -- WHERE hook 1 %s
     16  -- restrict by stackSumSkyfile.good_frac, stackRun.skycell_id, stackRun.label
     17  GROUP BY
     18      tess_id,
     19      skycell_id
     20  ) AS TMP
     21WHERE num_filter == %d
     22
  • trunk/ippTools/src/Makefile.am

    r28075 r28091  
    2222        regtool \
    2323        stacktool \
     24        staticskytool \
    2425        warptool \
    2526        receivetool \
     
    6667        regtool.h \
    6768        stacktool.h \
     69        staticskytool.h \
    6870        warptool.h \
    6971        pubtool.h
     
    197199    stacktoolConfig.c
    198200
     201staticskytool_CFLAGS = $(PSLIB_CFLAGS) $(PSMODULES_CFLAGS) $(IPPDB_CFLAGS)
     202staticskytool_LDADD = $(PSLIB_LIBS) $(PSMODULES_LIBS) $(IPPDB_LIBS) libpxtools.la
     203staticskytool_SOURCES = \
     204    staticskytool.c \
     205    staticskytoolConfig.c
     206
    199207pxadmin_CFLAGS = $(PSLIB_CFLAGS) $(PSMODULES_CFLAGS) $(IPPDB_CFLAGS)
    200208pxadmin_LDADD = $(PSLIB_LIBS) $(PSMODULES_LIBS) $(IPPDB_LIBS) libpxtools.la
  • trunk/ippTools/src/chiptool.c

    r28056 r28091  
    141141    )
    142142{
    143     // start a transaction so we don't end up with an exp without any associted
     143    // start a transaction so we don't end up with an exp without any associated
    144144    // imfiles
    145145    if (!psDBTransaction(config->dbh)) {
  • trunk/ippTools/src/pxtools.c

    r28089 r28091  
    4949
    5050psString pxMergeCodeVersions(psString version1, psString version2) {
    51   psString out = NULL;
    52 
    53   bool mod1 = false;
    54   bool mod2 = false;
    55 
    56   psS32 num1;
    57   psS32 num2;
    58   psS32 numO;
    59 
    60   if (!version1) {
    61     psStringAppend(&out,version2);
     51    psString out = NULL;
     52
     53    bool mod1 = false;
     54    bool mod2 = false;
     55
     56    psS32 num1;
     57    psS32 num2;
     58    psS32 numO;
     59
     60    if (!version1) {
     61        psStringAppend(&out, "%s", version2);
     62        return(out);
     63    }
     64    if (!version2) {
     65        psStringAppend(&out, "%s", version1);
     66        return(out);
     67    }
     68 
     69    if (strchr(version1,'M')) {
     70        psStringSubstitute(&version1,"M","");
     71        mod1 = true;
     72    }
     73    if (strchr(version2,'M')) {
     74        psStringSubstitute(&version2,"M","");
     75        mod2 = true;
     76    }
     77
     78    num1 = strtol(version1,NULL,10);
     79    num2 = strtol(version2,NULL,10);
     80
     81    if (num1 >= num2) {
     82        numO = num1;
     83    }
     84    else {
     85        numO = num2;
     86    }
     87 
     88    psStringAppend(&out,"%" PRId32,numO);
     89    if (mod1 || mod2) {
     90        psStringAppend(&out,"M");
     91    }
    6292    return(out);
    63   }
    64   if (!version2) {
    65     psStringAppend(&out,version1);
    66     return(out);
    67   }
    68  
    69   if (strchr(version1,'M')) {
    70     psStringSubstitute(&version1,"M","");
    71     mod1 = true;
    72   }
    73   if (strchr(version2,'M')) {
    74     psStringSubstitute(&version2,"M","");
    75     mod2 = true;
    76   }
    77 
    78   num1 = strtol(version1,NULL,10);
    79   num2 = strtol(version2,NULL,10);
    80 
    81   if (num1 >= num2) {
    82     numO = num1;
    83   }
    84   else {
    85     numO = num2;
    86   }
    87  
    88   psStringAppend(&out,"%" PRId32,numO);
    89   if (mod1 || mod2) {
    90     psStringAppend(&out,"M");
    91   }
    92   return(out);
    9393}
    9494
     
    9696                         psS64 *maskfrac_npix, psF32 *maskfrac_static, psF32 *maskfrac_dynamic,
    9797                         psF32 *maskfrac_magic, psF32 *maskfrac_advisory) {
    98   psString query = pxDataGet(dbQFile);
     98    psString query = pxDataGet(dbQFile);
    9999/*   psString text_id = NULL; */
    100100/*   psStringAppend(&text_id," %" PRId64,stage_id); */
    101101/*   psStringSubstitute(&query,text_id,"@STAGE_ID@"); */
    102102/*   psFree(text_id); */
    103   if (!p_psDBRunQueryF(config->dbh, query, stage_id)) {
    104     psError(PS_ERR_UNKNOWN, false, "database error");
     103    if (!p_psDBRunQueryF(config->dbh, query, stage_id)) {
     104        psError(PS_ERR_UNKNOWN, false, "database error");
     105        psFree(query);
     106        return(false);
     107    }
    105108    psFree(query);
    106     return(false);
    107   }
    108   psFree(query);
    109   psArray *output = p_psDBFetchResult(config->dbh);
    110   if (!output) {
    111     psError(PS_ERR_UNKNOWN, false, "database error");
    112     return(false);
    113   }
    114  
    115   for (long i = 0; i < psArrayLength(output); i++) {
    116     psMetadata *row = output->data[i];
    117 
    118     psS32 this_npix = psMetadataLookupS32(NULL, row, "maskfrac_npix");
    119     psF32 this_static = psMetadataLookupF32(NULL, row, "maskfrac_static");
    120     psF32 this_dynamic = psMetadataLookupF32(NULL, row, "maskfrac_dynamic");
    121     psF32 this_magic = psMetadataLookupF32(NULL, row, "maskfrac_magic");
    122     psF32 this_advisory = psMetadataLookupF32(NULL, row, "maskfrac_advisory");
    123     psString this_version = psMetadataLookupStr(NULL, row, "software_ver");
    124 
    125     *software_ver = pxMergeCodeVersions(*software_ver,this_version);
     109    psArray *output = p_psDBFetchResult(config->dbh);
     110    if (!output) {
     111        psError(PS_ERR_UNKNOWN, false, "database error");
     112        return(false);
     113    }
     114 
     115    for (long i = 0; i < psArrayLength(output); i++) {
     116        psMetadata *row = output->data[i];
     117
     118        psS32 this_npix = psMetadataLookupS32(NULL, row, "maskfrac_npix");
     119        psF32 this_static = psMetadataLookupF32(NULL, row, "maskfrac_static");
     120        psF32 this_dynamic = psMetadataLookupF32(NULL, row, "maskfrac_dynamic");
     121        psF32 this_magic = psMetadataLookupF32(NULL, row, "maskfrac_magic");
     122        psF32 this_advisory = psMetadataLookupF32(NULL, row, "maskfrac_advisory");
     123        psString this_version = psMetadataLookupStr(NULL, row, "software_ver");
     124
     125        *software_ver = pxMergeCodeVersions(*software_ver,this_version);
    126126/*     printf("%ld : %d %f %f %f %f <-> %ld %f %f %f %f\n",i,this_npix,this_static,this_dynamic,this_magic,this_advisory, */
    127127/*         *maskfrac_npix,*maskfrac_static,*maskfrac_dynamic,*maskfrac_magic,*maskfrac_advisory); */
    128     if (this_npix > 0) {
    129       *maskfrac_static = ((*maskfrac_static * *maskfrac_npix) + (this_npix * this_static)) / (this_npix + *maskfrac_npix);
    130       *maskfrac_dynamic = ((*maskfrac_dynamic * *maskfrac_npix) + (this_npix * this_dynamic)) / (this_npix + *maskfrac_npix);
    131       *maskfrac_magic = ((*maskfrac_magic * *maskfrac_npix) + (this_npix * this_magic)) / (this_npix + *maskfrac_npix);
    132       *maskfrac_advisory = ((*maskfrac_advisory * *maskfrac_npix) + (this_npix * this_advisory)) / (this_npix + *maskfrac_npix);
    133       *maskfrac_npix += this_npix;
    134     }
    135   }
    136   psFree(output);
    137   return(true);
     128        if (this_npix > 0) {
     129            *maskfrac_static = ((*maskfrac_static * *maskfrac_npix) + (this_npix * this_static)) / (this_npix + *maskfrac_npix);
     130            *maskfrac_dynamic = ((*maskfrac_dynamic * *maskfrac_npix) + (this_npix * this_dynamic)) / (this_npix + *maskfrac_npix);
     131            *maskfrac_magic = ((*maskfrac_magic * *maskfrac_npix) + (this_npix * this_magic)) / (this_npix + *maskfrac_npix);
     132            *maskfrac_advisory = ((*maskfrac_advisory * *maskfrac_npix) + (this_npix * this_advisory)) / (this_npix + *maskfrac_npix);
     133            *maskfrac_npix += this_npix;
     134        }
     135    }
     136    psFree(output);
     137    return(true);
    138138}
    139139
    140140bool pxSetRunSoftware(pxConfig *config, const psString tableName, const psString stage_id_name, const psS64 stage_id,
    141141                      psString software_ver) {
    142   char *query = "UPDATE %s SET software_ver = '%s' WHERE %s = %" PRId64;
     142    char *query = "UPDATE %s SET software_ver = '%s' WHERE %s = %" PRId64;
    143143/*   printf(query,tableName,software_ver,stage_id_name,stage_id); */
    144   if (!p_psDBRunQueryF(config->dbh,query,tableName,software_ver,stage_id_name,stage_id)) {
    145     psError(PS_ERR_UNKNOWN, false,
    146             "failed to set software version for %s %" PRId64,stage_id_name,stage_id);
    147     return(false);
    148   }
    149  
    150   return(true);
     144    if (!p_psDBRunQueryF(config->dbh,query,tableName,software_ver,stage_id_name,stage_id)) {
     145        psError(PS_ERR_UNKNOWN, false,
     146                "failed to set software version for %s %" PRId64,stage_id_name,stage_id);
     147        return(false);
     148    }
     149 
     150    return(true);
    151151}
    152152
     
    154154                      psS64 maskfrac_npix, psF32 maskfrac_static, psF32 maskfrac_dynamic,
    155155                      psF32 maskfrac_magic, psF32 maskfrac_advisory) {
    156   char *query = "UPDATE %s SET maskfrac_npix = %f, maskfrac_static = %f, maskfrac_dynamic = %f, maskfrac_magic = %f, maskfrac_advisory = %f WHERE %s = %" PRId64;
    157   if (!p_psDBRunQueryF(config->dbh,query,tableName,(float) maskfrac_npix,maskfrac_static,
    158                       maskfrac_dynamic, maskfrac_magic,maskfrac_advisory,stage_id_name,stage_id)) {
    159     psError(PS_ERR_UNKNOWN, false,
    160             "failed to set maskfrac stats for %s %" PRId64,stage_id_name,stage_id);
    161     return(false);
    162   }
    163  
    164 
    165 
    166   return(true);
     156    char *query = "UPDATE %s SET maskfrac_npix = %f, maskfrac_static = %f, maskfrac_dynamic = %f, maskfrac_magic = %f, maskfrac_advisory = %f WHERE %s = %" PRId64;
     157    if (!p_psDBRunQueryF(config->dbh,query,tableName,(float) maskfrac_npix,maskfrac_static,
     158                        maskfrac_dynamic, maskfrac_magic,maskfrac_advisory,stage_id_name,stage_id)) {
     159        psError(PS_ERR_UNKNOWN, false,
     160                "failed to set maskfrac stats for %s %" PRId64,stage_id_name,stage_id);
     161        return(false);
     162    }
     163 
     164
     165
     166    return(true);
    167167}
    168168
     
    293293    char *comma = ",";
    294294
    295 #   define addColumn(_tab, _val) \
    296         do { \
    297             if (_val) { \
    298                 psStringAppend(pQuery, "%s %s.%s = '%s'", separator, _tab, #_val, _val); \
    299                 separator = comma; \
    300             } \
    301         } while (0)
     295#   define addColumn(_tab, _val)                                        \
     296    do {                                                                \
     297        if (_val) {                                                     \
     298            psStringAppend(pQuery, "%s %s.%s = '%s'", separator, _tab, #_val, _val); \
     299            separator = comma;                                          \
     300        }                                                               \
     301    } while (0)
    302302
    303303    addColumn(runTable, state);
     
    436436        if (import_version && strcmp(import_version, schema_version)) {
    437437            psError(PS_ERR_UNKNOWN, true, "input file schema_version: %s does not match data base: %s",
    438                 import_version, schema_version);
     438                    import_version, schema_version);
    439439            return false;
    440440        } else if (!import_version) {
  • trunk/ippTools/src/staticskytool.c

    r27963 r28091  
    11/*
    2  * stacktool.c
     2 * staticskytool.c
    33 *
    44 * Copyright (C) 2007-2010  Joshua Hoblitt, Paul Price
     
    2929
    3030#include "pxtools.h"
    31 #include "stacktool.h"
     31#include "staticskytool.h"
    3232
    3333static bool definebyqueryMode(pxConfig *config);
    34 static bool definerunMode(pxConfig *config);
    3534static bool updaterunMode(pxConfig *config);
    36 static bool addinputskyfileMode(pxConfig *config);
    37 static bool inputskyfileMode(pxConfig *config);
    38 static bool tosumMode(pxConfig *config);
    39 static bool addsumskyfileMode(pxConfig *config);
    40 static bool sumskyfileMode(pxConfig *config);
    41 static bool revertsumskyfileMode(pxConfig *config);
    42 static bool pendingcleanuprunMode(pxConfig *config);
    43 static bool pendingcleanupskyfileMode(pxConfig *config);
    44 static bool donecleanupMode(pxConfig *config);
    45 static bool updatesumskyfileMode(pxConfig *config);
     35static bool inputsMode(pxConfig *config);
     36static bool todoMode(pxConfig *config);
     37static bool addresultMode(pxConfig *config);
     38static bool resultMode(pxConfig *config);
     39static bool revertMode(pxConfig *config);
     40static bool updateresult(pxConfig *config);
    4641static bool exportrunMode(pxConfig *config);
    4742static bool importrunMode(pxConfig *config);
    48 
    49 static bool setstackRunState(pxConfig *config, psS64 stack_id, const char *state);
    5043
    5144# define MODECASE(caseName, func) \
     
    6053    psLibInit(NULL);
    6154
    62     pxConfig *config = stacktoolConfig(NULL, argc, argv);
     55    pxConfig *config = staticskytoolConfig(NULL, argc, argv);
    6356    if (!config) {
    6457        psError(PXTOOLS_ERR_CONFIG, false, "failed to configure");
     
    6760
    6861    switch (config->mode) {
    69         MODECASE(STACKTOOL_MODE_DEFINEBYQUERY, definebyqueryMode);
    70         MODECASE(STACKTOOL_MODE_UPDATERUN,     updaterunMode);
    71         MODECASE(STACKTOOL_MODE_INPUTS,        inputsMode);
    72         MODECASE(STACKTOOL_MODE_TODO,          todoMode);
    73         MODECASE(STACKTOOL_MODE_ADDRESULT,     addresultMode);
    74         MODECASE(STACKTOOL_MODE_RESULT,        resultMode);
    75         MODECASE(STACKTOOL_MODE_REVERT,        revertMode);
    76         MODECASE(STACKTOOL_MODE_UPDATERESULT,  updateresultMode);
    77         MODECASE(STACKTOOL_MODE_EXPORTRUN,     exportrunMode);
    78         MODECASE(STACKTOOL_MODE_IMPORTRUN,     importrunMode);
     62        MODECASE(STATICSKYTOOL_MODE_DEFINEBYQUERY,    definebyqueryMode);
     63        MODECASE(STATICSKYTOOL_MODE_UPDATERUN,         updaterunMode);
     64        MODECASE(STATICSKYTOOL_MODE_INPUTS,            inputsMode);
     65        MODECASE(STATICSKYTOOL_MODE_TODO,              todoMode);
     66        MODECASE(STATICSKYTOOL_MODE_ADDRESULT,         addresultMode);
     67        MODECASE(STATICSKYTOOL_MODE_RESULT,            resultMode);
     68        MODECASE(STATICSKYTOOL_MODE_REVERT,            revertMode);
     69        MODECASE(STATICSKYTOOL_MODE_UPDATERESULT,      updateresult);
     70        MODECASE(STATICSKYTOOL_MODE_EXPORTRUN,         exportrunMode);
     71        MODECASE(STATICSKYTOOL_MODE_IMPORTRUN,         importrunMode);
    7972        default:
    8073            psAbort("invalid option (this should not happen)");
     
    114107    PXOPT_LOOKUP_TIME(registered, config->args, "-set_registered", false, false);
    115108
    116     psMetadata *where = psMetadataAlloc();
    117     psMetadata *having = psMetadataAlloc(); // HAVING clause
    118 
    119     PXOPT_COPY_F32(config->args, where, "-select_good_frac_min", "stackSumSkyfile.good_frac", ">=");
    120     PXOPT_COPY_STR(config->args, where, "-select_skycell_id",    "stackRun.skycell_id",       "==");
    121     pxAddLabelSearchArgs(config, where, "-select_label",         "stackRun.label",            "LIKE");
    122     pxAddLabelSearchArgs(config, where, "-select_filter",        "stackRun.filter",           "LIKE");
    123 
    124     // these are used to build the HAVING restriction
    125     PXOPT_COPY_S32(config->args, having, "-min_num",    "num",        ">=");
    126     PXOPT_COPY_S32(config->args, having, "-min_filter", "num_filter", ">=");
     109    psMetadata *whereMD = psMetadataAlloc();
     110
     111    PXOPT_COPY_STR(config->args, whereMD, "-select_skycell_id",    "stackRun.skycell_id",       "==");
     112    PXOPT_COPY_STR(config->args, whereMD, "-select_tess_id",       "stackRun.tess_id",          "==");
     113    PXOPT_COPY_F32(config->args, whereMD, "-select_good_frac_min", "stackSumSkyfile.good_frac", ">=");
     114    pxAddLabelSearchArgs(config, whereMD, "-select_label",         "stackRun.label",            "LIKE");
     115    pxAddLabelSearchArgs(config, whereMD, "-select_filter",        "stackRun.filter",           "LIKE");
     116
     117    // find the number of requested filters:
     118    psMetadataItem *filters = psMetadataLookup(config->args, "-select_filter");
     119    psAssert (filters, "-select_filter must exist");
     120    psAssert (filters->type == PS_DATA_METADATA_MULTI, "-select_filter should be a multi container");
     121    psAssert (filters->data.list->n, "-select_filter should at least have a place-holder");
     122    int num_filter = filters->data.list->n;
     123    if (num_filter < 2) {
     124        psError(PXTOOLS_ERR_CONFIG, false, "invalid request: only 1 filter selected");
     125        psFree(whereMD);
     126        return false;
     127    }
    127128
    128129    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    129130    PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
    130 
    131     if (!psListLength(where->list)) {
    132         psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
    133         psFree(where);
    134         psFree(having);
    135         return false;
    136     }
    137131
    138132    psString select = pxDataGet("staticskytool_definebyquery_select.sql");
    139133    if (!select) {
    140134        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    141         psFree(where);
    142         psFree(having);
    143         return false;
    144     }
    145 
    146     psString where1 = psStringCopy("");
    147     if (psListLength(where->list)) {
    148         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    149         psStringAppend(&where1, "\nAND %s", whereClause);
    150         psFree(whereClause);
    151     }
    152 
    153     psString where2 = psStringCopy("");
    154     if (label) {
    155         psStringAppend(&where2, "\nWHERE stackRun.label = '%s'", label);
    156     }
    157 
    158     // Restriction on aggregated quantities using HAVING
    159     {
    160         psString havingClause = NULL;   // HAVING string
    161         if (psListLength(having->list)) {
    162             havingClause = psDBGenerateWhereConditionSQL(having, NULL);
    163         }
    164 
    165         if (min_new > 0) {
    166             if (havingClause) {
    167                 psStringAppend(&havingClause, " AND");
    168             }
    169             psStringAppend(&havingClause,
    170                            " (num_warp - num_stack >= %d OR (num_warp >= %d AND num_stack IS NULL))",
    171                            min_new, min_new);
    172         }
    173         if (isfinite(min_frac)) {
    174             if (havingClause) {
    175                 psStringAppend(&havingClause, " AND");
    176             }
    177             // Avoiding division by zero
    178             psStringAppend(&havingClause, " (num_warp >= %f * num_stack OR num_stack IS NULL)",
    179                            (double)min_frac);
    180         }
    181         if (havingClause) {
    182             psStringAppend(&select, " HAVING %s", havingClause);
    183             psFree(havingClause);
    184         }
    185     }
    186     psFree(having);
    187 
    188     if (!p_psDBRunQueryF(config->dbh, select, where1, where2)) {
     135        psFree(whereMD);
     136        return false;
     137    }
     138
     139    if (!psListLength(whereMD->list)) {
     140        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
     141        psFree(whereMD);
     142        return false;
     143    }
     144
     145    // this 'where' is used for both staticskytool_definebyquery_select.sql and staticskytool_definebyquery_inputs.sql
     146    psString where = NULL;
     147    psString whereClause = psDBGenerateWhereConditionSQL(whereMD, NULL);
     148    psStringAppend(&where, "\nAND %s", whereClause);
     149    psFree(whereClause);
     150    psFree(whereMD);
     151
     152    if (!p_psDBRunQueryF(config->dbh, select, where, num_filter)) {
    189153        psError(PS_ERR_UNKNOWN, false, "database error");
    190154        psFree(select);
    191         psFree(where1);
    192         psFree(where2);
    193155        return false;
    194156    }
    195157    psFree(select);
    196     psFree(where1);
    197     psFree(where2);
     158
     159    // we now have a list of (tess_id, skycell_id) that (potentially) meet out needs
     160    // we now need to loop over all of these and for each pair, select the best set of
     161    // inputs
    198162
    199163    psArray *output = p_psDBFetchResult(config->dbh);
     
    212176    }
    213177    if (!psArrayLength(output)) {
    214         psWarning("stacktool: no rows found");
     178        psWarning("staticskytool: no rows found");
    215179        psFree(output);
    216180        psFree(where);
     
    219183    if (pretend) {
    220184        // negative simple so the default is true
    221         if (!ippdbPrintMetadatas(stdout, output, "stackSkycells", !simple)) {
     185        if (!ippdbPrintMetadatas(stdout, output, "staticskyInput", !simple)) {
    222186            psError(PS_ERR_UNKNOWN, false, "failed to print array");
    223187            psFree(output);
     
    230194    }
    231195
    232     psString insert = NULL;             // Insertion query
    233     if (randomLimit > 0) {
    234         insert = pxDataGet("stacktool_definebyquery_insert_random_part1.sql");
    235     } else {
    236         insert = pxDataGet("stacktool_definebyquery_insert.sql");
    237     }
    238     if (!insert) {
     196    psString inputsSQL = pxDataGet("staticskytool_definebyquery_inputs.sql");
     197    if (!inputsSQL) {
    239198        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    240199        psFree(where);
     
    242201    }
    243202
    244     if (psListLength(where->list)) {
    245         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    246         psStringAppend(&insert, " AND %s", whereClause);
    247         psFree(whereClause);
    248     }
    249     psFree(where);
    250 
    251     if (randomLimit > 0) {
    252         psString part2 = pxDataGet("stacktool_definebyquery_insert_random_part2.sql");
    253         if (!part2) {
    254             psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
    255             psFree(insert);
    256             return false;
    257         }
    258         psStringAppend(&insert, "%s", part2);
    259         psFree(part2);
    260     }
    261 
    262     if (!psDBTransaction(config->dbh)) {
    263         psError(PS_ERR_UNKNOWN, false, "database error");
    264         psFree(where);
    265         return false;
    266     }
    267 
    268     psArray *list = psArrayAllocEmpty(16); // List of runs, to print
    269203    for (long i = 0; i < output->n; i++) {
    270204        psMetadata *row = output->data[i]; // Row from select
     
    276210            psError(PS_ERR_UNKNOWN, false, "failed to lookup skycell_id");
    277211            psFree(output);
    278             psFree(insert);
    279             psFree(list);
     212            psFree(inputsSQL);
    280213            if (!psDBRollback(config->dbh)) {
    281214                psError(PS_ERR_UNKNOWN, false, "database error");
     
    288221            psError(PS_ERR_UNKNOWN, false, "failed to lookup tess_id");
    289222            psFree(output);
    290             psFree(insert);
    291             psFree(list);
     223            psFree(inputsSQL);
    292224            if (!psDBRollback(config->dbh)) {
    293225                psError(PS_ERR_UNKNOWN, false, "database error");
     
    296228        }
    297229
    298         psString filter = psMetadataLookupStr(&status, row, "filter");
    299         if (!status) {
    300             psError(PS_ERR_UNKNOWN, false, "failed to lookup filter");
     230        // query for the inputs
     231        if (!p_psDBRunQueryF(config->dbh, inputsSQL, tess_id, skycell_id, where)) {
     232            psError(PS_ERR_UNKNOWN, false, "database error");
    301233            psFree(output);
    302             psFree(insert);
    303             psFree(list);
    304             if (!psDBRollback(config->dbh)) {
    305                 psError(PS_ERR_UNKNOWN, false, "database error");
    306             }
    307             return false;
    308         }
    309 
    310         // create a new stackRun for this stack
    311         stackRunRow *run = stackRunRowAlloc(
    312             0,                          // ID
    313             "new",                      // state
    314             workdir,
    315             label,
    316             data_group ? data_group : label,
    317             dist_group,
    318             reduction,
    319             dvodb,
    320             registered,
    321             skycell_id,
    322             tess_id,
    323             filter,
    324             note);
    325 
    326         if (!stackRunInsertObject(config->dbh, run)) {
    327             if (!psDBRollback(config->dbh)) {
    328                 psError(PS_ERR_UNKNOWN, false, "database error");
    329             }
    330             psError(PS_ERR_UNKNOWN, false, "database error");
     234            psFree(inputsSQL);
     235            return false;
     236        }
     237       
     238        psArray *inputs = p_psDBFetchResult(config->dbh);
     239        if (!inputs) {
     240            psErrorCode err = psErrorCodeLast();
     241            switch (err) {
     242              case PS_ERR_DB_CLIENT:
     243                psError(PXTOOLS_ERR_SYS, false, "database error");
     244              case PS_ERR_DB_SERVER:
     245                psError(PXTOOLS_ERR_PROG, false, "database error");
     246              default:
     247                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     248            }
     249            psFree(inputs);
    331250            psFree(output);
    332             psFree(run);
    333             psFree(insert);
    334             psFree(list);
    335             if (!psDBRollback(config->dbh)) {
    336                 psError(PS_ERR_UNKNOWN, false, "database error");
    337             }
    338             return false;
    339         }
    340 
    341         // figure out the new stack_id
    342         psS64 stack_id = psDBLastInsertID(config->dbh);
    343         run->stack_id = stack_id;
    344 
    345         psArrayAdd(list, list->n, run);
    346         psFree(run);
    347 
    348         // Create a suitable insertion query for this run
    349         psString thisInsert = psStringCopy(insert);
    350         psString idString = NULL;
    351         psStringAppend(&idString, "%" PRId64, stack_id);
    352         psStringSubstitute(&thisInsert, idString, "@STACK_ID@");
    353         psFree(idString);
    354 
    355         // replace @FILTER@, @SKYCELL_ID@, @RANDOM_LIMIT@
    356         psStringSubstitute(&thisInsert, filter, "@FILTER@");
    357         psStringSubstitute(&thisInsert, skycell_id, "@SKYCELL_ID@");
    358 
    359         if (randomLimit > 0) {
    360           psString limString = NULL;
    361           psStringAppend(&limString, "%d", randomLimit);
    362           psStringSubstitute(&thisInsert, limString, "@RANDOM_LIMIT@");
    363           psFree(limString);
    364         }
    365 
    366         // XXX this insert uses a select to generate the list of warp_ids for the stack,
    367         // we have applied a set of criteria above (WHERE) to select the relevant warps
    368         // this insert needs to use exactly the same restrictions (race condition is probably not critical)
    369         // the insert below seems to only restrict matches to the skycell, tess, and filter
    370         if (!p_psDBRunQuery(config->dbh, thisInsert)) {
    371             psError(PS_ERR_UNKNOWN, false, "database error");
    372             psFree(thisInsert);
    373             psFree(insert);
     251            psFree(inputsSQL);
     252            return false;
     253        }
     254        if (!psArrayLength(inputs)) {
     255            psWarning("staticskytool ERROR: no rows found for known tess_id, skycell_id?");
     256            continue;
     257        }
     258
     259        // XXX if we are unable to guarantee that all selected inputs have all and only the
     260        // requested filters, see the code at the bottom of this file (ifdef'ed out for now)
     261
     262        // insert a new staticsky entry and find its new id
     263        if (!psDBTransaction(config->dbh)) {
     264            psError(PS_ERR_UNKNOWN, false, "database error");
     265            psFree(inputs);
    374266            psFree(output);
    375             psFree(list);
    376             if (!psDBRollback(config->dbh)) {
    377                 psError(PS_ERR_UNKNOWN, false, "database error");
    378             }
    379             return false;
    380         }
    381         psFree(thisInsert);
    382 
    383 # if (0)
    384         {
    385           psArray *output = p_psDBFetchResult(config->dbh);
    386           if (!output) {
    387             psErrorCode err = psErrorCodeLast();
    388             switch (err) {
    389             case PS_ERR_DB_CLIENT:
    390               psError(PXTOOLS_ERR_SYS, false, "database error");
    391             case PS_ERR_DB_SERVER:
    392               psError(PXTOOLS_ERR_PROG, false, "database error");
    393             default:
    394               psError(PXTOOLS_ERR_PROG, false, "unknown error");
    395             }
    396             psFree(where);
    397             return false;
    398           }
    399           if (!psArrayLength(output)) {
    400             psWarning("stacktool (definebyquery, insert): no rows found");
     267            psFree(inputsSQL);
     268            return false;
     269        }
     270
     271        // create a chipRun
     272        if (!staticskyRunInsert(config->dbh,
     273                                0x0,         // sky_id
     274                                "new",       // state
     275                                workdir,
     276                                label,
     277                                data_group,
     278                                dist_group,
     279                                reduction,
     280                                registered,
     281                                note
     282                )
     283            ) {
     284            if (!psDBRollback(config->dbh)) {
     285                psError(PS_ERR_UNKNOWN, false, "database error failed to rollback transaction");
     286            }
     287            psError(PS_ERR_UNKNOWN, false, "database error");
     288            psFree(inputs);
    401289            psFree(output);
    402             psFree(where);
    403             return true;
    404           }
    405           // negative simple so the default is true
    406           if (!ippdbPrintMetadatas(stdout, output, "stackSkycells", !simple)) {
    407             psError(PS_ERR_UNKNOWN, false, "failed to print array");
    408             psFree(output);
    409             psFree(where);
    410             return false;
    411           }
    412           psFree(output);
    413           psFree(where);
    414           return true;
    415         }
    416 # endif
    417 
    418     }
     290            psFree(inputsSQL);
     291            return false;
     292        }
     293
     294        psS64 sky_id =  psDBLastInsertID(config->dbh);
     295
     296        // loop over the possible inputs and record only the valid ones
     297        for (int j = 0; j < inputs->n; j++) {
     298            psMetadata *inputRow = inputs->data[j]; // Row from select
     299           
     300            // pull out the skycell_id, tess_id, filter
     301            psS64 stack_id = psMetadataLookupS64(&status, inputRow, "stack_id");
     302            psAssert(status, "failed to find stack_id?");
     303           
     304            // add a staticskyInput entry
     305            if (!staticskyInputInsert(config->dbh, sky_id, stack_id)) {
     306                if (!psDBRollback(config->dbh)) {
     307                    psError(PS_ERR_UNKNOWN, false, "database error failed to rollback transaction");
     308                }
     309                psError(PS_ERR_UNKNOWN, false, "database error");
     310                psFree(inputs);
     311                psFree(output);
     312                psFree(inputsSQL);
     313                return false;
     314            }
     315        }
     316        psFree (inputs);
     317       
     318        if (!psDBCommit(config->dbh)) {
     319            psError(PS_ERR_UNKNOWN, false, "database error");
     320            psFree(output);
     321            psFree(inputsSQL);
     322            return false;
     323        }
     324    }
     325    psFree(inputsSQL);
    419326    psFree(output);
    420 
    421     if (!psDBCommit(config->dbh)) {
    422         psError(PS_ERR_UNKNOWN, false, "database error");
    423         psFree(list);
    424         return false;
    425     }
    426 
    427     if (!stackRunPrintObjects(stdout, list, !simple)) {
    428         psError(PS_ERR_UNKNOWN, false, "failed to print object");
    429         psFree(list);
    430         return false;
    431     }
    432     psFree(list);
    433327    return true;
    434328}
     
    438332    PS_ASSERT_PTR_NON_NULL(config, false);
    439333
    440 #ifdef notdef
    441     PXOPT_LOOKUP_S64(stack_id, config->args, "-stack_id", false, false);
    442     PXOPT_LOOKUP_STR(state, config->args, "-state", true, false);
    443     PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
    444 #endif
    445334    psMetadata *where = psMetadataAlloc();
    446     PXOPT_COPY_S64(config->args, where, "-stack_id",  "stack_id",   "==");
    447     PXOPT_COPY_STR(config->args, where, "-label",     "label",     "==");
    448     PXOPT_COPY_STR(config->args, where, "-state",     "state",     "==");
     335    PXOPT_COPY_S64(config->args, where, "-sky_id",  "sky_id",   "==");
     336    PXOPT_COPY_STR(config->args, where, "-label",   "label",    "==");
     337    PXOPT_COPY_STR(config->args, where, "-state",   "state",    "==");
    449338    if (!psListLength(where->list)) {
    450339        psFree(where);
     
    453342    }
    454343
    455     psString query = psStringCopy("UPDATE stackRun");
     344    psString query = psStringCopy("UPDATE staticskyRun");
    456345
    457346    // pxUpdateRun gets parameters from config->args and updates
    458     bool result = pxUpdateRun(config, where, &query, "stackRun", "stack_id", "stackSumSkyfile", true);
    459 
     347    bool result = pxUpdateRun(config, where, &query, "staticskyRun", "sky_id", "staticskyResult", true);
    460348    psFree(query);
    461349    psFree(where);
    462350
    463351    return result;
    464 
    465 #ifdef notdef
    466     // Hack-y work around to make stacktool more like the other tools, without breaking other stuff (hopefully).
    467 
    468     if ((state)&&(stack_id)) {
    469         // set detRun.state to state
    470         return setstackRunState(config, stack_id, state);
    471     }
    472 
    473     if ((state)&&(label)) {
    474       return setstackRunStateByLabel(config, label, state);
    475     }
    476 
    477     psError(PS_ERR_UNKNOWN, false, "Required options not found.");
    478     return false;
    479 #endif
    480352}
    481353
     
    485357    PS_ASSERT_PTR_NON_NULL(config, false);
    486358
    487     // XXX require at least a stack id (add better search options)
    488     PXOPT_LOOKUP_S64(stack_id, config->args, "-stack_id", true, false);
     359    // XXX require at least a sky id (add better search options)
     360    PXOPT_LOOKUP_S64(sky_id, config->args, "-sky_id", true, false);
    489361
    490362    psMetadata *where = psMetadataAlloc();
    491     PXOPT_COPY_S64(config->args, where, "-warp_id", "warp_id", "==");
    492     PXOPT_COPY_S64(config->args, where, "-stack_id", "stack_id", "==");
     363    PXOPT_COPY_S64(config->args, where, "-sky_id", "sky_id", "==");
    493364
    494365    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    495366    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    496367
    497     psString query = pxDataGet("stacktool_inputskyfile.sql");
     368    psString query = pxDataGet("staticskytool_inputs.sql");
    498369    if (!query) {
    499370        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     
    502373
    503374    if (psListLength(where->list)) {
    504         psString whereClause = psDBGenerateWhereConditionSQL(where, "stackInputSkyfile");
    505         psStringAppend(&query, " AND %s", whereClause);
     375        psString whereClause = psDBGenerateWhereConditionSQL(where, "staticskyInput");
     376        psStringAppend(&query, " WHERE %s", whereClause);
    506377        psFree(whereClause);
    507378    }
     
    537408    }
    538409    if (!psArrayLength(output)) {
    539         psTrace("stacktool", PS_LOG_INFO, "no rows found");
     410        psTrace("staticskytool", PS_LOG_INFO, "no rows found");
    540411        psFree(output);
    541412        return true;
     
    544415    if (psArrayLength(output)) {
    545416        // negative simple so the default is true
    546         if (!ippdbPrintMetadatas(stdout, output, "stackInputSkyfile", !simple)) {
     417        if (!ippdbPrintMetadatas(stdout, output, "staticskyInput", !simple)) {
    547418            psError(PS_ERR_UNKNOWN, false, "failed to print array");
    548419            psFree(output);
     
    561432    PS_ASSERT_PTR_NON_NULL(config, false);
    562433
    563     psMetadata *where = psMetadataAlloc();
    564     PXOPT_COPY_S64(config->args, where, "-warp_id", "warp_id", "==");
    565     PXOPT_COPY_S64(config->args, where, "-stack_id", "stack_id", "==");
    566     pxAddLabelSearchArgs (config, where, "-label", "stackRun.label", "==");
     434    psMetadata *whereMD = psMetadataAlloc();
     435    PXOPT_COPY_S64(config->args, whereMD, "-sky_id", "sky_id", "==");
     436    pxAddLabelSearchArgs (config, whereMD, "-label", "staticskyRun.label", "==");
    567437
    568438    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
    569439    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    570440
    571     psString query = pxDataGet("stacktool_tosum.sql");
     441    psString query = pxDataGet("staticskytool_todo.sql");
    572442    if (!query) {
    573443        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     
    575445    }
    576446
    577     if (psListLength(where->list)) {
    578         psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    579         psStringAppend(&query, " AND %s", whereClause);
    580         psFree(whereClause);
    581     }
    582     psFree(where);
     447    if (!psListLength(whereMD->list)) {
     448        psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required");
     449        psFree(whereMD);
     450        return false;
     451    }
     452
     453    psString where = NULL;
     454    psString whereClause = psDBGenerateWhereConditionSQL(whereMD, NULL);
     455    psStringAppend(&where, "\n AND %s", whereClause);
     456    psFree(whereClause);
     457    psFree(whereMD);
    583458
    584459    // treat limit == 0 as "no limit"
     
    589464    }
    590465
    591     if (!p_psDBRunQuery(config->dbh, query)) {
     466    // the where clause is required and matches the WHERE hook format string
     467    if (!p_psDBRunQueryF(config->dbh, query, where)) {
    592468        psError(PS_ERR_UNKNOWN, false, "database error");
    593469        psFree(query);
     
    611487    }
    612488    if (!psArrayLength(output)) {
    613         psTrace("stacktool", PS_LOG_INFO, "no rows found");
     489        psTrace("staticskytool", PS_LOG_INFO, "no rows found");
    614490        psFree(output);
    615491        return true;
     
    618494    if (psArrayLength(output)) {
    619495        // negative simple so the default is true
    620         if (!ippdbPrintMetadatas(stdout, output, "stackSumSkyfile", !simple)) {
     496        if (!ippdbPrintMetadatas(stdout, output, "staticskyResult", !simple)) {
    621497            psError(PS_ERR_UNKNOWN, false, "failed to print array");
    622498            psFree(output);
     
    626502
    627503    psFree(output);
    628 
    629504    return true;
    630505}
    631506
    632 
    633507static bool addresultMode(pxConfig *config)
    634508{
     
    636510
    637511    // required
     512    PXOPT_LOOKUP_S64(sky_id, config->args, "-sky_id", true, false);
    638513    PXOPT_LOOKUP_S64(stack_id, config->args, "-stack_id", true, false);
    639514
    640515    // optional
    641     PXOPT_LOOKUP_STR(uri, config->args, "-uri", false, false);
    642516    PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", false, false);
    643     PXOPT_LOOKUP_F64(bg, config->args, "-bg", false, false);
    644     PXOPT_LOOKUP_F64(bg_stdev, config->args, "-bg_stdev", false, false);
    645     PXOPT_LOOKUP_F32(dtime_stack, config->args, "-dtime_stack", false, false);
    646     PXOPT_LOOKUP_F32(dtime_match_mean, config->args, "-dtime_match_mean", false, false);
    647     PXOPT_LOOKUP_F32(dtime_match_stdev, config->args, "-dtime_match_stdev", false, false);
    648     PXOPT_LOOKUP_F32(dtime_initial, config->args, "-dtime_initial", false, false);
    649     PXOPT_LOOKUP_F32(dtime_reject, config->args, "-dtime_reject", false, false);
    650     PXOPT_LOOKUP_F32(dtime_final, config->args, "-dtime_final", false, false);
    651517    PXOPT_LOOKUP_F32(dtime_phot, config->args, "-dtime_phot", false, false);
    652518    PXOPT_LOOKUP_F32(dtime_script, config->args, "-dtime_script", false, false);
    653     PXOPT_LOOKUP_F32(match_mean, config->args, "-match_mean", false, false);
    654     PXOPT_LOOKUP_F32(match_stdev, config->args, "-match_stdev", false, false);
    655     PXOPT_LOOKUP_F32(match_rms, config->args, "-match_rms", false, false);
    656     PXOPT_LOOKUP_F32(stamps_mean, config->args, "-stamps_mean", false, false);
    657     PXOPT_LOOKUP_F32(stamps_stdev, config->args, "-stamps_stdev", false, false);
    658     PXOPT_LOOKUP_S32(stamps_min, config->args, "-stamps_min", false, false);
    659     PXOPT_LOOKUP_S32(reject_images, config->args, "-reject_images", false, false);
    660     PXOPT_LOOKUP_F32(reject_pix_mean, config->args, "-reject_pix_mean", false, false);
    661     PXOPT_LOOKUP_F32(reject_pix_stdev, config->args, "-reject_pix_stdev", false, false);
    662519    PXOPT_LOOKUP_S32(sources, config->args, "-sources", false, false);
    663520    PXOPT_LOOKUP_STR(hostname, config->args, "-hostname", false, false);
     
    668525    PXOPT_LOOKUP_S16(quality, config->args, "-quality", false, false);
    669526
     527    // XXX not sure we need a transaction here...
    670528    if (!psDBTransaction(config->dbh)) {
    671529        psError(PS_ERR_UNKNOWN, false, "database error");
     
    673531    }
    674532
    675     // XXX need to validate the stack_id here
    676     // XXX instead of validiting it here we should just use forgein key
    677     // constrants
    678     if (!stackSumSkyfileInsert(config->dbh,
     533    if (!staticskyResultInsert(config->dbh,
     534                               sky_id,
    679535                               stack_id,
    680                                uri,
    681536                               path_base,
    682                                bg,
    683                                bg_stdev,
    684                                dtime_stack,
    685                                dtime_match_mean,
    686                                dtime_match_stdev,
    687                                dtime_initial,
    688                                dtime_reject,
    689                                dtime_final,
    690537                               dtime_phot,
    691538                               dtime_script,
    692                                match_mean,
    693                                match_stdev,
    694                                match_rms,
    695                                stamps_mean,
    696                                stamps_stdev,
    697                                stamps_min,
    698                                reject_images,
    699                                reject_pix_mean,
    700                                reject_pix_stdev,
    701539                               sources,
    702540                               hostname,
     
    712550    }
    713551
    714     if (fault == 0) {
    715         if (!setstackRunState(config, stack_id, "full")) {
    716             if (!psDBRollback(config->dbh)) {
    717                 psError(PS_ERR_UNKNOWN, false, "database error");
    718             }
    719             psError(PS_ERR_UNKNOWN, false, "failed to change stackRun's state");
    720             return false;
    721         }
    722     }
    723 
    724552    // point of no return
    725553    if (!psDBCommit(config->dbh)) {
     
    731559}
    732560
    733 
     561// XXX what is this used by?  what filters are needed?
    734562static bool resultMode(pxConfig *config)
    735563{
     
    737565
    738566    psMetadata *where = psMetadataAlloc();
    739     PXOPT_COPY_S64(config->args, where, "-stack_id", "stackSumSkyfile.stack_id", "==");
    740     PXOPT_COPY_STR(config->args, where, "-tess_id", "stackRun.tess_id", "==");
    741     PXOPT_COPY_STR(config->args, where, "-skycell_id", "stackRun.skycell_id", "==");
    742     PXOPT_COPY_STR(config->args, where, "-filter", "stackRun.filter", "LIKE");
    743     PXOPT_COPY_STR(config->args, where, "-label", "stackRun.label", "==");
    744     PXOPT_COPY_STR(config->args, where, "-data_group", "stackRun.data_group", "LIKE");
    745     PXOPT_COPY_S16(config->args, where, "-fault", "stackSumSkyfile.fault", "==");
    746 
    747 //  The following three selectors are incompatible with the sql so omit them
    748 //    PXOPT_COPY_S64(config->args, where, "-warp_id", "warpRun.warp_id", "==");
    749 //     PXOPT_COPY_S64(config->args, where, "-exp_id", "rawExp.exp_id", "==");
    750 //    PXOPT_COPY_STR(config->args, where, "-exp_name", "rawExp.exp_name", "==");
     567    PXOPT_COPY_S64(config->args, where, "-sky_id",     "staticskyRun.sky_id", "==");
     568    PXOPT_COPY_STR(config->args, where, "-label",      "staticskyRun.label", "==");
     569    PXOPT_COPY_STR(config->args, where, "-data_group", "staticskyRun.data_group", "LIKE");
     570    PXOPT_COPY_S16(config->args, where, "-fault",      "staticskyResult.fault", "==");
    751571
    752572    PXOPT_LOOKUP_BOOL(all, config->args, "-all", false);
     
    755575    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    756576
    757     psString query = pxDataGet("stacktool_sumskyfile.sql");
     577    psString query = pxDataGet("staticskytool_result.sql");
    758578    if (!query) {
    759579        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     
    801621    }
    802622    if (!psArrayLength(output)) {
    803         psTrace("stacktool", PS_LOG_INFO, "no rows found");
     623        psTrace("staticskytool", PS_LOG_INFO, "no rows found");
    804624        psFree(output);
    805625        return true;
     
    807627
    808628    if (psArrayLength(output)) {
    809         if (!ippdbPrintMetadatas(stdout, output, "stackSumSkyfile", !simple)) {
     629        if (!ippdbPrintMetadatas(stdout, output, "staticskyResult", !simple)) {
    810630            psError(PS_ERR_UNKNOWN, false, "failed to print array");
    811631            psFree(output);
     
    819639}
    820640
    821 
    822641static bool revertMode(pxConfig *config)
    823642{
    824643    PS_ASSERT_PTR_NON_NULL(config, false);
    825644
     645# if (0)
    826646    psMetadata *where = psMetadataAlloc();
    827647    PXOPT_COPY_S64(config->args, where, "-stack_id", "stackSumSkyfile.stack_id", "==");
     
    836656
    837657    // Delete product
    838     psString delete = pxDataGet("stacktool_revertsumskyfile_delete.sql");
     658    psString delete = pxDataGet("staticskytool_revertsumskyfile_delete.sql");
    839659    if (!delete) {
    840660        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     
    857677
    858678    int numRows = psDBAffectedRows(config->dbh); // Number of row affected
    859     psLogMsg("stacktool", PS_LOG_INFO, "Deleted %d rows", numRows);
     679    psLogMsg("staticskytool", PS_LOG_INFO, "Deleted %d rows", numRows);
    860680
    861681    psFree(where);
     682# endif
    862683
    863684    return true;
    864685}
    865686
    866 
    867 static bool updateresultState(pxConfig *config, psS64 stack_id, const char *state)
    868 {
    869     PS_ASSERT_PTR_NON_NULL(state, false);
    870 
     687# if (0)
     688static bool updateresultState(pxConfig *config)
     689{
    871690    // check that state is a valid string value
    872691    if (!pxIsValidState(state)) {
     
    881700        return false;
    882701    }
    883 
    884702    return true;
    885703}
    886 
    887 static bool updateresultMode(pxConfig *config)
     704# endif
     705
     706static bool updateresult(pxConfig *config)
    888707{
    889708    PS_ASSERT_PTR_NON_NULL(config, false);
    890709
     710# if (0)
    891711    PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false);
    892712
     
    901721    psFree (where);
    902722
     723# endif
    903724    return true;
    904725}
     
    906727bool exportrunMode(pxConfig *config)
    907728{
     729# if (0)
    908730  typedef struct ExportTable {
    909731    char tableName[80];
     
    934756
    935757  ExportTable tables [] = {
    936     {"stackRun", "stacktool_export_run.sql"},
    937     {"stackInputSkyfile", "stacktool_export_input_skyfile.sql"},
    938     {"stackSumSkyfile", "stacktool_export_sum_skyfile.sql"},
     758    {"stackRun", "staticskytool_export_run.sql"},
     759    {"stackInputSkyfile", "staticskytool_export_input_skyfile.sql"},
     760    {"stackSumSkyfile", "staticskytool_export_sum_skyfile.sql"},
    939761  };
    940762
     
    999821    fclose (f);
    1000822
     823# endif
    1001824    return true;
    1002825}
     
    1004827bool importrunMode(pxConfig *config)
    1005828{
     829# if (0)
    1006830  unsigned int nFail;
    1007831
     
    1072896  }
    1073897
     898# endif
    1074899  return true;
    1075900}
     901
     902# if (0)
     903        // now we need to loop over all requested filters and check that each is found
     904        // XXX is this needed?  haven't we required that we only match the requested filters
     905        // and that N unique filters are found?
     906
     907        psVector *found = psVectorAlloc(inputs->n, PS_TYPE_U8);
     908        psVectorInit (found, 0);
     909
     910        psMetadataItem *filter = NULL;
     911        psListIterator *iter = psListIteratorAlloc (filters->data.list, PS_LIST_HEAD, false);
     912        while ((filter = psListGetAndIncrement(iter))) {
     913
     914            bool foundOne = false;
     915
     916            psAssert (filter->type == PS_DATA_STR, "filter is not a string?");
     917            for (int j = 0; !foundOne && (j < inputs->n); j++) {
     918                if (found->data.U8[j]) continue;
     919                psMetadata *inputRow = inputs->data[j]; // Row from select
     920
     921                // pull out the skycell_id, tess_id, filter
     922                psString inFilter = psMetadataLookupStr(&status, row, "filter");
     923                psAssert (status);
     924
     925                found->data.U8[j] = true;
     926                foundOne = true;
     927            }
     928            if (!foundOne) {
     929                // this required filter was not found in the inputs, skip the entry
     930                skip();
     931            }
     932        }           
     933# endif
     934
  • trunk/ippTools/src/staticskytoolConfig.c

    r27963 r28091  
    5252    psMetadataAddF32(definebyqueryArgs,  PS_LIST_TAIL, "-select_good_frac_min", 0, "define min good_frac", 0.0);
    5353    psMetadataAddStr(definebyqueryArgs,  PS_LIST_TAIL, "-select_label", PS_META_DUPLICATE_OK, "search by stackRun label (LIKE comparison, multiple OK)", NULL);
    54     psMetadataAddStr(definebyqueryArgs,  PS_LIST_TAIL, "-select_filter", PS_META_DUPLICATE_OK, "search by filter (LIKE comparison, multiple OK)", NULL);
     54    psMetadataAddStr(definebyqueryArgs,  PS_LIST_TAIL, "-select_filter", PS_META_DUPLICATE_OK, "search by filter (LIKE comparison, multiple required)", NULL);
    5555    psMetadataAddStr(definebyqueryArgs,  PS_LIST_TAIL, "-set_workdir", 0, "define workdir (required)", NULL);
    5656    psMetadataAddStr(definebyqueryArgs,  PS_LIST_TAIL, "-set_label", 0, "define label", NULL);
     
    8989    // -addresult
    9090    psMetadata *addresultArgs = psMetadataAlloc();
    91     psMetadataAddS64(addresultArgs, PS_LIST_TAIL, "-sky_id", 0, "define stack ID (required)", 0);
     91    psMetadataAddS64(addresultArgs, PS_LIST_TAIL, "-sky_id", 0, "define sky ID (required)", 0);
     92    psMetadataAddS64(addresultArgs, PS_LIST_TAIL, "-stack_id", 0, "define stack ID (required)", 0);
    9293    psMetadataAddStr(addresultArgs, PS_LIST_TAIL, "-path_base", 0, "define base output location", 0);
    9394    psMetadataAddF32(addresultArgs, PS_LIST_TAIL, "-dtime_phot", 0, "define photometry time", NAN);
     
    9697    psMetadataAddStr(addresultArgs, PS_LIST_TAIL, "-hostname", 0, "define hostname", 0);
    9798    psMetadataAddF32(addresultArgs, PS_LIST_TAIL, "-good_frac", 0, "define fraction of good pixels", NAN);
    98     psMetadataAddS16(addresultArgs, PS_LIST_TAIL, "-quality", 0, "set quality", 0)
     99    psMetadataAddS16(addresultArgs, PS_LIST_TAIL, "-quality", 0, "set quality", 0);
    99100    psMetadataAddS16(addresultArgs, PS_LIST_TAIL, "-fault", 0, "set fault code", 0);
    100101
     
    102103    psMetadata *resultArgs= psMetadataAlloc();
    103104    psMetadataAddS64(resultArgs, PS_LIST_TAIL, "-sky_id", 0, "search by staticsky ID", 0);
    104     psMetadataAddStr(resultArgs, PS_LIST_TAIL, "-tess_id", 0, "search by tess ID", 0);
    105     psMetadataAddStr(resultArgs, PS_LIST_TAIL, "-skycell_id", 0, "search by skycell ID", 0);
     105    // psMetadataAddStr(resultArgs, PS_LIST_TAIL, "-tess_id", 0, "search by tess ID", 0);
     106    // psMetadataAddStr(resultArgs, PS_LIST_TAIL, "-skycell_id", 0, "search by skycell ID", 0);
    106107    psMetadataAddStr(resultArgs, PS_LIST_TAIL, "-label", 0, "search by label", NULL);
    107108    psMetadataAddStr(resultArgs, PS_LIST_TAIL, "-data_group", 0, "search by data_group (LIKE comparison)", NULL);
     
    109110    psMetadataAddU64(resultArgs, PS_LIST_TAIL, "-limit", 0, "limit result set to N items", 0);
    110111    psMetadataAddBool(resultArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false);
     112    psMetadataAddBool(resultArgs, PS_LIST_TAIL, "-all", 0, "allow no search terms", false);
    111113
    112114    // -revert
     
    143145    PXOPT_ADD_MODE("-inputs",        "Get inputs",           STATICSKYTOOL_MODE_INPUTS,        inputsArgs);
    144146    PXOPT_ADD_MODE("-todo",          "Get runs to do",       STATICSKYTOOL_MODE_TODO,          todoArgs);
    145     PXOPT_ADD_MODE("-addresult",     "Add result of run",    STATICSKYTOOL_MODE_ADDRESULT,     addresultsArgs);
     147    PXOPT_ADD_MODE("-addresult",     "Add result of run",    STATICSKYTOOL_MODE_ADDRESULT,     addresultArgs);
    146148    PXOPT_ADD_MODE("-result",        "Get result of run",    STATICSKYTOOL_MODE_RESULT,        resultArgs);
    147149    PXOPT_ADD_MODE("-revert",        "Revert failed run",    STATICSKYTOOL_MODE_REVERT,        revertArgs);
Note: See TracChangeset for help on using the changeset viewer.