Changeset 15583 for trunk/ippTools/src/flatcorr.c
- Timestamp:
- Nov 9, 2007, 5:58:52 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/flatcorr.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/flatcorr.c
r15578 r15583 79 79 } 80 80 81 82 #define ADDRENAMEPARAMSTR(from, to, oldname, newname, comment) \ 83 { \ 84 bool status = false; \ 85 psString str = psMetadataLookupStr(&status, from, "-" oldname); \ 86 if (!status) { \ 87 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -" oldname); \ 88 return false; \ 89 } \ 90 if (str) { \ 91 if (!psMetadataAddStr(to, PS_LIST_TAIL, newname, PS_META_DUPLICATE_OK, comment, str)) { \ 92 psError(PS_ERR_UNKNOWN, false, "failed to add item " newname); \ 93 psFree(to); \ 94 return false; \ 95 } \ 96 } \ 97 } 98 99 #define ADDPARAMSTR(from, to, name) \ 100 ADDRENAMEPARAMSTR(from, to, name, name, "==") 101 102 #define ADDRENAMEPARAMF(from, to, type, oldname, newname, comment) \ 103 { \ 104 bool status = false; \ 105 ps##type var = psMetadataLookup##type(&status, from, "-" oldname); \ 106 if (!status) { \ 107 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -" oldname); \ 108 return false; \ 109 } \ 110 if (!isnan(var)) { \ 111 if (!psMetadataAdd##type(to, PS_LIST_TAIL, newname, PS_META_DUPLICATE_OK, comment, var)) { \ 112 psError(PS_ERR_UNKNOWN, false, "failed to add item " newname); \ 113 psFree(to); \ 114 return false; \ 115 } \ 116 } \ 117 } 118 119 #define ADDPARAMF(from, to, type, name) \ 120 ADDRENAMEPARAMF(from, to, type, name, name, "==") 121 81 122 static bool newrunMode(pxConfig *config) 82 123 { 83 124 PS_ASSERT_PTR_NON_NULL(config, false); 84 125 126 psMetadata *where = psMetadataAlloc(); 127 // convert exp_id into a psS64 128 { 129 bool status = false; 130 psString var = psMetadataLookupStr(&status, config->args, "-exp_id"); 131 if (!status) { 132 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_id"); 133 return false; 134 } 135 if (var) { 136 if (!psMetadataAddS64(where, PS_LIST_TAIL, "exp_id", 0, "==", (psS64)atoll(var))) { 137 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id"); 138 psFree(where); 139 return false; 140 } 141 } 142 } 143 ADDPARAMSTR(config->args, where, "exp_name"); 144 ADDRENAMEPARAMSTR(config->args, where, "inst", "camera", "=="); 145 ADDPARAMSTR(config->args, where, "telescope"); 146 ADDPARAMSTR(config->args, where, "dateobs_begin"); 147 ADDPARAMSTR(config->args, where, "dateobs_end"); 148 ADDPARAMSTR(config->args, where, "exp_tag"); 149 ADDPARAMSTR(config->args, where, "exp_type"); 150 ADDPARAMSTR(config->args, where, "filelevel"); 151 ADDPARAMSTR(config->args, where, "reduction"); 152 ADDPARAMSTR(config->args, where, "filter"); 153 ADDRENAMEPARAMF(config->args, where, F64, "airmass_min", "airmass", ">="); 154 ADDRENAMEPARAMF(config->args, where, F64, "airmass_max", "airmass", "<"); 155 ADDRENAMEPARAMF(config->args, where, F64, "ra_min", "ra", ">="); 156 ADDRENAMEPARAMF(config->args, where, F64, "ra_max", "ra", "<"); 157 ADDRENAMEPARAMF(config->args, where, F64, "decl_min", "decl", ">="); 158 ADDRENAMEPARAMF(config->args, where, F64, "decl_max", "decl", "<"); 159 ADDRENAMEPARAMF(config->args, where, F32, "exp_time_min", "exp_time", ">="); 160 ADDRENAMEPARAMF(config->args, where, F32, "exp_time_max", "exp_time", "<"); 161 ADDRENAMEPARAMF(config->args, where, F32, "sat_pixel_frac_min", "sat_pixel_frac", ">="); 162 ADDRENAMEPARAMF(config->args, where, F32, "sat_pixel_frac_max", "sat_pixel_frac", "<"); 163 ADDRENAMEPARAMF(config->args, where, F64, "bg_min", "bt", ">="); 164 ADDRENAMEPARAMF(config->args, where, F64, "bg_max", "bt", "<"); 165 ADDRENAMEPARAMF(config->args, where, F64, "bg_stdev_min", "bg_stdev", ">="); 166 ADDRENAMEPARAMF(config->args, where, F64, "bg_stdev_max", "bg_stdev", "<"); 167 ADDRENAMEPARAMF(config->args, where, F64, "bg_mean_stdev_min", "bg_mean_stdev", ">="); 168 ADDRENAMEPARAMF(config->args, where, F64, "bg_mean_stdev_max", "bg_mean_stdev", "<"); 169 ADDRENAMEPARAMF(config->args, where, F64, "alt_min", "alt", ">="); 170 ADDRENAMEPARAMF(config->args, where, F64, "alt_max", "alt", "<"); 171 ADDRENAMEPARAMF(config->args, where, F64, "az_min", "az", ">="); 172 ADDRENAMEPARAMF(config->args, where, F64, "az_max", "az", "<"); 173 ADDRENAMEPARAMF(config->args, where, F32, "ccd_temp_min", "ccd_temp", ">="); 174 ADDRENAMEPARAMF(config->args, where, F32, "ccd_temp_max", "ccd_temp", "<"); 175 ADDRENAMEPARAMF(config->args, where, F64, "posang_min", "posang", ">="); 176 ADDRENAMEPARAMF(config->args, where, F64, "posang_max", "posang", "<"); 177 ADDPARAMSTR(config->args, where, "object"); 178 ADDRENAMEPARAMF(config->args, where, F32, "solang_min", "solang", ">="); 179 ADDRENAMEPARAMF(config->args, where, F32, "solang_max", "solang", "<"); 180 181 if (where->list->n < 1) { 182 psFree(where); 183 where = NULL; 184 } 185 186 bool status = false; 187 psString workdir = psMetadataLookupStr(&status, config->args, "-set_workdir"); 188 if (!status) { 189 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -set_workdir"); 190 return false; 191 } 192 193 psString label = psMetadataLookupStr(&status, config->args, "-set_label"); 194 if (!status) { 195 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -set_label"); 196 return false; 197 } 198 199 psString reduction = psMetadataLookupStr(&status, config->args, "-set_reduction"); 200 if (!status) { 201 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -set_reduction"); 202 return false; 203 } 204 205 psString expgroup = psMetadataLookupStr(&status, config->args, "-set_expgroup"); 206 if (!status) { 207 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -set_expgroup"); 208 return false; 209 } 210 211 psString dvodb = psMetadataLookupStr(&status, config->args, "-set_dvodb"); 212 if (!status) { 213 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -set_dvodb"); 214 return false; 215 } 216 217 // find the exp_id of all the exposures that we want to queue up. 218 psString query = pxDataGet("chiptool_find_rawexp.sql"); 219 if (!query) { 220 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 221 return false; 222 } 223 224 if (where) { 225 psString whereClause = psDBGenerateWhereConditionSQL(where, "rawExp"); 226 psFree(where); 227 psStringAppend(&query, " AND %s", whereClause); 228 psFree(whereClause); 229 } 230 231 if (!p_psDBRunQuery(config->dbh, query)) { 232 psError(PS_ERR_UNKNOWN, false, "database error"); 233 psFree(query); 234 return false; 235 } 236 psFree(query); 237 238 psArray *output = p_psDBFetchResult(config->dbh); 239 if (!output) { 240 psError(PS_ERR_UNKNOWN, false, "database error"); 241 return false; 242 } 243 if (!psArrayLength(output)) { 244 psTrace("chiptool", PS_LOG_INFO, "no rows found"); 245 psFree(output); 246 return true; 247 } 248 249 // start a transaction so we don't end up with an exp without any associted 250 // imfiles 251 if (!psDBTransaction(config->dbh)) { 252 psError(PS_ERR_UNKNOWN, false, "database error"); 253 psFree(output); 254 return false; 255 } 256 257 // create a new flatcorrRun 258 if (!flatcorrRunInsert(config->dbh, 259 0, // corr_id 260 dvodb, 261 "reg", // state 262 workdir, 263 label 264 )) { 265 psError(PS_ERR_UNKNOWN, false, "database error"); 266 return false; 267 } 268 269 // figure out the ID of the flatcorrRun we just created 270 psS64 corr_id = psDBLastInsertID(config->dbh); 271 272 // loop over our list of exp_ids 273 for (long i = 0; i < psArrayLength(output); i++) { 274 psMetadata *md = output->data[i]; 275 276 psS64 exp_id = psMetadataLookupS64(&status, md, "exp_id"); 277 if (!status) { 278 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for exp_id"); 279 psFree(output); 280 return false; 281 } 282 283 // queue the exp 284 psS64 chip_id = pxchipQueueByExpTag(config, exp_id, workdir, label, reduction, expgroup, dvodb); 285 if (!chip_id) { 286 if (!psDBRollback(config->dbh)) { 287 psError(PS_ERR_UNKNOWN, false, "database error"); 288 } 289 psError(PS_ERR_UNKNOWN, false, 290 "failed to trying to queue exp_id: %" PRId64, exp_id); 291 psFree(output); 292 return false; 293 } 294 295 // add a flatcorrExp to the flatcorr Run we just created 296 if (!flatcorrExpInsert(config->dbh, 297 corr_id, 298 chip_id 299 )) { 300 psError(PS_ERR_UNKNOWN, false, "database error"); 301 return false; 302 } 303 304 } 305 psFree(output); 306 307 if (!psDBCommit(config->dbh)) { 308 psError(PS_ERR_UNKNOWN, false, "database error"); 309 return false; 310 } 311 312 return true; 313 } 314 315 static bool pendingMode(pxConfig *config) 316 { 317 PS_ASSERT_PTR_NON_NULL(config, false); 318 85 319 return false; 86 320 } 87 321 88 static bool pendingMode(pxConfig *config)322 static bool updateMode(pxConfig *config) 89 323 { 90 324 PS_ASSERT_PTR_NON_NULL(config, false); … … 92 326 return false; 93 327 } 94 95 static bool updateMode(pxConfig *config)96 {97 PS_ASSERT_PTR_NON_NULL(config, false);98 99 return false;100 }
Note:
See TracChangeset
for help on using the changeset viewer.
