- 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/regtool.c (modified) (32 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/regtool.c
r24866 r27840 37 37 static bool revertprocessedimfileMode(pxConfig *config); 38 38 static bool updateprocessedimfileMode(pxConfig *config); 39 static bool pendingcompressimfileMode(pxConfig *config); 39 40 // exp 40 41 static bool pendingexpMode(pxConfig *config); … … 44 45 static bool updateprocessedexpMode(pxConfig *config); 45 46 static bool cleardupexpMode(pxConfig *config); 47 static bool finishcompressexpMode(pxConfig *config); 48 49 static bool updatebyqueryMode(pxConfig *config); 50 46 51 static bool exportrunMode(pxConfig *config); 47 52 static bool importrunMode(pxConfig *config); … … 77 82 MODECASE(REGTOOL_MODE_REVERTPROCESSEDEXP, revertprocessedexpMode); 78 83 MODECASE(REGTOOL_MODE_UPDATEPROCESSEDEXP, updateprocessedexpMode); 84 MODECASE(REGTOOL_MODE_UPDATEBYQUERY, updatebyqueryMode); 85 MODECASE(REGTOOL_MODE_PENDINGCOMPRESSIMFILE, pendingcompressimfileMode); 86 MODECASE(REGTOOL_MODE_FINISHCOMPRESSEXP, finishcompressexpMode); 79 87 MODECASE(REGTOOL_MODE_CLEARDUPEXP, cleardupexpMode); 80 88 MODECASE(REGTOOL_MODE_EXPORTRUN, exportrunMode); … … 117 125 psString query = pxDataGet("regtool_pendingimfile.sql"); 118 126 if (!query) { 119 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");127 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 120 128 return false; 121 129 } … … 189 197 PXOPT_LOOKUP_STR(obs_mode, config->args, "-obs_mode", false, false); 190 198 PXOPT_LOOKUP_STR(obs_group, config->args, "-obs_group", false, false); 199 PXOPT_LOOKUP_STR(data_state, config->args, "-data_state", false, false); 191 200 192 201 PXOPT_LOOKUP_F32(airmass, config->args, "-airmass", false, false); … … 224 233 PXOPT_LOOKUP_F32(teltemp_extra, config->args, "-teltemp_extra", false, false); 225 234 PXOPT_LOOKUP_F32(pon_time, config->args, "-pon_time", false, false); 235 PXOPT_LOOKUP_S16(burntool_state, config->args, "-burntool_state", false, false); 226 236 PXOPT_LOOKUP_F64(user_1, config->args, "-user_1", false, false); 227 237 PXOPT_LOOKUP_F64(user_2, config->args, "-user_2", false, false); … … 238 248 PXOPT_LOOKUP_TIME(dateobs, config->args, "-dateobs", false, false); 239 249 PXOPT_LOOKUP_STR(hostname, config->args, "-hostname", false, false); 250 PXOPT_LOOKUP_S32(bytes, config->args, "-bytes", false, false); 251 PXOPT_LOOKUP_STR(md5sum, config->args, "-md5sum", false, false); 240 252 241 253 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); … … 252 264 class_id, 253 265 uri, 266 data_state, 254 267 exp_type, 255 268 filelevel, … … 307 320 quality, 308 321 NULL, 309 0 322 0, 323 bytes, 324 md5sum, 325 0 // burntool_state 310 326 )) { 311 327 psError(PS_ERR_UNKNOWN, false, "database error"); … … 327 343 PXOPT_COPY_TIME(config->args, where, "-dateobs_begin", "dateobs", ">="); 328 344 PXOPT_COPY_TIME(config->args, where, "-dateobs_end", "dateobs", "<="); 345 PXOPT_COPY_STR(config->args, where, "-filter", "filter", "LIKE"); 346 PXOPT_COPY_STR(config->args, where, "-exp_type", "exp_type", "=="); 347 PXOPT_COPY_STR(config->args, where, "-obs_mode", "obs_mode", "=="); 348 PXOPT_COPY_STR(config->args, where, "-data_state", "data_state", "=="); 329 349 330 350 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 331 351 PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false); 352 PXOPT_LOOKUP_BOOL(allfiles, config->args, "-allfiles", false); 353 if (allfiles) { 354 faulted = false; 355 } 332 356 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 357 PXOPT_LOOKUP_BOOL(all, config->args, "-all", false); 358 PXOPT_LOOKUP_BOOL(ordered_by_date, config->args, "-ordered_by_date", false); 359 360 // build where string for some parameters that don't fit PXOPT_COPY* 361 psString where2 = NULL; 362 if (!pxmagicAddWhere(config, &where2, "rawImfile")) { 363 psError(psErrorCodeLast(), false, "pxmagicAddWhere failed"); 364 return false; 365 } 366 if (!pxspaceAddWhere(config, &where2, "rawImfile")) { 367 psError(psErrorCodeLast(), false, "pxspaceAddWhere failed"); 368 return false; 369 } 333 370 334 371 psString query = pxDataGet("regtool_processedimfile.sql"); 335 372 if (!query) { 336 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");373 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 337 374 psFree(where); 338 375 return false; … … 343 380 psStringAppend(&query, " AND %s", whereClause); 344 381 psFree(whereClause); 382 } else if (!all && !where2) { 383 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 384 return false; 345 385 } 346 386 psFree(where); 387 if (where2) { 388 psStringAppend(&query, " %s", where2); 389 psFree(where2); 390 } 347 391 348 392 if (faulted) { 349 393 // list only faulted rows 350 394 psStringAppend(&query, " %s", "AND rawImfile.fault != 0"); 351 } else {395 } else if (!allfiles) { 352 396 // don't list faulted rows 353 397 psStringAppend(&query, " %s", "AND rawImfile.fault = 0"); 398 } 399 400 // add the ORDER BY statement if desired 401 if (ordered_by_date) { 402 psStringAppend(&query, " ORDER BY dateobs"); 354 403 } 355 404 … … 417 466 psString query = pxDataGet("regtool_revertprocessedimfile.sql"); 418 467 if (!query) { 419 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");468 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 420 469 psFree(where); 421 470 return false; … … 428 477 } else { 429 478 psFree(where); 430 psError(PXTOOLS_ERR_ DATA, false, "search parameters are required");479 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 431 480 return false; 432 481 } … … 456 505 457 506 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 458 PXOPT_LOOKUP_F64(user_1, config->args, "-user_1", false, false); 459 460 if ((fault == INT16_MAX) && !isfinite(user_1)) { 461 psError(PS_ERR_UNKNOWN, false, "one of -fault or -user_1 must be selected"); 462 return false; 463 } 464 if ((fault != INT16_MAX) && isfinite(user_1)) { 465 psError(PS_ERR_UNKNOWN, false, "only one of -fault or -user_1 must be selected"); 507 PXOPT_LOOKUP_S16(burntool_state, config->args, "-burntool_state", false, false); 508 PXOPT_LOOKUP_S32(set_bytes, config->args, "-set_bytes", false, false); 509 PXOPT_LOOKUP_STR(set_md5sum, config->args, "-set_md5sum", false, false); 510 PXOPT_LOOKUP_STR(set_state, config->args, "-set_state", false, false); 511 512 if ((fault == INT16_MAX) && !isfinite(burntool_state) && !(set_state)) { 513 psError(PS_ERR_UNKNOWN, false, "one of -fault or -burntool_state or -set_state must be selected"); 514 return false; 515 } 516 if ((fault != INT16_MAX) && isfinite(burntool_state)) { 517 psError(PS_ERR_UNKNOWN, false, "only one of -fault or -burntool_state must be selected"); 466 518 return false; 467 519 } … … 472 524 473 525 if (fault != INT16_MAX) { 474 // this is fairly dangerous : can set all if the where is not set... 475 if (!pxSetFaultCode(config->dbh, "rawImfile", where, fault)) { 476 psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag"); 477 psFree (where); 478 return false; 479 } 480 } 481 482 if (isfinite(user_1)) { 483 psString query = pxDataGet("regtool_updateprocessedimfile.sql"); 484 if (!query) { 485 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 486 return false; 487 } 488 489 if (!p_psDBRunQueryF(config->dbh, query, user_1, exp_id, class_id)) { 490 psError(PS_ERR_UNKNOWN, false, "database error"); 491 psFree(query); 492 return false; 493 } 494 psFree(query); 526 // this is fairly dangerous : can set all if the where is not set... 527 if (!pxSetFaultCode(config->dbh, "rawImfile", where, fault)) { 528 psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag"); 529 psFree (where); 530 return false; 531 } 532 psFree (where); 533 return(true); 495 534 } 496 535 psFree (where); 497 536 537 psString setvalues = NULL; 538 if (burntool_state != INT16_MAX) { 539 psStringAppend(&setvalues,"rawImfile.burntool_state = %d",burntool_state); 540 } 541 if (set_bytes != INT32_MAX) { 542 if (setvalues) { 543 psStringAppend(&setvalues,","); 544 } 545 psStringAppend(&setvalues,"rawImfile.bytes = %d",set_bytes); 546 } 547 if (set_md5sum) { 548 if (setvalues) { 549 psStringAppend(&setvalues,","); 550 } 551 psStringAppend(&setvalues,"rawImfile.md5sum = '%s'",set_md5sum); 552 } 553 if (set_state) { 554 if (setvalues) { 555 psStringAppend(&setvalues,","); 556 } 557 psStringAppend(&setvalues,"rawImfile.data_state = '%s'",set_state); 558 } 559 560 psString query = pxDataGet("regtool_updateprocessedimfile.sql"); 561 if (!query) { 562 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 563 return false; 564 } 565 566 // printf(query,setvalues,exp_id,class_id); 567 if (!p_psDBRunQueryF(config->dbh, query, setvalues, exp_id,class_id)) { 568 psError(PS_ERR_UNKNOWN, false, "database error"); 569 psFree(query); 570 psFree(setvalues); 571 return false; 572 } 573 psFree(setvalues); 574 psFree(query); 575 498 576 return true; 577 } 578 579 static bool pendingcompressimfileMode(pxConfig *config) { 580 PS_ASSERT_PTR_NON_NULL(config, false); 581 582 psMetadata *where = psMetadataAlloc(); 583 PXOPT_COPY_S64(config->args, where, "-exp_id", "exp_id", "=="); 584 PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "=="); 585 586 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 587 if (whereClause) { 588 psStringPrepend(&whereClause, "\n AND "); 589 } 590 PXOPT_LOOKUP_BOOL(compress, config->args, "-compress", false); 591 PXOPT_LOOKUP_BOOL(clean, config->args, "-clean", false); 592 593 if ((compress && clean) || (!compress && !clean)) { 594 psStringAppend(&whereClause, "\n AND ((data_state = 'goto_compressed' AND state = 'goto_compressed')\n OR (data_state = 'goto_lossy' AND state = 'goto_lossy')) "); 595 } 596 else if (compress) { 597 psStringAppend(&whereClause, "\n AND ((data_state = 'goto_compressed' AND state = 'goto_compressed')) "); 598 } 599 else if (clean) { 600 psStringAppend(&whereClause, "\n AND ((data_state = 'goto_lossy' AND state = 'goto_lossy')) "); 601 } 602 else { 603 psStringAppend(&whereClause, "\n AND ((data_state = 'goto_compressed' AND state = 'goto_compressed')\n OR (data_state = 'goto_lossy' AND state = 'goto_lossy')) "); 604 } 605 606 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 607 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 608 609 psString query = pxDataGet("regtool_pendingcompressimfile.sql"); 610 if (!query) { 611 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 612 return(false); 613 } 614 psString limitString = NULL; 615 if (limit) { 616 limitString = psDBGenerateLimitSQL(limit); 617 psStringPrepend(&limitString, "\n"); 618 } 619 // printf(query,whereClause,limitString); 620 if (!p_psDBRunQueryF(config->dbh, query, whereClause, limitString ? limitString : "")) { 621 psError(PXTOOLS_ERR_PROG, false, "database error"); 622 psFree(limitString); 623 psFree(query); 624 psFree(whereClause); 625 psFree(where); 626 return(false); 627 } 628 psFree(limitString); 629 psFree(query); 630 psFree(whereClause); 631 psFree(where); 632 633 psArray *output = p_psDBFetchResult(config->dbh); 634 if (!output) { 635 psErrorCode err = psErrorCodeLast(); 636 switch (err) { 637 case PS_ERR_DB_CLIENT: 638 psError(PXTOOLS_ERR_SYS, false, "database error"); 639 case PS_ERR_DB_SERVER: 640 psError(PXTOOLS_ERR_PROG, false, "database error"); 641 default: 642 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 643 } 644 645 return false; 646 } 647 if (!psArrayLength(output)) { 648 psTrace("regtool", PS_LOG_INFO, "no rows found"); 649 psFree(output); 650 return true; 651 } 652 653 // negate simple so the default is true 654 if (!ippdbPrintMetadatas(stdout, output, "regPendingCompressImfile", !simple)) { 655 psError(PXTOOLS_ERR_PROG, false, "failed to print array"); 656 psFree(output); 657 return false; 658 } 659 660 psFree(output); 661 662 return true; 499 663 } 500 664 … … 513 677 psString query = pxDataGet("regtool_pendingexp.sql"); 514 678 if (!query) { 515 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");679 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 516 680 return false; 517 681 } … … 590 754 PXOPT_LOOKUP_STR(exp_type, config->args, "-exp_type", false, false); 591 755 PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", false, false); 756 PXOPT_LOOKUP_STR(state, config->args, "-state", false, false); 592 757 PXOPT_LOOKUP_STR(dvodb, config->args, "-dvodb", false, false); 593 758 PXOPT_LOOKUP_STR(tess_id, config->args, "-tess_id", false, false); … … 651 816 psString query = pxDataGet("regtool_pendingexp.sql"); 652 817 if (!query) { 653 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");818 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 654 819 return false; 655 820 } … … 751 916 filelevel, 752 917 workdir, 918 state, 753 919 reduction, 754 920 dvodb, … … 849 1015 workdir, 850 1016 label, 1017 NULL, // data_group 1018 NULL, // dist_group 851 1019 reduction, 852 NULL, // expgroup1020 NULL, // expgroup 853 1021 dvodb, 854 1022 tess_id, 855 end_stage 1023 end_stage, 1024 NULL // note 856 1025 )) { 857 1026 // rollback … … 881 1050 psString query = pxDataGet("regtool_processedexp.sql"); 882 1051 if (!query) { 883 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1052 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 884 1053 return false; 885 1054 } … … 891 1060 PXOPT_COPY_STR(config->args, where, "-inst", "camera", "=="); 892 1061 PXOPT_COPY_STR(config->args, where, "-telescope", "telescope", "=="); 893 PXOPT_COPY_TIME(config->args, where, "-dateobs_begin", "dateobs", ">="); 894 PXOPT_COPY_TIME(config->args, where, "-dateobs_end", "dateobs", "<="); 1062 PXOPT_COPY_TIME(config->args, where, "-dateobs_begin", "dateobs", ">="); 1063 PXOPT_COPY_TIME(config->args, where, "-dateobs_end", "dateobs", "<="); 1064 PXOPT_COPY_STR(config->args, where, "-state", "state", "=="); 895 1065 PXOPT_COPY_STR(config->args, where, "-exp_tag", "exp_tag", "=="); 896 1066 PXOPT_COPY_STR(config->args, where, "-exp_type", "exp_type", "=="); 897 1067 PXOPT_COPY_STR(config->args, where, "-filelevel", "filelevel", "=="); 898 1068 PXOPT_COPY_STR(config->args, where, "-reduction", "reduction", "=="); 899 PXOPT_COPY_STR(config->args, where, "-filter", "filter", " ==");1069 PXOPT_COPY_STR(config->args, where, "-filter", "filter", "LIKE"); 900 1070 PXOPT_COPY_F32(config->args, where, "-airmass_min", "airmass", ">="); 901 1071 PXOPT_COPY_F32(config->args, where, "-airmass_max", "airmass", "<"); … … 926 1096 PXOPT_COPY_F32(config->args, where, "-sun_angle_max", "sun_angle", "<"); 927 1097 1098 psString where2 = NULL; 1099 if (!pxmagicAddWhere(config, &where2, "rawExp")) { 1100 psError(psErrorCodeLast(), false, "pxmagicAddWhere failed"); 1101 return false; 1102 } 1103 if (!pxspaceAddWhere(config, &where2, "rawExp")) { 1104 psError(psErrorCodeLast(), false, "pxSpaceAddWhere failed"); 1105 return false; 1106 } 1107 928 1108 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 929 1109 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); … … 931 1111 932 1112 if (psListLength(where->list)) { 933 psString whereClause = psDBGenerateWhereConditionSQL(where, "rawExp");934 psStringAppend(&query, " AND %s", whereClause);935 psFree(whereClause);1113 psString whereClause = psDBGenerateWhereConditionSQL(where, "rawExp"); 1114 psStringAppend(&query, " AND %s", whereClause); 1115 psFree(whereClause); 936 1116 } 937 1117 psFree(where); 938 1118 1119 if (where2) { 1120 psStringAppend(&query, " %s ", where2); 1121 psFree(where2); 1122 } 1123 939 1124 if (faulted) { 940 // list only faulted rows941 psStringAppend(&query, " %s", "AND rawExp.fault != 0");1125 // list only faulted rows 1126 psStringAppend(&query, " %s", "AND rawExp.fault != 0"); 942 1127 } else { 943 // don't list faulted rows944 psStringAppend(&query, " %s", "AND rawExp.fault = 0");1128 // don't list faulted rows 1129 psStringAppend(&query, " %s", "AND rawExp.fault = 0"); 945 1130 } 946 1131 947 1132 // treat limit == 0 as "no limit" 948 1133 if (limit) { 949 psString limitString = psDBGenerateLimitSQL(limit);950 psStringAppend(&query, " %s", limitString);951 psFree(limitString);1134 psString limitString = psDBGenerateLimitSQL(limit); 1135 psStringAppend(&query, " %s", limitString); 1136 psFree(limitString); 952 1137 } 953 1138 954 1139 if (!p_psDBRunQuery(config->dbh, query)) { 955 psError(PS_ERR_UNKNOWN, false, "database error");956 return false;1140 psError(PS_ERR_UNKNOWN, false, "database error"); 1141 return false; 957 1142 } 958 1143 psFree(query); … … 960 1145 psArray *output = p_psDBFetchResult(config->dbh); 961 1146 if (!output) { 962 psErrorCode err = psErrorCodeLast();963 switch (err) {964 case PS_ERR_DB_CLIENT:965 psError(PXTOOLS_ERR_SYS, false, "database error");966 case PS_ERR_DB_SERVER:967 psError(PXTOOLS_ERR_PROG, false, "database error");968 default:969 psError(PXTOOLS_ERR_PROG, false, "unknown error");970 }971 972 return false;1147 psErrorCode err = psErrorCodeLast(); 1148 switch (err) { 1149 case PS_ERR_DB_CLIENT: 1150 psError(PXTOOLS_ERR_SYS, false, "database error"); 1151 case PS_ERR_DB_SERVER: 1152 psError(PXTOOLS_ERR_PROG, false, "database error"); 1153 default: 1154 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 1155 } 1156 1157 return false; 973 1158 } 974 1159 if (!psArrayLength(output)) { 975 psTrace("regtool", PS_LOG_INFO, "no rows found"); 1160 psTrace("regtool", PS_LOG_INFO, "no rows found"); 1161 psFree(output); 1162 return true; 1163 } 1164 1165 if (psArrayLength(output)) { 1166 // negative simple so the default is true 1167 if (!ippdbPrintMetadatas(stdout, output, "rawExp", !simple)) { 1168 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 976 1169 psFree(output); 977 return true; 978 } 979 980 if (psArrayLength(output)) { 981 // negative simple so the default is true 982 if (!ippdbPrintMetadatas(stdout, output, "rawExp", !simple)) { 983 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 984 psFree(output); 985 return false; 986 } 1170 return false; 1171 } 987 1172 } 988 1173 … … 994 1179 static bool revertprocessedexpMode(pxConfig *config) 995 1180 { 996 PS_ASSERT_PTR_NON_NULL(config, false); 997 998 psMetadata *where = psMetadataAlloc(); 999 PXOPT_COPY_S64(config->args, where, "-exp_id", "exp_id", "=="); 1000 PXOPT_COPY_S16(config->args, where, "-fault", "fault", "=="); 1001 PXOPT_COPY_S64(config->args, where, "-exp_id_begin", "exp_id", ">="); 1002 PXOPT_COPY_S64(config->args, where, "-exp_id_end", "exp_id", "<="); 1003 1004 psString query = pxDataGet("regtool_revertprocessedexp.sql"); 1005 if (!query) { 1006 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1007 psFree(where); 1008 return false; 1009 } 1010 1011 if (psListLength(where->list)) { 1012 psString whereClause = psDBGenerateWhereConditionSQL(where, "rawExp"); 1013 psStringAppend(&query, " AND %s", whereClause); 1014 psFree(whereClause); 1015 } else { 1016 psFree(where); 1017 psError(PXTOOLS_ERR_DATA, false, "search parameters are required"); 1018 return false; 1019 } 1181 PS_ASSERT_PTR_NON_NULL(config, false); 1182 1183 psMetadata *where = psMetadataAlloc(); 1184 PXOPT_COPY_S64(config->args, where, "-exp_id", "exp_id", "=="); 1185 PXOPT_COPY_S16(config->args, where, "-fault", "fault", "=="); 1186 PXOPT_COPY_S64(config->args, where, "-exp_id_begin", "exp_id", ">="); 1187 PXOPT_COPY_S64(config->args, where, "-exp_id_end", "exp_id", "<="); 1188 1189 psString query = pxDataGet("regtool_revertprocessedexp.sql"); 1190 if (!query) { 1191 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1020 1192 psFree(where); 1021 1022 if (!p_psDBRunQuery(config->dbh, query)) { 1023 psError(PS_ERR_UNKNOWN, false, "database error"); 1024 psFree(query); 1025 return false; 1026 } 1193 return false; 1194 } 1195 1196 if (psListLength(where->list)) { 1197 psString whereClause = psDBGenerateWhereConditionSQL(where, "rawExp"); 1198 psStringAppend(&query, " AND %s", whereClause); 1199 psFree(whereClause); 1200 } else { 1201 psFree(where); 1202 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 1203 return false; 1204 } 1205 psFree(where); 1206 1207 if (!p_psDBRunQuery(config->dbh, query)) { 1208 psError(PS_ERR_UNKNOWN, false, "database error"); 1027 1209 psFree(query); 1028 1029 int numUpdated = psDBAffectedRows(config->dbh); 1030 1031 psLogMsg("regtool", PS_LOG_INFO, "Updated %d rawExp", numUpdated); 1032 1033 return true; 1210 return false; 1211 } 1212 psFree(query); 1213 1214 int numUpdated = psDBAffectedRows(config->dbh); 1215 1216 psLogMsg("regtool", PS_LOG_INFO, "Updated %d rawExp", numUpdated); 1217 1218 return true; 1034 1219 } 1035 1220 … … 1037 1222 static bool updateprocessedexpMode(pxConfig *config) 1038 1223 { 1039 PS_ASSERT_PTR_NON_NULL(config, false); 1040 1041 psMetadata *where = psMetadataAlloc(); 1042 PXOPT_COPY_S64(config->args, where, "-exp_id", "exp_id", "=="); 1043 1044 PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false); 1045 1046 if (!pxSetFaultCode(config->dbh, "rawExp", where, fault)) { 1047 psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag"); 1048 psFree(where); 1049 return false; 1050 } 1224 PS_ASSERT_PTR_NON_NULL(config, false); 1225 1226 psMetadata *where = psMetadataAlloc(); 1227 PXOPT_COPY_S64(config->args, where, "-exp_id", "exp_id", "=="); 1228 1229 PXOPT_LOOKUP_S16(fault, config->args, "-fault", true, false); 1230 1231 if (!pxSetFaultCode(config->dbh, "rawExp", where, fault)) { 1232 psError(PS_ERR_UNKNOWN, false, "failed to set set fault flag"); 1051 1233 psFree(where); 1052 1053 return true; 1054 } 1234 return false; 1235 } 1236 psFree(where); 1237 1238 return true; 1239 } 1240 1241 1242 static bool finishcompressexpMode(pxConfig *config) { 1243 1244 PS_ASSERT_PTR_NON_NULL(config, false); 1245 1246 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1247 1248 psMetadata *where = psMetadataAlloc(); 1249 PXOPT_COPY_S64(config->args, where, "-exp_id", "exp_id", "=="); 1250 1251 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1252 1253 psString query = pxDataGet("regtool_finishcompressexp.sql"); 1254 if (!query) { 1255 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1256 return(false); 1257 } 1258 if (where && psListLength(where->list)) { 1259 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1260 psStringAppend(&query, " %s ", whereClause); 1261 psFree(whereClause); 1262 } 1263 psFree(where); 1264 1265 if (limit) { 1266 psString limitString = psDBGenerateLimitSQL(limit); 1267 psStringAppend(&query, " %s ", limitString); 1268 psFree(limitString); 1269 } 1270 // printf(query); 1271 // return(false); 1272 if (!p_psDBRunQuery(config->dbh, query)) { 1273 psError(PS_ERR_UNKNOWN, false, "database error"); 1274 psFree(query); 1275 return(false); 1276 } 1277 psFree(query); 1278 1279 psArray *output = p_psDBFetchResult(config->dbh); 1280 if (!output) { 1281 psError(PS_ERR_UNKNOWN, false, "database error"); 1282 return(false); 1283 } 1284 if (!psArrayLength(output)) { 1285 psTrace("chiptool", PS_LOG_INFO, "no rows found"); 1286 psFree(output); 1287 return(true); 1288 } 1289 1290 for (long i = 0; i < psArrayLength(output); i++) { 1291 psMetadata *md = output->data[i]; 1292 1293 rawExpRow *row = rawExpObjectFromMetadata(md); 1294 if (!psDBTransaction(config->dbh)) { 1295 psError(PS_ERR_UNKNOWN, false, "database error"); 1296 return(false); 1297 } 1298 1299 if (strcmp(row->state,"goto_compressed") == 0) { 1300 if (!pxrawExpSetState(config,row->exp_id, "compressed")) { 1301 psError(PS_ERR_UNKNOWN, false, "failed to set rawExp.state for exp_id: %" PRId64, row->exp_id); 1302 psFree(row); 1303 psFree(output); 1304 return(false); 1305 } 1306 } 1307 else if (strcmp(row->state,"goto_lossy") == 0) { 1308 if (!pxrawExpSetState(config,row->exp_id, "lossy")) { 1309 psError(PS_ERR_UNKNOWN, false, "failed to set rawExp.state for exp_id: %" PRId64, row->exp_id); 1310 psFree(row); 1311 psFree(output); 1312 return(false); 1313 } 1314 } 1315 if (!psDBCommit(config->dbh)) { 1316 psError(PS_ERR_UNKNOWN, false, "database error"); 1317 return false; 1318 } 1319 psFree(row); 1320 } 1321 1322 psFree(output); 1323 return(true); 1324 } 1325 1326 static bool updatebyqueryMode(pxConfig *config) { 1327 PS_ASSERT_PTR_NON_NULL(config, false); 1328 1329 PXOPT_LOOKUP_STR(set_state, config->args, "-set_state", true, false); 1330 1331 // XX test this out; need to make this consistent with the list in regtoolConfig.c 1332 psMetadata *where = psMetadataAlloc(); 1333 PXOPT_COPY_S64(config->args, where, "-exp_id", "rawExp.exp_id", "=="); 1334 PXOPT_COPY_STR(config->args, where, "-exp_name", "rawExp.exp_name", "=="); 1335 PXOPT_COPY_STR(config->args, where, "-inst", "rawExp.camera", "=="); 1336 PXOPT_COPY_STR(config->args, where, "-telescope", "rawExp.telescope", "=="); 1337 PXOPT_COPY_TIME(config->args, where, "-dateobs_begin", "rawExp.dateobs", ">="); 1338 PXOPT_COPY_TIME(config->args, where, "-dateobs_end", "rawExp.dateobs", "<="); 1339 PXOPT_COPY_STR(config->args, where, "-exp_tag", "rawExp.exp_tag", "=="); 1340 PXOPT_COPY_STR(config->args, where, "-exp_type", "rawExp.exp_type", "=="); 1341 PXOPT_COPY_STR(config->args, where, "-filelevel", "rawExp.filelevel", "=="); 1342 PXOPT_COPY_STR(config->args, where, "-state", "rawExp.state", "=="); 1343 PXOPT_COPY_STR(config->args, where, "-reduction", "rawExp.reduction", "=="); 1344 PXOPT_COPY_STR(config->args, where, "-filter", "rawExp.filter", "=="); 1345 PXOPT_COPY_F32(config->args, where, "-airmass_min", "rawExp.airmass", ">="); 1346 PXOPT_COPY_F32(config->args, where, "-airmass_max", "rawExp.airmass", "<"); 1347 PXOPT_COPY_RADEC(config->args, where, "-ra_min", "rawExp.ra", ">="); 1348 PXOPT_COPY_RADEC(config->args, where, "-ra_max", "rawExp.ra", "<"); 1349 PXOPT_COPY_RADEC(config->args, where, "-decl_min", "rawExp.decl", ">="); 1350 PXOPT_COPY_RADEC(config->args, where, "-decl_max", "rawExp.decl", "<"); 1351 PXOPT_COPY_F32(config->args, where, "-exp_time_min", "rawExp.exp_time", ">="); 1352 PXOPT_COPY_F32(config->args, where, "-exp_time_max", "rawExp.exp_time", "<"); 1353 PXOPT_COPY_F32(config->args, where, "-sat_pixel_frac_min", "rawExp.sat_pixel_frac", ">="); 1354 PXOPT_COPY_F32(config->args, where, "-sat_pixel_frac_max", "rawExp.sat_pixel_frac", "<"); 1355 PXOPT_COPY_F64(config->args, where, "-bg_min", "rawExp.bg", ">="); 1356 PXOPT_COPY_F64(config->args, where, "-bg_max", "rawExp.bg", "<"); 1357 PXOPT_COPY_F64(config->args, where, "-bg_stdev_min", "rawExp.bg_stdev", ">="); 1358 PXOPT_COPY_F64(config->args, where, "-bg_stdev_max", "rawExp.bg_stdev", "<"); 1359 PXOPT_COPY_F64(config->args, where, "-bg_mean_stdev_min", "rawExp.bg_mean_stdev", ">="); 1360 PXOPT_COPY_F64(config->args, where, "-bg_mean_stdev_max", "rawExp.bg_mean_stdev", "<"); 1361 PXOPT_COPY_F64(config->args, where, "-alt_min", "rawExp.alt", ">="); 1362 PXOPT_COPY_F64(config->args, where, "-alt_max", "rawExp.alt", "<"); 1363 PXOPT_COPY_F64(config->args, where, "-az_min", "rawExp.az", ">="); 1364 PXOPT_COPY_F64(config->args, where, "-az_max", "rawExp.az", "<"); 1365 PXOPT_COPY_F64(config->args, where, "-ccd_temp_min", "rawExp.ccd_temp", ">="); 1366 PXOPT_COPY_F64(config->args, where, "-ccd_temp_max", "rawExp.ccd_temp", "<"); 1367 PXOPT_COPY_F64(config->args, where, "-posang_min", "rawExp.posang", ">="); 1368 PXOPT_COPY_F64(config->args, where, "-posang_max", "rawExp.posang", "<"); 1369 PXOPT_COPY_F32(config->args, where, "-sun_angle_min", "rawExp.sun_angle", ">="); 1370 PXOPT_COPY_F32(config->args, where, "-sun_angle_max", "rawExp.sun_angle", "<"); 1371 PXOPT_COPY_STR(config->args, where, "-object", "rawExp.object", "=="); 1372 PXOPT_COPY_STR(config->args, where, "-comment", "rawExp.comment", "LIKE"); 1373 PXOPT_COPY_STR(config->args, where, "-obs_mode", "rawExp.obs_mode", "LIKE"); 1374 1375 1376 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 1377 psStringPrepend(&whereClause,"\n AND "); 1378 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1379 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1380 1381 psString limitString = NULL; 1382 if (limit) { 1383 limitString = psDBGenerateLimitSQL(limit); 1384 psStringPrepend(&limitString, "\n"); 1385 } 1386 // Update the imfiles first, because if you select by state, you'll clobber things 1387 psString query = pxDataGet("regtool_updatebyqueryimfile.sql"); 1388 if (!query) { 1389 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1390 return(false); 1391 } 1392 1393 // printf(query,set_state,whereClause,limitString); 1394 if (!p_psDBRunQueryF(config->dbh, query, set_state, whereClause, limitString ? limitString : "")) { 1395 psError(PXTOOLS_ERR_PROG, false, "database error"); 1396 psFree(limitString); 1397 psFree(query); 1398 psFree(whereClause); 1399 psFree(where); 1400 return(false); 1401 } 1402 1403 psFree(query); 1404 // Now up date the exposure. 1405 query = pxDataGet("regtool_updatebyquery.sql"); 1406 if (!query) { 1407 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1408 return(false); 1409 } 1410 if (!p_psDBRunQueryF(config->dbh, query, set_state,whereClause, limitString ? limitString : "")) { 1411 psError(PXTOOLS_ERR_PROG, false, "database error"); 1412 psFree(limitString); 1413 psFree(query); 1414 psFree(whereClause); 1415 psFree(where); 1416 return(false); 1417 } 1418 1419 psFree(limitString); 1420 psFree(query); 1421 psFree(whereClause); 1422 psFree(where); 1423 1424 return true; 1425 } 1426 1055 1427 1056 1428 … … 1072 1444 psError(PS_ERR_UNKNOWN, false, "database error"); 1073 1445 } 1074 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1446 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1075 1447 return false; 1076 1448 } … … 1098 1470 psError(PS_ERR_UNKNOWN, false, "database error"); 1099 1471 } 1100 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1472 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1101 1473 return false; 1102 1474 } … … 1179 1551 } 1180 1552 1553 if (!pxExportVersion(config, f)) { 1554 psError(PS_ERR_UNKNOWN, false, "failed to write dbversion to output file"); 1555 return false; 1556 } 1557 1181 1558 psMetadata *where = psMetadataAlloc(); 1182 1559 PXOPT_COPY_S64(config->args, where, "-exp_id", "exp_id", "=="); … … 1190 1567 psString query = pxDataGet(tables[i].sqlFilename); 1191 1568 if (!query) { 1192 psError(PXTOOLS_ERR_ DATA, false, "failed to retreive SQL statement");1569 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 1193 1570 return false; 1194 1571 } … … 1248 1625 1249 1626 psMetadata *input = psMetadataConfigRead (NULL, &nFail, infile, false); 1627 1628 if (!pxCheckImportVersion(config, input)) { 1629 psError(PS_ERR_UNKNOWN, false, "pxCheckImportVersion failed"); 1630 return false; 1631 } 1632 1250 1633 1251 1634 fprintf (stdout, "---- input ----\n");
Note:
See TracChangeset
for help on using the changeset viewer.
