Changeset 8406
- Timestamp:
- Aug 16, 2006, 5:31:39 PM (20 years ago)
- Location:
- trunk/ippTools/src
- Files:
-
- 2 edited
-
dettool.c (modified) (5 diffs)
-
dettoolConfig.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ippTools/src/dettool.c
r8383 r8406 43 43 static detNormalizedStatImfileRow *detStackedToDetNormalizedStatImfile(pxConfig *config, detStackedImfileRow *stackedImfile); 44 44 static detNormalizedImfileRow *detNormalizedStatToDetNormalizedmfile(pxConfig *config, detNormalizedStatImfileRow *statImfile); 45 static detResidImfileRow *detNormalizedToDetResidImfile(pxConfig *config, detNormalizedImfileRow *normalizedImfile); 45 46 static psArray *validDetInputClassIds(pxConfig *config, const char *det_id); 46 47 static psArray *searchInputImfiles(pxConfig *config, const char *det_id); … … 2357 2358 } 2358 2359 2359 static bool toresidexpMode(pxConfig *config)2360 {2361 return true;2362 }2363 2360 2364 2361 static bool normalizedframeMode(pxConfig *config) … … 2449 2446 PS_ASSERT_PTR_NON_NULL(config, false); 2450 2447 2451 // det_id, exp_id, class_id, & recipe are required 2448 // make sure that there is a coresponding entry in detNormalizedImfile 2449 // and the exp_id specified is valid 2450 // select * from detNormalizedImfile 2451 // by det_id, iteration, class_id 2452 // where det_id, iteration, class_id is not in detResidImfile 2453 psString query = psStringCopy( 2454 "SELECT" 2455 " detNormalizedImfile.*" 2456 " FROM detNormalizedImfile" 2457 " LEFT JOIN detInputExp" 2458 " USING(det_id, iteration)" 2459 " LEFT JOIN detResidImfile" 2460 " ON detNormalizedImfile.det_id = detResidImfile.det_id" 2461 " AND detNormalizedImfile.iteration= detResidImfile.iteration" 2462 " AND detInputExp.exp_id = detResidImfile.exp_id" 2463 " AND detNormalizedImfile.class_id = detResidImfile.class_id" 2464 " WHERE" 2465 " detInputExp.exp_id = '%s'" 2466 " AND detResidImfile.det_id IS NULL" 2467 " AND detResidImfile.iteration IS NULL" 2468 " AND detResidImfile.exp_id IS NULL" 2469 " AND detResidImfile.class_id IS NULL" 2470 ); 2471 2472 { 2473 // build a query to search by det_id, iteration, class_id 2474 psMetadata *where = psMetadataAlloc(); 2475 bool status = false; 2476 psString det_id = psMetadataLookupStr(&status, config->args, "-det_id"); 2477 if (!status) { 2478 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -det_id"); 2479 psFree(where); 2480 psFree(query); 2481 return false; 2482 } 2483 if (det_id) { 2484 if (!psMetadataAddStr(where, PS_LIST_TAIL, "det_id", 0, "==", det_id)) { 2485 psError(PS_ERR_UNKNOWN, false, "failed to add item det_id"); 2486 psFree(where); 2487 psFree(query); 2488 return false; 2489 } 2490 } 2491 psS32 iteration = psMetadataLookupS32(&status, config->args, "-iteration"); 2492 if (!status) { 2493 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -iteration"); 2494 psFree(where); 2495 psFree(query); 2496 return false; 2497 } 2498 // always set iteration 2499 if (!psMetadataAddS32(where, PS_LIST_TAIL, "iteration", 0, "==", iteration)) { 2500 psError(PS_ERR_UNKNOWN, false, "failed to add item iteration"); 2501 psFree(where); 2502 psFree(query); 2503 return false; 2504 } 2505 psString class_id = psMetadataLookupStr(&status, config->args, "-class_id"); 2506 if (!status) { 2507 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class_id"); 2508 psFree(where); 2509 psFree(query); 2510 return false; 2511 } 2512 if (class_id) { 2513 if (!psMetadataAddStr(where, PS_LIST_TAIL, "class_id", 0, "==", class_id)) { 2514 psError(PS_ERR_UNKNOWN, false, "failed to add item class_id"); 2515 psFree(where); 2516 psFree(query); 2517 return false; 2518 } 2519 } 2520 2521 // there's not 2522 psString whereClaus = psDBGenerateWhereConditionSQL(where, "detNormalizedImfile"); 2523 psFree(where); 2524 if (whereClaus) { 2525 psStringAppend(&query, " AND %s", whereClaus); 2526 psFree(whereClaus); 2527 } 2528 } 2529 2530 // exp_id is manadatory to cross check that this is a exp_id for this 2531 // detRUn 2452 2532 bool status = false; 2453 psString det_id = psMetadataLookupStr(&status, config->args, "-det_id");2454 if (!status) {2455 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -det_id");2456 return false;2457 }2458 if (!det_id) {2459 psError(PS_ERR_UNKNOWN, true, "-det_id is required");2460 return false;2461 }2462 2533 psString exp_id = psMetadataLookupStr(&status, config->args, "-exp_id"); 2463 2534 if (!status) { 2464 2535 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_id"); 2536 psFree(query); 2465 2537 return false; 2466 2538 } 2467 2539 if (!exp_id) { 2468 2540 psError(PS_ERR_UNKNOWN, true, "-exp_id is required"); 2469 return false; 2470 } 2471 psString class_id = psMetadataLookupStr(&status, config->args, "-class_id"); 2472 if (!status) { 2473 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -class_id"); 2474 return false; 2475 } 2476 if (!class_id) { 2477 psError(PS_ERR_UNKNOWN, true, "-class_id is required"); 2541 psFree(query); 2542 return false; 2543 } 2544 2545 if (!p_psDBRunQuery(config->dbh, query, exp_id)) { 2546 psError(PS_ERR_UNKNOWN, false, "database error"); 2547 psFree(query); 2548 return false; 2549 } 2550 psFree(query); 2551 2552 psArray *output = p_psDBFetchResult(config->dbh); 2553 if (!output) { 2554 // XXX check psError here 2555 psError(PS_ERR_UNKNOWN, false, "no pending detNormalizedImfile rows found"); 2556 return false; 2557 } 2558 2559 // start a transaction so it's all rows or nothing 2560 if (!psDBTransaction(config->dbh)) { 2561 psError(PS_ERR_UNKNOWN, false, "database error"); 2562 psFree(output); 2563 return false; 2564 } 2565 2566 for (long i = 0; i < psArrayLength(output); i++) { 2567 psMetadata *row = output->data[i]; 2568 // convert metadata into a detNormalizedImfile object 2569 detNormalizedImfileRow *normalizedImfile = detNormalizedImfileObjectFromMetadata(row); 2570 // convert detNormalizedImfile object into a detResidImfile 2571 detResidImfileRow *residImfile = detNormalizedToDetResidImfile(config, normalizedImfile); 2572 psFree(normalizedImfile); 2573 if (!residImfile) { 2574 if (!psDBRollback(config->dbh)) { 2575 psError(PS_ERR_UNKNOWN, false, "database error"); 2576 } 2577 psError(PS_ERR_UNKNOWN, false, "failed to convert detNormalizedImfile to detResidImfile"); 2578 psFree(output); 2579 return false; 2580 } 2581 // insert detResidImfile object into the database 2582 if (!detResidImfileInsertObject(config->dbh, residImfile)) { 2583 if (!psDBRollback(config->dbh)) { 2584 psError(PS_ERR_UNKNOWN, false, "database error"); 2585 } 2586 psError(PS_ERR_UNKNOWN, false, "database error"); 2587 psFree(residImfile); 2588 psFree(output); 2589 } 2590 psFree(residImfile); 2591 } 2592 2593 psFree(output); 2594 2595 if (!psDBCommit(config->dbh)) { 2596 psError(PS_ERR_UNKNOWN, false, "database error"); 2597 return false; 2598 } 2599 2600 return true; 2601 } 2602 2603 static detResidImfileRow *detNormalizedToDetResidImfile(pxConfig *config, detNormalizedImfileRow *normalizedImfile) 2604 { 2605 PS_ASSERT_PTR_NON_NULL(config, NULL); 2606 PS_ASSERT_PTR_NON_NULL(normalizedImfile, NULL); 2607 2608 bool status = false; 2609 psString exp_id = psMetadataLookupStr(&status, config->args, "-exp_id"); 2610 if (!status) { 2611 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -exp_id"); 2612 return false; 2613 } 2614 if (!exp_id) { 2615 psError(PS_ERR_UNKNOWN, true, "-exp_id is required"); 2478 2616 return false; 2479 2617 } … … 2508 2646 } 2509 2647 2510 // iteration has a default value2511 psS32 iteration = psMetadataLookupS32(&status, config->args, "-iteration");2512 if (!status) {2513 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -iteration");2514 return false;2515 }2516 2517 // check det_id, exp_id, & class_id against the input rawImfiles2518 2519 // XXX what we really want here is to do a join but psDB doesn't support2520 // that type of operation2521 // we have to generate our own where claus as we want to exclude -stats2522 // from the search2523 psMetadata *where = psMetadataAlloc();2524 if (!psMetadataAddS32(where, PS_LIST_TAIL, "det_id", 0, "==",2525 (psS32)atoi(det_id))) {2526 psError(PS_ERR_UNKNOWN, false, "failed to add item det_id");2527 psFree(where);2528 return false;2529 }2530 if (!psMetadataAddStr(where, PS_LIST_TAIL, "exp_id", 0, "==", exp_id)) {2531 psError(PS_ERR_UNKNOWN, false, "failed to add item exp_id");2532 psFree(where);2533 return false;2534 }2535 2536 psArray *rawImfiles = searchRawImfiles(config, where);2537 psFree(where);2538 if (!rawImfiles) {2539 psError(PS_ERR_UNKNOWN, true,2540 "det_id %s, exp_id %s, class_id %s does not corespond to an input imfile",2541 det_id, exp_id, class_id);2542 return false;2543 }2544 2545 // iterate through rawImfiles looking for a match to our class_id2546 bool found = false;2547 for (long i = 0; i < psArrayLength(rawImfiles); i++) {2548 if (strcmp(class_id,2549 ((rawImfileRow *)rawImfiles->data[i])->class_id) == 0) {2550 found = true;2551 break;2552 }2553 }2554 2555 psFree(rawImfiles);2556 2557 if (!found) {2558 psError(PS_ERR_UNKNOWN, true,2559 "det_id %s, exp_id %s, class_id %s does not corespond to an input imfile",2560 det_id, exp_id, class_id);2561 return false;2562 }2563 2564 2648 // create a new detResidImfileRow and insert it 2565 detResidImfileRow *residImfile = detResidImfileRowAlloc( 2566 (psS32)atol(det_id), 2567 iteration, 2568 exp_id, 2569 class_id, 2570 recipe, 2571 uri, 2572 b1_uri, 2573 b2_uri 2574 ); 2575 2576 if (!detResidImfileInsertObject(config->dbh, residImfile)) { 2577 psError(PS_ERR_UNKNOWN, false, "database error"); 2578 psFree(residImfile); 2579 return false; 2580 } 2581 2582 psFree(residImfile); 2583 2584 return true; 2649 return detResidImfileRowAlloc( 2650 normalizedImfile->det_id, 2651 normalizedImfile->iteration, 2652 exp_id, 2653 normalizedImfile->class_id, 2654 recipe, 2655 uri, 2656 b1_uri, 2657 b2_uri 2658 ); 2585 2659 } 2586 2660 … … 2617 2691 2618 2692 psFree(residImfiles); 2693 2694 return true; 2695 } 2696 2697 static bool toresidexpMode(pxConfig *config) 2698 { 2699 PS_ASSERT_PTR_NON_NULL(config, false); 2700 2701 /* 2702 which returns a list of exposures for which all component class ids 2703 have had residuals created. This list includes the detrend id, 2704 iteration, exposure id, detrend type, and whether the exposure was 2705 included in the stack for this iteration. 2706 */ 2707 2708 2709 // select detRun.position 2710 // select detRun.iteration 2711 // select detRun.det_type 2712 // select detInputExp.exp_id 2713 // select detInputExp.include 2714 // by: 2715 // find the current iteration bassed on det_id 2716 // find all exp_ids in the current det_id/iteration from detInputExp 2717 // compare to detInputExp.imfiles to derResidImfile by class_id 2718 // and: 2719 // detResidImfile.{det_id, iteration, exp_id} is not in detResidExp 2720 2721 psString query = psStringCopy( 2722 "SELECT DISTINCT" 2723 " detRun.position AS det_id," 2724 " detRun.iteration," 2725 " detRun.det_type," 2726 " detInputExp.exp_id," 2727 " detInputExp.include" 2728 " FROM detRun" 2729 " LEFT JOIN detInputExp" 2730 " ON detRun.position = detInputExp.det_id" 2731 " AND detRun.iteration = detInputExp.iteration" 2732 " LEFT JOIN rawDetrendExp" 2733 " ON detInputExp.exp_id = rawDetrendExp.exp_id" 2734 " LEFT JOIN detResidImfile" 2735 " ON detRun.position = detResidImfile.det_id" 2736 " AND detRun.iteration = detResidImfile.iteration" 2737 " AND detInputExp.exp_id = detResidImfile.exp_id" 2738 " LEFT JOIN detResidExp" 2739 " ON detRun.position = detResidExp.det_id" 2740 " AND detRun.iteration = detResidExp.iteration" 2741 " AND detInputExp.exp_id = detResidExp.exp_id" 2742 " GROUP BY" 2743 " detInputExp.exp_id" 2744 " WHERE" 2745 " detResidExp.det_id IS NULL" 2746 " AND detResidExp.iteration IS NULL" 2747 " AND detResidExp.exp_id IS NULL" 2748 " HAVING rawDetrendExp.imfiles = COUNT(detStackedImfile.class_id)" 2749 ); 2750 2751 // XXX does it make sens to accept any search params? 2752 #if 0 2753 if (config->where) { 2754 psString whereClaus = psDBGenerateWhereConditionSQL(config->where); 2755 psStringAppend(&query, " AND %s", whereClaus); 2756 psFree(whereClaus); 2757 } 2758 #endif 2759 2760 if (!p_psDBRunQuery(config->dbh, query)) { 2761 psError(PS_ERR_UNKNOWN, false, "database error"); 2762 psFree(query); 2763 return false; 2764 } 2765 psFree(query); 2766 2767 psArray *output = p_psDBFetchResult(config->dbh); 2768 if (!output) { 2769 // XXX check psError here 2770 psError(PS_ERR_UNKNOWN, false, "no pending rawDetrendExp rows found"); 2771 return false; 2772 } 2773 2774 bool simple = false; 2775 { 2776 bool status = false; 2777 simple = psMetadataLookupBool(&status, config->args, "-simple"); 2778 if (!status) { 2779 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple"); 2780 return false; 2781 } 2782 } 2783 2784 // negative simple so the default is true 2785 if (!ippdbPrintMetadatas(stdout, output, "rawDetrendImfile", !simple)) { 2786 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 2787 psFree(output); 2788 return false; 2789 } 2790 2791 psFree(output); 2619 2792 2620 2793 return true; -
trunk/ippTools/src/dettoolConfig.c
r8382 r8406 249 249 psMetadataAddBool(normalizedArgs, PS_LIST_TAIL, "-simple", 0, 250 250 "use the simple output format", false); 251 252 // -toresidexp 253 psMetadata *toresidexpArgs = psMetadataAlloc(); 254 psMetadataAddBool(toresidexpArgs, PS_LIST_TAIL, "-simple", 0, 255 "use the simple output format", false); 251 256 252 257 // -normalizedframe … … 391 396 PXTOOL_MODE("-toresid", DETTOOL_MODE_TORESID, toresidArgs); 392 397 PXTOOL_MODE("-normalized", DETTOOL_MODE_NORMALIZED, normalizedArgs); 398 PXTOOL_MODE("-toresidexp", DETTOOL_MODE_TORESIDEXP, toresidexpArgs); 393 399 PXTOOL_MODE("-normalizedframe", DETTOOL_MODE_NORMALIZEDFRAME,normalizedframeArgs); 394 400 PXTOOL_MODE("-addresidimfile", DETTOOL_MODE_ADDRESIDIMFILE, addresidimfileArgs); … … 413 419 printf("\nPan-STARRS Detrend Tool\n"); 414 420 printf("Usage: %s <mode> [<options>]\n\n", argv[0]); 415 printf(" <mode> : [-pending|-definebyexp|-definebyquery|-runs|-selectrun|-select|-raw|-addprocessed|-tostack|-processed|-addstacked|-tonormalize|-addnormstat|-normstat|-stacked|-stackedframe|-addnormalizedimfile|-toresid|-normalized|- normalizedframe|-addresidimfile|-residimfile|-addresidexp|-residexp|-declaremasterframe|-masterframe|-master|-rerun]\n\n");421 printf(" <mode> : [-pending|-definebyexp|-definebyquery|-runs|-selectrun|-select|-raw|-addprocessed|-tostack|-processed|-addstacked|-tonormalize|-addnormstat|-normstat|-stacked|-stackedframe|-addnormalizedimfile|-toresid|-normalized|-toresidexp|-normalizedframe|-addresidimfile|-residimfile|-addresidexp|-residexp|-declaremasterframe|-masterframe|-master|-rerun]\n\n"); 416 422 fprintf (stdout, "-pending "); 417 423 psArgumentHelp(pendingArgs); … … 492 498 psArgumentHelp(normalizedArgs); 493 499 psFree(normalizedArgs); 500 501 fprintf (stdout, "-toresidexp"); 502 psArgumentHelp(toresidexpArgs); 503 psFree(toresidexpArgs); 494 504 495 505 fprintf (stdout, "-normalizedframe "); … … 552 562 psFree(toresidArgs); 553 563 psFree(normalizedArgs); 564 psFree(toresidexpArgs); 554 565 psFree(normalizedframeArgs); 555 566 psFree(addresidimfileArgs);
Note:
See TracChangeset
for help on using the changeset viewer.
