Changeset 7147 for trunk/ippTools/src/dettool.c
- Timestamp:
- May 18, 2006, 5:05:51 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/dettool.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/dettool.c
r7146 r7147 440 440 PS_ASSERT_PTR_NON_NULL(config, false); 441 441 442 return true; 443 } 442 // find all detStackedImfile for det_id 443 // XXX det_id is requried as a simplification 444 psArray *stackedImfiles = 445 detStackedImfileSelectRowObjects(config->dbh, config->where, 0); 446 if (!stackedImfiles) { 447 psError(PS_ERR_UNKNOWN, false, "no detStackedImfile rows found"); 448 return NULL; 449 } 450 451 // find all class_ids for the det_id's associated detInputExps 452 // find detInputExps in det_id 453 bool status = false; 454 psString det_id = psMetadataLookupStr(&status, config->args, "-det_id"); 455 if (!status) { 456 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -det_id"); 457 psFree(stackedImfiles); 458 return false; 459 } 460 461 psArray *inputExps = NULL; 462 { 463 psMetadata *where = psMetadataAlloc(); 464 if (!psMetadataAddS32(where, PS_LIST_TAIL, "det_id", 0, "==", 465 (psS32)atoi(det_id))) { 466 psError(PS_ERR_UNKNOWN, false, "failed to add item det_id"); 467 psFree(where); 468 psFree(stackedImfiles); 469 return false; 470 } 471 inputExps = detInputExpSelectRowObjects(config->dbh, where, 0); 472 psFree(where); 473 } 474 if (!inputExps) { 475 psError(PS_ERR_UNKNOWN, false, "no detInputExp rows found"); 476 } 477 478 // find rawImfiles associated with detInputExps 479 psArray *rawImfiles = NULL; 480 { 481 psMetadata *where = psMetadataAlloc(); 482 for (long i = 0; i < psArrayLength(inputExps); i++) { 483 if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_id", 0, "==", 484 ((detInputExpRow *)inputExps->data[i])->exp_id)) { 485 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id"); 486 psFree(where); 487 return false; 488 } 489 } 490 rawImfiles = rawImfileSelectRowObjects(config->dbh, where, 0); 491 // XXX this really should be sorted for uniqueness 492 psFree(where); 493 } 494 if (!rawImfiles) { 495 psError(PS_ERR_UNKNOWN, false, "no rawImfile rows found"); 496 } 497 498 psArray *valid_class_ids = NULL; 499 { 500 // All this jumping through hoops is so that we end up with unique 501 // values. PP thinks that making multiple passes through this array and 502 // deleting matched elements would end up being more expensive then a 503 // double sort and stagger scheme. JH thinks it would be cheaper to 504 // just do a unqiue sort and delete. So this is really just a cheap 505 // hack to avoid implimenting a unique sort function but at least it's 506 // stable. 507 psHash *hash = psHashAlloc(psArrayLength(rawImfiles)); 508 for (long i = 0; i < psArrayLength(rawImfiles); i++) { 509 psHashAdd(hash, 510 ((rawImfileRow *)rawImfiles->data[i])->class_id, 511 ((rawImfileRow *)rawImfiles->data[i])->class_id 512 ); 513 } 514 valid_class_ids = psHashToArray(hash); 515 psFree(hash); 516 } 517 psFree(rawImfiles); 518 519 // check class_ids for validity 520 for (long i = 0; i < psArrayLength(stackedImfiles); i++) { 521 bool valid = false; 522 for (long j = 0; j < psArrayLength(valid_class_ids); j++) { 523 if (strcmp(((detStackedImfileRow *)stackedImfiles->data[i])->class_id, 524 (char *)valid_class_ids->data[j]) == 0) { 525 valid = true; 526 if (!psArrayRemove(valid_class_ids, valid_class_ids->data[j])) { 527 psError(PS_ERR_UNKNOWN, false, "psArrayRemove() failed"); 528 psFree(stackedImfiles); 529 psFree(valid_class_ids); 530 return false; 531 } 532 j--; // must update loop index 533 } 534 } 535 if (!valid) { 536 psError(PS_ERR_UNKNOWN, true, 537 "class_id %s does not corespond to on contained in an detInputExp", 538 ((detStackedImfileRow *)stackedImfiles->data[i])->class_id); 539 psFree(stackedImfiles); 540 psFree(valid_class_ids); 541 return false; 542 } 543 } 544 545 // check for residual (unmatched) input imfile class_ids 546 if (psArrayLength(valid_class_ids)) { 547 psError(PS_ERR_UNKNOWN, true, "det_id frame is missing %d class_ids", 548 psArrayLength(valid_class_ids)); 549 psFree(valid_class_ids); 550 return false; 551 } 552 psFree(valid_class_ids); 553 554 // print detStackedImfile if all class_ids are matched 555 psMetadata *output = psMetadataAlloc(); 556 for (long i = 0; i < psArrayLength(stackedImfiles); i++) { 557 psMetadata *md = detStackedImfileMetadataFromObject( 558 stackedImfiles->data[i]); 559 psMetadataAddMetadata( 560 output, PS_LIST_TAIL, "detStackedImfile", PS_META_DUPLICATE_OK, 561 NULL, md 562 ); 563 } 564 565 psString str = psMetadataConfigFormat(output); 566 psFree(output); 567 fprintf(stdout, "%s\n", str); 568 psFree(str); 569 570 return true; 571 }
Note:
See TracChangeset
for help on using the changeset viewer.
