Changeset 28304 for branches/czw_branch/20100519/ippTools/src/pxtools.c
- Timestamp:
- Jun 10, 2010, 6:28:51 PM (16 years ago)
- Location:
- branches/czw_branch/20100519
- Files:
-
- 3 edited
-
. (modified) (1 prop)
-
ippTools/src (modified) (1 prop)
-
ippTools/src/pxtools.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/czw_branch/20100519
- Property svn:mergeinfo changed
-
branches/czw_branch/20100519/ippTools/src
- Property svn:ignore
-
old new 38 38 stamp-h1 39 39 warptool 40 40 staticskytool
-
- Property svn:ignore
-
branches/czw_branch/20100519/ippTools/src/pxtools.c
r28164 r28304 48 48 } 49 49 50 psString pxMergeCodeVersions(psString version1, psString version2) { 50 psString pxMergeCodeVersions(psString version1, psString version2) 51 { 52 if (!version1 && !version2) { 53 return NULL; 54 } 55 56 if (!version1) { 57 return psStringCopy(version2); 58 } 59 if (!version2) { 60 return psStringCopy(version1); 61 } 62 63 bool mod1 = false, mod2 = false; // Modified versions? 64 if (strchr(version1, 'M')) { 65 psStringSubstitute(&version1, "M", ""); 66 mod1 = true; 67 } 68 if (strchr(version2, 'M')) { 69 psStringSubstitute(&version2, "M", ""); 70 mod2 = true; 71 } 72 73 int num1 = strtol(version1, NULL, 10); 74 int num2 = strtol(version2, NULL, 10); 75 int numO = PS_MAX(num1, num2); 76 51 77 psString out = NULL; 52 53 bool mod1 = false; 54 bool mod2 = false; 55 56 psS32 num1; 57 psS32 num2; 58 psS32 numO; 59 60 if (!version1) { 61 psStringAppend(&out, "%s", version2); 62 return(out); 63 } 64 if (!version2) { 65 psStringAppend(&out, "%s", version1); 66 return(out); 67 } 68 69 if (strchr(version1,'M')) { 70 psStringSubstitute(&version1,"M",""); 71 mod1 = true; 72 } 73 if (strchr(version2,'M')) { 74 psStringSubstitute(&version2,"M",""); 75 mod2 = true; 76 } 77 78 num1 = strtol(version1,NULL,10); 79 num2 = strtol(version2,NULL,10); 80 81 if (num1 >= num2) { 82 numO = num1; 83 } 84 else { 85 numO = num2; 86 } 87 88 psStringAppend(&out,"%" PRId32,numO); 78 psStringAppend(&out, "%" PRId32, numO); 89 79 if (mod1 || mod2) { 90 psStringAppend(&out,"M");91 } 92 return (out);80 psStringAppend(&out, "M"); 81 } 82 return out; 93 83 } 94 84 95 85 bool pxCoalesceRunStatus(pxConfig *config, const psString dbQFile, psS64 stage_id, psString *software_ver, 96 psS64 *maskfrac_npix, psF32 *maskfrac_static, psF32 *maskfrac_dynamic, 97 psF32 *maskfrac_magic, psF32 *maskfrac_advisory) { 86 psS64 *maskfrac_npix, psF32 *maskfrac_static, psF32 *maskfrac_dynamic, 87 psF32 *maskfrac_magic, psF32 *maskfrac_advisory) 88 { 98 89 psString query = pxDataGet(dbQFile); 99 /* psString text_id = NULL; */ 100 /* psStringAppend(&text_id," %" PRId64,stage_id); */ 101 /* psStringSubstitute(&query,text_id,"@STAGE_ID@"); */ 102 /* psFree(text_id); */ 90 if (!query) { 91 psError(psErrorCodeLast(), false, "Unable to read query"); 92 return false; 93 } 103 94 if (!p_psDBRunQueryF(config->dbh, query, stage_id)) { 104 psError(PS_ERR_UNKNOWN, false, "database error");105 psFree(query);106 return(false);95 psError(psErrorCodeLast(), false, "database error"); 96 psFree(query); 97 return false; 107 98 } 108 99 psFree(query); 100 109 101 psArray *output = p_psDBFetchResult(config->dbh); 110 102 if (!output) { 111 psError(PS_ERR_UNKNOWN, false, "database error"); 112 return(false); 113 } 114 103 psError(psErrorCodeLast(), false, "database error"); 104 return false; 105 } 106 107 *maskfrac_npix = 0; 108 *maskfrac_static = 0.0; 109 *maskfrac_dynamic = 0.0; 110 *maskfrac_magic = 0.0; 111 *maskfrac_advisory = 0.0; 112 115 113 for (long i = 0; i < psArrayLength(output); i++) { 116 psMetadata *row = output->data[i]; 117 118 psS32 this_npix = psMetadataLookupS32(NULL, row, "maskfrac_npix"); 119 psF32 this_static = psMetadataLookupF32(NULL, row, "maskfrac_static"); 120 psF32 this_dynamic = psMetadataLookupF32(NULL, row, "maskfrac_dynamic"); 121 psF32 this_magic = psMetadataLookupF32(NULL, row, "maskfrac_magic"); 122 psF32 this_advisory = psMetadataLookupF32(NULL, row, "maskfrac_advisory"); 123 psString this_version = psMetadataLookupStr(NULL, row, "software_ver"); 124 125 *software_ver = pxMergeCodeVersions(*software_ver,this_version); 126 /* printf("%ld : %d %f %f %f %f <-> %ld %f %f %f %f\n",i,this_npix,this_static,this_dynamic,this_magic,this_advisory, */ 127 /* *maskfrac_npix,*maskfrac_static,*maskfrac_dynamic,*maskfrac_magic,*maskfrac_advisory); */ 128 if (this_npix > 0) { 129 *maskfrac_static = ((*maskfrac_static * *maskfrac_npix) + (this_npix * this_static)) / (this_npix + *maskfrac_npix); 130 *maskfrac_dynamic = ((*maskfrac_dynamic * *maskfrac_npix) + (this_npix * this_dynamic)) / (this_npix + *maskfrac_npix); 131 *maskfrac_magic = ((*maskfrac_magic * *maskfrac_npix) + (this_npix * this_magic)) / (this_npix + *maskfrac_npix); 132 *maskfrac_advisory = ((*maskfrac_advisory * *maskfrac_npix) + (this_npix * this_advisory)) / (this_npix + *maskfrac_npix); 133 *maskfrac_npix += this_npix; 134 } 114 psMetadata *row = output->data[i]; 115 116 psS32 this_npix = psMetadataLookupS32(NULL, row, "maskfrac_npix"); 117 psF32 this_static = psMetadataLookupF32(NULL, row, "maskfrac_static"); 118 psF32 this_dynamic = psMetadataLookupF32(NULL, row, "maskfrac_dynamic"); 119 psF32 this_magic = psMetadataLookupF32(NULL, row, "maskfrac_magic"); 120 psF32 this_advisory = psMetadataLookupF32(NULL, row, "maskfrac_advisory"); 121 122 psTrace("pxtools", 3, "Mask stats: %d %f %f %f %f\n", 123 this_npix, this_static, this_dynamic, this_magic, this_advisory); 124 125 if (this_npix == 0 || this_npix == PS_MAX_S32) { 126 continue; 127 } 128 if (!isfinite(this_static) || !isfinite(this_dynamic) || 129 !isfinite(this_magic) || !isfinite(this_advisory)) { 130 continue; 131 } 132 133 psString this_version = psMetadataLookupStr(NULL, row, "software_ver"); 134 *software_ver = pxMergeCodeVersions(*software_ver,this_version); 135 136 *maskfrac_npix += this_npix; 137 *maskfrac_static += this_npix * this_static; 138 *maskfrac_dynamic += this_npix * this_dynamic; 139 *maskfrac_magic += this_npix * this_magic; 140 *maskfrac_advisory += this_npix * this_advisory; 135 141 } 136 142 psFree(output); 137 return(true); 138 } 139 140 bool pxSetRunSoftware(pxConfig *config, const psString tableName, const psString stage_id_name, const psS64 stage_id, 141 psString software_ver) { 143 144 if (*maskfrac_npix > 0) { 145 *maskfrac_static /= *maskfrac_npix; 146 *maskfrac_dynamic /= *maskfrac_npix; 147 *maskfrac_magic /= *maskfrac_npix; 148 *maskfrac_advisory /= *maskfrac_npix; 149 } 150 151 return true; 152 } 153 154 bool pxSetRunSoftware(pxConfig *config, const psString tableName, const psString stage_id_name, 155 const psS64 stage_id, psString software_ver) 156 { 142 157 char *query = "UPDATE %s SET software_ver = '%s' WHERE %s = %" PRId64; 143 /* printf(query,tableName,software_ver,stage_id_name,stage_id); */ 144 if (!p_psDBRunQueryF(config->dbh,query,tableName,software_ver,stage_id_name,stage_id)) { 145 psError(PS_ERR_UNKNOWN, false, 146 "failed to set software version for %s %" PRId64,stage_id_name,stage_id); 147 return(false); 148 } 149 150 return(true); 151 } 152 153 bool pxSetRunMaskfrac(pxConfig *config, const psString tableName, const psString stage_id_name, const psS64 stage_id, 154 psS64 maskfrac_npix, psF32 maskfrac_static, psF32 maskfrac_dynamic, 155 psF32 maskfrac_magic, psF32 maskfrac_advisory) { 156 char *query = "UPDATE %s SET maskfrac_npix = %f, maskfrac_static = %f, maskfrac_dynamic = %f, maskfrac_magic = %f, maskfrac_advisory = %f WHERE %s = %" PRId64; 157 if (!p_psDBRunQueryF(config->dbh,query,tableName,(float) maskfrac_npix,maskfrac_static, 158 maskfrac_dynamic, maskfrac_magic,maskfrac_advisory,stage_id_name,stage_id)) { 159 psError(PS_ERR_UNKNOWN, false, 160 "failed to set maskfrac stats for %s %" PRId64,stage_id_name,stage_id); 161 return(false); 162 } 163 164 165 166 return(true); 167 } 168 169 bool pxCamSetRunMaskfrac(pxConfig *config, const psString tableName, const psString stage_id_name, const psS64 stage_id, 170 psS64 maskfrac_ref_npix, psF32 maskfrac_ref_static, psF32 maskfrac_ref_dynamic, 171 psF32 maskfrac_ref_magic, psF32 maskfrac_ref_advisory, 172 psS64 maskfrac_max_npix, psF32 maskfrac_max_static, psF32 maskfrac_max_dynamic, 173 psF32 maskfrac_max_magic, psF32 maskfrac_max_advisory) { 174 char *query = "UPDATE %s SET maskfrac_ref_npix = %f, maskfrac_ref_static = %f, maskfrac_ref_dynamic = %f, maskfrac_ref_magic = %f, maskfrac_ref_advisory = %f, maskfrac_max_npix = %f, maskfrac_max_static = %f, maskfrac_max_dynamic = %f, maskfrac_max_magic = %f, maskfrac_max_advisory = %f WHERE %s = %" PRId64; 175 if (!p_psDBRunQueryF(config->dbh,query,tableName,(float) maskfrac_ref_npix,maskfrac_ref_static, 176 maskfrac_ref_dynamic, maskfrac_ref_magic,maskfrac_ref_advisory, 177 (float) maskfrac_max_npix,maskfrac_max_static, 178 maskfrac_max_dynamic, maskfrac_max_magic,maskfrac_max_advisory, 179 stage_id_name,stage_id)) { 180 psError(PS_ERR_UNKNOWN, false, 181 "failed to set maskfrac stats for %s %" PRId64,stage_id_name,stage_id); 182 return(false); 158 if (!p_psDBRunQueryF(config->dbh, query, tableName, software_ver, stage_id_name, stage_id)) { 159 psError(psErrorCodeLast(), false, 160 "failed to set software version for %s %" PRId64, stage_id_name, stage_id); 161 return false; 162 } 163 164 return true; 165 } 166 167 bool pxSetRunMaskfrac(pxConfig *config, const psString tableName, const psString stage_id_name, 168 const psS64 stage_id, psS64 maskfrac_npix, psF32 maskfrac_static, 169 psF32 maskfrac_dynamic, psF32 maskfrac_magic, psF32 maskfrac_advisory) 170 { 171 char *query = "UPDATE %s SET maskfrac_npix = %f, maskfrac_static = %f, maskfrac_dynamic = %f, " 172 "maskfrac_magic = %f, maskfrac_advisory = %f WHERE %s = %" PRId64; 173 if (!p_psDBRunQueryF(config->dbh, query, tableName, (float)maskfrac_npix, maskfrac_static, 174 maskfrac_dynamic, maskfrac_magic, maskfrac_advisory, stage_id_name, stage_id)) { 175 psError(psErrorCodeLast(), false, 176 "failed to set maskfrac stats for %s %" PRId64,stage_id_name,stage_id); 177 return false; 178 } 179 180 181 182 return true; 183 } 184 185 bool pxCamSetRunMaskfrac(pxConfig *config, const psString tableName, 186 const psString stage_id_name, const psS64 stage_id, 187 psS64 maskfrac_ref_npix, psF32 maskfrac_ref_static, psF32 maskfrac_ref_dynamic, 188 psF32 maskfrac_ref_magic, psF32 maskfrac_ref_advisory, 189 psS64 maskfrac_max_npix, psF32 maskfrac_max_static, psF32 maskfrac_max_dynamic, 190 psF32 maskfrac_max_magic, psF32 maskfrac_max_advisory) { 191 char *query = "UPDATE %s SET maskfrac_ref_npix = %f, maskfrac_ref_static = %f, maskfrac_ref_dynamic = %f, " 192 "maskfrac_ref_magic = %f, maskfrac_ref_advisory = %f, maskfrac_max_npix = %f, maskfrac_max_static = %f, " 193 "maskfrac_max_dynamic = %f, maskfrac_max_magic = %f, maskfrac_max_advisory = %f WHERE %s = %" PRId64; 194 if (!p_psDBRunQueryF(config->dbh, query, tableName, (float)maskfrac_ref_npix, maskfrac_ref_static, 195 maskfrac_ref_dynamic, maskfrac_ref_magic, maskfrac_ref_advisory, 196 (float)maskfrac_max_npix, maskfrac_max_static, 197 maskfrac_max_dynamic, maskfrac_max_magic, maskfrac_max_advisory, 198 stage_id_name, stage_id)) { 199 psError(psErrorCodeLast(), false, 200 "failed to set maskfrac stats for %s %" PRId64,stage_id_name,stage_id); 201 return false; 183 202 } 184 185 186 187 return(true); 203 204 return true; 188 205 } 189 206 … … 222 239 psMetadataItem *item = psMetadataLookup(config->args, name); 223 240 if (!item) { 224 psError( PS_ERR_UNKNOWN, false, "failed to lookup value for %s", name);241 psError(psErrorCodeLast(), false, "failed to lookup value for %s", name); 225 242 return false; 226 243 } … … 239 256 item->comment = psStringCopy (op); 240 257 if (!psMetadataAddItem(where, item, PS_LIST_TAIL, PS_META_DUPLICATE_OK)) { 241 psError( PS_ERR_UNKNOWN, false, "failed to add item %s", field);258 psError(psErrorCodeLast(), false, "failed to add item %s", field); 242 259 psFree(where); 243 260 return false; … … 272 289 PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false); 273 290 291 if ((state)&&(!strcmp(state, "update"))) { 292 fprintf(stderr, "'-updaterun -set_state update' is not supported."); 293 if (!strcmp(runTable, "chipRun")) { 294 fprintf(stderr, " Use -setimfiletoupdate.\n"); 295 } else { 296 fprintf(stderr, " Use -setskyfiletoupdate.\n"); 297 } 298 exit(1); 299 } 300 274 301 psString dist_group = NULL; 275 302 if (has_dist_group) { … … 293 320 char *comma = ","; 294 321 295 # define addColumn(_tab, _val) \296 do { \297 if (_val) {\298 psStringAppend(pQuery, "%s %s.%s = '%s'", separator, _tab, #_val, _val); \299 separator = comma;\300 }\322 # define addColumn(_tab, _val) \ 323 do { \ 324 if (_val) { \ 325 psStringAppend(pQuery, "%s %s.%s = '%s'", separator, _tab, #_val, _val); \ 326 separator = comma; \ 327 } \ 301 328 } while (0) 302 329 … … 331 358 332 359 if (!p_psDBRunQueryF(config->dbh, *pQuery, joinHook)) { 333 psError( PS_ERR_UNKNOWN, false, "database error");360 psError(psErrorCodeLast(), false, "database error"); 334 361 return false; 335 362 } … … 343 370 344 371 if (!p_psDBRunQuery(config->dbh, query)) { 345 psError( PS_ERR_UNKNOWN, false, "database error");372 psError(psErrorCodeLast(), false, "database error"); 346 373 return false; 347 374 } … … 349 376 psArray *output = p_psDBFetchResult(config->dbh); 350 377 if (!output) { 351 psError( PS_ERR_UNKNOWN, false, "database error");378 psError(psErrorCodeLast(), false, "database error"); 352 379 return false; 353 380 } 354 381 if (!psArrayLength(output)) { 355 382 psFree(output); 356 psError(P S_ERR_UNKNOWN, true, "no rows in dbversion");383 psError(PXTOOLS_ERR_PROG, true, "no rows in dbversion"); 357 384 return false; 358 385 } 359 386 if (psArrayLength(output) > 1) { 360 psError(P S_ERR_UNKNOWN, true, "unexpected number of rows found in dbversion: %ld",387 psError(PXTOOLS_ERR_PROG, true, "unexpected number of rows found in dbversion: %ld", 361 388 psArrayLength(output)); 362 389 return false; … … 373 400 psArray *array = NULL; 374 401 if (!pxLookupVersion(config, &array)) { 375 psError( PS_ERR_UNKNOWN, false, "pxLookupVersion failed");402 psError(psErrorCodeLast(), false, "pxLookupVersion failed"); 376 403 return NULL; 377 404 } 378 405 psMetadata *md = array->data[0]; 379 406 if (!md) { 380 psError(P S_ERR_UNKNOWN, true, "output of pxLookupVersion is null");407 psError(PXTOOLS_ERR_PROG, true, "output of pxLookupVersion is null"); 381 408 return NULL; 382 409 } … … 394 421 psArray *array = NULL; 395 422 if (!pxLookupVersion(config, &array) || !array) { 396 psError( PS_ERR_UNKNOWN, false, "pxLookupVersion failed");423 psError(psErrorCodeLast(), false, "pxLookupVersion failed"); 397 424 return false; 398 425 } 399 426 if (!ippdbPrintMetadatas(file, array, "dbversion", true)) { 400 psError( PS_ERR_UNKNOWN, false, "failed to print array");427 psError(psErrorCodeLast(), false, "failed to print array"); 401 428 psFree(array); 402 429 return false; … … 414 441 psMetadataItem *multi_item = psMetadataLookup(input, "dbversion"); 415 442 if (!multi_item || (multi_item->type != PS_DATA_METADATA_MULTI)) { 416 psError(P S_ERR_UNKNOWN, true, "dbversion multi not found in input");443 psError(PXTOOLS_ERR_PROG, true, "dbversion multi not found in input"); 417 444 return false; 418 445 } … … 420 447 psMetadataItem *dbversion = psListGet(multi_item->data.list, 0); 421 448 if (!dbversion) { 422 psError(P S_ERR_UNKNOWN, true, "dbversion not found in input");449 psError(PXTOOLS_ERR_PROG, true, "dbversion not found in input"); 423 450 return false; 424 451 } … … 429 456 psString schema_version = pxGetDBVersion(config); 430 457 if (!schema_version) { 431 psError( PS_ERR_UNKNOWN, false, "pxGetDBVersion failed");458 psError(psErrorCodeLast(), false, "pxGetDBVersion failed"); 432 459 return false; 433 460 } … … 435 462 psString import_version = psMetadataLookupStr(NULL, md, "schema_version"); 436 463 if (import_version && strcmp(import_version, schema_version)) { 437 psError(P S_ERR_UNKNOWN, true, "input file schema_version: %s does not match data base: %s",438 import_version, schema_version);464 psError(PXTOOLS_ERR_PROG, true, "input file schema_version: %s does not match data base: %s", 465 import_version, schema_version); 439 466 return false; 440 467 } else if (!import_version) { 441 psError(P S_ERR_UNKNOWN, true, "input file schema_version is NULL");468 psError(PXTOOLS_ERR_PROG, true, "input file schema_version is NULL"); 442 469 return false; 443 470 } else { … … 445 472 } 446 473 } else { 447 psError(P S_ERR_UNKNOWN, true, "Unexpected config dump format");448 return false; 449 } 450 451 return true; 452 } 474 psError(PXTOOLS_ERR_PROG, true, "Unexpected config dump format"); 475 return false; 476 } 477 478 return true; 479 }
Note:
See TracChangeset
for help on using the changeset viewer.
