Changeset 18480
- Timestamp:
- Jul 11, 2008, 10:32:44 AM (18 years ago)
- Location:
- branches/eam_branch_20080706/ippTools/src
- Files:
-
- 5 edited
-
dettool.c (modified) (52 diffs)
-
dettool.h (modified) (1 diff)
-
dettoolConfig.c (modified) (20 diffs)
-
dettool_correction.c (modified) (10 diffs)
-
pxtools.h (modified) (1 diff)
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); -
branches/eam_branch_20080706/ippTools/src/dettool.h
r18157 r18480 17 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 18 */ 19 20 #ifdef HAVE_CONFIG_H 21 #include <config.h> 22 #endif 19 23 20 24 #ifndef DETTOOL_H -
branches/eam_branch_20080706/ippTools/src/dettoolConfig.c
r18468 r18480 18 18 */ 19 19 20 #ifdef HAVE_CONFIG_H21 #include <config.h>22 #endif23 24 #include <psmodules.h>25 26 #include "pxtools.h"27 20 #include "dettool.h" 28 21 … … 167 160 psMetadataAddStr(definebydetrunArgs, PS_LIST_TAIL, "-set_input_end", 0, "require input exp to be in this period", NULL); 168 161 169 // XXX EAM : it looks like the corresponding dettool functions don't exist:162 // *** these are in dettool_correction.c *** 170 163 // -makecorrection 171 164 psMetadata *makecorrectionArgs = psMetadataAlloc(); … … 224 217 psMetadataAddStr(inputArgs, PS_LIST_TAIL, "-det_id", 0, "search for detrend ID", NULL); 225 218 psMetadataAddS32(inputArgs, PS_LIST_TAIL, "-iteration", 0, "define iteration number", 0); 226 psMetadataAddS64(inputArgs, PS_LIST_TAIL, "-exp_id", 0, "search for exp ID", NULL);219 psMetadataAddS64(inputArgs, PS_LIST_TAIL, "-exp_id", 0, "search for exp ID", 0); 227 220 psMetadataAddBool(inputArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false); 228 221 … … 428 421 psMetadataAddS16(revertnormalizedimfileArgs, PS_LIST_TAIL, "-code", 0, "search by fault code", 0); 429 422 430 XXX EAM : cleaned to this point431 break into separate files432 433 423 // -tonormalizedexp 434 424 psMetadata *tonormalizedexpArgs = psMetadataAlloc(); … … 440 430 psMetadataAddStr(addnormalizedexpArgs, PS_LIST_TAIL, "-det_id", 0, "define detrend ID (required)", NULL); 441 431 psMetadataAddS32(addnormalizedexpArgs, PS_LIST_TAIL, "-iteration", 0, "define iteration number", 0); 432 psMetadataAddS16(addnormalizedexpArgs, PS_LIST_TAIL, "-code", 0, "set fault code", 0); 442 433 psMetadataAddStr(addnormalizedexpArgs, PS_LIST_TAIL, "-recip", 0, "search for recipe", NULL); 443 434 psMetadataAddF64(addnormalizedexpArgs, PS_LIST_TAIL, "-bg", 0, "define exposure background", NAN); … … 450 441 psMetadataAddF64(addnormalizedexpArgs, PS_LIST_TAIL, "-user_5", 0, "define user statistic (5)", NAN); 451 442 psMetadataAddStr(addnormalizedexpArgs, PS_LIST_TAIL, "-path_base", 0, "define base output location", NULL); 452 psMetadataAddS16(addnormalizedexpArgs, PS_LIST_TAIL, "-code", 0, "set fault code", 0);453 443 454 444 // -normalizedexp 455 445 psMetadata *normalizedexpArgs = psMetadataAlloc(); 456 psMetadataAddStr(normalizedexpArgs, PS_LIST_TAIL, "-det_id", 0, " definedetrend ID", NULL);457 psMetadataAddS32(normalizedexpArgs, PS_LIST_TAIL, "-iteration", 0, " defineiteration number", 0);446 psMetadataAddStr(normalizedexpArgs, PS_LIST_TAIL, "-det_id", 0, "search by detrend ID", NULL); 447 psMetadataAddS32(normalizedexpArgs, PS_LIST_TAIL, "-iteration", 0, "search by iteration number", 0); 458 448 psMetadataAddStr(normalizedexpArgs, PS_LIST_TAIL, "-recip", 0, "search for recipe", NULL); 459 psMetadataAddF64(normalizedexpArgs, PS_LIST_TAIL, "-bg", 0, "define exposure background", NAN);460 psMetadataAddF64(normalizedexpArgs, PS_LIST_TAIL, "-bg_stdev", 0, "define exposure background stdev", NAN);461 psMetadataAddF64(normalizedexpArgs, PS_LIST_TAIL, "-bg_mean_stdev", 0, "define exposure background mean stdev", NAN);462 psMetadataAddStr(normalizedexpArgs, PS_LIST_TAIL, "-path_base", 0, "define base output location", NULL);463 449 psMetadataAddU64(normalizedexpArgs, PS_LIST_TAIL, "-limit", 0, "limit result set to N items", 0); 464 450 psMetadataAddBool(normalizedexpArgs, PS_LIST_TAIL, "-faulted", 0, "only return imfiles with a fault status set", false); … … 475 461 psMetadataAddU64(toresidimfileArgs, PS_LIST_TAIL, "-limit", 0, "limit result set to N items", 0); 476 462 psMetadataAddBool(toresidimfileArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false); 477 478 // -toresidexp479 psMetadata *toresidexpArgs = psMetadataAlloc();480 psMetadataAddU64(toresidexpArgs, PS_LIST_TAIL, "-limit", 0, "limit result set to N items", 0);481 psMetadataAddBool(toresidexpArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false);482 463 483 464 // -addresidimfile … … 487 468 psMetadataAddStr(addresidimfileArgs, PS_LIST_TAIL, "-exp_id", 0, "define detrend ID (required)", NULL); 488 469 psMetadataAddStr(addresidimfileArgs, PS_LIST_TAIL, "-class_id", 0, "define class ID (required)", NULL); 470 psMetadataAddS16(addresidimfileArgs, PS_LIST_TAIL, "-code", 0, "set fault code", 0); 489 471 psMetadataAddStr(addresidimfileArgs, PS_LIST_TAIL, "-uri", 0, "define resid file URI", NULL); 490 472 psMetadataAddStr(addresidimfileArgs, PS_LIST_TAIL, "-recip", 0, "define recipe", NULL); … … 507 489 psMetadataAddF64(addresidimfileArgs, PS_LIST_TAIL, "-user_5", 0, "define user statistic (5)", NAN); 508 490 psMetadataAddStr(addresidimfileArgs, PS_LIST_TAIL, "-path_base", 0, "define base output location", NULL); 509 psMetadataAddS16(addresidimfileArgs, PS_LIST_TAIL, "-code", 0, "set fault code", 0);510 491 511 492 // -residimfile … … 513 494 psMetadataAddStr(residimfileArgs, PS_LIST_TAIL, "-det_id", 0, "search for detrend ID", NULL); 514 495 psMetadataAddS32(residimfileArgs, PS_LIST_TAIL, "-iteration", 0, "search for iteration number", 0); 515 psMetadataAddStr(residimfileArgs, PS_LIST_TAIL, "-exp_id", 0, " definedetrend ID", NULL);496 psMetadataAddStr(residimfileArgs, PS_LIST_TAIL, "-exp_id", 0, "search by detrend ID", NULL); 516 497 psMetadataAddStr(residimfileArgs, PS_LIST_TAIL, "-class_id", 0, "search for class ID", NULL); 517 498 psMetadataAddStr(residimfileArgs, PS_LIST_TAIL, "-recip", 0, "search for recipe", NULL); … … 523 504 // -revertresidimfile 524 505 psMetadata *revertresidimfileArgs = psMetadataAlloc(); 525 psMetadataAddStr(revertresidimfileArgs, PS_LIST_TAIL, "-det_id", 0, "search by detrend ID (required)", NULL); 526 psMetadataAddS32(revertresidimfileArgs, PS_LIST_TAIL, "-iteration", 0, "search by iteration number", 0); 527 psMetadataAddStr(revertresidimfileArgs, PS_LIST_TAIL, "-exp_id", 0, "search by detrend ID", NULL); 528 psMetadataAddStr(revertresidimfileArgs, PS_LIST_TAIL, "-class_id", 0, "search for class ID", NULL); 529 psMetadataAddS16(revertresidimfileArgs, PS_LIST_TAIL, "-code", 0, "search by fault code", 0); 506 psMetadataAddStr(revertresidimfileArgs, PS_LIST_TAIL, "-det_id", 0, "search by detrend ID (required)", NULL); 507 psMetadataAddS32(revertresidimfileArgs, PS_LIST_TAIL, "-iteration", 0, "search by iteration number", 0); 508 psMetadataAddStr(revertresidimfileArgs, PS_LIST_TAIL, "-exp_id", 0, "search by detrend ID", NULL); 509 psMetadataAddStr(revertresidimfileArgs, PS_LIST_TAIL, "-class_id", 0, "search for class ID", NULL); 510 psMetadataAddS16(revertresidimfileArgs, PS_LIST_TAIL, "-code", 0, "search by fault code", 0); 511 512 // -toresidexp 513 psMetadata *toresidexpArgs = psMetadataAlloc(); 514 psMetadataAddU64(toresidexpArgs, PS_LIST_TAIL, "-limit", 0, "limit result set to N items", 0); 515 psMetadataAddBool(toresidexpArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false); 530 516 531 517 // -addresidexp … … 534 520 psMetadataAddS32(addresidexpArgs, PS_LIST_TAIL, "-iteration", 0, "define iteration number", 0); 535 521 psMetadataAddStr(addresidexpArgs, PS_LIST_TAIL, "-exp_id", 0, "define detrend ID (required)", NULL); 522 psMetadataAddS16(addresidexpArgs, PS_LIST_TAIL, "-code", 0, "set fault code", 0); 536 523 psMetadataAddStr(addresidexpArgs, PS_LIST_TAIL, "-recip", 0, "define recipe", NULL); 537 524 psMetadataAddF64(addresidexpArgs, PS_LIST_TAIL, "-bg", 0, "define exposure background", NAN); … … 553 540 psMetadataAddF64(addresidexpArgs, PS_LIST_TAIL, "-user_5", 0, "define user statistic (5)", NAN); 554 541 psMetadataAddStr(addresidexpArgs, PS_LIST_TAIL, "-path_base", 0, "define base output location", NULL); 555 psMetadataAddS16(addresidexpArgs, PS_LIST_TAIL, "-code", 0, "set fault code", 0);556 542 psMetadataAddBool(addresidexpArgs, PS_LIST_TAIL, "-reject", 0, "exposure is not to be stacked in the next iteration", false); 557 543 … … 562 548 psMetadataAddStr(residexpArgs, PS_LIST_TAIL, "-exp_id", 0, "search for exp ID", NULL); 563 549 psMetadataAddStr(residexpArgs, PS_LIST_TAIL, "-recip", 0, "search for recipe", NULL); 550 psMetadataAddBool(residexpArgs, PS_LIST_TAIL, "-reject", 0, "search for acceptable residuals", false); 564 551 psMetadataAddU64(residexpArgs, PS_LIST_TAIL, "-limit", 0, "limit result set to N items", 0); 565 552 psMetadataAddBool(residexpArgs, PS_LIST_TAIL, "-faulted", 0, "only return imfiles with a fault status set", false); 566 psMetadataAddBool(residexpArgs, PS_LIST_TAIL, "-reject", 0, "search for acceptable residuals", false);567 553 psMetadataAddBool(residexpArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false); 568 554 … … 573 559 psMetadataAddStr(revertresidexpArgs, PS_LIST_TAIL, "-exp_id", 0, "search by detrend ID", NULL); 574 560 psMetadataAddS16(revertresidexpArgs, PS_LIST_TAIL, "-code", 0, "search by fault code", 0); 575 576 // -todetrunsummary577 psMetadata *todetrunsummaryArgs = psMetadataAlloc();578 psMetadataAddBool(todetrunsummaryArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false);579 psMetadataAddU64(todetrunsummaryArgs, PS_LIST_TAIL, "-limit", 0, "limit result set to N items", 0);580 561 581 562 // -updateresidexp … … 591 572 psMetadataAddBool(updateresidexpArgs, PS_LIST_TAIL, "-reject", 0, "exposure is not to be stacked in the next iteration", false); 592 573 574 // -todetrunsummary 575 psMetadata *todetrunsummaryArgs = psMetadataAlloc(); 576 psMetadataAddBool(todetrunsummaryArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false); 577 psMetadataAddU64(todetrunsummaryArgs, PS_LIST_TAIL, "-limit", 0, "limit result set to N items", 0); 578 593 579 // -adddetrunsummary 594 580 psMetadata *adddetrunsummaryArgs = psMetadataAlloc(); … … 605 591 psMetadata *detrunsummaryArgs = psMetadataAlloc(); 606 592 psMetadataAddStr(detrunsummaryArgs, PS_LIST_TAIL, "-det_id", 0, "search for detrend ID", NULL); 593 psMetadataAddS32(detrunsummaryArgs, PS_LIST_TAIL, "-iteration", 0, "search for iteration number", 0); 607 594 psMetadataAddU64(detrunsummaryArgs, PS_LIST_TAIL, "-limit", 0, "limit result set to N items", 0); 608 psMetadataAddS32(detrunsummaryArgs, PS_LIST_TAIL, "-iteration", 0, "search for iteration number", 0);609 595 psMetadataAddBool(detrunsummaryArgs, PS_LIST_TAIL, "-faulted", 0, "only return imfiles with a fault status set", false); 596 psMetadataAddBool(detrunsummaryArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false); 610 597 psMetadataAddBool(detrunsummaryArgs, PS_LIST_TAIL, "-reject", 0, "search for acceptable residuals", false); 611 psMetadataAddBool(detrunsummaryArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false);612 598 613 599 // -revertdetrunsummary … … 637 623 psMetadata *register_detrendArgs = psMetadataAlloc(); 638 624 psMetadataAddStr(register_detrendArgs, PS_LIST_TAIL, "-det_type", 0, "define the type of detrend run (required)", NULL); 639 psMetadataAddStr(register_detrendArgs, PS_LIST_TAIL, "-mode", 0, "define the mode of this detrend run", "master");640 625 psMetadataAddStr(register_detrendArgs, PS_LIST_TAIL, "-filelevel", 0, "define filelevel (required)", NULL); 641 626 psMetadataAddStr(register_detrendArgs, PS_LIST_TAIL, "-workdir", 0, "define workdir", NULL); … … 648 633 psMetadataAddF32(register_detrendArgs, PS_LIST_TAIL, "-exp_time_min", 0, "define min exposure time", NAN); 649 634 psMetadataAddF32(register_detrendArgs, PS_LIST_TAIL, "-exp_time_max", 0, "define max exposure time", NAN); 650 psMetadataAddF 64(register_detrendArgs, PS_LIST_TAIL, "-ccd_temp_min", 0, "define min ccd tempature", NAN);651 psMetadataAddF 64(register_detrendArgs, PS_LIST_TAIL, "-ccd_temp_max", 0, "define max ccd tempature", NAN);635 psMetadataAddF32(register_detrendArgs, PS_LIST_TAIL, "-ccd_temp_min", 0, "define min ccd tempature", NAN); 636 psMetadataAddF32(register_detrendArgs, PS_LIST_TAIL, "-ccd_temp_max", 0, "define max ccd tempature", NAN); 652 637 psMetadataAddF64(register_detrendArgs, PS_LIST_TAIL, "-posang_min", 0, "define min rotator position angle", NAN); 653 638 psMetadataAddF64(register_detrendArgs, PS_LIST_TAIL, "-posang_max", 0, "define max rotator position angle", NAN); … … 750 735 psFree(modes); 751 736 752 // generate SQL where clause753 config->where = psMetadataAlloc();754 755 addWhereStr(det_id);756 PXOPT_ADD_WHERE_S32(iteration);757 PXOPT_ADD_WHERE_STR(det_type);758 PXOPT_ADD_WHERE_STR(exp_id);759 PXOPT_ADD_WHERE_STR(class_id);760 PXOPT_ADD_WHERE_STR_ALIAS("-inst","camera");761 PXOPT_ADD_WHERE_STR(telescope);762 PXOPT_ADD_WHERE_STR(exp_type);763 PXOPT_ADD_WHERE_S32(imfiles);764 PXOPT_ADD_WHERE_STR(filter);765 PXOPT_ADD_WHERE_STR(recipe);766 PXOPT_ADD_WHERE_S32(guide_version);767 PXOPT_ADD_WHERE_BOOL_ALIAS_INVERT("-reject", "accept");768 PXOPT_ADD_WHERE_S16_ALIAS("-code", "fault");769 770 if (config->where->list->n < 1) {771 psFree(config->where);772 config->where = NULL;773 }774 775 737 // define Database handle, if used 776 738 // do this last so we don't setup a connection before CLI options are -
branches/eam_branch_20080706/ippTools/src/dettool_correction.c
r18336 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 … … 37 24 PS_ASSERT_PTR_NON_NULL(config, false); 38 25 39 bool status = false; 40 psString det_id = psMetadataLookupStr(&status, config->args, "-det_id"); 41 if (!status) { 42 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -det_id"); 43 return false; 44 } 45 if (!det_id) { 46 psError(PS_ERR_UNKNOWN, true, "-det_id is required"); 47 return false; 48 } 49 50 psArray *runs = detRunSelectRowObjects(config->dbh, config->where, 1); 26 PXOPT_LOOKUP_STR(det_id, config->args, "-det_id", true, false); // required 27 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); // optional 28 29 // build the needed where 30 psMetadata *where = psMetadataAlloc(); 31 psMetadataAddS64(where, PS_LIST_TAIL, "det_id", 0, "==", (psS64)atoll(det_id)); 32 psArray *runs = detRunSelectRowObjects(config->dbh, where, 1); 33 psFree (where); 34 51 35 if (!psArrayLength(runs)) { 52 36 psError(PS_ERR_UNKNOWN, false, "database error"); … … 103 87 } 104 88 105 psArray *detRuns = NULL; 106 { 107 psMetadata *where = psMetadataAlloc(); 108 psMetadataAddS64(where, PS_LIST_TAIL, "det_id", 0, "==", new_det_id); 109 detRuns = psDBSelectRows(config->dbh, "detRun", where, 0); 110 psFree(where); 111 } 89 psMetadata *where_new = psMetadataAlloc(); 90 psMetadataAddS64(where, PS_LIST_TAIL, "det_id", 0, "==", new_det_id); 91 psArray *detRuns = psDBSelectRows(config->dbh, "detRun", where_new, 0); 92 psFree(where_new); 93 112 94 if (!detRuns) { 113 95 psError(PS_ERR_UNKNOWN, false, "can't find the detRun we just created"); … … 118 100 psAbort("found more then one detRun matching det_id %" PRId64 "(this should not happen)", new_det_id); 119 101 return false; 120 }121 122 bool simple = false;123 {124 bool status = false;125 simple = psMetadataLookupBool(&status, config->args, "-simple");126 if (!status) {127 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");128 return false;129 }130 102 } 131 103 … … 145 117 PS_ASSERT_PTR_NON_NULL(config, false); 146 118 147 bool status = false; 148 psU64 limit = psMetadataLookupU64(&status, config->args, "-limit"); 149 if (!status) { 150 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit"); 151 return false; 152 } 119 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 120 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 153 121 154 122 psString query = pxDataGet("dettool_tocorrectexp.sql"); … … 183 151 } 184 152 185 bool simple = false;186 {187 bool status = false;188 simple = psMetadataLookupBool(&status, config->args, "-simple");189 if (!status) {190 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");191 return false;192 }193 }194 195 153 // negative simple so the default is true 196 154 if (!ippdbPrintMetadatas(stdout, output, "detRun", !simple)) { … … 209 167 PS_ASSERT_PTR_NON_NULL(config, false); 210 168 211 bool status = false; 212 psU64 limit = psMetadataLookupU64(&status, config->args, "-limit"); 213 if (!status) { 214 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit"); 215 return false; 216 } 169 psMetadata *where = psMetadataAlloc(); 170 PXOPT_COPY_STR(config->args, where, "-det_type", "det_type", "=="); 171 172 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 173 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 217 174 218 175 psString query = pxDataGet("dettool_tocorrectimfile.sql"); … … 222 179 } 223 180 224 if (config->where) { 225 psString whereClause = psDBGenerateWhereConditionSQL(config->where, "det1"); 181 if (psListLength(where->list)) { 182 // NOTE the SQL uses an intermediate table 'det1' for this query 183 psString whereClause = psDBGenerateWhereConditionSQL(where, "det1"); 226 184 psStringAppend(&query, " AND %s", whereClause); 227 185 psFree(whereClause); 228 186 } 187 psFree (where); 229 188 230 189 // treat limit == 0 as "no limit" … … 253 212 } 254 213 255 bool simple = false;256 {257 bool status = false;258 simple = psMetadataLookupBool(&status, config->args, "-simple");259 if (!status) {260 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");261 return false;262 }263 }264 265 214 // negative simple so the default is true 266 215 if (!ippdbPrintMetadatas(stdout, output, "detPendingCorrectImfile", !simple)) { … … 275 224 } 276 225 226 // NOTE : the command-line args are parsed by register_detrend_imfileMode 277 227 bool addcorrectimfileMode(pxConfig *config) 278 228 { -
branches/eam_branch_20080706/ippTools/src/pxtools.h
r18468 r18480 22 22 23 23 #include <stdio.h> 24 #include <string.h> // for strcmp and strncmp 24 25 #include <strings.h> // for strcasecmp 25 26 #include <unistd.h> // for unlink 27 28 // #include <stdlib.h> 29 // #include <stdint.h> 30 // #include <inttypes.h> 31 26 32 #include <pslib.h> 27 33 #include <psmodules.h>
Note:
See TracChangeset
for help on using the changeset viewer.
