Changeset 27838 for branches/tap_branches/ippTools/src/chiptool.c
- Timestamp:
- May 3, 2010, 8:41:49 AM (16 years ago)
- Location:
- branches/tap_branches
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
ippTools/src (modified) (1 prop)
-
ippTools/src/chiptool.c (modified) (40 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/tap_branches
- Property svn:mergeinfo changed
-
branches/tap_branches/ippTools/src
- Property svn:ignore
-
old new 16 16 difftool 17 17 disttool 18 dqstatstool 18 19 faketool 19 20 flatcorr
-
- Property svn:ignore
-
branches/tap_branches/ippTools/src/chiptool.c
r25851 r27838 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); … … 58 59 static bool importrunMode(pxConfig *config); 59 60 static bool runstateMode(pxConfig *config); 61 static bool setimfiletoupdateMode(pxConfig *config); 62 static bool listrunMode(pxConfig *config); 60 63 61 64 # define MODECASE(caseName, func) \ … … 77 80 switch (config->mode) { 78 81 MODECASE(CHIPTOOL_MODE_DEFINEBYQUERY, definebyqueryMode); 82 MODECASE(CHIPTOOL_MODE_DEFINECOPY, definecopyMode); 79 83 MODECASE(CHIPTOOL_MODE_UPDATERUN, updaterunMode); 80 84 MODECASE(CHIPTOOL_MODE_PENDINGIMFILE, pendingimfileMode); … … 95 99 MODECASE(CHIPTOOL_MODE_TOFULLIMFILE, tofullimfileMode); 96 100 MODECASE(CHIPTOOL_MODE_TOPURGEDIMFILE, topurgedimfileMode); 97 MODECASE(CHIPTOOL_MODE_TOSCRUBBEDIMFILE, toscrubbedimfileMode);101 MODECASE(CHIPTOOL_MODE_TOSCRUBBEDIMFILE, toscrubbedimfileMode); 98 102 MODECASE(CHIPTOOL_MODE_EXPORTRUN, exportrunMode); 99 103 MODECASE(CHIPTOOL_MODE_IMPORTRUN, importrunMode); 100 104 MODECASE(CHIPTOOL_MODE_RUNSTATE, runstateMode); 105 MODECASE(CHIPTOOL_MODE_SETIMFILETOUPDATE, setimfiletoupdateMode); 106 MODECASE(CHIPTOOL_MODE_LISTRUN, listrunMode); 101 107 default: 102 108 psAbort("invalid option (this should not happen)"); … … 120 126 } 121 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 } 122 240 123 241 static bool definebyqueryMode(pxConfig *config) … … 129 247 psMetadata *where = psMetadataAlloc(); 130 248 pxchipGetSearchArgs (config, where); // rawExp only 131 pxAddLabelSearchArgs (config, where, "-label", "newExp.label", "LIKE"); 249 pxAddLabelSearchArgs (config, where, "-label", "newExp.label", "LIKE"); // define using newExp label 132 250 133 251 // psListLength(where->list) is at least 1 because exp_type defaults to "object" … … 135 253 if ((psListLength(where->list) <= 1) && !psMetadataLookupBool(NULL, config->args, "-all")) { 136 254 psFree(where); 137 psError(PXTOOLS_ERR_ DATA, false, "search parameters are required");255 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 138 256 return false; 139 257 } … … 157 275 psString query = pxDataGet("chiptool_find_rawexp.sql"); 158 276 if (!query) { 159 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");277 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 160 278 psFree(where); 161 279 return false; … … 197 315 } 198 316 199 // start a transaction so we don't end up with an exp without any associted 200 // imfiles 201 if (!psDBTransaction(config->dbh)) { 202 psError(PS_ERR_UNKNOWN, false, "database error"); 203 psFree(output); 204 return false; 205 } 206 207 // if end_stage is warp (or NULL), check for valid tess_id 208 for (long i = 0; i < psArrayLength(output); i++) { 209 psMetadata *md = output->data[i]; 210 211 bool status; 212 char *end_stage = psMetadataLookupStr(&status, md, "end_stage"); 213 if (end_stage && strcasecmp(end_stage, "warp")) continue; 214 215 char *raw_tess_id = psMetadataLookupStr(&status, md, "tess_id"); 216 if (raw_tess_id || tess_id) continue; 217 218 char *label = psMetadataLookupStr(&status, md, "label"); 219 psS64 exp_id = psMetadataLookupS64(&status, md, "exp_id"); 220 221 if (!status) { 222 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"); 223 397 psFree(output); 224 398 return false; 225 399 } 226 } 227 228 229 # define GET_VALUE(PTYPE,CTYPE,VALUE,NAME) \ 230 PTYPE VALUE; \ 231 { bool status; \ 232 VALUE = psMetadataLookup##CTYPE(&status, md, NAME); \ 233 if (!status) { \ 234 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for %s", NAME); \ 235 psFree(output); \ 236 return false; \ 237 } } 238 239 // loop over our list of exp_ids 240 for (long i = 0; i < psArrayLength(output); i++) { 241 psMetadata *md = output->data[i]; 242 243 rawExpRow *row = rawExpObjectFromMetadata(md); 244 if (!row) { 245 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata into chipRun"); 246 psFree(output); 247 return false; 248 } 249 250 GET_VALUE (psS64, S64, exp_id, "exp_id"); 251 GET_VALUE (psString, Str, raw_workdir, "workdir"); 252 GET_VALUE (psString, Str, raw_label, "label"); 253 GET_VALUE (psString, Str, raw_reduction, "reduction"); 254 // GET_VALUE (psString, Str, raw_expgroup, "expgroup"); 255 GET_VALUE (psString, Str, raw_dvodb, "dvodb"); 256 GET_VALUE (psString, Str, raw_tess_id, "tess_id"); 257 GET_VALUE (psString, Str, raw_end_stage, "end_stage"); 258 259 if (!row->exp_id) { 260 psError(PS_ERR_UNKNOWN, false, "failed to find value for exp_id"); 261 psFree(output); 262 return false; 263 } 264 265 // queue the exp 266 if (!pxchipQueueByExpTag(config, 267 exp_id, 268 workdir ? workdir : raw_workdir, 269 label ? label : raw_label, 270 data_group ? data_group : (label ? label : raw_label), 271 dist_group, 272 reduction ? reduction : raw_reduction, 273 // expgroup ? expgroup : raw_expgroup, 274 // XXX how does expgroup get defined? 275 expgroup, 276 dvodb ? dvodb : raw_dvodb, 277 tess_id ? tess_id : raw_tess_id, 278 end_stage ? end_stage : raw_end_stage, 279 note 280 )) { 281 if (!psDBRollback(config->dbh)) { 282 psError(PS_ERR_UNKNOWN, false, "database error"); 283 } 284 psError(PS_ERR_UNKNOWN, false, 285 "failed to trying to queue exp_id: %" PRId64, exp_id); 286 psFree(output); 287 return false; 288 } 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; 289 409 } 290 410 psFree(output); 291 292 if (!psDBCommit(config->dbh)) {293 psError(PS_ERR_UNKNOWN, false, "database error");294 return false;295 }296 411 297 412 return true; … … 314 429 if (!psListLength(where->list)) { 315 430 psFree(where); 316 psError(PXTOOLS_ERR_ DATA, false, "search parameters are required");317 return false; 318 } 319 psString query = psStringCopy("UPDATE chipRun JOIN rawExp USING(exp_id) ");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"); 320 435 321 436 // pxUpdateRun gets parameters from config->args and updates 322 bool result = pxUpdateRun(config, where, &query, "chipRun", true);437 bool result = pxUpdateRun(config, where, &query, "chipRun", "chip_id", "chipProcessedImfile", true); 323 438 if (!result) { 324 psError( PXTOOLS_ERR_DATA, false, "pxUpdateRun failed");439 psError(psErrorCodeLast(), false, "pxUpdateRun failed"); 325 440 } 326 441 … … 346 461 psString query = pxDataGet("chiptool_pendingimfile.sql"); 347 462 if (!query) { 348 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");463 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 349 464 return false; 350 465 } … … 586 701 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 587 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 } 588 707 589 708 psMetadata *where = psMetadataAlloc(); … … 594 713 PXOPT_COPY_STR(config->args, where, "-reduction", "chipRun.reduction", "=="); 595 714 pxAddLabelSearchArgs (config, where, "-label", "chipRun.label", "LIKE"); 715 pxAddLabelSearchArgs (config, where, "-data_group", "chipRun.data_group", "LIKE"); 596 716 PXOPT_COPY_S64(config->args, where, "-magicked", "chipProcessedImfile.magicked", "=="); 597 717 … … 600 720 // add cuts on ra and decl if supplied 601 721 if (!pxspaceAddWhere(config, &where2, "rawExp")) { 602 psError( PXTOOLS_ERR_DATA, false, "pxSpaceAddWhere failed");722 psError(psErrorCodeLast(), false, "pxSpaceAddWhere failed"); 603 723 return false; 604 724 } … … 606 726 psString query = pxDataGet("chiptool_processedimfile.sql"); 607 727 if (!query) { 608 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");728 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 609 729 return false; 610 730 } … … 612 732 if (psListLength(where->list)) { 613 733 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 614 psStringAppend(&query, " WHERE %s ", whereClause);734 psStringAppend(&query, " WHERE %s %s", whereClause, where2 ? where2 : ""); 615 735 psFree(whereClause); 616 736 } else if (psMetadataLookupBool(NULL, config->args, "-all") || (faulted || where2)) { … … 618 738 } else { 619 739 psFree(where); 620 psError(PXTOOLS_ERR_ DATA, false, "search parameters (or -all) are required");740 psError(PXTOOLS_ERR_CONFIG, false, "search parameters (or -all) are required"); 621 741 return false; 622 742 } … … 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; … … 720 853 PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "=="); 721 854 PXOPT_LOOKUP_STR(state, config->args, "-set_state", false, NULL); 722 855 if (psListLength(where->list) == 0) { 856 psError(PS_ERR_UNKNOWN, true, "search parameters are required"); 857 return false; 858 } 859 723 860 if (!state) { 724 861 PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false); 725 862 726 863 if (!pxSetFaultCode(config->dbh, "chipProcessedImfile", where, fault)) { 727 864 psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag"); … … 732 869 else { 733 870 if (!pxchipProcessedImfileSetStateByQuery(config,where,state)) { 734 psError(PS_ERR_UNKNOWN, false, "failed to set chipProcessedImfile state");735 return(false);871 psError(PS_ERR_UNKNOWN, false, "failed to set chipProcessedImfile state"); 872 return(false); 736 873 } 737 874 } 738 875 739 876 740 877 return true; 741 878 } … … 839 976 psString query = pxDataGet("chiptool_unmasked.sql"); 840 977 if (!query) { 841 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");978 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 842 979 return false; 843 980 } … … 917 1054 psString query = pxDataGet("chiptool_pendingcleanuprun.sql"); 918 1055 if (!query) { 919 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1056 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 920 1057 return false; 921 1058 } … … 981 1118 psString query = pxDataGet("chiptool_pendingcleanupimfile.sql"); 982 1119 if (!query) { 983 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1120 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 984 1121 return false; 985 1122 } … … 1042 1179 psString query = pxDataGet("chiptool_donecleanup.sql"); 1043 1180 if (!query) { 1044 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1181 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1045 1182 return false; 1046 1183 } … … 1100 1237 // make sure that the state string is valid 1101 1238 if (!pxIsValidState(state)) { 1102 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); 1103 1240 return false; 1104 1241 } … … 1113 1250 psString query = pxDataGet("chiptool_run.sql"); 1114 1251 if (!query) { 1115 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1252 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1116 1253 return false; 1117 1254 } … … 1175 1312 psString query = pxDataGet("chiptool_completely_processed_exp.sql"); 1176 1313 if (!query) { 1177 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1314 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1178 1315 return false; 1179 1316 } … … 1254 1391 chipRun->tess_id, 1255 1392 chipRun->end_stage, 1393 chipRun->magicked, 1256 1394 NULL // note does not propagate 1257 1395 )) { … … 1295 1433 } 1296 1434 1297 psString set_magic = ""; 1435 psString set_magicked_imfile = psStringCopy(""); 1436 psString set_magicked_run = psStringCopy(""); 1298 1437 if (!strcmp(data_state, "full")) { 1299 // copy the magicked state from the input to the output when transitioning to full state 1300 set_magic = "\n , chipProcessedImfile.magicked = rawImfile.magicked"; 1301 } 1302 1303 // note only updates if chipRun.state = run_state 1304 // XXX note that we have removed this constraint for now 1305 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)) { 1306 1455 psFree(query); 1307 1456 psError(PS_ERR_UNKNOWN, false, "database error"); … … 1314 1463 } 1315 1464 psFree(query); 1465 psFree(set_magicked_imfile); 1466 psFree(set_magicked_run); 1316 1467 if (psDBAffectedRows(config->dbh) < 1) { 1317 1468 psError(PS_ERR_UNKNOWN, false, "should have affected atleast 1 row"); … … 1320 1471 1321 1472 query = pxDataGet("chiptool_change_exp_state.sql"); 1322 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)) { 1323 1474 psFree(query); 1324 1475 // rollback … … 1395 1546 psString query = pxDataGet(tables[i].sqlFilename); 1396 1547 if (!query) { 1397 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1548 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1398 1549 return false; 1399 1550 } … … 1431 1582 1432 1583 if (clean) { 1433 bool success = true; 1584 bool success = true; 1434 1585 if (!strcmp(tables[i].tableName, "chipRun")) { 1435 1586 success = pxSetStateCleaned("chipRun", "state", output); … … 1535 1686 psString query = pxDataGet("chiptool_runstate.sql"); 1536 1687 if (!query) { 1537 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1688 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1538 1689 return false; 1539 1690 } … … 1544 1695 psFree(whereClause); 1545 1696 } else { 1546 psError(PXTOOLS_ERR_ DATA, true, "search parameters or -all are required");1697 psError(PXTOOLS_ERR_CONFIG, true, "search parameters or -all are required"); 1547 1698 return false; 1548 1699 } … … 1596 1747 return true; 1597 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.
