Changeset 28109
- Timestamp:
- May 26, 2010, 11:43:32 AM (16 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/pxtools.c (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/pxtools.c
r28107 r28109 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 86 psS64 *maskfrac_npix, psF32 *maskfrac_static, psF32 *maskfrac_dynamic, 97 psF32 *maskfrac_magic, psF32 *maskfrac_advisory) { 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");95 psError(psErrorCodeLast(), false, "database error"); 105 96 psFree(query); 106 return (false);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 } 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; 114 112 115 113 for (long i = 0; i < psArrayLength(output); i++) { … … 121 119 psF32 this_magic = psMetadataLookupF32(NULL, row, "maskfrac_magic"); 122 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 123 133 psString this_version = psMetadataLookupStr(NULL, row, "software_ver"); 124 125 psTrace("pxtools", 3, "Mask stats: %d %f %f %f %f %s\n",126 this_npix, this_static, this_dynamic, this_magic, this_advisory, this_version);127 128 134 *software_ver = pxMergeCodeVersions(*software_ver,this_version); 129 /* printf("%ld : %d %f %f %f %f <-> %ld %f %f %f %f\n",i,this_npix,this_static,this_dynamic,this_magic,this_advisory, */ 130 /* *maskfrac_npix,*maskfrac_static,*maskfrac_dynamic,*maskfrac_magic,*maskfrac_advisory); */ 131 if (this_npix > 0) { 132 *maskfrac_static = ((*maskfrac_static * *maskfrac_npix) + (this_npix * this_static)) / (this_npix + *maskfrac_npix); 133 *maskfrac_dynamic = ((*maskfrac_dynamic * *maskfrac_npix) + (this_npix * this_dynamic)) / (this_npix + *maskfrac_npix); 134 *maskfrac_magic = ((*maskfrac_magic * *maskfrac_npix) + (this_npix * this_magic)) / (this_npix + *maskfrac_npix); 135 *maskfrac_advisory = ((*maskfrac_advisory * *maskfrac_npix) + (this_npix * this_advisory)) / (this_npix + *maskfrac_npix); 136 *maskfrac_npix += this_npix; 137 } 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; 138 141 } 139 142 psFree(output); 140 return(true); 141 } 142 143 bool pxSetRunSoftware(pxConfig *config, const psString tableName, const psString stage_id_name, const psS64 stage_id, 144 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 { 145 157 char *query = "UPDATE %s SET software_ver = '%s' WHERE %s = %" PRId64; 146 /* printf(query,tableName,software_ver,stage_id_name,stage_id); */ 147 if (!p_psDBRunQueryF(config->dbh,query,tableName,software_ver,stage_id_name,stage_id)) { 148 psError(PS_ERR_UNKNOWN, false, 149 "failed to set software version for %s %" PRId64,stage_id_name,stage_id); 150 return(false); 151 } 152 153 return(true); 154 } 155 156 bool pxSetRunMaskfrac(pxConfig *config, const psString tableName, const psString stage_id_name, const psS64 stage_id, 157 psS64 maskfrac_npix, psF32 maskfrac_static, psF32 maskfrac_dynamic, 158 psF32 maskfrac_magic, psF32 maskfrac_advisory) { 159 char *query = "UPDATE %s SET maskfrac_npix = %f, maskfrac_static = %f, maskfrac_dynamic = %f, maskfrac_magic = %f, maskfrac_advisory = %f WHERE %s = %" PRId64; 160 if (!p_psDBRunQueryF(config->dbh,query,tableName,(float) maskfrac_npix,maskfrac_static, 161 maskfrac_dynamic, maskfrac_magic,maskfrac_advisory,stage_id_name,stage_id)) { 162 psError(PS_ERR_UNKNOWN, 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, 163 176 "failed to set maskfrac stats for %s %" PRId64,stage_id_name,stage_id); 164 return(false); 165 } 166 167 168 169 return(true); 170 } 171 172 bool pxCamSetRunMaskfrac(pxConfig *config, const psString tableName, const psString stage_id_name, const psS64 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, 173 187 psS64 maskfrac_ref_npix, psF32 maskfrac_ref_static, psF32 maskfrac_ref_dynamic, 174 188 psF32 maskfrac_ref_magic, psF32 maskfrac_ref_advisory, 175 189 psS64 maskfrac_max_npix, psF32 maskfrac_max_static, psF32 maskfrac_max_dynamic, 176 190 psF32 maskfrac_max_magic, psF32 maskfrac_max_advisory) { 177 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; 178 if (!p_psDBRunQueryF(config->dbh,query,tableName,(float) maskfrac_ref_npix,maskfrac_ref_static, 179 maskfrac_ref_dynamic, maskfrac_ref_magic,maskfrac_ref_advisory, 180 (float) maskfrac_max_npix,maskfrac_max_static, 181 maskfrac_max_dynamic, maskfrac_max_magic,maskfrac_max_advisory, 182 stage_id_name,stage_id)) { 183 psError(PS_ERR_UNKNOWN, false, 184 "failed to set maskfrac stats for %s %" PRId64,stage_id_name,stage_id); 185 return(false); 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; 186 202 } 187 203 188 189 190 return(true); 204 return true; 191 205 } 192 206 … … 225 239 psMetadataItem *item = psMetadataLookup(config->args, name); 226 240 if (!item) { 227 psError( PS_ERR_UNKNOWN, false, "failed to lookup value for %s", name);241 psError(psErrorCodeLast(), false, "failed to lookup value for %s", name); 228 242 return false; 229 243 } … … 242 256 item->comment = psStringCopy (op); 243 257 if (!psMetadataAddItem(where, item, PS_LIST_TAIL, PS_META_DUPLICATE_OK)) { 244 psError( PS_ERR_UNKNOWN, false, "failed to add item %s", field);258 psError(psErrorCodeLast(), false, "failed to add item %s", field); 245 259 psFree(where); 246 260 return false; … … 334 348 335 349 if (!p_psDBRunQueryF(config->dbh, *pQuery, joinHook)) { 336 psError( PS_ERR_UNKNOWN, false, "database error");350 psError(psErrorCodeLast(), false, "database error"); 337 351 return false; 338 352 } … … 346 360 347 361 if (!p_psDBRunQuery(config->dbh, query)) { 348 psError( PS_ERR_UNKNOWN, false, "database error");362 psError(psErrorCodeLast(), false, "database error"); 349 363 return false; 350 364 } … … 352 366 psArray *output = p_psDBFetchResult(config->dbh); 353 367 if (!output) { 354 psError( PS_ERR_UNKNOWN, false, "database error");368 psError(psErrorCodeLast(), false, "database error"); 355 369 return false; 356 370 } 357 371 if (!psArrayLength(output)) { 358 372 psFree(output); 359 psError(P S_ERR_UNKNOWN, true, "no rows in dbversion");373 psError(PXTOOLS_ERR_PROG, true, "no rows in dbversion"); 360 374 return false; 361 375 } 362 376 if (psArrayLength(output) > 1) { 363 psError(P S_ERR_UNKNOWN, true, "unexpected number of rows found in dbversion: %ld",377 psError(PXTOOLS_ERR_PROG, true, "unexpected number of rows found in dbversion: %ld", 364 378 psArrayLength(output)); 365 379 return false; … … 376 390 psArray *array = NULL; 377 391 if (!pxLookupVersion(config, &array)) { 378 psError( PS_ERR_UNKNOWN, false, "pxLookupVersion failed");392 psError(psErrorCodeLast(), false, "pxLookupVersion failed"); 379 393 return NULL; 380 394 } 381 395 psMetadata *md = array->data[0]; 382 396 if (!md) { 383 psError(P S_ERR_UNKNOWN, true, "output of pxLookupVersion is null");397 psError(PXTOOLS_ERR_PROG, true, "output of pxLookupVersion is null"); 384 398 return NULL; 385 399 } … … 397 411 psArray *array = NULL; 398 412 if (!pxLookupVersion(config, &array) || !array) { 399 psError( PS_ERR_UNKNOWN, false, "pxLookupVersion failed");413 psError(psErrorCodeLast(), false, "pxLookupVersion failed"); 400 414 return false; 401 415 } 402 416 if (!ippdbPrintMetadatas(file, array, "dbversion", true)) { 403 psError( PS_ERR_UNKNOWN, false, "failed to print array");417 psError(psErrorCodeLast(), false, "failed to print array"); 404 418 psFree(array); 405 419 return false; … … 417 431 psMetadataItem *multi_item = psMetadataLookup(input, "dbversion"); 418 432 if (!multi_item || (multi_item->type != PS_DATA_METADATA_MULTI)) { 419 psError(P S_ERR_UNKNOWN, true, "dbversion multi not found in input");433 psError(PXTOOLS_ERR_PROG, true, "dbversion multi not found in input"); 420 434 return false; 421 435 } … … 423 437 psMetadataItem *dbversion = psListGet(multi_item->data.list, 0); 424 438 if (!dbversion) { 425 psError(P S_ERR_UNKNOWN, true, "dbversion not found in input");439 psError(PXTOOLS_ERR_PROG, true, "dbversion not found in input"); 426 440 return false; 427 441 } … … 432 446 psString schema_version = pxGetDBVersion(config); 433 447 if (!schema_version) { 434 psError( PS_ERR_UNKNOWN, false, "pxGetDBVersion failed");448 psError(psErrorCodeLast(), false, "pxGetDBVersion failed"); 435 449 return false; 436 450 } … … 438 452 psString import_version = psMetadataLookupStr(NULL, md, "schema_version"); 439 453 if (import_version && strcmp(import_version, schema_version)) { 440 psError(P S_ERR_UNKNOWN, true, "input file schema_version: %s does not match data base: %s",454 psError(PXTOOLS_ERR_PROG, true, "input file schema_version: %s does not match data base: %s", 441 455 import_version, schema_version); 442 456 return false; 443 457 } else if (!import_version) { 444 psError(P S_ERR_UNKNOWN, true, "input file schema_version is NULL");458 psError(PXTOOLS_ERR_PROG, true, "input file schema_version is NULL"); 445 459 return false; 446 460 } else { … … 448 462 } 449 463 } else { 450 psError(P S_ERR_UNKNOWN, true, "Unexpected config dump format");451 return false; 452 } 453 454 return true; 455 } 464 psError(PXTOOLS_ERR_PROG, true, "Unexpected config dump format"); 465 return false; 466 } 467 468 return true; 469 }
Note:
See TracChangeset
for help on using the changeset viewer.
