- Timestamp:
- Oct 21, 2010, 2:45:13 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20100823/ippTools/src/difftool.c
r29324 r29515 48 48 static bool pendingcleanuprunMode(pxConfig *config); 49 49 static bool pendingcleanupskyfileMode(pxConfig *config); 50 static bool revertcleanupMode(pxConfig *config); 50 51 static bool donecleanupMode(pxConfig *config); 51 52 static bool updatediffskyfileMode(pxConfig *config); … … 60 61 static bool tofullskyfileMode(pxConfig *config); 61 62 static bool listrunMode(pxConfig *config); 63 static bool listssrunMode(pxConfig *config); 62 64 static bool setskyfiletoupdateMode(pxConfig *config); 63 65 … … 99 101 MODECASE(DIFFTOOL_MODE_PENDINGCLEANUPRUN, pendingcleanuprunMode); 100 102 MODECASE(DIFFTOOL_MODE_PENDINGCLEANUPSKYFILE, pendingcleanupskyfileMode); 103 MODECASE(DIFFTOOL_MODE_REVERTCLEANUP, revertcleanupMode); 101 104 MODECASE(DIFFTOOL_MODE_DONECLEANUP, donecleanupMode); 102 105 MODECASE(DIFFTOOL_MODE_UPDATEDIFFSKYFILE, updatediffskyfileMode); … … 108 111 MODECASE(DIFFTOOL_MODE_TOFULLSKYFILE, tofullskyfileMode); 109 112 MODECASE(DIFFTOOL_MODE_LISTRUN, listrunMode); 113 MODECASE(DIFFTOOL_MODE_LISTSSRUN, listssrunMode); 110 114 MODECASE(DIFFTOOL_MODE_SETSKYFILETOUPDATE, setskyfiletoupdateMode); 111 115 … … 478 482 } 479 483 psFree(where); 484 485 psStringAppend(&query, "\nORDER by priority DESC, diff_id"); 480 486 481 487 // treat limit == 0 as "no limit" … … 1236 1242 PXOPT_COPY_F32(config->args, warp2Where, "-good_frac", "warpSkyfile.good_frac", ">="); 1237 1243 PXOPT_COPY_STR(config->args, stackWhere, "-stack_label", "stackRun.label", "=="); 1244 PXOPT_COPY_STR(config->args, stackWhere, "-stack_data_group", "stackRun.data_group", "=="); 1238 1245 1239 1246 PXOPT_LOOKUP_BOOL(bothways, config->args, "-bothways", false); … … 1609 1616 PXOPT_COPY_S64(config->args, selectWhere, "-warp_id", "inputWarpRun.warp_id", "=="); 1610 1617 PXOPT_COPY_S64(config->args, selectWhere, "-exp_id", "inputRawExp.exp_id", "=="); 1618 PXOPT_COPY_S64(config->args, selectWhere, "-template_exp_id", "templateRawExp.exp_id", "=="); 1611 1619 PXOPT_COPY_STR(config->args, selectWhere, "-filter", "inputRawExp.filter", "=="); 1612 1620 PXOPT_COPY_STR(config->args, selectWhere, "-obs_mode", "inputRawExp.obs_mode", "=="); … … 1647 1655 PXOPT_COPY_F32(config->args, selectWhere, "-sun_angle_min", "inputRawExp.sun_angle", ">="); 1648 1656 PXOPT_COPY_F32(config->args, selectWhere, "-sun_angle_max", "inputRawExp.sun_angle", "<"); 1649 PXOPT_COPY_STR(config->args, selectWhere, "-comment", "inputRawExp.comment", "LIKE"); 1657 PXOPT_COPY_STR(config->args, selectWhere, "-input_comment", "inputRawExp.comment", "LIKE"); 1658 PXOPT_COPY_STR(config->args, selectWhere, "-template_comment", "templateRawExp.comment", "LIKE"); 1650 1659 1651 1660 PXOPT_LOOKUP_BOOL(not_bothways, config->args, "-not-bothways", false); … … 1680 1689 1681 1690 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 1691 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 1682 1692 PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false); 1683 1693 … … 1839 1849 long numGood = 0; // Number of good rows added 1840 1850 for (long i = 0; i < results->n; i++) { 1851 if (limit && numGood >= limit) { 1852 break; 1853 } 1841 1854 psMetadata *row = results->data[i]; // Result row from query 1842 1855 … … 2535 2548 2536 2549 2550 static bool revertcleanupMode(pxConfig *config) 2551 { 2552 PS_ASSERT_PTR_NON_NULL(config, false); 2553 2554 psMetadata *where = psMetadataAlloc(); 2555 PXOPT_COPY_S64(config->args, where, "-diff_id", "diffSkyfile.diff_id", "=="); 2556 pxAddLabelSearchArgs (config, where, "-label", "diffRun.label", "LIKE"); 2557 pxAddLabelSearchArgs (config, where, "-data_group", "diffRun.data_group", "LIKE"); 2558 2559 PXOPT_LOOKUP_STR(state, config->args, "-state", false, false); 2560 2561 if (!psListLength(where->list)) { 2562 psFree(where); 2563 psError(PXTOOLS_ERR_CONFIG, false, "search parameters are required"); 2564 return false; 2565 } 2566 if (!state) { 2567 state = "error_cleaned"; 2568 } 2569 char *newState = NULL; 2570 if (!strcmp(state, "error_cleaned")) { 2571 newState = "goto_cleaned"; 2572 } else if (!strcmp(state, "error_purged")) { 2573 newState = "goto_purged"; 2574 } else if (!strcmp(state, "error_scrubbed")) { 2575 newState = "goto_scrubbed"; 2576 } else { 2577 psError(PXTOOLS_ERR_CONFIG, true, "-state must be either error_cleaned, error_purged, or error_scrubbed"); 2578 return false; 2579 } 2580 2581 psString query = pxDataGet("difftool_revertcleanup.sql"); 2582 if (!query) { 2583 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 2584 return false; 2585 } 2586 2587 if (psListLength(where->list)) { 2588 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 2589 psStringAppend(&query, " AND %s", whereClause); 2590 psFree(whereClause); 2591 } 2592 psFree(where); 2593 2594 if (!p_psDBRunQueryF(config->dbh, query, newState, state, state)) { 2595 psError(PS_ERR_UNKNOWN, false, "database error"); 2596 psFree(query); 2597 return false; 2598 } 2599 psFree(query); 2600 2601 int numDeleted = psDBAffectedRows(config->dbh); 2602 2603 psLogMsg("difftool", PS_LOG_INFO, "Reverted %d diffRuns and diffSkyfiles", numDeleted); 2604 2605 return true; 2606 } 2537 2607 static bool donecleanupMode(pxConfig *config) 2538 2608 { … … 2877 2947 2878 2948 psMetadata *where = psMetadataAlloc(); 2879 PXOPT_COPY_S64(config->args, where, "-diff_id", "diffRun.diff_id", "=="); 2880 PXOPT_COPY_STR(config->args, where, "-tess_id", "diffRun.tess_id", "=="); 2881 PXOPT_COPY_S64(config->args, where, "-magicked", "diffRun.magicked", "=="); 2882 pxAddLabelSearchArgs (config, where, "-label", "diffRun.label", "LIKE"); 2949 PXOPT_COPY_S64(config->args, where, "-diff_id", "diffRun.diff_id", "=="); 2950 PXOPT_COPY_STR(config->args, where, "-tess_id", "diffRun.tess_id", "LIKE"); 2951 PXOPT_COPY_S64(config->args, where, "-magicked", "diffRun.magicked", "=="); 2952 PXOPT_COPY_STR(config->args, where, "-state", "diffRun.state", "=="); 2953 pxAddLabelSearchArgs (config, where, "-label", "diffRun.label", "LIKE"); 2883 2954 pxAddLabelSearchArgs (config, where, "-data_group", "diffRun.data_group", "LIKE"); 2884 2955 pxAddLabelSearchArgs (config, where, "-dist_group", "diffRun.dist_group", "LIKE"); 2885 2956 2886 2957 PXOPT_LOOKUP_BOOL(template, config->args, "-template", false); 2887 2958 if (!template) { … … 2905 2976 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 2906 2977 PXOPT_LOOKUP_BOOL(pstamp_order, config->args, "-pstamp_order", false); 2907 2978 PXOPT_LOOKUP_S16(diff_mode, config->args, "-diff_mode", false, false); 2979 if (diff_mode) { 2980 PXOPT_COPY_S16(config->args, where, "-diff_mode", "diffRun.diff_mode", "=="); 2981 } 2908 2982 2909 2983 psString where2 = NULL; … … 2983 3057 return true; 2984 3058 } 3059 static bool listssrunMode(pxConfig *config) 3060 { 3061 PS_ASSERT_PTR_NON_NULL(config, false); 3062 3063 psMetadata *where = psMetadataAlloc(); 3064 PXOPT_COPY_S64(config->args, where, "-diff_id", "diffRun.diff_id", "=="); 3065 PXOPT_COPY_S64(config->args, where, "-stack_id", "stackInput.stack_id", "=="); 3066 PXOPT_COPY_S64(config->args, where, "-template_stack_id", "stackTemplate.stack_id", "=="); 3067 PXOPT_COPY_STR(config->args, where, "-tess_id", "diffRun.tess_id", "LIKE"); 3068 PXOPT_COPY_STR(config->args, where, "-state", "diffRun.state", "=="); 3069 pxAddLabelSearchArgs (config, where, "-label", "diffRun.label", "LIKE"); 3070 pxAddLabelSearchArgs (config, where, "-data_group", "diffRun.data_group", "LIKE"); 3071 pxAddLabelSearchArgs (config, where, "-dist_group", "diffRun.dist_group", "LIKE"); 3072 3073 // lookup these so we don't compare to zero if they are not supplied 3074 PXOPT_LOOKUP_F64(mjd_obs_begin, config->args, "-mjd_obs_begin", false, false); 3075 PXOPT_LOOKUP_F64(mjd_obs_end, config->args, "-mjd_obs_end", false, false); 3076 3077 PXOPT_LOOKUP_BOOL(template, config->args, "-template", false); 3078 3079 if (!template) { 3080 if (mjd_obs_begin) { 3081 PXOPT_COPY_F64(config->args, where, "-mjd_obs_begin", "stackInput.mjd_obs", ">="); 3082 } 3083 if (mjd_obs_end) { 3084 PXOPT_COPY_F64(config->args, where, "-mjd_obs_end", "stackInput.mjd_obs", "<="); 3085 } 3086 PXOPT_COPY_STR(config->args, where, "-filter", "stackInputRun.filter", "LIKE"); 3087 } else { 3088 if (mjd_obs_begin) { 3089 PXOPT_COPY_F64(config->args, where, "-mjd_obs_begin", "stackTemplate.mjd_obs", ">="); 3090 } 3091 if (mjd_obs_end) { 3092 PXOPT_COPY_F64(config->args, where, "-mjd_obs_end", "stackTemplate.mjd_obs", "<="); 3093 } 3094 PXOPT_COPY_STR(config->args, where, "-filter", "stackTemplateRun.filter", "LIKE"); 3095 } 3096 3097 PXOPT_LOOKUP_BOOL(all, config->args, "-all", false); 3098 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 3099 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 3100 PXOPT_LOOKUP_BOOL(pstamp_order, config->args, "-pstamp_order", false); 3101 3102 psString where2 = NULL; 3103 psString query = pxDataGet("difftool_listssrun.sql"); 3104 if (!query) { 3105 psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement"); 3106 return false; 3107 } 3108 3109 if (psListLength(where->list)) { 3110 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 3111 psStringAppend(&query, " AND %s", whereClause); 3112 psFree(whereClause); 3113 } else if (where2) { 3114 psStringAppend(&query, " AND %s", where2); 3115 } else if (!all) { 3116 psError(PXTOOLS_ERR_CONFIG, true, "search parameters or -all are required"); 3117 return false; 3118 } 3119 psFree(where); 3120 3121 if (pstamp_order) { 3122 if (template) { 3123 psStringAppend(&query, " ORDER BY stackTemplate.stack_id, diff_id DESC"); 3124 } else { 3125 psStringAppend(&query, " ORDER BY stackInput.stack_id, diff_id DESC"); 3126 } 3127 } 3128 3129 // treat limit == 0 as "no limit" 3130 if (limit) { 3131 psString limitString = psDBGenerateLimitSQL(limit); 3132 psStringAppend(&query, " %s", limitString); 3133 psFree(limitString); 3134 } 3135 3136 if (!p_psDBRunQuery(config->dbh, query)) { 3137 psError(PS_ERR_UNKNOWN, false, "database error"); 3138 psFree(query); 3139 return false; 3140 } 3141 psFree(query); 3142 3143 psArray *output = p_psDBFetchResult(config->dbh); 3144 if (!output) { 3145 psErrorCode err = psErrorCodeLast(); 3146 switch (err) { 3147 case PS_ERR_DB_CLIENT: 3148 psError(PXTOOLS_ERR_SYS, false, "database error"); 3149 case PS_ERR_DB_SERVER: 3150 psError(PXTOOLS_ERR_PROG, false, "database error"); 3151 default: 3152 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 3153 } 3154 3155 return false; 3156 } 3157 if (!psArrayLength(output)) { 3158 psTrace("difftool", PS_LOG_INFO, "no rows found"); 3159 psFree(output); 3160 return true; 3161 } 3162 3163 if (psArrayLength(output)) { 3164 // negative simple so the default is true 3165 if (!ippdbPrintMetadatas(stdout, output, "diffRun", !simple)) { 3166 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 3167 psFree(output); 3168 return false; 3169 } 3170 } 3171 3172 psFree(output); 3173 3174 return true; 3175 } 2985 3176 // a very specfic function to queue a cleaned warpSkyfile to be updated 2986 3177 static bool setskyfiletoupdateMode(pxConfig *config)
Note:
See TracChangeset
for help on using the changeset viewer.
