Changeset 28091
- Timestamp:
- May 25, 2010, 1:38:50 PM (16 years ago)
- Location:
- trunk/ippTools
- Files:
-
- 5 added
- 9 edited
-
notes.txt (modified) (1 diff)
-
share/Makefile.am (modified) (1 diff)
-
share/pxadmin_create_tables.sql (modified) (5 diffs)
-
share/staticskytool_definebyquery.sql (modified) (1 diff)
-
share/staticskytool_definebyquery_inputs.sql (added)
-
share/staticskytool_definebyquery_select.sql (added)
-
share/staticskytool_inputs.sql (added)
-
share/staticskytool_result.sql (added)
-
share/staticskytool_todo.sql (added)
-
src/Makefile.am (modified) (3 diffs)
-
src/chiptool.c (modified) (1 diff)
-
src/pxtools.c (modified) (5 diffs)
-
src/staticskytool.c (modified) (43 diffs)
-
src/staticskytoolConfig.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/notes.txt
r19092 r28091 1 2 2010.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? 1 13 2 14 2008.07.19 EAM -
trunk/ippTools/share/Makefile.am
r28043 r28091 289 289 stacktool_sumskyfile.sql \ 290 290 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 \ 291 296 warptool_change_skyfile_data_state.sql \ 292 297 warptool_change_run_state.sql \ -
trunk/ippTools/share/pxadmin_create_tables.sql
r28089 r28091 1617 1617 -- A static sky analysis set 1618 1618 CREATE TABLE staticskyRun ( 1619 s s_id BIGINT AUTO_INCREMENT, -- unique identifier1619 sky_id BIGINT AUTO_INCREMENT, -- unique identifier 1620 1620 state VARCHAR(64) NOT NULL, -- state of run (new, full, etc.) 1621 1621 workdir VARCHAR(255) NOT NULL, -- working directory … … 1626 1626 note VARCHAR(255), -- note 1627 1627 registered TIMESTAMP DEFAULT CURRENT_TIMESTAMP, -- time run was registered 1628 PRIMARY KEY(s s_id),1628 PRIMARY KEY(sky_id), 1629 1629 KEY(state), 1630 1630 KEY(label), … … 1635 1635 -- Inputs for static sky analysis 1636 1636 CREATE TABLE staticskyInput ( 1637 s s_id BIGINT, -- static sky identifier1637 sky_id BIGINT, -- static sky identifier 1638 1638 stack_id BIGINT, -- stack identifier 1639 PRIMARY KEY(s s_id,stack_id),1639 PRIMARY KEY(sky_id,stack_id), 1640 1640 KEY(stack_id), 1641 FOREIGN KEY(s s_id) REFERENCES staticskyRun(ss_id),1641 FOREIGN KEY(sky_id) REFERENCES staticskyRun(sky_id), 1642 1642 FOREIGN KEY(stack_id) REFERENCES stackSumSkyfile(stack_id) 1643 1643 ) ENGINE=innodb DEFAULT CHARSET=latin1; … … 1645 1645 -- Result of static sky analysis 1646 1646 CREATE TABLE staticskyResult ( 1647 s s_id BIGINT, -- static sky identifier1647 sky_id BIGINT, -- static sky identifier 1648 1648 path_base VARCHAR(255) NOT NULL, -- root name for outputs 1649 1649 dtime_phot FLOAT, -- elapsed time for photometry … … 1654 1654 quality SMALLINT NOT NULL, -- bad quality flag 1655 1655 fault SMALLINT NOT NULL, -- fault code 1656 PRIMARY KEY(s s_id),1656 PRIMARY KEY(sky_id), 1657 1657 KEY(good_frac), 1658 1658 KEY(fault), 1659 1659 KEY(quality), 1660 FOREIGN KEY(s s_id) REFERENCES staticskyRun(ss_id)1660 FOREIGN KEY(sky_id) REFERENCES staticskyRun(sky_id) 1661 1661 ) ENGINE=innodb DEFAULT CHARSET=latin1; 1662 1662 -
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 1 SELECT 2 tess_id, 3 skycell_id, 4 num_filter 5 FROM ( 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 21 WHERE num_filter == %d 22 -
trunk/ippTools/src/Makefile.am
r28075 r28091 22 22 regtool \ 23 23 stacktool \ 24 staticskytool \ 24 25 warptool \ 25 26 receivetool \ … … 66 67 regtool.h \ 67 68 stacktool.h \ 69 staticskytool.h \ 68 70 warptool.h \ 69 71 pubtool.h … … 197 199 stacktoolConfig.c 198 200 201 staticskytool_CFLAGS = $(PSLIB_CFLAGS) $(PSMODULES_CFLAGS) $(IPPDB_CFLAGS) 202 staticskytool_LDADD = $(PSLIB_LIBS) $(PSMODULES_LIBS) $(IPPDB_LIBS) libpxtools.la 203 staticskytool_SOURCES = \ 204 staticskytool.c \ 205 staticskytoolConfig.c 206 199 207 pxadmin_CFLAGS = $(PSLIB_CFLAGS) $(PSMODULES_CFLAGS) $(IPPDB_CFLAGS) 200 208 pxadmin_LDADD = $(PSLIB_LIBS) $(PSMODULES_LIBS) $(IPPDB_LIBS) libpxtools.la -
trunk/ippTools/src/chiptool.c
r28056 r28091 141 141 ) 142 142 { 143 // start a transaction so we don't end up with an exp without any associ ted143 // start a transaction so we don't end up with an exp without any associated 144 144 // imfiles 145 145 if (!psDBTransaction(config->dbh)) { -
trunk/ippTools/src/pxtools.c
r28089 r28091 49 49 50 50 psString 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 } 62 92 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);93 93 } 94 94 … … 96 96 psS64 *maskfrac_npix, psF32 *maskfrac_static, psF32 *maskfrac_dynamic, 97 97 psF32 *maskfrac_magic, psF32 *maskfrac_advisory) { 98 psString query = pxDataGet(dbQFile);98 psString query = pxDataGet(dbQFile); 99 99 /* psString text_id = NULL; */ 100 100 /* psStringAppend(&text_id," %" PRId64,stage_id); */ 101 101 /* psStringSubstitute(&query,text_id,"@STAGE_ID@"); */ 102 102 /* 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 } 105 108 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); 126 126 /* printf("%ld : %d %f %f %f %f <-> %ld %f %f %f %f\n",i,this_npix,this_static,this_dynamic,this_magic,this_advisory, */ 127 127 /* *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); 138 138 } 139 139 140 140 bool pxSetRunSoftware(pxConfig *config, const psString tableName, const psString stage_id_name, const psS64 stage_id, 141 141 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; 143 143 /* 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); 151 151 } 152 152 … … 154 154 psS64 maskfrac_npix, psF32 maskfrac_static, psF32 maskfrac_dynamic, 155 155 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); 167 167 } 168 168 … … 293 293 char *comma = ","; 294 294 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) 302 302 303 303 addColumn(runTable, state); … … 436 436 if (import_version && strcmp(import_version, schema_version)) { 437 437 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); 439 439 return false; 440 440 } else if (!import_version) { -
trunk/ippTools/src/staticskytool.c
r27963 r28091 1 1 /* 2 * sta cktool.c2 * staticskytool.c 3 3 * 4 4 * Copyright (C) 2007-2010 Joshua Hoblitt, Paul Price … … 29 29 30 30 #include "pxtools.h" 31 #include "sta cktool.h"31 #include "staticskytool.h" 32 32 33 33 static bool definebyqueryMode(pxConfig *config); 34 static bool definerunMode(pxConfig *config);35 34 static 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); 35 static bool inputsMode(pxConfig *config); 36 static bool todoMode(pxConfig *config); 37 static bool addresultMode(pxConfig *config); 38 static bool resultMode(pxConfig *config); 39 static bool revertMode(pxConfig *config); 40 static bool updateresult(pxConfig *config); 46 41 static bool exportrunMode(pxConfig *config); 47 42 static bool importrunMode(pxConfig *config); 48 49 static bool setstackRunState(pxConfig *config, psS64 stack_id, const char *state);50 43 51 44 # define MODECASE(caseName, func) \ … … 60 53 psLibInit(NULL); 61 54 62 pxConfig *config = sta cktoolConfig(NULL, argc, argv);55 pxConfig *config = staticskytoolConfig(NULL, argc, argv); 63 56 if (!config) { 64 57 psError(PXTOOLS_ERR_CONFIG, false, "failed to configure"); … … 67 60 68 61 switch (config->mode) { 69 MODECASE(STA CKTOOL_MODE_DEFINEBYQUERY,definebyqueryMode);70 MODECASE(STA CKTOOL_MODE_UPDATERUN,updaterunMode);71 MODECASE(STA CKTOOL_MODE_INPUTS,inputsMode);72 MODECASE(STA CKTOOL_MODE_TODO,todoMode);73 MODECASE(STA CKTOOL_MODE_ADDRESULT,addresultMode);74 MODECASE(STA CKTOOL_MODE_RESULT,resultMode);75 MODECASE(STA CKTOOL_MODE_REVERT,revertMode);76 MODECASE(STA CKTOOL_MODE_UPDATERESULT, updateresultMode);77 MODECASE(STA CKTOOL_MODE_EXPORTRUN,exportrunMode);78 MODECASE(STA CKTOOL_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); 79 72 default: 80 73 psAbort("invalid option (this should not happen)"); … … 114 107 PXOPT_LOOKUP_TIME(registered, config->args, "-set_registered", false, false); 115 108 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 } 127 128 128 129 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 129 130 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 }137 131 138 132 psString select = pxDataGet("staticskytool_definebyquery_select.sql"); 139 133 if (!select) { 140 134 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)) { 189 153 psError(PS_ERR_UNKNOWN, false, "database error"); 190 154 psFree(select); 191 psFree(where1);192 psFree(where2);193 155 return false; 194 156 } 195 157 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 198 162 199 163 psArray *output = p_psDBFetchResult(config->dbh); … … 212 176 } 213 177 if (!psArrayLength(output)) { 214 psWarning("sta cktool: no rows found");178 psWarning("staticskytool: no rows found"); 215 179 psFree(output); 216 180 psFree(where); … … 219 183 if (pretend) { 220 184 // negative simple so the default is true 221 if (!ippdbPrintMetadatas(stdout, output, "sta ckSkycells", !simple)) {185 if (!ippdbPrintMetadatas(stdout, output, "staticskyInput", !simple)) { 222 186 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 223 187 psFree(output); … … 230 194 } 231 195 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) { 239 198 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 240 199 psFree(where); … … 242 201 } 243 202 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 print269 203 for (long i = 0; i < output->n; i++) { 270 204 psMetadata *row = output->data[i]; // Row from select … … 276 210 psError(PS_ERR_UNKNOWN, false, "failed to lookup skycell_id"); 277 211 psFree(output); 278 psFree(insert); 279 psFree(list); 212 psFree(inputsSQL); 280 213 if (!psDBRollback(config->dbh)) { 281 214 psError(PS_ERR_UNKNOWN, false, "database error"); … … 288 221 psError(PS_ERR_UNKNOWN, false, "failed to lookup tess_id"); 289 222 psFree(output); 290 psFree(insert); 291 psFree(list); 223 psFree(inputsSQL); 292 224 if (!psDBRollback(config->dbh)) { 293 225 psError(PS_ERR_UNKNOWN, false, "database error"); … … 296 228 } 297 229 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"); 301 233 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); 331 250 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); 374 266 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); 401 289 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); 419 326 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);433 327 return true; 434 328 } … … 438 332 PS_ASSERT_PTR_NON_NULL(config, false); 439 333 440 #ifdef notdef441 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 #endif445 334 psMetadata *where = psMetadataAlloc(); 446 PXOPT_COPY_S64(config->args, where, "-s tack_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", "=="); 449 338 if (!psListLength(where->list)) { 450 339 psFree(where); … … 453 342 } 454 343 455 psString query = psStringCopy("UPDATE sta ckRun");344 psString query = psStringCopy("UPDATE staticskyRun"); 456 345 457 346 // 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); 460 348 psFree(query); 461 349 psFree(where); 462 350 463 351 return result; 464 465 #ifdef notdef466 // 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 state470 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 #endif480 352 } 481 353 … … 485 357 PS_ASSERT_PTR_NON_NULL(config, false); 486 358 487 // XXX require at least a s tackid (add better search options)488 PXOPT_LOOKUP_S64(s tack_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); 489 361 490 362 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", "=="); 493 364 494 365 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 495 366 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 496 367 497 psString query = pxDataGet("sta cktool_inputskyfile.sql");368 psString query = pxDataGet("staticskytool_inputs.sql"); 498 369 if (!query) { 499 370 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); … … 502 373 503 374 if (psListLength(where->list)) { 504 psString whereClause = psDBGenerateWhereConditionSQL(where, "sta ckInputSkyfile");505 psStringAppend(&query, " AND%s", whereClause);375 psString whereClause = psDBGenerateWhereConditionSQL(where, "staticskyInput"); 376 psStringAppend(&query, " WHERE %s", whereClause); 506 377 psFree(whereClause); 507 378 } … … 537 408 } 538 409 if (!psArrayLength(output)) { 539 psTrace("sta cktool", PS_LOG_INFO, "no rows found");410 psTrace("staticskytool", PS_LOG_INFO, "no rows found"); 540 411 psFree(output); 541 412 return true; … … 544 415 if (psArrayLength(output)) { 545 416 // negative simple so the default is true 546 if (!ippdbPrintMetadatas(stdout, output, "sta ckInputSkyfile", !simple)) {417 if (!ippdbPrintMetadatas(stdout, output, "staticskyInput", !simple)) { 547 418 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 548 419 psFree(output); … … 561 432 PS_ASSERT_PTR_NON_NULL(config, false); 562 433 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", "=="); 567 437 568 438 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 569 439 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 570 440 571 psString query = pxDataGet("sta cktool_tosum.sql");441 psString query = pxDataGet("staticskytool_todo.sql"); 572 442 if (!query) { 573 443 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); … … 575 445 } 576 446 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); 583 458 584 459 // treat limit == 0 as "no limit" … … 589 464 } 590 465 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)) { 592 468 psError(PS_ERR_UNKNOWN, false, "database error"); 593 469 psFree(query); … … 611 487 } 612 488 if (!psArrayLength(output)) { 613 psTrace("sta cktool", PS_LOG_INFO, "no rows found");489 psTrace("staticskytool", PS_LOG_INFO, "no rows found"); 614 490 psFree(output); 615 491 return true; … … 618 494 if (psArrayLength(output)) { 619 495 // negative simple so the default is true 620 if (!ippdbPrintMetadatas(stdout, output, "sta ckSumSkyfile", !simple)) {496 if (!ippdbPrintMetadatas(stdout, output, "staticskyResult", !simple)) { 621 497 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 622 498 psFree(output); … … 626 502 627 503 psFree(output); 628 629 504 return true; 630 505 } 631 506 632 633 507 static bool addresultMode(pxConfig *config) 634 508 { … … 636 510 637 511 // required 512 PXOPT_LOOKUP_S64(sky_id, config->args, "-sky_id", true, false); 638 513 PXOPT_LOOKUP_S64(stack_id, config->args, "-stack_id", true, false); 639 514 640 515 // optional 641 PXOPT_LOOKUP_STR(uri, config->args, "-uri", false, false);642 516 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);651 517 PXOPT_LOOKUP_F32(dtime_phot, config->args, "-dtime_phot", false, false); 652 518 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);662 519 PXOPT_LOOKUP_S32(sources, config->args, "-sources", false, false); 663 520 PXOPT_LOOKUP_STR(hostname, config->args, "-hostname", false, false); … … 668 525 PXOPT_LOOKUP_S16(quality, config->args, "-quality", false, false); 669 526 527 // XXX not sure we need a transaction here... 670 528 if (!psDBTransaction(config->dbh)) { 671 529 psError(PS_ERR_UNKNOWN, false, "database error"); … … 673 531 } 674 532 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, 679 535 stack_id, 680 uri,681 536 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,690 537 dtime_phot, 691 538 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,701 539 sources, 702 540 hostname, … … 712 550 } 713 551 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 724 552 // point of no return 725 553 if (!psDBCommit(config->dbh)) { … … 731 559 } 732 560 733 561 // XXX what is this used by? what filters are needed? 734 562 static bool resultMode(pxConfig *config) 735 563 { … … 737 565 738 566 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", "=="); 751 571 752 572 PXOPT_LOOKUP_BOOL(all, config->args, "-all", false); … … 755 575 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 756 576 757 psString query = pxDataGet("sta cktool_sumskyfile.sql");577 psString query = pxDataGet("staticskytool_result.sql"); 758 578 if (!query) { 759 579 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); … … 801 621 } 802 622 if (!psArrayLength(output)) { 803 psTrace("sta cktool", PS_LOG_INFO, "no rows found");623 psTrace("staticskytool", PS_LOG_INFO, "no rows found"); 804 624 psFree(output); 805 625 return true; … … 807 627 808 628 if (psArrayLength(output)) { 809 if (!ippdbPrintMetadatas(stdout, output, "sta ckSumSkyfile", !simple)) {629 if (!ippdbPrintMetadatas(stdout, output, "staticskyResult", !simple)) { 810 630 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 811 631 psFree(output); … … 819 639 } 820 640 821 822 641 static bool revertMode(pxConfig *config) 823 642 { 824 643 PS_ASSERT_PTR_NON_NULL(config, false); 825 644 645 # if (0) 826 646 psMetadata *where = psMetadataAlloc(); 827 647 PXOPT_COPY_S64(config->args, where, "-stack_id", "stackSumSkyfile.stack_id", "=="); … … 836 656 837 657 // Delete product 838 psString delete = pxDataGet("sta cktool_revertsumskyfile_delete.sql");658 psString delete = pxDataGet("staticskytool_revertsumskyfile_delete.sql"); 839 659 if (!delete) { 840 660 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); … … 857 677 858 678 int numRows = psDBAffectedRows(config->dbh); // Number of row affected 859 psLogMsg("sta cktool", PS_LOG_INFO, "Deleted %d rows", numRows);679 psLogMsg("staticskytool", PS_LOG_INFO, "Deleted %d rows", numRows); 860 680 861 681 psFree(where); 682 # endif 862 683 863 684 return true; 864 685 } 865 686 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) 688 static bool updateresultState(pxConfig *config) 689 { 871 690 // check that state is a valid string value 872 691 if (!pxIsValidState(state)) { … … 881 700 return false; 882 701 } 883 884 702 return true; 885 703 } 886 887 static bool updateresultMode(pxConfig *config) 704 # endif 705 706 static bool updateresult(pxConfig *config) 888 707 { 889 708 PS_ASSERT_PTR_NON_NULL(config, false); 890 709 710 # if (0) 891 711 PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false); 892 712 … … 901 721 psFree (where); 902 722 723 # endif 903 724 return true; 904 725 } … … 906 727 bool exportrunMode(pxConfig *config) 907 728 { 729 # if (0) 908 730 typedef struct ExportTable { 909 731 char tableName[80]; … … 934 756 935 757 ExportTable tables [] = { 936 {"stackRun", "sta cktool_export_run.sql"},937 {"stackInputSkyfile", "sta cktool_export_input_skyfile.sql"},938 {"stackSumSkyfile", "sta cktool_export_sum_skyfile.sql"},758 {"stackRun", "staticskytool_export_run.sql"}, 759 {"stackInputSkyfile", "staticskytool_export_input_skyfile.sql"}, 760 {"stackSumSkyfile", "staticskytool_export_sum_skyfile.sql"}, 939 761 }; 940 762 … … 999 821 fclose (f); 1000 822 823 # endif 1001 824 return true; 1002 825 } … … 1004 827 bool importrunMode(pxConfig *config) 1005 828 { 829 # if (0) 1006 830 unsigned int nFail; 1007 831 … … 1072 896 } 1073 897 898 # endif 1074 899 return true; 1075 900 } 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 52 52 psMetadataAddF32(definebyqueryArgs, PS_LIST_TAIL, "-select_good_frac_min", 0, "define min good_frac", 0.0); 53 53 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); 55 55 psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_workdir", 0, "define workdir (required)", NULL); 56 56 psMetadataAddStr(definebyqueryArgs, PS_LIST_TAIL, "-set_label", 0, "define label", NULL); … … 89 89 // -addresult 90 90 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); 92 93 psMetadataAddStr(addresultArgs, PS_LIST_TAIL, "-path_base", 0, "define base output location", 0); 93 94 psMetadataAddF32(addresultArgs, PS_LIST_TAIL, "-dtime_phot", 0, "define photometry time", NAN); … … 96 97 psMetadataAddStr(addresultArgs, PS_LIST_TAIL, "-hostname", 0, "define hostname", 0); 97 98 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); 99 100 psMetadataAddS16(addresultArgs, PS_LIST_TAIL, "-fault", 0, "set fault code", 0); 100 101 … … 102 103 psMetadata *resultArgs= psMetadataAlloc(); 103 104 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); 106 107 psMetadataAddStr(resultArgs, PS_LIST_TAIL, "-label", 0, "search by label", NULL); 107 108 psMetadataAddStr(resultArgs, PS_LIST_TAIL, "-data_group", 0, "search by data_group (LIKE comparison)", NULL); … … 109 110 psMetadataAddU64(resultArgs, PS_LIST_TAIL, "-limit", 0, "limit result set to N items", 0); 110 111 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); 111 113 112 114 // -revert … … 143 145 PXOPT_ADD_MODE("-inputs", "Get inputs", STATICSKYTOOL_MODE_INPUTS, inputsArgs); 144 146 PXOPT_ADD_MODE("-todo", "Get runs to do", STATICSKYTOOL_MODE_TODO, todoArgs); 145 PXOPT_ADD_MODE("-addresult", "Add result of run", STATICSKYTOOL_MODE_ADDRESULT, addresult sArgs);147 PXOPT_ADD_MODE("-addresult", "Add result of run", STATICSKYTOOL_MODE_ADDRESULT, addresultArgs); 146 148 PXOPT_ADD_MODE("-result", "Get result of run", STATICSKYTOOL_MODE_RESULT, resultArgs); 147 149 PXOPT_ADD_MODE("-revert", "Revert failed run", STATICSKYTOOL_MODE_REVERT, revertArgs);
Note:
See TracChangeset
for help on using the changeset viewer.
