Changeset 8498 for trunk/ippTools/src/dettool.c
- Timestamp:
- Aug 22, 2006, 5:26:10 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/ippTools/src/dettool.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/dettool.c
r8489 r8498 48 48 static detResidImfileRow *detNormalizedToDetResidImfile(pxConfig *config, detNormalizedImfileRow *normalizedImfile); 49 49 static detResidExpRow *mdToDetResidExp(pxConfig *config, psMetadata *row); 50 static detRunSummaryRow *mdToDetRunSummary(pxConfig *config, psMetadata *row); 50 51 static psArray *validDetInputClassIds(pxConfig *config, const char *det_id); 51 52 static psArray *searchInputImfiles(pxConfig *config, const char *det_id); … … 3486 3487 { 3487 3488 PS_ASSERT_PTR_NON_NULL(config, false); 3489 3490 // select detRun.position 3491 // select detRun.iteration 3492 // by: 3493 // find the current iteration bassed on det_id 3494 // find all exp_ids in the current det_id/iteration from detInputExp 3495 // find all exp_ids in the current det_id/iteration from detResidExp 3496 // compare the counts of exp_ids 3497 3498 psString query = psStringCopy( 3499 "SELECT DISTINCT" 3500 " det_id," 3501 " iteration" 3502 " FROM" 3503 " (SELECT DISTINCT" 3504 " detRun.position AS det_id," 3505 " detRun.iteration," 3506 " detInputExp.exp_id" 3507 " FROM detRun" 3508 " LEFT JOIN detInputExp" 3509 " ON detRun.position = detInputExp.det_id" 3510 " AND detRun.iteration = detInputExp.iteration" 3511 " LEFT JOIN rawDetrendExp" 3512 " ON detInputExp.exp_id = rawDetrendExp.exp_id" 3513 " LEFT JOIN detResidExp" 3514 " ON detRun.position = detResidExp.det_id" 3515 " AND detRun.iteration = detResidExp.iteration" 3516 " AND detInputExp.exp_id = detResidExp.exp_id" 3517 " GROUP BY" 3518 " detRun.position," 3519 " detRun.iteration" 3520 " HAVING" 3521 " COUNT(detResidExp.exp_id) = COUNT(detInputExp.exp_id)" 3522 " ) AS residdetrun" 3523 ); 3524 3525 { 3526 // build a query to search by det_id, iteration, exp_id 3527 psMetadata *where = psMetadataAlloc(); 3528 bool status = false; 3529 psString det_id = psMetadataLookupStr(&status, config->args, "-det_id"); 3530 if (!status) { 3531 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -det_id"); 3532 psFree(where); 3533 psFree(query); 3534 return false; 3535 } 3536 if (det_id) { 3537 if (!psMetadataAddStr(where, PS_LIST_TAIL, "det_id", 0, "==", det_id)) { 3538 psError(PS_ERR_UNKNOWN, false, "failed to add item det_id"); 3539 psFree(where); 3540 psFree(query); 3541 return false; 3542 } 3543 } 3544 psS32 iteration = psMetadataLookupS32(&status, config->args, "-iteration"); 3545 if (!status) { 3546 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -iteration"); 3547 psFree(where); 3548 psFree(query); 3549 return false; 3550 } 3551 // always set iteration 3552 if (!psMetadataAddS32(where, PS_LIST_TAIL, "iteration", 0, "==", iteration)) { 3553 psError(PS_ERR_UNKNOWN, false, "failed to add item iteration"); 3554 psFree(where); 3555 psFree(query); 3556 return false; 3557 } 3558 3559 // there's not 3560 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 3561 psFree(where); 3562 if (whereClause) { 3563 psStringAppend(&query, " WHERE %s", whereClause); 3564 psFree(whereClause); 3565 } 3566 } 3567 3568 if (!p_psDBRunQuery(config->dbh, query)) { 3569 psError(PS_ERR_UNKNOWN, false, "database error"); 3570 psFree(query); 3571 return false; 3572 } 3573 psFree(query); 3574 3575 psArray *output = p_psDBFetchResult(config->dbh); 3576 if (!output) { 3577 // XXX check psError here 3578 psError(PS_ERR_UNKNOWN, false, "no pending completed detrun iterations found"); 3579 return false; 3580 } 3581 3582 // start a transaction so it's all rows or nothing 3583 if (!psDBTransaction(config->dbh)) { 3584 psError(PS_ERR_UNKNOWN, false, "database error"); 3585 psFree(output); 3586 return false; 3587 } 3588 3589 for (long i = 0; i < psArrayLength(output); i++) { 3590 psMetadata *row = output->data[i]; 3591 // convert metadata into a detResidExp object 3592 detRunSummaryRow *runSummary = mdToDetRunSummary(config, row); 3593 if (!runSummary) { 3594 if (!psDBRollback(config->dbh)) { 3595 psError(PS_ERR_UNKNOWN, false, "database error"); 3596 } 3597 psError(PS_ERR_UNKNOWN, false, "failed to convert metadata to detResidExp"); 3598 psFree(output); 3599 return false; 3600 } 3601 // insert detResidExp object into the database 3602 if (!detRunSummaryInsertObject(config->dbh, runSummary)) { 3603 if (!psDBRollback(config->dbh)) { 3604 psError(PS_ERR_UNKNOWN, false, "database error"); 3605 } 3606 psError(PS_ERR_UNKNOWN, false, "database error"); 3607 psFree(runSummary); 3608 psFree(output); 3609 return false; 3610 } 3611 psFree(runSummary); 3612 } 3613 3614 psFree(output); 3615 3616 if (!psDBCommit(config->dbh)) { 3617 psError(PS_ERR_UNKNOWN, false, "database error"); 3618 return false; 3619 } 3488 3620 return true; 3621 } 3622 3623 static detRunSummaryRow *mdToDetRunSummary(pxConfig *config, psMetadata *row) 3624 { 3625 PS_ASSERT_PTR_NON_NULL(config, false); 3626 3627 bool status = false; 3628 // from row 3629 psS32 det_id = psMetadataLookupS32(&status, row, "det_id"); 3630 if (!status) { 3631 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for det_id"); 3632 return false; 3633 } 3634 psS32 iteration = psMetadataLookupS32(&status, row, "iteration"); 3635 if (!status) { 3636 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for iteration"); 3637 return false; 3638 } 3639 3640 // from config->args 3641 psF64 bg = psMetadataLookupF64(&status, config->args, "-bg"); 3642 if (!status) { 3643 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -bg"); 3644 return NULL; 3645 } 3646 if (isnan(bg)) { 3647 psError(PS_ERR_UNKNOWN, true, "-bg is required"); 3648 return NULL; 3649 } 3650 psF64 bg_stdev = psMetadataLookupF64(&status, config->args, "-bg_stdev"); 3651 if (!status) { 3652 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -bg_stdev"); 3653 return NULL; 3654 } 3655 if (isnan(bg_stdev)) { 3656 psError(PS_ERR_UNKNOWN, true, "-bg_stdev is required"); 3657 return NULL; 3658 } 3659 psF64 bg_mean_stdev = psMetadataLookupF64(&status, config->args, "-bg_mean_stdev"); 3660 if (!status) { 3661 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -bg_mean_stdev"); 3662 return NULL; 3663 } 3664 if (isnan(bg_mean_stdev)) { 3665 psError(PS_ERR_UNKNOWN, true, "-bg_mean_stdev is required"); 3666 return NULL; 3667 } 3668 // optional 3669 bool reject = psMetadataLookupBool(&status, config->args, "-reject"); 3670 if (!status) { 3671 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -reject"); 3672 return NULL; 3673 } 3674 3675 return detRunSummaryRowAlloc( 3676 det_id, 3677 iteration, 3678 bg, 3679 bg_stdev, 3680 bg_mean_stdev, 3681 !reject 3682 ); 3489 3683 } 3490 3684
Note:
See TracChangeset
for help on using the changeset viewer.
