- Timestamp:
- May 26, 2009, 1:59:32 PM (17 years ago)
- Location:
- branches/cnb_branches/cnb_branch_20090301
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
ippTools/src (modified) (1 prop)
-
ippTools/src/magictool.c (modified) (29 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/cnb_branches/cnb_branch_20090301
- Property svn:mergeinfo changed
-
branches/cnb_branches/cnb_branch_20090301/ippTools/src
- Property svn:ignore
-
old new 33 33 pstamptool 34 34 disttool 35 receivetool
-
- Property svn:ignore
-
branches/cnb_branches/cnb_branch_20090301/ippTools/src/magictool.c
r23594 r24244 127 127 PXOPT_LOOKUP_TIME(registered, config->args, "-registered", false, false); 128 128 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 129 130 psMetadata *where = psMetadataAlloc(); 131 PXOPT_COPY_S64(config->args, where, "-exp_id", "exp_id", "=="); 132 PXOPT_COPY_STR(config->args, where, "-diff_label", "diffRun.label", "=="); 133 129 PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false); 130 131 psMetadata *diffWhere = psMetadataAlloc(); // WHERE conditions for diffRuns 132 PXOPT_COPY_STR(config->args, diffWhere, "-diff_label", "diffRun.label", "=="); 133 PXOPT_COPY_S64(config->args, diffWhere, "-diff_id", "diff_id", "=="); 134 135 psMetadata *queryWhere = psMetadataAlloc(); // WHERE conditions for everything else 136 PXOPT_COPY_S64(config->args, queryWhere, "-exp_id", "exp_id", "=="); 134 137 135 138 // Get list of exposures ready to magic … … 146 149 PXOPT_LOOKUP_BOOL(rerun, config->args, "-rerun", false); 147 150 148 psString queryWhere = NULL; // WHERE conditions for entire query 151 psString diffWhereStr = NULL; // WHERE conditions for diffRuns 152 psString queryWhereStr = NULL; // WHERE conditions for entire query 149 153 if (!available) { 150 psStringAppend(& queryWhere, " \nWHEREdiffRun.state = 'full'");151 } else {152 // what if no skycells for the diff run completed?153 } 154 psStringAppend(&diffWhereStr, "\nAND diffRun.state = 'full'"); 155 } 156 // what if no skycells for the diff run completed? 157 154 158 if (!rerun) { 155 const char *newWhere = " magic_id IS NULL"; // String to add 156 if (queryWhere) { 157 psStringAppend(&queryWhere, " AND %s", newWhere); 158 } else { 159 psStringAppend(&queryWhere, "\nWHERE %s", newWhere); 160 } 161 } 159 psStringAppend(&queryWhereStr, "\n%s magic_id IS NULL", queryWhereStr ? "AND" : "WHERE"); 160 } 161 162 162 // now add the user specified qualifiers 163 if (psListLength( where->list)) {164 psString whereClause = psDBGenerateWhereConditionSQL( where, NULL);165 psStringAppend(& queryWhere, "\n%s %s", queryWhere == NULL ? "WHERE" : "AND", whereClause);163 if (psListLength(diffWhere->list)) { 164 psString whereClause = psDBGenerateWhereConditionSQL(diffWhere, NULL); 165 psStringAppend(&diffWhereStr, "\nAND %s", whereClause); 166 166 psFree(whereClause); 167 167 } 168 psFree(where); 169 if (!queryWhere) { 170 psStringAppend(&queryWhere, " "); 171 } 172 173 if (!p_psDBRunQueryF(config->dbh, query, queryWhere)) { 168 if (psListLength(queryWhere->list)) { 169 psString whereClause = psDBGenerateWhereConditionSQL(queryWhere, NULL); 170 psStringAppend(&queryWhereStr, "\n%s %s", queryWhereStr ? "AND" : "WHERE", whereClause); 171 psFree(whereClause); 172 } 173 psFree(diffWhere); 174 psFree(queryWhere); 175 176 // Ensure the WHERE strings have something 177 if (!diffWhereStr) { 178 diffWhereStr = psStringCopy(""); 179 } 180 if (!queryWhereStr) { 181 queryWhereStr = psStringCopy(""); 182 } 183 184 if (!p_psDBRunQueryF(config->dbh, query, diffWhereStr, diffWhereStr, queryWhereStr)) { 174 185 psError(PS_ERR_UNKNOWN, false, "database error"); 175 psFree(queryWhere); 186 psFree(diffWhereStr); 187 psFree(queryWhereStr); 176 188 psFree(query); 177 189 return false; 178 190 } 179 psFree(queryWhere); 191 psFree(diffWhereStr); 192 psFree(queryWhereStr); 180 193 psFree(query); 181 194 } … … 201 214 } 202 215 216 217 if (pretend) { 218 // negative simple so the default is true 219 if (!ippdbPrintMetadatas(stdout, output, "diffRun", !simple)) { 220 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 221 psFree(output); 222 return false; 223 } 224 psFree(output); 225 return true; 226 } 227 228 203 229 // Parse the list of exposures ready to magic 204 205 230 if (!psDBTransaction(config->dbh)) { 206 231 psError(PS_ERR_UNKNOWN, false, "database error"); … … 215 240 psS64 exp_id = psMetadataLookupS64(NULL, row, "exp_id"); // Exposure identifier 216 241 psS64 diff_id = psMetadataLookupS64(NULL, row, "diff_id"); // difference identifier 242 bool inverse = psMetadataLookupU64(NULL, row, "inverse"); // Inverse subtraction? Note types! 217 243 218 244 // create a new magicRun for this group 219 magicRunRow *run = magicRunRowAlloc(0, exp_id, diff_id, "new", workdir, "dirty", label, dvodb, registered, 0); 245 magicRunRow *run = magicRunRowAlloc(0, exp_id, diff_id, inverse, "new", workdir, "dirty", label, 246 dvodb, registered, 0); 220 247 if (!run) { 221 248 psAbort("failed to alloc magicRun object"); … … 296 323 297 324 // optional 325 PXOPT_LOOKUP_BOOL(inverse, config->args, "-inverse", false); 298 326 PXOPT_LOOKUP_STR(label, config->args, "-label", false, false); 299 327 PXOPT_LOOKUP_STR(dvodb, config->args, "-dvodb", false, false); … … 305 333 exp_id, 306 334 diff_id ? diff_id : PS_MAX_S64, 335 inverse, 307 336 "reg", // state 308 337 workdir, … … 363 392 // required 364 393 PXOPT_LOOKUP_S64(magic_id, config->args, "-magic_id", true, false); 365 PXOPT_LOOKUP_S64(diff_id, config->args, "-diff_id", true, false);366 394 PXOPT_LOOKUP_STR(node, config->args, "-node", true, false); 367 395 … … 369 397 config->dbh, 370 398 magic_id, 371 diff_id,372 399 node 373 400 ); … … 457 484 psMetadata *where = psMetadataAlloc(); 458 485 PXOPT_COPY_S64(config->args, where, "-magic_id", "magicRun.magic_id", "=="); 459 PXOPT_COPY_STR(config->args, where, "-label", "label", "==");486 pxAddLabelSearchArgs (config, where, "-label", "magicRun.label", "=="); 460 487 461 488 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); … … 535 562 536 563 // default values 537 PXOPT_LOOKUP_S16( code, config->args, "-code", false, false);538 539 if ( code> 0) {564 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 565 566 if (fault > 0) { 540 567 char *query = "UPDATE magicRun SET fault = %d, state = 'full' WHERE magic_id = %" PRId64; 541 if (!p_psDBRunQueryF(config->dbh, query, code, magic_id)) {568 if (!p_psDBRunQueryF(config->dbh, query, fault, magic_id)) { 542 569 psError(PS_ERR_UNKNOWN, false, 543 570 "failed to set fault for magic_id %" PRId64, magic_id); … … 561 588 psMetadata *where = psMetadataAlloc(); 562 589 PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "=="); 563 PXOPT_COPY_S16(config->args, where, "- code", "fault", "==");564 565 psString query = psStringCopy("UPDATE magicRun SET fault = 0, state = ' run' WHERE fault != 0");590 PXOPT_COPY_S16(config->args, where, "-fault", "fault", "=="); 591 592 psString query = psStringCopy("UPDATE magicRun SET fault = 0, state = 'new' WHERE fault != 0"); 566 593 567 594 if (psListLength(where->list)) { … … 584 611 PS_ASSERT_PTR_NON_NULL(config, false); 585 612 586 psMetadata *where = psMetadataAlloc(); 587 PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "=="); 588 PXOPT_COPY_STR(config->args, where, "-node", "node", "=="); 613 // Regrettably, there are multiple WHERE hooks which call the same things different names 614 psMetadata *templatesWhere = psMetadataAlloc(); // WHERE for selecting template 615 psMetadata *magicWhere = psMetadataAlloc(); // WHERE for selecting magic runs 616 617 PXOPT_COPY_S64(config->args, templatesWhere, "-magic_id", "magicRun.magic_id", "=="); 618 PXOPT_COPY_STR(config->args, templatesWhere, "-node", "diffInputSkyfile.skycell_id", "=="); 619 620 PXOPT_COPY_S64(config->args, magicWhere, "-magic_id", "magicRun.magic_id", "=="); 621 PXOPT_COPY_STR(config->args, magicWhere, "-node", "magicTree.node", "=="); 589 622 590 623 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); … … 597 630 } 598 631 599 if (psListLength(where->list)) { 600 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 601 psStringAppend(&query, " AND %s", whereClause); 632 psString templatesWhereStr = psStringCopy(""); // WHERE for selecting template 633 psString magicWhereStr = psStringCopy(""); // WHERE for selecting magic runs 634 635 if (psListLength(templatesWhere->list)) { 636 psString whereClause = psDBGenerateWhereConditionSQL(templatesWhere, NULL); 637 psStringAppend(&templatesWhereStr, "\nAND %s", whereClause); 602 638 psFree(whereClause); 603 639 } 604 psFree(where); 640 psFree(templatesWhere); 641 642 if (psListLength(magicWhere->list)) { 643 psString whereClause = psDBGenerateWhereConditionSQL(magicWhere, NULL); 644 psStringAppend(&magicWhereStr, "\nWHERE %s", whereClause); 645 psFree(whereClause); 646 } 647 psFree(magicWhere); 605 648 606 649 // treat limit == 0 as "no limit" … … 611 654 } 612 655 613 if (!p_psDBRunQuery(config->dbh, query)) { 614 psError(PS_ERR_UNKNOWN, false, "database error"); 656 if (!p_psDBRunQueryF(config->dbh, query, 657 templatesWhereStr, templatesWhereStr, 658 magicWhereStr, magicWhereStr)) { 659 psError(PS_ERR_UNKNOWN, false, "database error"); 660 psFree(templatesWhereStr); 661 psFree(magicWhereStr); 615 662 psFree(query); 616 663 return false; 617 664 } 665 psFree(templatesWhereStr); 666 psFree(magicWhereStr); 618 667 psFree(query); 619 668 … … 704 753 705 754 bool status = false; 706 psS 32 done = psMetadataLookupS32(&status, data, "done");755 psS64 done = psMetadataLookupS64(&status, data, "done"); 707 756 if (!status) { 708 757 psAbort("failed to lookup value for done column"); 709 758 } 710 psS 16 bad = psMetadataLookupS16(&status, data, "bad");759 psS64 bad = psMetadataLookupS64(&status, data, "bad"); 711 760 if (!status) { 712 761 psAbort("failed to lookup value for bad column"); … … 738 787 739 788 psMetadata *where = psMetadataAlloc(); 740 PXOPT_COPY_S64(config->args, where, "-magic_id", "magic _id", "==");741 PXOPT_COPY_STR(config->args, where, "-label", "label", "==");789 PXOPT_COPY_S64(config->args, where, "-magic_id", "magicRun.magic_id", "=="); 790 pxAddLabelSearchArgs (config, where, "-label", "magicRun.label", "=="); 742 791 743 792 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 793 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 744 794 745 795 // look for "inputs" that need to processed … … 750 800 } 751 801 752 psString where Clause= NULL;802 psString whereString = NULL; 753 803 if (psListLength(where->list)) { 754 whereClause = psDBGenerateWhereConditionSQL(where, NULL); 755 psStringAppend(&query, " AND %s", whereClause); 804 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 805 psStringAppend(&whereString, "\nAND %s", whereClause); 806 psFree(whereClause); 756 807 } 757 808 psFree(where); 758 809 759 if (!p_psDBRunQuery(config->dbh, query)) { 760 psError(PS_ERR_UNKNOWN, false, "database error"); 810 // treat limit == 0 as "no limit" 811 if (limit) { 812 psString limitString = psDBGenerateLimitSQL(limit); 813 psStringAppend(&query, " %s", limitString); 814 psFree(limitString); 815 } 816 817 if (!p_psDBRunQueryF(config->dbh, query, whereString, whereString)) { 818 psError(PS_ERR_UNKNOWN, false, "database error"); 819 psFree(whereString); 761 820 psFree(query); 762 821 return false; … … 782 841 } 783 842 843 if (limit) { 844 if (psArrayLength(output) >= limit) { 845 // we've found enough (note that limit was applied to the query so '> limit' won't happen) 846 // negative simple so the default is true 847 if (!ippdbPrintMetadatas(stdout, output, "magicMe", !simple)) { 848 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 849 psFree(output); 850 return false; 851 } 852 psFree(output); 853 return true; 854 } 855 } 856 784 857 // look for tree nodes that need to be processed 858 // XXX: This gets all nodes from all magicRuns that are in 'new'state 859 // That doens't seem particularly efficient 785 860 query = pxDataGet("magictool_toprocess_tree.sql"); 786 861 if (!query) { … … 789 864 } 790 865 791 if (whereClause) { 792 psString new = NULL; 793 psStringAppend(&new, "\n AND %s", whereClause); 794 psFree(whereClause); 795 whereClause = new; 796 } 797 if (!p_psDBRunQueryF(config->dbh, query, whereClause ? whereClause : "")) { 798 psError(PS_ERR_UNKNOWN, false, "database error"); 799 psFree(whereClause); 866 867 if (!p_psDBRunQueryF(config->dbh, query, whereString ? whereString : "")) { 868 psError(PS_ERR_UNKNOWN, false, "database error"); 869 psFree(whereString); 800 870 psFree(query); 801 871 return false; 802 872 } 803 psFree(where Clause);873 psFree(whereString); 804 874 psFree(query); 805 875 … … 828 898 while (index < psArrayLength(magicTree)) { 829 899 bool status; 900 if (limit && (psArrayLength(output) >= limit)) { 901 break; 902 } 830 903 psS64 current_magic_id = psMetadataLookupS64(&status, magicTree->data[index], "magic_id"); 831 904 if (!status) { … … 879 952 880 953 } 954 psFree(magicTree); 881 955 882 956 if (psArrayLength(output)) { 957 if (limit && (limit < psArrayLength(output))) { 958 // truncate the array 959 long arrayLength = psArrayLength(output); 960 for (long i = arrayLength - 1; i >= limit; i--) { 961 psArrayRemoveIndex(output, i); 962 } 963 } 883 964 // negative simple so the default is true 884 965 if (!ippdbPrintMetadatas(stdout, output, "magicMe", !simple)) { … … 889 970 } 890 971 891 psFree(magicTree);892 972 psFree(output); 893 973 … … 905 985 906 986 // optional 907 PXOPT_LOOKUP_STR( uri, config->args, "-uri", false, false);987 PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", false, false); 908 988 909 989 // default values 910 PXOPT_LOOKUP_S16( code, config->args, "-code", false, false);990 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 911 991 912 992 if (!magicNodeResultInsert(config->dbh, 913 993 magic_id, 914 994 node, 915 uri,916 code995 path_base, 996 fault 917 997 )) { 918 998 psError(PS_ERR_UNKNOWN, false, "database error"); … … 930 1010 PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "=="); 931 1011 PXOPT_COPY_STR(config->args, where, "-node", "node", "=="); 932 PXOPT_COPY_S16(config->args, where, "-code", "fault", "=="); 933 934 psString query = psStringCopy("DELETE FROM magicNodeResult WHERE fault != 0"); 1012 PXOPT_COPY_STR(config->args, where, "-label", "label", "=="); 1013 PXOPT_COPY_S16(config->args, where, "-fault", "magicNodeResult.fault", "=="); 1014 1015 psString query = pxDataGet("magictool_revertnode.sql"); 1016 if (!query) { 1017 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1018 return false; 1019 } 935 1020 936 1021 if (psListLength(where->list)) { … … 938 1023 psStringAppend(&query, " AND %s", whereClause); 939 1024 psFree(whereClause); 1025 } else { 1026 psError(PS_ERR_UNKNOWN, false, "search parameters are required"); 1027 psFree(where); 1028 return false; 940 1029 } 941 1030 psFree(where); … … 945 1034 return false; 946 1035 } 1036 1037 psS32 numUpdated = psDBAffectedRows(config->dbh); 1038 psLogMsg("magictool", PS_LOG_INFO, "Updated %d magic nodes", numUpdated); 1039 947 1040 return true; 948 1041 } … … 1024 1117 1025 1118 // default values 1026 PXOPT_LOOKUP_S16( code, config->args, "-code", false, false);1119 PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false); 1027 1120 1028 1121 if (!psDBTransaction(config->dbh)) { … … 1035 1128 uri, 1036 1129 streaks, 1037 code1130 fault 1038 1131 )) { 1039 1132 psError(PS_ERR_UNKNOWN, false, "database error"); … … 1081 1174 psMetadata *where = psMetadataAlloc(); 1082 1175 PXOPT_COPY_S64(config->args, where, "-magic_id", "magic_id", "=="); 1083 PXOPT_COPY_S16(config->args, where, "- code", "fault", "==");1176 PXOPT_COPY_S16(config->args, where, "-fault", "fault", "=="); 1084 1177 1085 1178 if (!psDBTransaction(config->dbh)) {
Note:
See TracChangeset
for help on using the changeset viewer.
