Changeset 18480 for branches/eam_branch_20080706/ippTools/src/dettool.c
- Timestamp:
- Jul 11, 2008, 10:32:44 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20080706/ippTools/src/dettool.c
r18468 r18480 18 18 */ 19 19 20 #ifdef HAVB_CONFIG_H21 #include <config.h>22 #endif23 24 #include <stdio.h>25 #include <string.h>26 #include <stdlib.h>27 #include <stdint.h>28 #include <inttypes.h>29 30 #include <ippdb.h>31 32 #include "pxtools.h"33 20 #include "dettool.h" 34 21 … … 98 85 //static psArray *searchInputImfiles(pxConfig *config, const char *det_id); 99 86 static detInputExpRow *rawDetrenTodetInputExpRow(rawExpRow *rawExp, psS64 det_id, psS32 iteration); 100 static psArray *searchRawImfiles(pxConfig *config , psMetadata *where);87 static psArray *searchRawImfiles(pxConfig *config); 101 88 static bool startNewIteration(pxConfig *config, psS64 det_id); 102 89 static psS32 incrementIteration(pxConfig *config, psS64 det_id); … … 812 799 } 813 800 814 if (camera) {815 psFree(detRun->camera);816 detRun->camera = psStringCopy(camera);817 }818 819 if (telescope) {820 psFree(detRun->telescope);821 detRun->telescope = psStringCopy(telescope);822 }823 824 801 if (exp_type) { 825 802 psFree(detRun->exp_type); … … 1630 1607 if (!query) { 1631 1608 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 1632 psFree(where);1633 1609 return false; 1634 1610 } … … 1841 1817 1842 1818 // this is NOT a command-line mode : it is used by 'addstackedMode' 1843 static psArray *searchRawImfiles(pxConfig *config , psMetadata *where)1819 static psArray *searchRawImfiles(pxConfig *config) 1844 1820 { 1845 1821 PS_ASSERT_PTR_NON_NULL(config, NULL); … … 2460 2436 2461 2437 if (psListLength(where->list)) { 2462 psString whereClause = psDBGenerateWhereConditionSQL( config->where, "detNormalizedImfile");2438 psString whereClause = psDBGenerateWhereConditionSQL(where, "detNormalizedImfile"); 2463 2439 psStringAppend(&query, " AND %s", whereClause); 2464 2440 psFree(whereClause); … … 2534 2510 { 2535 2511 PS_ASSERT_PTR_NON_NULL(config, false); 2536 2537 // required 2538 PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); 2539 2512 2513 PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); // required 2514 PXOPT_LOOKUP_S32(iteration, config->args, "-iteration", false, false); 2540 2515 PXOPT_LOOKUP_S16(code, config->args, "-code", false, false); 2541 2542 // Required if code == 0 2543 PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (code == 0), false); 2544 2545 // optional 2516 PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (code == 0), false); // Required if code == 0 2546 2517 PXOPT_LOOKUP_F64(bg, config->args, "-bg", false, false); 2547 2518 PXOPT_LOOKUP_F64(bg_stdev, config->args, "-bg_stdev", false, false); … … 2554 2525 PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", false, false); 2555 2526 2556 // default values2557 PXOPT_LOOKUP_S32(iteration, config->args, "-iteration", false, false);2558 2559 2527 psString query = pxDataGet("dettool_tonormalizedexp.sql"); 2560 2528 if (!query) { … … 2563 2531 } 2564 2532 2565 psStringAppend(&query, 2566 " WHERE det_id = %s" 2567 " AND iteration = %d", det_id, iteration); 2568 2533 // XXX in some other places, we put the arguments in the .sql and supply them to RunQuery 2534 psStringAppend(&query, " WHERE det_id = %s AND iteration = %d", det_id, iteration); 2569 2535 2570 2536 if (!p_psDBRunQuery(config->dbh, query)) { … … 2615 2581 PS_ASSERT_PTR_NON_NULL(config, false); 2616 2582 2583 psMetadata *where = psMetadataAlloc(); 2584 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 2585 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 2586 PXOPT_COPY_STR(config->args, where, "-recip", "recipe", "=="); 2587 2617 2588 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 2618 2589 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 2619 2590 PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false); 2620 2591 2621 psString query = psStringCopy( 2622 "SELECT" 2623 " detNormalizedExp.*" 2624 " FROM detNormalizedExp" 2625 " JOIN detRun" 2626 " USING(det_id, iteration)" 2627 " WHERE" 2628 " detRun.state = 'run'" 2629 " AND detRun.mode = 'master'" 2630 ); 2631 2632 if (config->where) { 2633 psString whereClause = psDBGenerateWhereSQL(config->where, NULL); 2592 psString query = pxDataGet("dettool_normalizedexp.sql"); 2593 if (!query) { 2594 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 2595 return false; 2596 } 2597 2598 if (psListLength(where->list)) { 2599 psString whereClause = psDBGenerateWhereSQL(where, NULL); 2634 2600 psStringAppend(&query, " %s", whereClause); 2635 2601 psFree(whereClause); 2636 2602 } 2603 psFree(where); 2637 2604 2638 2605 if (faulted) { … … 2687 2654 PS_ASSERT_PTR_NON_NULL(config, false); 2688 2655 2656 psMetadata *where = psMetadataAlloc(); 2657 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 2658 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 2659 PXOPT_COPY_S16(config->args, where, "-code", "fault", "=="); 2660 2689 2661 psString query = pxDataGet("dettool_revertnormalizedexp.sql"); 2690 2662 if (!query) { … … 2693 2665 } 2694 2666 2695 if ( config->where) {2696 psString whereClause = psDBGenerateWhereConditionSQL( config->where, "detNormalizedExp");2667 if (psListLength(where->list)) { 2668 psString whereClause = psDBGenerateWhereConditionSQL(where, "detNormalizedExp"); 2697 2669 psStringAppend(&query, " AND %s", whereClause); 2698 2670 psFree(whereClause); 2699 2671 } 2672 psFree(where); 2700 2673 2701 2674 if (!p_psDBRunQuery(config->dbh, query)) { … … 2727 2700 return false; 2728 2701 } 2729 2730 // XXX does it make sense to accept any search params?2731 #if 02732 if (config->where) {2733 psString whereClause = psDBGenerateWhereConditionSQL(config->where);2734 psStringAppend(&query, " AND %s", whereClause);2735 psFree(whereClause);2736 }2737 #endif2738 2702 2739 2703 // treat limit == 0 as "no limit" … … 2779 2743 PS_ASSERT_PTR_NON_NULL(config, false); 2780 2744 2781 // required2782 PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); 2783 PXOPT_LOOKUP_S TR(class_id, config->args, "-class_id", true, false);2784 PXOPT_LOOKUP_STR(exp_id, config->args, "-exp_id", true, false); 2785 2745 2746 PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); // required 2747 PXOPT_LOOKUP_S32(iteration, config->args, "-iteration", false, false); 2748 PXOPT_LOOKUP_STR(exp_id, config->args, "-exp_id", true, false); // required 2749 PXOPT_LOOKUP_STR(class_id, config->args, "-class_id", true, false); // required 2786 2750 PXOPT_LOOKUP_S16(code, config->args, "-code", false, false); 2787 2788 // Required if code == 0 2789 PXOPT_LOOKUP_STR(uri, config->args, "-uri", (code == 0), false); 2790 PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (code == 0), false); 2791 2792 // optional 2751 PXOPT_LOOKUP_STR(uri, config->args, "-uri", (code == 0), false); // Required if code == 0 2752 PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (code == 0), false); // Required if code == 0 2793 2753 PXOPT_LOOKUP_F64(bg, config->args, "-bg", false, false); 2794 2754 PXOPT_LOOKUP_F64(bg_stdev, config->args, "-bg_stdev", false, false); … … 2797 2757 PXOPT_LOOKUP_F64(bg_kurtosis, config->args, "-bg_kurtosis", false, false); 2798 2758 PXOPT_LOOKUP_F64(bin_stdev, config->args, "-bin_stdev", false, false); 2799 2800 2759 PXOPT_LOOKUP_F64(fringe_0, config->args, "-fringe_0", false, false); 2801 2760 PXOPT_LOOKUP_F64(fringe_1, config->args, "-fringe_1", false, false); … … 2804 2763 PXOPT_LOOKUP_F64(fringe_resid_1, config->args, "-fringe_resid_1", false, false); 2805 2764 PXOPT_LOOKUP_F64(fringe_resid_2, config->args, "-fringe_resid_2", false, false); 2806 2807 2765 PXOPT_LOOKUP_F64(user_1, config->args, "-user_1", false, false); 2808 2766 PXOPT_LOOKUP_F64(user_2, config->args, "-user_2", false, false); … … 2811 2769 PXOPT_LOOKUP_F64(user_5, config->args, "-user_5", false, false); 2812 2770 PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", false, false); 2813 2814 // default values2815 PXOPT_LOOKUP_S32(iteration, config->args, "-iteration", false, false);2816 2771 2817 2772 if (!detResidImfileInsert(config->dbh, … … 2854 2809 PS_ASSERT_PTR_NON_NULL(config, false); 2855 2810 2811 psMetadata *where = psMetadataAlloc(); 2812 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 2813 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 2814 PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "=="); 2815 PXOPT_COPY_STR(config->args, where, "-recip", "recipe", "=="); 2816 2856 2817 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 2857 2818 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 2858 2819 PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false); 2859 2820 2860 // select detResidImfile.* 2861 // by: 2862 // where det_id, iteration, exp_id is not in detResidExp; 2863 2864 psString query = psStringCopy( 2865 "SELECT" 2866 " detRun.det_type," 2867 " detRun.mode," 2868 " detResidImfile.*," 2869 " rawExp.exp_time" 2870 " FROM detResidImfile" 2871 " JOIN detRun" 2872 " USING(det_id, iteration)" 2873 " JOIN rawExp" 2874 " USING(exp_id)" 2875 " WHERE" 2876 ); 2877 // NOTE the above WHERE is completed with the following line: 2878 2821 psString query = pxDataGet("dettool_residimfile.sql"); 2822 if (!query) { 2823 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 2824 return false; 2825 } 2826 2827 // NOTE: the query ends in a WHERE, add the required restriction on detRun.state 2879 2828 char *value = NULL; 2880 2881 // add the two required restrictions: detRun.state and detRun.mode2882 2829 bool status; 2883 2830 if ((value = psMetadataLookupStr(&status, config->args, "-select_state"))) { … … 2887 2834 } 2888 2835 2889 if ( config->where) {2890 psString whereClause = psDBGenerateWhereConditionSQL( config->where, "detResidImfile");2836 if (psListLength(where->list)) { 2837 psString whereClause = psDBGenerateWhereConditionSQL(where, "detResidImfile"); 2891 2838 psStringAppend(&query, " AND %s", whereClause); 2892 2839 psFree(whereClause); 2893 2840 } 2841 psFree(where); 2894 2842 2895 2843 if (faulted) { … … 2943 2891 PS_ASSERT_PTR_NON_NULL(config, false); 2944 2892 2893 psMetadata *where = psMetadataAlloc(); 2894 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 2895 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 2896 PXOPT_COPY_STR(config->args, where, "-exp_id", "exp_id", "=="); 2897 PXOPT_COPY_STR(config->args, where, "-class_id", "class_id", "=="); 2898 PXOPT_COPY_S16(config->args, where, "-code", "fault", "=="); 2899 2945 2900 psString query = pxDataGet("dettool_revertresidimfile.sql"); 2946 2901 if (!query) { … … 2949 2904 } 2950 2905 2951 if ( config->where) {2952 psString whereClause = psDBGenerateWhereConditionSQL( config->where, "detResidImfile");2906 if (psListLength(where->list)) { 2907 psString whereClause = psDBGenerateWhereConditionSQL(where, "detResidImfile"); 2953 2908 psStringAppend(&query, " AND %s", whereClause); 2954 2909 psFree(whereClause); 2955 2910 } 2911 psFree(where); 2956 2912 2957 2913 if (!p_psDBRunQuery(config->dbh, query)) { … … 2971 2927 2972 2928 2929 /* 2930 The SQL returns a list of exposures for which all component class ids have had residuals 2931 created. This list includes the detrend id, iteration, exposure id, detrend type, and 2932 whether the exposure was included in the stack for this iteration. 2933 */ 2934 2973 2935 static bool toresidexpMode(pxConfig *config) 2974 2936 { 2975 2937 PS_ASSERT_PTR_NON_NULL(config, false); 2976 2977 /*2978 which returns a list of exposures for which all component class ids2979 have had residuals created. This list includes the detrend id,2980 iteration, exposure id, detrend type, and whether the exposure was2981 included in the stack for this iteration.2982 */2983 2938 2984 2939 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); … … 2990 2945 return false; 2991 2946 } 2992 2993 // XXX does it make sense to accept any search params?2994 #if 02995 if (config->where) {2996 psString whereClause = psDBGenerateWhereConditionSQL(config->where);2997 psStringAppend(&query, " AND %s", whereClause);2998 psFree(whereClause);2999 }3000 #endif3001 2947 3002 2948 // treat limit == 0 as "no limit" … … 3037 2983 } 3038 2984 2985 /* 2986 The SQL returns a list of exposures for which all component class ids have had residuals 2987 created. This list includes the detrend id, iteration, exposure id, detrend type, and 2988 whether the exposure was included in the stack for this iteration. 2989 */ 2990 3039 2991 static bool addresidexpMode(pxConfig *config) 3040 2992 { 3041 2993 PS_ASSERT_PTR_NON_NULL(config, false); 3042 2994 3043 // required 3044 PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); 3045 PXOPT_LOOKUP_STR(exp_id, config->args, "-exp_id", true, false); 3046 2995 // limit search by det_id, iteration, exp_id 2996 psMetadata *where = psMetadataAlloc(); 2997 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 2998 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 2999 PXOPT_COPY_STR(config->args, where, "-exp_id", "exp_id", "=="); 3000 3001 PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); // required 3002 PXOPT_LOOKUP_S32(iteration, config->args, "-iteration", false, false); 3003 PXOPT_LOOKUP_STR(exp_id, config->args, "-exp_id", true, false); // required 3047 3004 PXOPT_LOOKUP_S16(code, config->args, "-code", false, false); 3048 3049 // Required if code == 0 3050 PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (code == 0), false); 3051 3052 // optional 3005 PXOPT_LOOKUP_STR(recipe, config->args, "-recip", (code == 0), false); // Required if code == 0 3053 3006 PXOPT_LOOKUP_F64(bg, config->args, "-bg", false, false); 3054 3007 PXOPT_LOOKUP_F64(bg_stdev, config->args, "-bg_stdev", false, false); … … 3057 3010 PXOPT_LOOKUP_F64(bg_kurtosis, config->args, "-bg_kurtosis", false, false); 3058 3011 PXOPT_LOOKUP_F64(bin_stdev, config->args, "-bin_stdev", false, false); 3059 3060 3012 PXOPT_LOOKUP_F64(fringe_0, config->args, "-fringe_0", false, false); 3061 3013 PXOPT_LOOKUP_F64(fringe_1, config->args, "-fringe_1", false, false); … … 3064 3016 PXOPT_LOOKUP_F64(fringe_resid_1, config->args, "-fringe_resid_1", false, false); 3065 3017 PXOPT_LOOKUP_F64(fringe_resid_2, config->args, "-fringe_resid_2", false, false); 3066 3067 3018 PXOPT_LOOKUP_F64(user_1, config->args, "-user_1", false, false); 3068 3019 PXOPT_LOOKUP_F64(user_2, config->args, "-user_2", false, false); … … 3071 3022 PXOPT_LOOKUP_F64(user_5, config->args, "-user_5", false, false); 3072 3023 PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", false, false); 3073 3074 // default values3075 PXOPT_LOOKUP_S32(iteration, config->args, "-iteration", false, false);3076 3024 PXOPT_LOOKUP_BOOL(reject, config->args, "-reject", false); 3077 3078 /*3079 which returns a list of exposures for which all component class ids3080 have had residuals created. This list includes the detrend id,3081 iteration, exposure id, detrend type, and whether the exposure was3082 included in the stack for this iteration.3083 */3084 3025 3085 3026 psString query = pxDataGet("dettool_toresidexp.sql"); … … 3089 3030 } 3090 3031 3091 { 3092 // build a query to search by det_id, iteration, exp_id 3093 psMetadata *where = psMetadataAlloc(); 3094 3095 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 3096 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 3097 PXOPT_COPY_STR(config->args, where, "-exp_id", "exp_id", "=="); 3098 3099 3100 // there's not 3101 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 3102 psFree(where); 3103 if (whereClause) { 3104 psStringAppend(&query, " WHERE %s", whereClause); 3105 psFree(whereClause); 3106 } 3107 } 3032 if (psListLength(where->list)) { 3033 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 3034 psStringAppend(&query, " WHERE %s", whereClause); 3035 psFree(whereClause); 3036 } 3037 psFree(where); 3108 3038 3109 3039 if (!p_psDBRunQuery(config->dbh, query)) { … … 3164 3094 PS_ASSERT_PTR_NON_NULL(config, false); 3165 3095 3166 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 3167 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 3096 psMetadata *where = psMetadataAlloc(); 3097 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 3098 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 3099 PXOPT_COPY_STR(config->args, where, "-exp_id", "exp_id", "=="); 3100 PXOPT_COPY_STR(config->args, where, "-recip", "recipe", "=="); 3101 3102 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 3103 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 3168 3104 PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false); 3169 3170 psString query = psStringCopy( 3171 "SELECT" 3172 " detRun.mode," 3173 " detResidExp.*," 3174 " detInputExp.include" 3175 " FROM detRun" 3176 " JOIN detInputExp" 3177 " USING(det_id, iteration)" 3178 " JOIN detResidExp" 3179 " USING(det_id, iteration, exp_id)" 3180 " WHERE" 3181 " detRun.state = 'run'" 3182 ); 3183 3184 if (config->where) { 3185 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "detResidExp"); 3105 PXOPT_LOOKUP_BOOL(reject, config->args, "-reject", false); 3106 3107 psString query = pxDataGet("dettool_residexp.sql"); 3108 if (!query) { 3109 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 3110 return false; 3111 } 3112 3113 if (psListLength(where->list)) { 3114 psString whereClause = psDBGenerateWhereConditionSQL(where, "detResidExp"); 3186 3115 psStringAppend(&query, " AND %s", whereClause); 3187 3116 psFree(whereClause); 3188 3117 } 3118 psFree(where); 3189 3119 3190 3120 if (faulted) { … … 3196 3126 } 3197 3127 3128 // list only accepted rows 3129 // XXX the usage of this flag is unclear : -reject means "accepted"? 3130 if (reject) { 3131 psStringAppend(&query, " %s", "AND detResidExp.accept != 0"); 3132 } 3133 3198 3134 // treat limit == 0 as "no limit" 3199 3135 if (limit) { … … 3238 3174 PS_ASSERT_PTR_NON_NULL(config, false); 3239 3175 3176 psMetadata *where = psMetadataAlloc(); 3177 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 3178 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 3179 PXOPT_COPY_STR(config->args, where, "-exp_id", "exp_id", "=="); 3180 PXOPT_COPY_S16(config->args, where, "-code", "fault", "=="); 3181 3240 3182 psString query = pxDataGet("dettool_revertresidexp.sql"); 3241 3183 if (!query) { … … 3244 3186 } 3245 3187 3246 if ( config->where) {3247 psString whereClause = psDBGenerateWhereConditionSQL( config->where, "detResidExp");3188 if (psListLength(where->list)) { 3189 psString whereClause = psDBGenerateWhereConditionSQL(where, "detResidExp"); 3248 3190 psStringAppend(&query, " AND %s", whereClause); 3249 3191 psFree(whereClause); 3250 3192 } 3193 psFree(where); 3251 3194 3252 3195 if (!p_psDBRunQuery(config->dbh, query)) { … … 3266 3209 3267 3210 3211 static bool updateresidexpMode(pxConfig *config) 3212 { 3213 PS_ASSERT_PTR_NON_NULL(config, false); 3214 3215 PXOPT_LOOKUP_BOOL(reject, config->args, "-reject", false); 3216 3217 // build a query to search by det_id, iteration, exp_id 3218 psMetadata *where = psMetadataAlloc(); 3219 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 3220 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 3221 PXOPT_COPY_STR(config->args, where, "-exp_id", "exp_id", "=="); 3222 3223 // find the values we're going to set 3224 // copy everything but det_id, iteration, & exp_id from the args and 3225 // remove the '-' prefix 3226 psMetadata *set = psMetadataAlloc(); 3227 PXOPT_COPY_STR(config->args, set, "-recip", "recipe", "=="); 3228 PXOPT_COPY_F64(config->args, set, "-bg", "bg", "=="); 3229 PXOPT_COPY_F64(config->args, set, "-bg_stdev", "bg_stdev", "=="); 3230 PXOPT_COPY_F64(config->args, set, "-bg_mean_stdev", "bg_mean_stdev", "=="); 3231 PXOPT_COPY_STR(config->args, set, "-path_base", "path_base", "=="); 3232 3233 // this can't be PXOPT_ macro-ized as reject is !'d 3234 if (!psMetadataAddBool(set, PS_LIST_TAIL, "accept", 0, "==", !reject)) { 3235 psError(PS_ERR_UNKNOWN, false, "failed to add item accept"); 3236 psFree(set); 3237 psFree(where); 3238 return false; 3239 } 3240 3241 long changed = psDBUpdateRows(config->dbh, "detResidExp", where, set); 3242 psFree(set); 3243 psFree(where); 3244 3245 if (changed < 0) { 3246 psError(PS_ERR_UNKNOWN, false, "no rows were updated"); 3247 return false; 3248 } 3249 3250 return true; 3251 } 3252 3253 /* The SQL returns a list of detrend runs (with detrend id, iteration and detrend type) which 3254 * have completed all residexps. 3255 */ 3256 3268 3257 static bool todetrunsummaryMode(pxConfig *config) 3269 3258 { … … 3272 3261 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 3273 3262 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 3274 3275 /* which returns a list of detrend runs (with detrend id, iteration and3276 * detrend type) which have completed all residexps.3277 */3278 3263 3279 3264 psString query = pxDataGet("dettool_todetrunsummary.sql"); … … 3282 3267 return false; 3283 3268 } 3284 3285 // XXX does it make sense to accept any search params?3286 #if 03287 if (config->where) {3288 psString whereClause = psDBGenerateWhereConditionSQL(config->where);3289 psStringAppend(&query, " AND %s", whereClause);3290 psFree(whereClause);3291 }3292 #endif3293 3269 3294 3270 // treat limit == 0 as "no limit" … … 3329 3305 } 3330 3306 3331 static bool updateresidexpMode(pxConfig *config) 3332 { 3333 PS_ASSERT_PTR_NON_NULL(config, false); 3334 3335 PXOPT_LOOKUP_BOOL(reject, config->args, "-reject", false); 3336 3307 // this function is used to generate the detrunSummary entries used below 3308 // XXX why is this a separate function? roll it back into adddetrunsummary? 3309 static detRunSummaryRow *mdToDetRunSummary(pxConfig *config, psMetadata *row) 3310 { 3311 PS_ASSERT_PTR_NON_NULL(config, false); 3312 3313 bool status = false; 3314 // from row 3315 psS64 det_id = psMetadataLookupS64(&status, row, "det_id"); 3316 if (!status) { 3317 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for det_id"); 3318 return false; 3319 } 3320 psS32 iteration = psMetadataLookupS32(&status, row, "iteration"); 3321 if (!status) { 3322 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for iteration"); 3323 return false; 3324 } 3325 3326 // optional 3327 PXOPT_LOOKUP_F64(bg, config->args, "-bg", false, false); 3328 PXOPT_LOOKUP_F64(bg_stdev, config->args, "-bg_stdev", false, false); 3329 PXOPT_LOOKUP_F64(bg_mean_stdev, config->args, "-bg_mean_stdev", false, false); 3330 3331 // default values 3332 PXOPT_LOOKUP_S16(code, config->args, "-code", false, false); 3333 PXOPT_LOOKUP_BOOL(accept, config->args, "-accept", false); 3334 3335 return detRunSummaryRowAlloc( 3336 det_id, 3337 iteration, 3338 bg, 3339 bg_stdev, 3340 bg_mean_stdev, 3341 accept, 3342 code 3343 ); 3344 } 3345 3346 static bool adddetrunsummaryMode(pxConfig *config) 3347 { 3348 PS_ASSERT_PTR_NON_NULL(config, false); 3349 3337 3350 // build a query to search by det_id, iteration, exp_id 3338 3351 psMetadata *where = psMetadataAlloc(); 3339 3352 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 3340 3353 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 3341 PXOPT_COPY_STR(config->args, where, "-exp_id", "exp_id", "=="); 3342 3343 // find the values we're going to set 3344 // copy everything but det_id, iteration, & exp_id from the args and 3345 // remove the '-' prefix 3346 psMetadata *set = psMetadataAlloc(); 3347 // XXX if PXOPT_COPY_* errors here the where md will leak 3348 PXOPT_COPY_STR(config->args, set, "-recip", "recipe", "=="); 3349 PXOPT_COPY_F64(config->args, set, "-bg", "bg", "=="); 3350 PXOPT_COPY_F64(config->args, set, "-bg_stdev", "bg_stdev", "=="); 3351 PXOPT_COPY_F64(config->args, set, "-bg_mean_stdev", "bg_mean_stdev", "=="); 3352 PXOPT_COPY_STR(config->args, set, "-path_base", "path_base", "=="); 3353 3354 // this can't be PXOPT_ macro-ized as reject is !'d 3355 if (!psMetadataAddBool(set, PS_LIST_TAIL, "accept", 0, "==", !reject)) { 3356 psError(PS_ERR_UNKNOWN, false, "failed to add item accept"); 3357 psFree(set); 3358 psFree(where); 3359 return false; 3360 } 3361 3362 long changed = psDBUpdateRows(config->dbh, "detResidExp", where, set); 3363 psFree(set); 3364 psFree(where); 3365 3366 if (changed < 0) { 3367 psError(PS_ERR_UNKNOWN, false, "no rows were updated"); 3368 return false; 3369 } 3370 3371 return true; 3372 } 3373 3374 static bool adddetrunsummaryMode(pxConfig *config) 3375 { 3376 PS_ASSERT_PTR_NON_NULL(config, false); 3377 3378 // required 3379 PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); 3380 3381 // optional 3354 3355 PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); // required 3382 3356 PXOPT_LOOKUP_BOOL(again, config->args, "-again", false); 3357 3358 // The values supplied as arguments on the command (eg, -bg) are parsed 3359 // by mdToDetRunSummary below. 3360 // XXX why is there ever more than one? 3383 3361 3384 3362 psString query = pxDataGet("dettool_find_completed_runs.sql"); … … 3388 3366 } 3389 3367 3390 // build a query to search by det_id, iteration, exp_id 3391 psMetadata *where = psMetadataAlloc(); 3392 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 3393 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 3394 3395 { 3396 // there's not 3368 if (psListLength(where->list)) { 3397 3369 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 3398 psFree(where); 3399 if (whereClause) { 3400 psStringAppend(&query, " WHERE %s", whereClause); 3401 psFree(whereClause); 3402 } 3403 } 3370 psStringAppend(&query, " WHERE %s", whereClause); 3371 psFree(whereClause); 3372 } 3373 psFree(where); 3404 3374 3405 3375 if (!p_psDBRunQuery(config->dbh, query)) { … … 3428 3398 } 3429 3399 3400 // XXX why is there ever more than one result here? 3430 3401 for (long i = 0; i < psArrayLength(output); i++) { 3431 3402 psMetadata *row = output->data[i]; … … 3456 3427 3457 3428 // XXX this logic does not deal with the case of -code being set 3429 // XXX it should be an error for -again and -code to both be set 3458 3430 if (again) { 3459 3431 if (!startNewIteration(config, (psS64)atoll(det_id))) { … … 3482 3454 } 3483 3455 3484 static detRunSummaryRow *mdToDetRunSummary(pxConfig *config, psMetadata *row)3485 {3486 PS_ASSERT_PTR_NON_NULL(config, false);3487 3488 bool status = false;3489 // from row3490 psS64 det_id = psMetadataLookupS64(&status, row, "det_id");3491 if (!status) {3492 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for det_id");3493 return false;3494 }3495 psS32 iteration = psMetadataLookupS32(&status, row, "iteration");3496 if (!status) {3497 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for iteration");3498 return false;3499 }3500 3501 // optional3502 PXOPT_LOOKUP_F64(bg, config->args, "-bg", false, false);3503 PXOPT_LOOKUP_F64(bg_stdev, config->args, "-bg_stdev", false, false);3504 PXOPT_LOOKUP_F64(bg_mean_stdev, config->args, "-bg_mean_stdev", false, false);3505 // default values3506 PXOPT_LOOKUP_BOOL(accept, config->args, "-accept", false);3507 PXOPT_LOOKUP_S16(code, config->args, "-code", false, false);3508 3509 return detRunSummaryRowAlloc(3510 det_id,3511 iteration,3512 bg,3513 bg_stdev,3514 bg_mean_stdev,3515 accept,3516 code3517 );3518 }3519 3520 3456 static bool detrunsummaryMode(pxConfig *config) 3521 3457 { 3522 3458 PS_ASSERT_PTR_NON_NULL(config, false); 3459 3460 psMetadata *where = psMetadataAlloc(); 3461 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 3462 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 3523 3463 3524 3464 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); … … 3526 3466 PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false); 3527 3467 3528 psString query = psStringCopy( 3529 "SELECT DISTINCT\n" 3530 " detRunSummary.*,\n" 3531 " detRun.det_type,\n" 3532 " detRun.mode\n" 3533 " FROM detRun\n" 3534 " JOIN detRunSummary\n" 3535 " USING(det_id, iteration)\n" 3536 " WHERE\n" 3537 " detRun.state = 'run'\n" 3538 ); 3539 3540 if (config->where) { 3541 psString whereClause = psDBGenerateWhereConditionSQL(config->where, NULL); 3468 psString query = pxDataGet("dettool_detrunsummary.sql"); 3469 if (!query) { 3470 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 3471 psFree(where); 3472 return false; 3473 } 3474 3475 if (psListLength(where->list)) { 3476 psString whereClause = psDBGenerateWhereConditionSQL(where, "NULL"); 3542 3477 psStringAppend(&query, " AND %s", whereClause); 3543 3478 psFree(whereClause); 3544 3479 } 3480 psFree(where); 3545 3481 3546 3482 if (faulted) { … … 3594 3530 PS_ASSERT_PTR_NON_NULL(config, false); 3595 3531 3532 psMetadata *where = psMetadataAlloc(); 3533 PXOPT_COPY_STR(config->args, where, "-det_id", "det_id", "=="); 3534 PXOPT_COPY_S32(config->args, where, "-iteration", "iteration", "=="); 3535 PXOPT_COPY_STR(config->args, where, "-code", "fault", "=="); 3536 3596 3537 psString query = pxDataGet("dettool_revertdetrunsummary.sql"); 3597 3538 if (!query) { … … 3600 3541 } 3601 3542 3602 if ( config->where) {3603 psString whereClause = psDBGenerateWhereConditionSQL( config->where, "detRunSummary");3543 if (psListLength(where->list)) { 3544 psString whereClause = psDBGenerateWhereConditionSQL(where, "detRunSummary"); 3604 3545 psStringAppend(&query, " AND %s", whereClause); 3605 3546 psFree(whereClause); 3606 3547 } 3548 psFree(where); 3607 3549 3608 3550 if (!p_psDBRunQuery(config->dbh, query)) { … … 3625 3567 { 3626 3568 PS_ASSERT_PTR_NON_NULL(config, false); 3627 3628 // required 3629 PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); 3630 3569 3570 PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); // required 3631 3571 PXOPT_LOOKUP_BOOL(accept, config->args, "-accept", false); 3632 3572 PXOPT_LOOKUP_BOOL(reject, config->args, "-reject", false); … … 3656 3596 PS_ASSERT_PTR_NON_NULL(config, false); 3657 3597 3658 // det_id is required 3659 // XXX this isn't strictly nessicary but not having the det_id complicates 3660 // incrementing the iteration number 3661 PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); 3662 3598 PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); // required 3663 3599 PXOPT_LOOKUP_BOOL(again, config->args, "-again", false); 3664 3600 PXOPT_LOOKUP_STR(state, config->args, "-state", false, false); 3601 3665 3602 // either -rerun or -state must be specified 3666 3603 if (!(again || state)) { … … 3669 3606 } 3670 3607 if (again && state) { 3671 psError(PS_ERR_UNKNOWN, true, " either -again or -state must be specified");3608 psError(PS_ERR_UNKNOWN, true, "-accept and -reject are exclusive"); 3672 3609 return false; 3673 3610 } … … 3688 3625 } 3689 3626 3627 // used by updatedetrunMode 3690 3628 static bool startNewIteration(pxConfig *config, psS64 det_id) 3691 3629 { … … 3698 3636 } 3699 3637 3700 // XXX this query was not restricted by det_id, resulting 3701 // in an inconsistent UPDATE below. I added this AND clause 3702 // though there may be a cleaner method (EAM 2006.10.08) 3638 // restrict the update only to the specified det_id 3703 3639 psStringAppend(&query, " WHERE det_id = %" PRId64 , det_id); 3704 3640 … … 3953 3889 PS_ASSERT_PTR_NON_NULL(config, false); 3954 3890 3955 // required 3956 PXOPT_LOOKUP_STR(det_type, config->args, "-det_type", true, false); 3957 PXOPT_LOOKUP_STR(filelevel, config->args, "-filelevel", false, false); 3958 3959 // optional 3891 PXOPT_LOOKUP_STR(det_type, config->args, "-det_type", true, false); // required 3892 PXOPT_LOOKUP_STR(filelevel, config->args, "-filelevel", true, false); // required 3960 3893 PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", false, false); 3961 3894 PXOPT_LOOKUP_STR(camera, config->args, "-inst", false, false); … … 3980 3913 PXOPT_LOOKUP_STR(parent, config->args, "-parent", false, false); 3981 3914 PXOPT_LOOKUP_STR(label, config->args, "-label", false, false); 3982 3983 // default3984 3915 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 3985 3916 … … 3993 3924 0, // the iteration is fixed at 0 3994 3925 det_type, 3995 "register", // mode 3926 "register", // mode is required to be "register" 3996 3927 "register", // state 3997 3928 filelevel, … … 4064 3995 } 4065 3996 3997 // NOTE : this function is also used by addcorrectimfileMode 4066 3998 bool register_detrend_imfileMode(pxConfig *config) 4067 3999 { 4068 4000 PS_ASSERT_PTR_NON_NULL(config, false); 4069 4070 // required 4071 PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); 4072 PXOPT_LOOKUP_STR(class_id, config->args, "-class_id", true, false); 4073 PXOPT_LOOKUP_STR(uri, config->args, "-uri", true, false); 4074 4075 // optional 4001 4002 PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); // required 4003 PXOPT_LOOKUP_STR(class_id, config->args, "-class_id", true, false); // required 4004 PXOPT_LOOKUP_STR(uri, config->args, "-uri", true, false); // required 4076 4005 PXOPT_LOOKUP_F64(bg, config->args, "-bg", false, false); 4077 4006 PXOPT_LOOKUP_F64(bg_stdev, config->args, "-bg_stdev", false, false);
Note:
See TracChangeset
for help on using the changeset viewer.
