Changeset 11851 for trunk/ippTools/src/stacktool.c
- Timestamp:
- Feb 16, 2007, 12:10:39 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/stacktool.c (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/stacktool.c
r11814 r11851 33 33 static bool definerunMode(pxConfig *config); 34 34 static bool updaterunMode(pxConfig *config); 35 static bool addinputexpMode(pxConfig *config); 36 static bool expMode(pxConfig *config); 37 static bool imfileMode(pxConfig *config); 38 static bool tooverlapMode(pxConfig *config); 39 static bool addoverlapMode(pxConfig *config); 40 static bool scmapMode(pxConfig *config); 41 static bool towarpedMode(pxConfig *config); 42 static bool addwarpedMode(pxConfig *config); 43 static bool warpedMode(pxConfig *config); 44 45 #if 0 46 static bool tostackedimfileMode(pxConfig *config); 47 //static bool addstackedimfileMode(pxConfig *config); 48 static bool stackedimfileMode(pxConfig *config); 49 static bool todiffimfileMode(pxConfig *config); 50 //static bool adddiffimfileMode(pxConfig *config); 51 static bool diffimfileMode(pxConfig *config); 52 #endif 53 54 static bool parseAndInsertSkyCellMap(pxConfig *config, const char *mapfile); 55 static bool setp4RunState(pxConfig *config, const char *p4_id, const char *state); 56 static bool isValidMode(pxConfig *config, const char *mode); 35 static bool addinputscfileMode(pxConfig *config); 36 static bool inputscfileMode(pxConfig *config); 37 static bool tosumMode(pxConfig *config); 38 static bool addsumscfileMode(pxConfig *config); 39 static bool sumscfileMode(pxConfig *config); 40 41 static bool setp6RunState(pxConfig *config, const char *p4_id, const char *state); 57 42 58 43 # define MODECASE(caseName, func) \ … … 68 53 69 54 pxConfig *config = p6toolConfig(NULL, argc, argv); 55 if (!config) { 56 psError(PXTOOLS_ERR_CONFIG, false, "failed to configure"); 57 goto FAIL; 58 } 70 59 71 60 switch (config->mode) { 72 61 MODECASE(P6TOOL_MODE_DEFINERUN, definerunMode); 73 62 MODECASE(P6TOOL_MODE_UPDATERUN, updaterunMode); 74 MODECASE(P6TOOL_MODE_ADDINPUTEXP, addinputexpMode); 75 MODECASE(P6TOOL_MODE_EXP, expMode); 76 MODECASE(P6TOOL_MODE_IMFILE, imfileMode); 77 MODECASE(P6TOOL_MODE_TOOVERLAP, tooverlapMode); 78 MODECASE(P6TOOL_MODE_ADDOVERLAP, addoverlapMode); 79 MODECASE(P6TOOL_MODE_SCMAP, scmapMode); 80 MODECASE(P6TOOL_MODE_TOWARPED, towarpedMode); 81 MODECASE(P6TOOL_MODE_ADDWARPED, addwarpedMode); 82 MODECASE(P6TOOL_MODE_WARPED, warpedMode); 83 84 #if 0 85 MODECASE(P6TOOL_MODE_ADDSCFILE, addscfileMode); 86 MODECASE(P6TOOL_MODE_SCFILE, scfileMode); 87 MODECASE(P6TOOL_MODE_TOSTACKEDIMFILE, tostackedimfileMode); 88 // MODECASE(P6TOOL_MODE_ADDSTACKEDIMFILE, addstackedimfileMode); 89 MODECASE(P6TOOL_MODE_STACKEDIMFILE, stackedimfileMode); 90 MODECASE(P6TOOL_MODE_TODIFFIMFILE, todiffimfileMode); 91 // MODECASE(P6TOOL_MODE_ADDDIFFIMFILE, adddiffimfileMode); 92 MODECASE(P6TOOL_MODE_DIFFIMFILE, diffimfileMode); 93 #endif 63 MODECASE(P6TOOL_MODE_ADDINPUTSCFILE, addinputscfileMode); 64 MODECASE(P6TOOL_MODE_INPUTSCFILE, inputscfileMode); 65 MODECASE(P6TOOL_MODE_TOSUM, tosumMode); 66 MODECASE(P6TOOL_MODE_ADDSUMSCFILE, addsumscfileMode); 67 MODECASE(P6TOOL_MODE_SUMSCFILE, sumscfileMode); 94 68 default: 95 69 psAbort("invalid option (this should not happen)"); … … 104 78 FAIL: 105 79 psErrorStackPrint(stderr, "\n"); 80 int exit_status = pxerrorGetExitStatus(); 106 81 107 82 psFree(config); … … 109 84 psLibFinalize(); 110 85 111 exit( EXIT_FAILURE);86 exit(exit_status); 112 87 } 113 88 … … 126 101 if (!mode) { 127 102 psError(PS_ERR_UNKNOWN, true, "-mode is required"); 128 return false;129 }130 // check mode131 if (mode && !isValidMode(config, mode)) {132 psError(PS_ERR_UNKNOWN, false, "invalud mode");133 103 return false; 134 104 } … … 230 200 if (state) { 231 201 // set detRun.state to state 232 return setp 4RunState(config, p4_id, state);233 } 234 235 return true; 236 } 237 238 239 static bool addinput expMode(pxConfig *config)202 return setp6RunState(config, p4_id, state); 203 } 204 205 return true; 206 } 207 208 209 static bool addinputscfileMode(pxConfig *config) 240 210 { 241 211 PS_ASSERT_PTR_NON_NULL(config, false); … … 293 263 294 264 295 static bool expMode(pxConfig *config) 296 { 297 PS_ASSERT_PTR_NON_NULL(config, false); 298 299 bool status = false; 300 psU64 limit = psMetadataLookupU64(&status, config->args, "-limit"); 301 if (!status) { 302 psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -limit"); 303 return false; 304 } 305 306 // find all rawImfiles matching the default query 307 psString query = psStringCopy( 308 "SELECT\n" 309 " p3ProcessedExp.*\n" 310 " FROM p4Run\n" 311 " JOIN p4InputExp\n" 312 " USING(p4_id)\n" 313 " JOIN p3ProcessedExp\n" 314 " ON p4InputExp.exp_tag = p3ProcessedExp.exp_tag\n" 315 " AND p4InputExp.p3_version = p3ProcessedExp.p3_version\n" 316 " WHERE\n" 317 " p4Run.state = 'run'\n" 318 " AND p3ProcessedExp.fault = 0\n" 319 ); 320 321 if (config->where) { 322 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4InputExp"); 323 psStringAppend(&query, " AND %s", whereClause); 324 psFree(whereClause); 325 } 326 327 // treat limit == 0 as "no limit" 328 if (limit) { 329 psString limitString = psDBGenerateLimitSQL(limit); 330 psStringAppend(&query, " %s", limitString); 331 psFree(limitString); 332 } 333 334 if (!p_psDBRunQuery(config->dbh, query)) { 335 psError(PS_ERR_UNKNOWN, false, "database error"); 336 psFree(query); 337 return false; 338 } 339 psFree(query); 340 341 psArray *output = p_psDBFetchResult(config->dbh); 342 if (!output) { 343 psErrorCode err = psErrorCodeLast(); 344 switch (err) { 345 case PS_ERR_DB_CLIENT: 346 psError(PXTOOLS_ERR_SYS, false, "database error"); 347 case PS_ERR_DB_SERVER: 348 psError(PXTOOLS_ERR_PROG, false, "database error"); 349 default: 350 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 351 } 352 353 return false; 354 } 355 if (!psArrayLength(output)) { 356 psError(PS_ERR_UNKNOWN, false, "no pending rawImfile rows found"); 357 psFree(output); 358 return true; 359 } 360 361 bool simple = false; 362 { 363 bool status = false; 364 simple = psMetadataLookupBool(&status, config->args, "-simple"); 365 if (!status) { 366 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple"); 367 return false; 368 } 369 } 370 371 if (psArrayLength(output)) { 372 // negative simple so the default is true 373 if (!ippdbPrintMetadatas(stdout, output, "p4InputExp", !simple)) { 374 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 375 psFree(output); 376 return false; 377 } 378 } 379 380 psFree(output); 381 382 return true; 383 } 384 385 386 static bool imfileMode(pxConfig *config) 265 static bool inputscfileMode(pxConfig *config) 387 266 { 388 267 PS_ASSERT_PTR_NON_NULL(config, false); … … 472 351 473 352 474 static bool to overlapMode(pxConfig *config)353 static bool tosumMode(pxConfig *config) 475 354 { 476 355 PS_ASSERT_PTR_NON_NULL(config, false); … … 570 449 571 450 572 static bool add overlapMode(pxConfig *config)451 static bool addsumscfileMode(pxConfig *config) 573 452 { 574 453 PS_ASSERT_PTR_NON_NULL(config, false); … … 590 469 } 591 470 592 if (!parseAndInsertSkyCellMap(config, mapfile)) {593 psError(PS_ERR_UNKNOWN, false, "failed to inject mapfile: %s into the database", mapfile);594 // rollback595 if (!psDBRollback(config->dbh)) {596 psError(PS_ERR_UNKNOWN, false, "database error");597 }598 return false;599 }600 601 471 // point of no return 602 472 if (!psDBCommit(config->dbh)) { … … 609 479 610 480 611 static bool parseAndInsertSkyCellMap(pxConfig *config, const char *mapfile) 612 { 613 unsigned int nFail = 0; 614 psMetadata *skycells = psMetadataConfigRead(NULL, &nFail, mapfile, false); 615 if (!skycells) { 616 psError(PS_ERR_UNKNOWN, false, "failed to parse mapfile: %s", mapfile); 617 return false; 618 } 619 if (nFail) { 620 psError(PS_ERR_UNKNOWN, false, "there were %d errors parsing mapfile: %s", nFail, mapfile); 621 psFree(skycells); 622 return false; 623 } 624 625 psMetadataItem *item = NULL; 626 psMetadataIterator *iter = psMetadataIteratorAlloc(skycells, 0, NULL); 627 if ((item = psMetadataGetAndIncrement(iter))) { 628 if (item->type != PS_DATA_METADATA) { 629 psError(PS_ERR_UNKNOWN, false, "mapfile: %s is in the wrong format", mapfile); 630 psFree(iter); 631 psFree(skycells); 632 return false; 633 } 634 635 psMetadata *sc = item->data.md; 636 // this conversion isn't strictly nessicary but it's an easy way of 637 // validating the format 638 p4SkyCellMapRow *row = p4SkyCellMapObjectFromMetadata(sc); 639 if (!row) { 640 psError(PS_ERR_UNKNOWN, false, "failed to convert mapfile: %s metdata entry into a p4SkyCellMap object", mapfile); 641 psFree(iter); 642 psFree(skycells); 643 return false; 644 } 645 646 if (!p4SkyCellMapInsertObject(config->dbh, row)) { 647 psErrorCode err = psErrorCodeLast(); 648 switch (err) { 649 case PS_ERR_DB_CLIENT: 650 psError(PXTOOLS_ERR_SYS, false, "database error"); 651 case PS_ERR_DB_SERVER: 652 psError(PXTOOLS_ERR_PROG, false, "database error"); 653 default: 654 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 655 } 656 psFree(row); 657 psFree(iter); 658 psFree(skycells); 659 return false; 660 } 661 662 psFree(row); 663 } 664 psFree(iter); 665 psFree(skycells); 666 667 return true; 668 } 669 670 671 static bool scmapMode(pxConfig *config) 481 static bool sumscfileMode(pxConfig *config) 672 482 { 673 483 PS_ASSERT_PTR_NON_NULL(config, false); … … 683 493 psString query = psStringCopy( 684 494 "SELECT\n" 685 " p4S kyCellMap.*\n"495 " p4Scfile.*\n" 686 496 " FROM p4Run\n" 687 " JOIN p4S kyCellMap\n"497 " JOIN p4Scfile\n" 688 498 " USING(p4_id)\n" 689 499 " WHERE\n" … … 692 502 693 503 if (config->where) { 694 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4S kyCellMap");504 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4Scfile"); 695 505 psStringAppend(&query, " AND %s", whereClause); 696 506 psFree(whereClause); … … 726 536 } 727 537 if (!psArrayLength(output)) { 728 psError(PS_ERR_UNKNOWN, false, "no p4S kyCellMaprows found");538 psError(PS_ERR_UNKNOWN, false, "no p4Scfile rows found"); 729 539 psFree(output); 730 540 return true; … … 743 553 if (psArrayLength(output)) { 744 554 // negative simple so the default is true 745 if (!ippdbPrintMetadatas(stdout, output, "p4SkyCellMap", !simple)) {746 psError(PS_ERR_UNKNOWN, false, "failed to print array");747 psFree(output);748 return false;749 }750 }751 752 psFree(output);753 754 return true;755 }756 757 758 static bool towarpedMode(pxConfig *config)759 {760 PS_ASSERT_PTR_NON_NULL(config, false);761 762 bool status = false;763 psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");764 if (!status) {765 psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -limit");766 return false;767 }768 769 // find all rawImfiles matching the default query770 psString query = psStringCopy(771 "SELECT\n"772 " p4SkyCellMap.*\n"773 " FROM p4Run\n"774 " JOIN p4SkyCellMap\n"775 " USING(p4_id)\n"776 " LEFT JOIN p4Scfile\n"777 " USING(p4_id, skycell_id, tess_id, exp_tag, p3_version)\n"778 " WHERE\n"779 " p4Run.state = 'run'\n"780 " AND p4Scfile.p4_id IS NULL\n"781 " AND p4Scfile.skycell_id IS NULL\n"782 " AND p4Scfile.tess_id IS NULL\n"783 " AND p4Scfile.exp_tag IS NULL\n"784 " AND p4Scfile.p3_version IS NULL\n"785 );786 787 if (config->where) {788 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4SkyCellMap");789 psStringAppend(&query, " AND %s", whereClause);790 psFree(whereClause);791 }792 793 // treat limit == 0 as "no limit"794 if (limit) {795 psString limitString = psDBGenerateLimitSQL(limit);796 psStringAppend(&query, " %s", limitString);797 psFree(limitString);798 }799 800 if (!p_psDBRunQuery(config->dbh, query)) {801 psError(PS_ERR_UNKNOWN, false, "database error");802 psFree(query);803 return false;804 }805 psFree(query);806 807 psArray *output = p_psDBFetchResult(config->dbh);808 if (!output) {809 psErrorCode err = psErrorCodeLast();810 switch (err) {811 case PS_ERR_DB_CLIENT:812 psError(PXTOOLS_ERR_SYS, false, "database error");813 case PS_ERR_DB_SERVER:814 psError(PXTOOLS_ERR_PROG, false, "database error");815 default:816 psError(PXTOOLS_ERR_PROG, false, "unknown error");817 }818 819 return false;820 }821 if (!psArrayLength(output)) {822 psError(PS_ERR_UNKNOWN, false, "no p4PendingSkyCell rows found");823 psFree(output);824 return true;825 }826 827 bool simple = false;828 {829 bool status = false;830 simple = psMetadataLookupBool(&status, config->args, "-simple");831 if (!status) {832 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");833 return false;834 }835 }836 837 if (psArrayLength(output)) {838 // negative simple so the default is true839 if (!ippdbPrintMetadatas(stdout, output, "p4PendingSkyCell", !simple)) {840 psError(PS_ERR_UNKNOWN, false, "failed to print array");841 psFree(output);842 return false;843 }844 }845 846 psFree(output);847 848 return true;849 }850 851 852 static bool addwarpedMode(pxConfig *config)853 {854 PS_ASSERT_PTR_NON_NULL(config, false);855 856 bool status = false;857 psString p4_id = psMetadataLookupStr(&status, config->args, "-p4_id");858 if (!status) {859 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -p4_id");860 return false;861 }862 if (!p4_id) {863 psError(PS_ERR_UNKNOWN, true, "-p4_id is required");864 return false;865 }866 867 psString skycell_id = psMetadataLookupStr(&status, config->args, "-skycell_id");868 if (!status) {869 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -skycell_id");870 return false;871 }872 if (!skycell_id) {873 psError(PS_ERR_UNKNOWN, true, "-skycell_id is required");874 return false;875 }876 877 psString tess_id = psMetadataLookupStr(&status, config->args, "-tess_id");878 if (!status) {879 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -tess_id");880 return false;881 }882 if (!tess_id) {883 psError(PS_ERR_UNKNOWN, true, "-tess_id is required");884 return false;885 }886 887 psString exp_tag = psMetadataLookupStr(&status, config->args, "-exp_tag");888 if (!status) {889 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_tag");890 return false;891 }892 if (!exp_tag) {893 psError(PS_ERR_UNKNOWN, true, "-exp_tag is required");894 return false;895 }896 897 psString uri = psMetadataLookupStr(&status, config->args, "-uri");898 if (!status) {899 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -uri");900 return false;901 }902 if (!uri) {903 psError(PS_ERR_UNKNOWN, true, "-uri is required");904 return false;905 }906 907 // defaults to 0908 psS32 p3_version = psMetadataLookupS32(&status, config->args, "-p3_version");909 if (!status) {910 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -p3_version");911 return false;912 }913 914 // optional915 psF64 bg = psMetadataLookupF64(&status, config->args, "-bg");916 if (!status) {917 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -bg");918 return false;919 }920 921 psF64 bg_mean_stdev = psMetadataLookupF64(&status, config->args, "-bg_mean_stdev");922 if (!status) {923 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -bg_mean_stdev");924 return false;925 }926 927 928 // XXX need to validate that this coresponds to an p4InputImfile929 if (!p4ScfileInsert(config->dbh,930 (psS32)atoi(p4_id),931 skycell_id,932 tess_id,933 exp_tag,934 p3_version,935 uri,936 bg,937 bg_mean_stdev938 )) {939 psError(PS_ERR_UNKNOWN, false, "database error");940 return false;941 }942 943 return true;944 }945 946 static bool warpedMode(pxConfig *config)947 {948 PS_ASSERT_PTR_NON_NULL(config, false);949 950 bool status = false;951 psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");952 if (!status) {953 psError(PXTOOLS_ERR_PROG, false, "failed to lookup value for -limit");954 return false;955 }956 957 // find all rawImfiles matching the default query958 psString query = psStringCopy(959 "SELECT\n"960 " p4Scfile.*\n"961 " FROM p4Run\n"962 " JOIN p4Scfile\n"963 " USING(p4_id)\n"964 " WHERE\n"965 " p4Run.state = 'run'\n"966 );967 968 if (config->where) {969 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4Scfile");970 psStringAppend(&query, " AND %s", whereClause);971 psFree(whereClause);972 }973 974 // treat limit == 0 as "no limit"975 if (limit) {976 psString limitString = psDBGenerateLimitSQL(limit);977 psStringAppend(&query, " %s", limitString);978 psFree(limitString);979 }980 981 if (!p_psDBRunQuery(config->dbh, query)) {982 psError(PS_ERR_UNKNOWN, false, "database error");983 psFree(query);984 return false;985 }986 psFree(query);987 988 psArray *output = p_psDBFetchResult(config->dbh);989 if (!output) {990 psErrorCode err = psErrorCodeLast();991 switch (err) {992 case PS_ERR_DB_CLIENT:993 psError(PXTOOLS_ERR_SYS, false, "database error");994 case PS_ERR_DB_SERVER:995 psError(PXTOOLS_ERR_PROG, false, "database error");996 default:997 psError(PXTOOLS_ERR_PROG, false, "unknown error");998 }999 1000 return false;1001 }1002 if (!psArrayLength(output)) {1003 psError(PS_ERR_UNKNOWN, false, "no p4Scfile rows found");1004 psFree(output);1005 return true;1006 }1007 1008 bool simple = false;1009 {1010 bool status = false;1011 simple = psMetadataLookupBool(&status, config->args, "-simple");1012 if (!status) {1013 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");1014 return false;1015 }1016 }1017 1018 if (psArrayLength(output)) {1019 // negative simple so the default is true1020 555 if (!ippdbPrintMetadatas(stdout, output, "p4Scfile", !simple)) { 1021 556 psError(PS_ERR_UNKNOWN, false, "failed to print array"); … … 1030 565 } 1031 566 1032 #if 0 1033 static bool tostackedimfileMode(pxConfig *config) 1034 { 1035 PS_ASSERT_PTR_NON_NULL(config, NULL); 1036 1037 psString query = psStringCopy( 1038 " SELECT DISTINCT" 1039 " p4WarpedImfile.*," 1040 " p4Run.workdir" 1041 " FROM p4Run" 1042 " JOIN p4WarpedImfile" 1043 " USING(p4_id)" 1044 " LEFT JOIN p4StackedImfile" 1045 " USING(p4_id, class_id)" 1046 " WHERE" 1047 " p4Run.state = 'run'" 1048 " AND p4StackedImfile.p4_id IS NULL" 1049 " AND p4Stackedmfile.class_id IS NULL" 1050 ); 1051 1052 if (config->where) { 1053 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4WarpedImfile"); 1054 psStringAppend(&query, " AND %s", whereClause); 1055 psFree(whereClause); 1056 } 1057 1058 if (!p_psDBRunQuery(config->dbh, query)) { 1059 psError(PS_ERR_UNKNOWN, false, "database error"); 1060 psFree(query); 1061 return false; 1062 } 1063 psFree(query); 1064 1065 psArray *output = p_psDBFetchResult(config->dbh); 1066 if (!output) { 1067 psError(PS_ERR_UNKNOWN, false, "database error"); 1068 return false; 1069 } 1070 if (!psArrayLength(output)) { 1071 psError(PS_ERR_UNKNOWN, false, "no p4WarpedImfile rows found"); 1072 psFree(output); 1073 return true; 1074 } 1075 1076 bool simple = false; 1077 { 1078 bool status = false; 1079 simple = psMetadataLookupBool(&status, config->args, "-simple"); 1080 if (!status) { 1081 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple"); 1082 return false; 1083 } 1084 } 1085 1086 // negative simple so the default is true 1087 if (!ippdbPrintMetadatas(stdout, output, "p4WarpedImfile", !simple)) { 1088 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1089 psFree(output); 1090 return false; 1091 } 1092 1093 psFree(output); 1094 1095 return true; 1096 } 1097 1098 static bool addstackedimfileMode(pxConfig *config) 1099 { 1100 PS_ASSERT_PTR_NON_NULL(config, NULL); 1101 1102 bool status = false; 1103 psString p4_id = psMetadataLookupStr(&status, config->args, "-p4_id"); 1104 if (!status) { 1105 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -p4_id"); 1106 return false; 1107 } 1108 if (!p4_id) { 1109 psError(PS_ERR_UNKNOWN, true, "-p4_id is required"); 1110 return false; 1111 } 1112 1113 psString class_id = psMetadataLookupStr(&status, config->args, "-class_id"); 1114 if (!status) { 1115 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class_id"); 1116 return false; 1117 } 1118 if (!class_id) { 1119 psError(PS_ERR_UNKNOWN, true, "-class_id is required"); 1120 return false; 1121 } 1122 1123 psString uri = psMetadataLookupStr(&status, config->args, "-uri"); 1124 if (!status) { 1125 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -uri"); 1126 return false; 1127 } 1128 if (!uri) { 1129 psError(PS_ERR_UNKNOWN, true, "-uri is required"); 1130 return false; 1131 } 1132 1133 // optional 1134 psString b1_uri = psMetadataLookupStr(&status, config->args, "-b1_uri"); 1135 if (!status) { 1136 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -b1_uri"); 1137 return false; 1138 } 1139 1140 psString b2_uri = psMetadataLookupStr(&status, config->args, "-b2_uri"); 1141 if (!status) { 1142 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -b2_uri"); 1143 return false; 1144 } 1145 1146 // XXX need to validate that this coresponds to an p4WarpedImfile 1147 if (!p4StackedImfileInsert(config->dbh, 1148 (psS32)atoi(p4_id), 1149 class_id, 1150 uri, 1151 b1_uri, 1152 b2_uri 1153 )) { 1154 psError(PS_ERR_UNKNOWN, false, "database error"); 1155 return false; 1156 } 1157 1158 return true; 1159 } 1160 1161 static bool stackedimfileMode(pxConfig *config) 1162 { 1163 PS_ASSERT_PTR_NON_NULL(config, NULL); 1164 1165 psString query = psStringCopy( 1166 " SELECT DISTINCT" 1167 " p4StackedImfile.*" 1168 " FROM p4Run" 1169 " JOIN p4StackedImfile" 1170 " USING(p4_id)" 1171 " WHERE" 1172 " p4Run.state = 'run'" 1173 ); 1174 1175 if (config->where) { 1176 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4StackedImfile"); 1177 psStringAppend(&query, " AND %s", whereClause); 1178 psFree(whereClause); 1179 } 1180 1181 if (!p_psDBRunQuery(config->dbh, query)) { 1182 psError(PS_ERR_UNKNOWN, false, "database error"); 1183 psFree(query); 1184 return false; 1185 } 1186 psFree(query); 1187 1188 psArray *output = p_psDBFetchResult(config->dbh); 1189 if (!output) { 1190 psError(PS_ERR_UNKNOWN, false, "database error"); 1191 return false; 1192 } 1193 if (!psArrayLength(output)) { 1194 psError(PS_ERR_UNKNOWN, false, "no p4StackedImfile rows found"); 1195 psFree(output); 1196 return true; 1197 } 1198 1199 bool simple = false; 1200 { 1201 bool status = false; 1202 simple = psMetadataLookupBool(&status, config->args, "-simple"); 1203 if (!status) { 1204 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple"); 1205 return false; 1206 } 1207 } 1208 1209 // negative simple so the default is true 1210 if (!ippdbPrintMetadatas(stdout, output, "p4StackedImfile", !simple)) { 1211 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1212 psFree(output); 1213 return false; 1214 } 1215 1216 psFree(output); 1217 1218 return true; 1219 } 1220 1221 static bool todiffimfileMode(pxConfig *config) 1222 { 1223 PS_ASSERT_PTR_NON_NULL(config, NULL); 1224 1225 psString query = psStringCopy( 1226 " SELECT DISTINCT" 1227 " p4StackedImfile.*," 1228 " p4WarpedImfile.uri as warped_uri," 1229 " p4Run.workdir" 1230 " FROM p4Run" 1231 " JOIN p4StackedImfile" 1232 " USING(p4_id)" 1233 " JOIN p4WarpedImfile" 1234 " USING(p4_id, class_id)" 1235 " LEFT JOIN p4DiffImfile" 1236 " ON p4WarpedImfile.p4_id = p4DiffImfile.p4_id" 1237 " AND p4WarpedImfile.exp_tag = p4DiffImfile.exp_tag" 1238 " AND p4WarpedImfile.p3_version = p4DiffImfile.p3_version" 1239 " AND p4WarpedImfile.class_id = p4DiffImfile.class_id" 1240 " WHERE" 1241 " p4Run.state = 'run'" 1242 " AND p4DiffImfile.p4_id IS NULL" 1243 " AND p4DiffImfile.exp_tag IS NULL" 1244 " AND p4DiffImfile.p3_version IS NULL" 1245 " AND p4DiffImfile.class_id IS NULL" 1246 ); 1247 1248 if (config->where) { 1249 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4StackedImfile"); 1250 psStringAppend(&query, " AND %s", whereClause); 1251 psFree(whereClause); 1252 } 1253 1254 if (!p_psDBRunQuery(config->dbh, query)) { 1255 psError(PS_ERR_UNKNOWN, false, "database error"); 1256 psFree(query); 1257 return false; 1258 } 1259 psFree(query); 1260 1261 psArray *output = p_psDBFetchResult(config->dbh); 1262 if (!output) { 1263 psError(PS_ERR_UNKNOWN, false, "database error"); 1264 return false; 1265 } 1266 if (!psArrayLength(output)) { 1267 psError(PS_ERR_UNKNOWN, false, "no p4StackedImfile rows found"); 1268 psFree(output); 1269 return true; 1270 } 1271 1272 bool simple = false; 1273 { 1274 bool status = false; 1275 simple = psMetadataLookupBool(&status, config->args, "-simple"); 1276 if (!status) { 1277 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple"); 1278 return false; 1279 } 1280 } 1281 1282 // negative simple so the default is true 1283 if (!ippdbPrintMetadatas(stdout, output, "p4StackedImfile", !simple)) { 1284 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1285 psFree(output); 1286 return false; 1287 } 1288 1289 psFree(output); 1290 1291 return true; 1292 } 1293 1294 static bool adddiffimfileMode(pxConfig *config) 1295 { 1296 PS_ASSERT_PTR_NON_NULL(config, NULL); 1297 1298 bool status = false; 1299 psString p4_id = psMetadataLookupStr(&status, config->args, "-p4_id"); 1300 if (!status) { 1301 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -p4_id"); 1302 return false; 1303 } 1304 if (!p4_id) { 1305 psError(PS_ERR_UNKNOWN, true, "-p4_id is required"); 1306 return false; 1307 } 1308 1309 psString exp_tag = psMetadataLookupStr(&status, config->args, "-exp_tag"); 1310 if (!status) { 1311 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_tag"); 1312 return false; 1313 } 1314 if (!exp_tag) { 1315 psError(PS_ERR_UNKNOWN, true, "-exp_tag is required"); 1316 return false; 1317 } 1318 1319 psString class_id = psMetadataLookupStr(&status, config->args, "-class_id"); 1320 if (!status) { 1321 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class_id"); 1322 return false; 1323 } 1324 if (!class_id) { 1325 psError(PS_ERR_UNKNOWN, true, "-class_id is required"); 1326 return false; 1327 } 1328 1329 psString uri = psMetadataLookupStr(&status, config->args, "-uri"); 1330 if (!status) { 1331 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -uri"); 1332 return false; 1333 } 1334 if (!uri) { 1335 psError(PS_ERR_UNKNOWN, true, "-uri is required"); 1336 return false; 1337 } 1338 1339 // defaults to 0 1340 psS32 p3_version = psMetadataLookupS32(&status, config->args, "-p3_version"); 1341 if (!status) { 1342 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -p3_version"); 1343 return false; 1344 } 1345 1346 // optional 1347 psString b1_uri = psMetadataLookupStr(&status, config->args, "-b1_uri"); 1348 if (!status) { 1349 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -b1_uri"); 1350 return false; 1351 } 1352 1353 psString b2_uri = psMetadataLookupStr(&status, config->args, "-b2_uri"); 1354 if (!status) { 1355 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -b2_uri"); 1356 return false; 1357 } 1358 1359 // XXX need to validate that this coresponds to an p4InputImfile 1360 if (!p4DiffImfileInsert(config->dbh, 1361 (psS32)atoi(p4_id), 1362 exp_tag, 1363 p3_version, 1364 class_id, 1365 uri, 1366 b1_uri, 1367 b2_uri 1368 )) { 1369 psError(PS_ERR_UNKNOWN, false, "database error"); 1370 return false; 1371 } 1372 1373 return true; 1374 } 1375 1376 static bool diffimfileMode(pxConfig *config) 1377 { 1378 PS_ASSERT_PTR_NON_NULL(config, NULL); 1379 1380 psString query = psStringCopy( 1381 " SELECT DISTINCT" 1382 " p4DiffImfile.*" 1383 " FROM p4Run" 1384 " JOIN p4DiffImfile" 1385 " USING(p4_id)" 1386 " WHERE" 1387 " p4Run.state = 'run'" 1388 ); 1389 1390 if (config->where) { 1391 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "p4DiffImfile"); 1392 psStringAppend(&query, " AND %s", whereClause); 1393 psFree(whereClause); 1394 } 1395 1396 if (!p_psDBRunQuery(config->dbh, query)) { 1397 psError(PS_ERR_UNKNOWN, false, "database error"); 1398 psFree(query); 1399 return false; 1400 } 1401 psFree(query); 1402 1403 psArray *output = p_psDBFetchResult(config->dbh); 1404 if (!output) { 1405 psError(PS_ERR_UNKNOWN, false, "database error"); 1406 return false; 1407 } 1408 if (!psArrayLength(output)) { 1409 psError(PS_ERR_UNKNOWN, false, "no p4DiffImfile rows found"); 1410 psFree(output); 1411 return true; 1412 } 1413 1414 bool simple = false; 1415 { 1416 bool status = false; 1417 simple = psMetadataLookupBool(&status, config->args, "-simple"); 1418 if (!status) { 1419 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple"); 1420 return false; 1421 } 1422 } 1423 1424 // negative simple so the default is true 1425 if (!ippdbPrintMetadatas(stdout, output, "p4DiffImfile", !simple)) { 1426 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 1427 psFree(output); 1428 return false; 1429 } 1430 1431 psFree(output); 1432 1433 return true; 1434 } 1435 #endif 1436 1437 static bool setp4RunState(pxConfig *config, const char *p4_id, const char *state) 1438 { 1439 PS_ASSERT_PTR_NON_NULL(p4_id, false); 567 568 static bool setp6RunState(pxConfig *config, const char *p6_id, const char *state) 569 { 570 PS_ASSERT_PTR_NON_NULL(p6_id, false); 1440 571 PS_ASSERT_PTR_NON_NULL(state, false); 1441 572 … … 1453 584 1454 585 char *query = "UPDATE p4Run SET state = '%s' WHERE p4_id = '%s'"; 1455 if (!p_psDBRunQuery(config->dbh, query, state, p 4_id)) {586 if (!p_psDBRunQuery(config->dbh, query, state, p6_id)) { 1456 587 psError(PS_ERR_UNKNOWN, false, 1457 "failed to change state for p4_id %s", p4_id); 1458 return false; 1459 } 1460 1461 return true; 1462 } 1463 1464 static bool isValidMode(pxConfig *config, const char *mode) 1465 { 1466 PS_ASSERT_PTR_NON_NULL(config, false); 1467 PS_ASSERT_PTR_NON_NULL(mode, false); 1468 1469 // check that state is a valid string value 1470 if (!( 1471 (strncmp(mode, "warp", 5) == 0) 1472 || (strncmp(mode, "diff", 5) == 0) 1473 || (strncmp(mode, "stack", 6) == 0) 1474 || (strncmp(mode, "magic", 6) == 0) 1475 ) 1476 ) { 1477 psError(PS_ERR_UNKNOWN, false, 1478 "invalid detRun mode: %s", mode); 1479 return false; 1480 } 1481 1482 return true; 1483 } 588 "failed to change state for p6_id %s", p6_id); 589 return false; 590 } 591 592 return true; 593 }
Note:
See TracChangeset
for help on using the changeset viewer.
