Changeset 28091 for trunk/ippTools/src/staticskytool.c
- Timestamp:
- May 25, 2010, 1:38:50 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/staticskytool.c (modified) (43 diffs)
Legend:
- Unmodified
- Added
- Removed
-
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
Note:
See TracChangeset
for help on using the changeset viewer.
