Changeset 8451 for trunk/ippTools/src/dettool.c
- Timestamp:
- Aug 21, 2006, 3:16:45 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/dettool.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/dettool.c
r8420 r8451 44 44 static detNormalizedImfileRow *detNormalizedStatToDetNormalizedmfile(pxConfig *config, detNormalizedStatImfileRow *statImfile); 45 45 static detResidImfileRow *detNormalizedToDetResidImfile(pxConfig *config, detNormalizedImfileRow *normalizedImfile); 46 static detResidExpRow *mdToDetResidExp(pxConfig *config, psMetadata *row); 46 47 static psArray *validDetInputClassIds(pxConfig *config, const char *det_id); 47 48 static psArray *searchInputImfiles(pxConfig *config, const char *det_id); … … 706 707 iteration, 707 708 rawExp->exp_id, 708 true, // use 709 false // accept 709 true // use 710 710 ); 711 711 } … … 2834 2834 { 2835 2835 PS_ASSERT_PTR_NON_NULL(config, false); 2836 2837 /* 2838 which returns a list of exposures for which all component class ids 2839 have had residuals created. This list includes the detrend id, 2840 iteration, exposure id, detrend type, and whether the exposure was 2841 included in the stack for this iteration. 2842 */ 2843 2844 2845 // select detRun.position 2846 // select detRun.iteration 2847 // select detRun.det_type 2848 // select detInputExp.exp_id 2849 // select detInputExp.include 2850 // by: 2851 // find the current iteration bassed on det_id 2852 // find all exp_ids in the current det_id/iteration from detInputExp 2853 // compare to detInputExp.imfiles to derResidImfile by class_id 2854 // and: 2855 // detResidImfile.{det_id, iteration, exp_id} is not in detResidExp 2856 2857 psString query = psStringCopy( 2858 "SELECT DISTINCT" 2859 " det_id," 2860 " iteration," 2861 " exp_id," 2862 " include" 2863 " FROM" 2864 " (SELECT DISTINCT" 2865 " detRun.position AS det_id," 2866 " detRun.iteration," 2867 " detRun.det_type," 2868 " detInputExp.exp_id," 2869 " detInputExp.include," 2870 " rawDetrendExp.imfiles" 2871 " FROM detRun" 2872 " LEFT JOIN detInputExp" 2873 " ON detRun.position = detInputExp.det_id" 2874 " AND detRun.iteration = detInputExp.iteration" 2875 " LEFT JOIN rawDetrendExp" 2876 " ON detInputExp.exp_id = rawDetrendExp.exp_id" 2877 " LEFT JOIN detResidImfile" 2878 " ON detRun.position = detResidImfile.det_id" 2879 " AND detRun.iteration = detResidImfile.iteration" 2880 " AND detInputExp.exp_id = detResidImfile.exp_id" 2881 " LEFT JOIN detResidExp" 2882 " ON detRun.position = detResidExp.det_id" 2883 " AND detRun.iteration = detResidExp.iteration" 2884 " AND detInputExp.exp_id = detResidExp.exp_id" 2885 " WHERE" 2886 " detResidExp.det_id IS NULL" 2887 " AND detResidExp.iteration IS NULL" 2888 " AND detResidExp.exp_id IS NULL" 2889 " GROUP BY" 2890 " detInputExp.exp_id" 2891 " HAVING" 2892 " rawDetrendExp.imfiles = COUNT(detResidImfile.class_id)" 2893 " ) AS toresidexp" 2894 ); 2895 2896 { 2897 // build a query to search by det_id, iteration, exp_id 2898 psMetadata *where = psMetadataAlloc(); 2899 bool status = false; 2900 psString det_id = psMetadataLookupStr(&status, config->args, "-det_id"); 2901 if (!status) { 2902 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -det_id"); 2903 psFree(where); 2904 psFree(query); 2905 return false; 2906 } 2907 if (det_id) { 2908 if (!psMetadataAddStr(where, PS_LIST_TAIL, "det_id", 0, "==", det_id)) { 2909 psError(PS_ERR_UNKNOWN, false, "failed to add item det_id"); 2910 psFree(where); 2911 psFree(query); 2912 return false; 2913 } 2914 } 2915 psS32 iteration = psMetadataLookupS32(&status, config->args, "-iteration"); 2916 if (!status) { 2917 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -iteration"); 2918 psFree(where); 2919 psFree(query); 2920 return false; 2921 } 2922 // always set iteration 2923 if (!psMetadataAddS32(where, PS_LIST_TAIL, "iteration", 0, "==", iteration)) { 2924 psError(PS_ERR_UNKNOWN, false, "failed to add item iteration"); 2925 psFree(where); 2926 psFree(query); 2927 return false; 2928 } 2929 psString exp_id = psMetadataLookupStr(&status, config->args, "-exp_id"); 2930 if (!status) { 2931 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_id"); 2932 psFree(where); 2933 psFree(query); 2934 return false; 2935 } 2936 if (exp_id) { 2937 if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_id", 0, "==", exp_id)) { 2938 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id"); 2939 psFree(where); 2940 psFree(query); 2941 return false; 2942 } 2943 } 2944 2945 // there's not 2946 psString whereClaus = psDBGenerateWhereConditionSQL(where, "detNormalizedImfile"); 2947 psFree(where); 2948 if (whereClaus) { 2949 psStringAppend(&query, " AND %s", whereClaus); 2950 psFree(whereClaus); 2951 } 2952 } 2953 2954 if (!p_psDBRunQuery(config->dbh, query)) { 2955 psError(PS_ERR_UNKNOWN, false, "database error"); 2956 psFree(query); 2957 return false; 2958 } 2959 psFree(query); 2960 2961 psArray *output = p_psDBFetchResult(config->dbh); 2962 if (!output) { 2963 // XXX check psError here 2964 psError(PS_ERR_UNKNOWN, false, "no pending rawDetrendExp rows found"); 2965 return false; 2966 } 2967 2968 // start a transaction so it's all rows or nothing 2969 if (!psDBTransaction(config->dbh)) { 2970 psError(PS_ERR_UNKNOWN, false, "database error"); 2971 psFree(output); 2972 return false; 2973 } 2974 2975 for (long i = 0; i < psArrayLength(output); i++) { 2976 psMetadata *row = output->data[i]; 2977 // convert metadata into a detResidExp object 2978 detResidExpRow *residExp = mdToDetResidExp(config, row); 2979 if (!residExp) { 2980 if (!psDBRollback(config->dbh)) { 2981 psError(PS_ERR_UNKNOWN, false, "database error"); 2982 } 2983 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata to detResidExp"); 2984 psFree(output); 2985 return false; 2986 } 2987 // insert detResidExp object into the database 2988 if (!detResidExpInsertObject(config->dbh, residExp)) { 2989 if (!psDBRollback(config->dbh)) { 2990 psError(PS_ERR_UNKNOWN, false, "database error"); 2991 } 2992 psError(PS_ERR_UNKNOWN, false, "database error"); 2993 psFree(residExp); 2994 psFree(output); 2995 } 2996 psFree(residExp); 2997 } 2998 2999 psFree(output); 3000 3001 if (!psDBCommit(config->dbh)) { 3002 psError(PS_ERR_UNKNOWN, false, "database error"); 3003 return false; 3004 } 3005 3006 return true; 3007 } 3008 3009 static detResidExpRow *mdToDetResidExp(pxConfig *config, psMetadata *row) 3010 { 3011 PS_ASSERT_PTR_NON_NULL(config, NULL); 3012 PS_ASSERT_PTR_NON_NULL(row, NULL); 3013 3014 bool status = false; 3015 // values from row 3016 psS32 det_id = psMetadataLookupS32(&status, row, "det_id"); 3017 if (!status) { 3018 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for det_id"); 3019 return false; 3020 } 3021 if (isnan(det_id)) { 3022 psError(PS_ERR_UNKNOWN, true, "det_id is required"); 3023 return false; 3024 } 3025 psS32 iteration = psMetadataLookupS32(&status, row, "iteration"); 3026 if (!status) { 3027 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for iteration"); 3028 return false; 3029 } 3030 psString exp_id = psMetadataLookupStr(&status, row, "exp_id"); 3031 if (!status) { 3032 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for exp_id"); 3033 return false; 3034 } 3035 if (!exp_id) { 3036 psError(PS_ERR_UNKNOWN, true, "exp_id is required"); 3037 return false; 3038 } 3039 3040 // values from config 3041 psF32 stats = psMetadataLookupF32(&status, config->args, "-stats"); 3042 if (!status) { 3043 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -stats"); 3044 return false; 3045 } 3046 if (isnan(stats)) { 3047 psError(PS_ERR_UNKNOWN, true, "-stats is required"); 3048 return false; 3049 } 3050 // optional 3051 bool reject = psMetadataLookupBool(&status, config->args, "-reject"); 3052 if (!status) { 3053 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -reject"); 3054 return false; 3055 } 3056 psString b1_uri = psMetadataLookupStr(&status, config->args, "-b1_uri"); 3057 if (!status) { 3058 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -b1_uri"); 3059 return false; 3060 } 3061 if (!b1_uri) { 3062 psError(PS_ERR_UNKNOWN, true, "-b1_uri is required"); 3063 return false; 3064 } 3065 psString b2_uri = psMetadataLookupStr(&status, config->args, "-b2_uri"); 3066 if (!status) { 3067 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -b2_uri"); 3068 return false; 3069 } 3070 if (!b2_uri) { 3071 psError(PS_ERR_UNKNOWN, true, "-b2_uri is required"); 3072 return false; 3073 } 3074 3075 // create a new detResidImfileRow and insert it 3076 return detResidExpRowAlloc( 3077 det_id, 3078 iteration, 3079 exp_id, 3080 stats, 3081 !reject, 3082 b1_uri, 3083 b2_uri 3084 ); 3085 } 3086 3087 #if 0 3088 PS_ASSERT_PTR_NON_NULL(config, false); 2836 3089 2837 3090 // det_id, exp_id, & recipe are required 3091 2838 3092 bool status = false; 2839 3093 psString det_id = psMetadataLookupStr(&status, config->args, "-det_id"); … … 2855 3109 return false; 2856 3110 } 2857 psString class_id = psMetadataLookupStr(&status, config->args, "-class_id");2858 if (!status) { 2859 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for - class_id");2860 return false; 2861 } 2862 if (! class_id) {2863 psError(PS_ERR_UNKNOWN, true, "- class_id is required");3111 psString exp_id = psMetadataLookupStr(&status, config->args, "-exp_id"); 3112 if (!status) { 3113 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_id"); 3114 return false; 3115 } 3116 if (!exp_id) { 3117 psError(PS_ERR_UNKNOWN, true, "-exp_id is required"); 2864 3118 return false; 2865 3119 } … … 2935 3189 return true; 2936 3190 } 3191 #endif 2937 3192 2938 3193 static bool residexpMode(pxConfig *config) … … 3226 3481 newIteration, 3227 3482 inputExp->exp_id, 3228 true, // use 3229 true // accept 3483 true // use 3230 3484 ); 3231 3485 psArrayAdd(newInputExps, 0, newInputExp);
Note:
See TracChangeset
for help on using the changeset viewer.
