- Timestamp:
- May 3, 2010, 8:50:52 AM (16 years ago)
- Location:
- branches/simtest_nebulous_branches
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
ippTools/src (modified) (1 prop)
-
ippTools/src/chiptool.c (modified) (39 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/simtest_nebulous_branches
- Property svn:mergeinfo changed
-
branches/simtest_nebulous_branches/ippTools/src
- Property svn:ignore
-
old new 1 *.la 2 *.lo 1 3 .deps 2 4 .gdb_history … … 4 6 Makefile 5 7 Makefile.in 8 addtool 9 caltool 10 camtool 11 chiptool 6 12 config.h 7 13 config.h.in 8 stamp-h1 9 *.la 10 *.lo 14 detselect 15 dettool 16 difftool 17 disttool 18 dqstatstool 19 faketool 20 flatcorr 21 guidetool 22 magicdstool 23 magictool 24 pstamptool 25 pubtool 26 pxadmin 27 pxdata.c 28 pxinject 11 29 pxtoolsErrorCodes.c 12 30 pxtoolsErrorCodes.h 13 pxadmin14 pxinject15 pztool16 31 pzgetexp 17 32 pzgetimfiles 33 pztool 34 receivetool 18 35 regtool 19 guidetool 20 chiptool 21 camtool 36 stacktool 37 stamp-h1 22 38 warptool 23 difftool24 stacktool25 faketool26 dettool27 detselect28 pxdata.c29 magictool30 magicdstool31 caltool32 flatcorr33 pstamptool34 disttool35 receivetool36 37 pubtool
-
- Property svn:ignore
-
branches/simtest_nebulous_branches/ippTools/src/chiptool.c
r24562 r27840 36 36 37 37 static bool definebyqueryMode(pxConfig *config); 38 static bool definecopyMode(pxConfig *config); 38 39 static bool updaterunMode(pxConfig *config); 39 40 static bool pendingimfileMode(pxConfig *config); … … 54 55 static bool tofullimfileMode(pxConfig *config); 55 56 static bool topurgedimfileMode(pxConfig *config); 57 static bool toscrubbedimfileMode(pxConfig *config); 56 58 static bool exportrunMode(pxConfig *config); 57 59 static bool importrunMode(pxConfig *config); 60 static bool runstateMode(pxConfig *config); 61 static bool setimfiletoupdateMode(pxConfig *config); 62 static bool listrunMode(pxConfig *config); 58 63 59 64 # define MODECASE(caseName, func) \ … … 75 80 switch (config->mode) { 76 81 MODECASE(CHIPTOOL_MODE_DEFINEBYQUERY, definebyqueryMode); 82 MODECASE(CHIPTOOL_MODE_DEFINECOPY, definecopyMode); 77 83 MODECASE(CHIPTOOL_MODE_UPDATERUN, updaterunMode); 78 84 MODECASE(CHIPTOOL_MODE_PENDINGIMFILE, pendingimfileMode); … … 93 99 MODECASE(CHIPTOOL_MODE_TOFULLIMFILE, tofullimfileMode); 94 100 MODECASE(CHIPTOOL_MODE_TOPURGEDIMFILE, topurgedimfileMode); 101 MODECASE(CHIPTOOL_MODE_TOSCRUBBEDIMFILE, toscrubbedimfileMode); 95 102 MODECASE(CHIPTOOL_MODE_EXPORTRUN, exportrunMode); 96 103 MODECASE(CHIPTOOL_MODE_IMPORTRUN, importrunMode); 104 MODECASE(CHIPTOOL_MODE_RUNSTATE, runstateMode); 105 MODECASE(CHIPTOOL_MODE_SETIMFILETOUPDATE, setimfiletoupdateMode); 106 MODECASE(CHIPTOOL_MODE_LISTRUN, listrunMode); 97 107 default: 98 108 psAbort("invalid option (this should not happen)"); … … 116 126 } 117 127 128 // Queue exposures for chip processing 129 static bool queue_exposures(pxConfig *config, // Configuration 130 const psArray *exps, // Exposures information 131 const char *workdir, // Working directory, or NULL to inherit 132 const char *label, // Label, or NULL to inherit 133 const char *data_group, // Data group, or NULL to inherit 134 const char *dist_group, // Distribution group, or NULL to inherit 135 const char *reduction, // Reduction class, or NULL to inherit 136 const char *expgroup, // Exposure group 137 const char *dvodb, // DVO database, or NULL to inherit 138 const char *tess_id, // Tessellation identifier, or NULL to inherit 139 const char *end_stage, // End stage, or NULL to inherit 140 const char *note // Note 141 ) 142 { 143 // start a transaction so we don't end up with an exp without any associted 144 // imfiles 145 if (!psDBTransaction(config->dbh)) { 146 psError(PS_ERR_UNKNOWN, false, "database error"); 147 return false; 148 } 149 150 // if end_stage is warp (or NULL), check for valid tess_id 151 for (long i = 0; i < psArrayLength(exps); i++) { 152 psMetadata *md = exps->data[i]; 153 154 bool status; 155 char *end_stage = psMetadataLookupStr(&status, md, "end_stage"); 156 if (end_stage && strcasecmp(end_stage, "warp")) continue; 157 158 char *raw_tess_id = psMetadataLookupStr(&status, md, "tess_id"); 159 if (raw_tess_id || tess_id) continue; 160 161 char *label = psMetadataLookupStr(&status, md, "label"); 162 psS64 exp_id = psMetadataLookupS64(&status, md, "exp_id"); 163 164 if (!status) { 165 psError(PS_ERR_UNKNOWN, false, 166 "cannot queue analysis to WARP without a defined tess id: label: %s, exp_id %" PRId64, 167 label, exp_id); 168 return false; 169 } 170 } 171 172 173 # define GET_VALUE(PTYPE,CTYPE,VALUE,NAME) \ 174 PTYPE VALUE; \ 175 { \ 176 bool status; \ 177 VALUE = psMetadataLookup##CTYPE(&status, md, NAME); \ 178 if (!status) { \ 179 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for %s", NAME); \ 180 return false; \ 181 } \ 182 } 183 184 // loop over our list of exp_ids 185 for (long i = 0; i < psArrayLength(exps); i++) { 186 psMetadata *md = exps->data[i]; 187 188 rawExpRow *row = rawExpObjectFromMetadata(md); 189 if (!row) { 190 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into chipRun"); 191 return false; 192 } 193 194 GET_VALUE (psS64, S64, exp_id, "exp_id"); 195 GET_VALUE (psString, Str, raw_workdir, "workdir"); 196 GET_VALUE (psString, Str, raw_label, "label"); 197 GET_VALUE (psString, Str, raw_reduction, "reduction"); 198 // GET_VALUE (psString, Str, raw_expgroup, "expgroup"); 199 GET_VALUE (psString, Str, raw_dvodb, "dvodb"); 200 GET_VALUE (psString, Str, raw_tess_id, "tess_id"); 201 GET_VALUE (psString, Str, raw_end_stage, "end_stage"); 202 203 if (!row->exp_id) { 204 psError(PS_ERR_UNKNOWN, false, "failed to find value for exp_id"); 205 return false; 206 } 207 208 // queue the exp 209 if (!pxchipQueueByExpTag(config, 210 exp_id, 211 workdir ? workdir : raw_workdir, 212 label ? label : raw_label, 213 data_group ? data_group : (label ? label : raw_label), 214 dist_group, 215 reduction ? reduction : raw_reduction, 216 // expgroup ? expgroup : raw_expgroup, 217 // XXX how does expgroup get defined? 218 expgroup, 219 dvodb ? dvodb : raw_dvodb, 220 tess_id ? tess_id : raw_tess_id, 221 end_stage ? end_stage : raw_end_stage, 222 note 223 )) { 224 if (!psDBRollback(config->dbh)) { 225 psError(PS_ERR_UNKNOWN, false, "database error"); 226 } 227 psError(PS_ERR_UNKNOWN, false, 228 "failed to trying to queue exp_id: %" PRId64, exp_id); 229 return false; 230 } 231 } 232 233 if (!psDBCommit(config->dbh)) { 234 psError(PS_ERR_UNKNOWN, false, "database error"); 235 return false; 236 } 237 238 return true; 239 } 118 240 119 241 static bool definebyqueryMode(pxConfig *config) … … 125 247 psMetadata *where = psMetadataAlloc(); 126 248 pxchipGetSearchArgs (config, where); // rawExp only 127 pxAddLabelSearchArgs (config, where, "-label", "newExp.label", "LIKE"); 249 pxAddLabelSearchArgs (config, where, "-label", "newExp.label", "LIKE"); // define using newExp label 128 250 129 251 // psListLength(where->list) is at least 1 because exp_type defaults to "object" … … 131 253 if ((psListLength(where->list) <= 1) && !psMetadataLookupBool(NULL, config->args, "-all")) { 132 254 psFree(where); 133 psError(PXTOOLS_ERR_ DATA, false, "search parameters are required");255 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 134 256 return false; 135 257 } … … 142 264 PXOPT_LOOKUP_STR(tess_id, config->args, "-set_tess_id", false, false); 143 265 PXOPT_LOOKUP_STR(end_stage, config->args, "-set_end_stage", false, false); 266 PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false); 267 PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false); 268 PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false); 144 269 145 270 // default … … 150 275 psString query = pxDataGet("chiptool_find_rawexp.sql"); 151 276 if (!query) { 152 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");277 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 153 278 psFree(where); 154 279 return false; … … 190 315 } 191 316 192 // start a transaction so we don't end up with an exp without any associted 193 // imfiles 194 if (!psDBTransaction(config->dbh)) { 195 psError(PS_ERR_UNKNOWN, false, "database error"); 196 psFree(output); 197 return false; 198 } 199 200 // if end_stage is warp (or NULL), check for valid tess_id 201 for (long i = 0; i < psArrayLength(output); i++) { 202 psMetadata *md = output->data[i]; 203 204 bool status; 205 char *end_stage = psMetadataLookupStr(&status, md, "end_stage"); 206 if (end_stage && strcasecmp(end_stage, "warp")) continue; 207 208 char *raw_tess_id = psMetadataLookupStr(&status, md, "tess_id"); 209 if (raw_tess_id || tess_id) continue; 210 211 char *label = psMetadataLookupStr(&status, md, "label"); 212 psS64 exp_id = psMetadataLookupS64(&status, md, "exp_id"); 213 214 if (!status) { 215 psError(PS_ERR_UNKNOWN, false, "cannot queue analysis to WARP without a defined tess id: label: %s, exp_id %" PRId64, label, exp_id); 317 if (!queue_exposures(config, output, workdir, label, data_group, dist_group, reduction, expgroup, 318 dvodb, tess_id, end_stage, note)) { 319 psError(psErrorCodeLast(), false, "Unable to queue exposures for chip."); 320 psFree(output); 321 return false; 322 } 323 psFree(output); 324 325 return true; 326 } 327 328 static bool definecopyMode(pxConfig *config) 329 { 330 PS_ASSERT_PTR_NON_NULL(config, NULL); 331 332 PXOPT_LOOKUP_S64(exp_id, config->args, "-exp_id", false, false); 333 334 psMetadata *where = psMetadataAlloc(); 335 pxchipGetSearchArgs (config, where); // rawExp only 336 pxAddLabelSearchArgs (config, where, "-label", "chipOld.label", "LIKE"); 337 338 // psListLength(where->list) is at least 1 because exp_type defaults to "object" 339 // so we require a list longer than 1 entry 340 if ((psListLength(where->list) <= 1) && !psMetadataLookupBool(NULL, config->args, "-all")) { 341 psFree(where); 342 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 343 return false; 344 } 345 346 PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", true, false); 347 PXOPT_LOOKUP_STR(label, config->args, "-set_label", true, false); 348 PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false); 349 PXOPT_LOOKUP_STR(expgroup, config->args, "-set_expgroup", false, false); 350 PXOPT_LOOKUP_STR(dvodb, config->args, "-set_dvodb", false, false); 351 PXOPT_LOOKUP_STR(tess_id, config->args, "-set_tess_id", false, false); 352 PXOPT_LOOKUP_STR(end_stage, config->args, "-set_end_stage", false, false); 353 PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false); 354 PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false); 355 PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false); 356 357 // default 358 PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false); 359 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 360 361 // find the exp_id of all the exposures that we want to queue up. 362 psString query = pxDataGet("chiptool_definecopy.sql"); 363 if (!query) { 364 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 365 psFree(where); 366 return false; 367 } 368 369 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 370 psStringAppend(&query, " AND %s", whereClause); 371 372 psFree(whereClause); 373 psFree(where); 374 375 if (!p_psDBRunQueryF(config->dbh, query, label)) { 376 psError(PS_ERR_UNKNOWN, false, "database error"); 377 psFree(query); 378 return false; 379 } 380 psFree(query); 381 382 psArray *output = p_psDBFetchResult(config->dbh); 383 if (!output) { 384 psError(PS_ERR_UNKNOWN, false, "database error"); 385 return false; 386 } 387 if (!psArrayLength(output)) { 388 psTrace("chiptool", PS_LOG_INFO, "no rows found"); 389 psFree(output); 390 return true; 391 } 392 393 if (pretend) { 394 // negative simple so the default is true 395 if (!ippdbPrintMetadatas(stdout, output, "rawExp", !simple)) { 396 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 216 397 psFree(output); 217 398 return false; 218 399 } 219 } 220 221 222 # define GET_VALUE(PTYPE,CTYPE,VALUE,NAME) \ 223 PTYPE VALUE; \ 224 { bool status; \ 225 VALUE = psMetadataLookup##CTYPE(&status, md, NAME); \ 226 if (!status) { \ 227 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for %s", NAME); \ 228 psFree(output); \ 229 return false; \ 230 } } 231 232 // loop over our list of exp_ids 233 for (long i = 0; i < psArrayLength(output); i++) { 234 psMetadata *md = output->data[i]; 235 236 rawExpRow *row = rawExpObjectFromMetadata(md); 237 if (!row) { 238 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into chipRun"); 239 psFree(output); 240 return false; 241 } 242 243 GET_VALUE (psS64, S64, exp_id, "exp_id"); 244 GET_VALUE (psString, Str, raw_workdir, "workdir"); 245 GET_VALUE (psString, Str, raw_label, "label"); 246 GET_VALUE (psString, Str, raw_reduction, "reduction"); 247 // GET_VALUE (psString, Str, raw_expgroup, "expgroup"); 248 GET_VALUE (psString, Str, raw_dvodb, "dvodb"); 249 GET_VALUE (psString, Str, raw_tess_id, "tess_id"); 250 GET_VALUE (psString, Str, raw_end_stage, "end_stage"); 251 252 if (!row->exp_id) { 253 psError(PS_ERR_UNKNOWN, false, "failed to find value for exp_id"); 254 psFree(output); 255 return false; 256 } 257 258 // queue the exp 259 if (!pxchipQueueByExpTag(config, 260 exp_id, 261 workdir ? workdir : raw_workdir, 262 label ? label : raw_label, 263 reduction ? reduction : raw_reduction, 264 // expgroup ? expgroup : raw_expgroup, 265 // XXX how does expgroup get defined? 266 expgroup, 267 dvodb ? dvodb : raw_dvodb, 268 tess_id ? tess_id : raw_tess_id, 269 end_stage ? end_stage : raw_end_stage 270 )) { 271 if (!psDBRollback(config->dbh)) { 272 psError(PS_ERR_UNKNOWN, false, "database error"); 273 } 274 psError(PS_ERR_UNKNOWN, false, 275 "failed to trying to queue exp_id: %" PRId64, exp_id); 276 psFree(output); 277 return false; 278 } 400 psFree(output); 401 return true; 402 } 403 404 if (!queue_exposures(config, output, workdir, label, data_group, dist_group, reduction, expgroup, 405 dvodb, tess_id, end_stage, note)) { 406 psError(psErrorCodeLast(), false, "Unable to queue exposures for chip."); 407 psFree(output); 408 return false; 279 409 } 280 410 psFree(output); 281 282 if (!psDBCommit(config->dbh)) {283 psError(PS_ERR_UNKNOWN, false, "database error");284 return false;285 }286 411 287 412 return true; … … 299 424 PXOPT_COPY_STR(config->args, where, "-label", "chipRun.label", "=="); 300 425 PXOPT_COPY_STR(config->args, where, "-state", "chipRun.state", "=="); 301 302 if (!psListLength(where->list) && 303 !psMetadataLookupBool(NULL, config->args, "-all")) { 426 PXOPT_COPY_STR(config->args, where, "-data_group", "chipRun.data_group", "=="); 427 PXOPT_COPY_STR(config->args, where, "-dist_group", "chipRun.dist_group", "=="); 428 429 if (!psListLength(where->list)) { 304 430 psFree(where); 305 where = NULL; 306 psError(PXTOOLS_ERR_DATA, false, "search parameters are required"); 307 return false; 308 } 309 310 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, false); 311 PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false); 312 313 if ((!state) && (!label)) { 314 psError(PXTOOLS_ERR_DATA, false, "parameters are required"); 315 psFree(where); 316 return false; 317 } 318 319 if (state) { 320 // set chipRun.state to state 321 if (!pxchipRunSetStateByQuery(config, where, state)) { 322 psFree(where); 323 return false; 324 } 325 } 326 327 if (label) { 328 // set chipRun.label to label 329 if (!pxchipRunSetLabelByQuery(config, where, label)) { 330 psFree(where); 331 return false; 332 } 333 } 334 431 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 432 return false; 433 } 434 psString query = psStringCopy("UPDATE chipRun JOIN rawExp USING(exp_id) -- join hook %s\n"); 435 436 // pxUpdateRun gets parameters from config->args and updates 437 bool result = pxUpdateRun(config, where, &query, "chipRun", "chip_id", "chipProcessedImfile", true); 438 if (!result) { 439 psError(psErrorCodeLast(), false, "pxUpdateRun failed"); 440 } 441 442 psFree(query); 335 443 psFree(where); 336 444 337 return true;445 return result; 338 446 } 339 447 … … 353 461 psString query = pxDataGet("chiptool_pendingimfile.sql"); 354 462 if (!query) { 355 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");463 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 356 464 return false; 357 465 } … … 593 701 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 594 702 PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false); 703 PXOPT_LOOKUP_BOOL(allfiles, config->args, "-allfiles", false); 704 if (allfiles) { 705 faulted = false; 706 } 595 707 596 708 psMetadata *where = psMetadataAlloc(); … … 601 713 PXOPT_COPY_STR(config->args, where, "-reduction", "chipRun.reduction", "=="); 602 714 pxAddLabelSearchArgs (config, where, "-label", "chipRun.label", "LIKE"); 603 PXOPT_COPY_S64(config->args, where, "-magicked", "chipRun.magicked", "=="); 604 605 if (!psListLength(where->list) && 606 !psMetadataLookupBool(NULL, config->args, "-all")) { 607 psFree(where); 608 psError(PXTOOLS_ERR_DATA, false, "search parameters (or -all) are required"); 715 pxAddLabelSearchArgs (config, where, "-data_group", "chipRun.data_group", "LIKE"); 716 PXOPT_COPY_S64(config->args, where, "-magicked", "chipProcessedImfile.magicked", "=="); 717 718 psString where2 = NULL; 719 pxmagicAddWhere(config, &where2, "chipProcessedImfile"); 720 // add cuts on ra and decl if supplied 721 if (!pxspaceAddWhere(config, &where2, "rawExp")) { 722 psError(psErrorCodeLast(), false, "pxSpaceAddWhere failed"); 609 723 return false; 610 724 } … … 612 726 psString query = pxDataGet("chiptool_processedimfile.sql"); 613 727 if (!query) { 614 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");615 return false; 616 } 617 618 if ( where &&psListLength(where->list)) {728 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 729 return false; 730 } 731 732 if (psListLength(where->list)) { 619 733 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 620 psStringAppend(&query, " WHERE %s ", whereClause);734 psStringAppend(&query, " WHERE %s %s", whereClause, where2 ? where2 : ""); 621 735 psFree(whereClause); 736 } else if (psMetadataLookupBool(NULL, config->args, "-all") || (faulted || where2)) { 737 psStringAppend(&query, " WHERE chipRun.chip_id IS NOT NULL %s", where2 ? where2 : ""); 738 } else { 739 psFree(where); 740 psError(PXTOOLS_ERR_CONFIG, false, "search parameters (or -all) are required"); 741 return false; 622 742 } 623 743 psFree(where); … … 626 746 // list only faulted rows 627 747 psStringAppend(&query, " %s", "AND chipProcessedImfile.fault != 0"); 628 } else {748 } else if (!allfiles) { 629 749 // don't list faulted rows 630 750 psStringAppend(&query, " %s", "AND chipProcessedImfile.fault = 0"); … … 683 803 && !psMetadataLookupBool(NULL, config->args, "-all")) { 684 804 psFree(where); 685 psError(PXTOOLS_ERR_ DATA, false, "search parameters are required");805 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 686 806 return false; 687 807 } … … 689 809 psString query = pxDataGet("chiptool_revertprocessedimfile.sql"); 690 810 if (!query) { 691 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 811 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 812 psFree(where); 813 return false; 814 } 815 psString query_update = pxDataGet("chiptool_revertupdatedimfile.sql"); 816 if (!query) { 817 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 692 818 psFree(where); 693 819 return false; … … 697 823 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 698 824 psStringAppend(&query, " AND %s", whereClause); 825 psStringAppend(&query_update, " AND %s", whereClause); 699 826 psFree(whereClause); 700 827 } … … 708 835 } 709 836 psFree(query); 837 if (!p_psDBRunQuery(config->dbh, query_update)) { 838 psError(PS_ERR_UNKNOWN, false, "database error"); 839 psFree(query_update); 840 return false; 841 } 842 psFree(query_update); 710 843 711 844 return true; … … 719 852 PXOPT_COPY_S64(config->args, where, "-chip_id", "chip_id", "=="); 720 853 PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "=="); 721 PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false); 722 723 if (!pxSetFaultCode(config->dbh, "chipProcessedImfile", where, fault)) { 854 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, NULL); 855 if (psListLength(where->list) == 0) { 856 psError(PS_ERR_UNKNOWN, true, "search parameters are required"); 857 return false; 858 } 859 860 if (!state) { 861 PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false); 862 863 if (!pxSetFaultCode(config->dbh, "chipProcessedImfile", where, fault)) { 724 864 psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag"); 725 865 return false; 726 } 727 psFree(where); 866 } 867 psFree(where); 868 } 869 else { 870 if (!pxchipProcessedImfileSetStateByQuery(config,where,state)) { 871 psError(PS_ERR_UNKNOWN, false, "failed to set chipProcessedImfile state"); 872 return(false); 873 } 874 } 875 728 876 729 877 return true; … … 828 976 psString query = pxDataGet("chiptool_unmasked.sql"); 829 977 if (!query) { 830 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");978 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 831 979 return false; 832 980 } … … 906 1054 psString query = pxDataGet("chiptool_pendingcleanuprun.sql"); 907 1055 if (!query) { 908 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1056 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 909 1057 return false; 910 1058 } … … 970 1118 psString query = pxDataGet("chiptool_pendingcleanupimfile.sql"); 971 1119 if (!query) { 972 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1120 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 973 1121 return false; 974 1122 } … … 1031 1179 psString query = pxDataGet("chiptool_donecleanup.sql"); 1032 1180 if (!query) { 1033 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1181 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1034 1182 return false; 1035 1183 } … … 1089 1237 // make sure that the state string is valid 1090 1238 if (!pxIsValidState(state)) { 1091 psError(PXTOOLS_ERR_ DATA, false, "%s is not a valid state", state);1239 psError(PXTOOLS_ERR_CONFIG, false, "%s is not a valid state", state); 1092 1240 return false; 1093 1241 } 1094 1242 1095 1243 psMetadata *where = psMetadataAlloc(); 1244 pxchipGetSearchArgs (config, where); // chipRun, chipProcessedImfile, rawExp 1245 PXOPT_COPY_S64(config->args, where, "-chip_id", "chipRun.chip_id", "=="); 1246 PXOPT_COPY_STR(config->args, where, "-reduction", "chipRun.reduction", "=="); 1096 1247 pxAddLabelSearchArgs (config, where, "-label", "label", "=="); 1097 1248 PXOPT_COPY_STR(config->args, where, "-state", "state", "=="); … … 1099 1250 psString query = pxDataGet("chiptool_run.sql"); 1100 1251 if (!query) { 1101 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1252 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1102 1253 return false; 1103 1254 } … … 1161 1312 psString query = pxDataGet("chiptool_completely_processed_exp.sql"); 1162 1313 if (!query) { 1163 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1314 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1164 1315 return false; 1165 1316 } … … 1233 1384 chipRun->workdir, 1234 1385 chipRun->label, 1386 chipRun->data_group, 1387 chipRun->dist_group, 1235 1388 chipRun->reduction, 1236 1389 chipRun->expgroup, 1237 1390 chipRun->dvodb, 1238 1391 chipRun->tess_id, 1239 chipRun->end_stage 1392 chipRun->end_stage, 1393 chipRun->magicked, 1394 NULL // note does not propagate 1240 1395 )) { 1241 1396 if (!psDBRollback(config->dbh)) { … … 1278 1433 } 1279 1434 1280 psString set_magic = ""; 1435 psString set_magicked_imfile = psStringCopy(""); 1436 psString set_magicked_run = psStringCopy(""); 1281 1437 if (!strcmp(data_state, "full")) { 1282 // copy the magicked state from the input to the output when transitioning to full state 1283 set_magic = "\n , chipProcessedImfile.magicked = rawImfile.magicked"; 1284 } 1285 1286 // note only updates if chipRun.state = run_state 1287 // XXX note that we have removed this constraint for now 1288 if (!p_psDBRunQueryF(config->dbh, query, data_state, set_magic, chip_id, class_id)) { 1438 // if (chipProcessedImfile.magicked < 0 and rawImfile.magicked = 0) leave magicked unchanged. This will 1439 // block warp processing until destreaking has been done 1440 // otherwise copy magicked from the rawImfile 1441 // Same thing for chipRun/rawExp 1442 psStringAppend(&set_magicked_imfile, "\n , chipProcessedImfile.magicked = IF((chipProcessedImfile.magicked < 0" 1443 " AND rawImfile.magicked = 0), chipProcessedImfile.magicked, rawImfile.magicked)"); 1444 psStringAppend(&set_magicked_run, "\n , chipRun.magicked = IF((chipRun.magicked < 0 AND rawExp.magicked = 0), " 1445 " chipRun.magicked, rawExp.magicked)"); 1446 1447 } else if (!strcmp(data_state, "cleaned") || !strcmp(data_state, "purged")) { 1448 // if magicked is non-zero set it to -1 1449 // Once one imfile has been cleaned, the chipRun is no longer 'magicked' 1450 psStringAppend(&set_magicked_imfile, "\n, chipProcessedImfile.magicked = IF(chipProcessedImfile.magicked = 0, 0, -1)," 1451 " chipRun.magicked = IF(chipRun.magicked = 0, 0, -1)"); 1452 } 1453 1454 if (!p_psDBRunQueryF(config->dbh, query, data_state, set_magicked_imfile, chip_id, class_id)) { 1289 1455 psFree(query); 1290 1456 psError(PS_ERR_UNKNOWN, false, "database error"); … … 1297 1463 } 1298 1464 psFree(query); 1465 psFree(set_magicked_imfile); 1466 psFree(set_magicked_run); 1299 1467 if (psDBAffectedRows(config->dbh) < 1) { 1300 1468 psError(PS_ERR_UNKNOWN, false, "should have affected atleast 1 row"); … … 1303 1471 1304 1472 query = pxDataGet("chiptool_change_exp_state.sql"); 1305 if (!p_psDBRunQueryF(config->dbh, query, data_state, chip_id, data_state)) {1473 if (!p_psDBRunQueryF(config->dbh, query, data_state, set_magicked_run, chip_id, data_state)) { 1306 1474 psFree(query); 1307 1475 // rollback … … 1333 1501 return change_imfile_data_state(config, "purged", "goto_purged"); 1334 1502 } 1335 1503 static bool toscrubbedimfileMode(pxConfig *config) 1504 { 1505 return change_imfile_data_state(config, "scrubbed", "goto_scrubbed"); 1506 } 1336 1507 bool exportrunMode(pxConfig *config) 1337 1508 { … … 1357 1528 } 1358 1529 1530 if (!pxExportVersion(config, f)) { 1531 psError(PS_ERR_UNKNOWN, false, "failed to write dbversion output file"); 1532 return false; 1533 } 1534 1359 1535 psMetadata *where = psMetadataAlloc(); 1360 1536 PXOPT_COPY_S64(config->args, where, "-chip_id", "chip_id", "=="); … … 1370 1546 psString query = pxDataGet(tables[i].sqlFilename); 1371 1547 if (!query) { 1372 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1548 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1373 1549 return false; 1374 1550 } … … 1406 1582 1407 1583 if (clean) { 1408 bool success = true; 1584 bool success = true; 1409 1585 if (!strcmp(tables[i].tableName, "chipRun")) { 1410 1586 success = pxSetStateCleaned("chipRun", "state", output); … … 1448 1624 psVector *identifiers = psVectorAllocEmpty(16, PS_TYPE_U64); // Identifiers inserted 1449 1625 1626 psMetadataIterator *iter = psMetadataIteratorAlloc(input, PS_LIST_HEAD, NULL); // Iterator 1627 1628 if (!pxCheckImportVersion(config, input)) { 1629 psError(PS_ERR_UNKNOWN, false, "pxCheckImportVersion failed"); 1630 return false; 1631 } 1632 // first item is the dbversion, skip it 1633 psMetadataItem *dbversion = psMetadataGetAndIncrement(iter); 1634 (void) dbversion; 1635 1450 1636 if (!psDBTransaction(config->dbh)) { 1451 1637 psError(PS_ERR_UNKNOWN, false, "database error"); … … 1453 1639 } 1454 1640 1455 psMetadataIterator *iter = psMetadataIteratorAlloc(input, PS_LIST_HEAD, NULL); // Iterator1456 1641 psMetadataItem *item; // Item from iteration 1457 1642 while ((item = psMetadataGetAndIncrement(iter))) { … … 1482 1667 return true; 1483 1668 } 1669 1670 static bool runstateMode(pxConfig *config) 1671 { 1672 PS_ASSERT_PTR_NON_NULL(config, false); 1673 1674 psMetadata *where = psMetadataAlloc(); 1675 PXOPT_COPY_S64(config->args, where, "-chip_id", "chipRun.chip_id", "=="); 1676 PXOPT_COPY_S64(config->args, where, "-exp_id", "rawExp.exp_id", "=="); 1677 PXOPT_COPY_STR(config->args, where, "-exp_name", "rawExp.exp_name", "=="); 1678 pxAddLabelSearchArgs (config, where, "-label", "chipRun.label", "LIKE"); 1679 1680 // PXOPT_LOOKUP_BOOL(all, config->args, "-all", false); 1681 PXOPT_LOOKUP_BOOL(no_magic, config->args, "-no_magic", false); 1682 1683 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1684 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1685 1686 psString query = pxDataGet("chiptool_runstate.sql"); 1687 if (!query) { 1688 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1689 return false; 1690 } 1691 1692 if (psListLength(where->list)) { 1693 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1694 psStringAppend(&query, " WHERE %s", whereClause); 1695 psFree(whereClause); 1696 } else { 1697 psError(PXTOOLS_ERR_CONFIG, true, "search parameters or -all are required"); 1698 return false; 1699 } 1700 psFree(where); 1701 1702 // treat limit == 0 as "no limit" 1703 if (limit) { 1704 psString limitString = psDBGenerateLimitSQL(limit); 1705 psStringAppend(&query, " %s", limitString); 1706 psFree(limitString); 1707 } 1708 1709 if (!p_psDBRunQuery(config->dbh, query)) { 1710 psError(PS_ERR_UNKNOWN, false, "database error"); 1711 psFree(query); 1712 return false; 1713 } 1714 psFree(query); 1715 1716 psArray *output = p_psDBFetchResult(config->dbh); 1717 if (!output) { 1718 psErrorCode err = psErrorCodeLast(); 1719 switch (err) { 1720 case PS_ERR_DB_CLIENT: 1721 psError(PXTOOLS_ERR_SYS, false, "database error"); 1722 case PS_ERR_DB_SERVER: 1723 psError(PXTOOLS_ERR_PROG, false, "database error"); 1724 default: 1725 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 1726 } 1727 1728 return false; 1729 } 1730 if (!psArrayLength(output)) { 1731 psTrace("chiptool", PS_LOG_INFO, "no rows found"); 1732 psFree(output); 1733 return true; 1734 } 1735 1736 if (psArrayLength(output)) { 1737 // negative simple so the default is true 1738 if (!ippdbPrintMetadatas(stdout, output, "chipRunState", !simple)) { 1739 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1740 psFree(output); 1741 return false; 1742 } 1743 } 1744 1745 psFree(output); 1746 1747 return true; 1748 } 1749 1750 // a very specfic function to queue a cleaned chipProcessedImfile to be updated 1751 static bool setimfiletoupdateMode(pxConfig *config) 1752 { 1753 PS_ASSERT_PTR_NON_NULL(config, NULL); 1754 1755 PXOPT_LOOKUP_S64(chip_id, config->args, "-chip_id", true, false); 1756 PXOPT_LOOKUP_STR(class_id, config->args, "-class_id", false, false); 1757 PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false); 1758 1759 psString query = pxDataGet("chiptool_setimfiletoupdate.sql"); 1760 if (!query) { 1761 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1762 return false; 1763 } 1764 1765 psString setHook = psStringCopy(""); 1766 if (label) { 1767 psStringAppend(&setHook, "\n , chipRun.label = '%s'", label); 1768 } 1769 1770 if (class_id) { 1771 psStringAppend(&query, " AND (chipProcessedImfile.class_id = '%s')", class_id); 1772 } 1773 1774 if (!p_psDBRunQueryF(config->dbh, query, setHook, chip_id)) { 1775 psError(PS_ERR_UNKNOWN, false, "database error"); 1776 return false; 1777 } 1778 1779 psFree(setHook); 1780 psFree(query); 1781 1782 return true; 1783 } 1784 1785 static bool listrunMode(pxConfig *config) 1786 { 1787 PS_ASSERT_PTR_NON_NULL(config, NULL); 1788 1789 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1790 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1791 PXOPT_LOOKUP_BOOL(pstamp_order, config->args, "-pstamp_order", false); 1792 1793 psMetadata *where = psMetadataAlloc(); 1794 pxchipGetSearchArgs (config, where); // chipRun, chipProcessedImfile, rawExp 1795 PXOPT_COPY_S64(config->args, where, "-chip_id", "chipRun.chip_id", "=="); 1796 PXOPT_COPY_STR(config->args, where, "-reduction", "chipRun.reduction", "=="); 1797 PXOPT_COPY_STR(config->args, where, "-state", "chipRun.state", "=="); 1798 pxAddLabelSearchArgs (config, where, "-label", "chipRun.label", "LIKE"); 1799 pxAddLabelSearchArgs (config, where, "-data_group", "chipRun.data_group", "LIKE"); 1800 pxAddLabelSearchArgs (config, where, "-dist_group", "chipRun.dist_group", "LIKE"); 1801 PXOPT_COPY_S64(config->args, where, "-magicked", "chipRun.magicked", "=="); 1802 1803 psString where2 = NULL; 1804 pxmagicAddWhere(config, &where2, "chipRun"); 1805 // add cuts on ra and decl if supplied 1806 if (!pxspaceAddWhere(config, &where2, "rawExp")) { 1807 psError(psErrorCodeLast(), false, "pxSpaceAddWhere failed"); 1808 return false; 1809 } 1810 1811 psString query = pxDataGet("chiptool_listrun.sql"); 1812 if (!query) { 1813 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1814 return false; 1815 } 1816 1817 if (psListLength(where->list)) { 1818 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1819 psStringAppend(&query, " WHERE %s %s", whereClause, where2 ? where2 : ""); 1820 psFree(whereClause); 1821 } else if (psMetadataLookupBool(NULL, config->args, "-all") || where2) { 1822 psStringAppend(&query, " WHERE chipRun.chip_id IS NOT NULL %s", where2 ? where2 : ""); 1823 } else { 1824 psFree(where); 1825 psError(PXTOOLS_ERR_CONFIG, false, "search parameters (or -all) are required"); 1826 return false; 1827 } 1828 psFree(where); 1829 1830 if (pstamp_order) { 1831 // put runs in order of exposure id with newest chip Runs first 1832 // The postage stamp parser depends on this behavior 1833 psStringAppend(&query, "\nORDER by exp_id, chip_id DESC"); 1834 } 1835 1836 // treat limit == 0 as "no limit" 1837 if (limit) { 1838 psString limitString = psDBGenerateLimitSQL(limit); 1839 psStringAppend(&query, " %s", limitString); 1840 psFree(limitString); 1841 } 1842 1843 if (!p_psDBRunQuery(config->dbh, query)) { 1844 psError(PS_ERR_UNKNOWN, false, "database error"); 1845 psFree(query); 1846 return false; 1847 } 1848 psFree(query); 1849 1850 psArray *output = p_psDBFetchResult(config->dbh); 1851 if (!output) { 1852 psError(PS_ERR_UNKNOWN, false, "database error"); 1853 return false; 1854 } 1855 if (!psArrayLength(output)) { 1856 psTrace("chiptool", PS_LOG_INFO, "no rows found"); 1857 psFree(output); 1858 return true; 1859 } 1860 1861 // negative simple so the default is true 1862 if (!ippdbPrintMetadatas(stdout, output, "chipRun", !simple)) { 1863 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1864 psFree(output); 1865 return false; 1866 } 1867 1868 psFree(output); 1869 1870 return true; 1871 }
Note:
See TracChangeset
for help on using the changeset viewer.
