Changeset 18530
- Timestamp:
- Jul 14, 2008, 8:54:45 PM (18 years ago)
- Location:
- branches/eam_branch_20080706
- Files:
-
- 4 added
- 11 edited
-
ippTools/share/Makefile.am (modified) (1 diff)
-
ippTools/share/magictool_addmask.sql (added)
-
ippTools/share/magictool_inputs.sql (added)
-
ippTools/share/magictool_mask.sql (added)
-
ippTools/share/magictool_toprocess_inputs.sql (modified) (1 diff)
-
ippTools/share/magictool_toprocess_tree.sql (modified) (1 diff)
-
ippTools/share/magictool_totree.sql (added)
-
ippTools/share/pxadmin_create_tables.sql (modified) (1 diff)
-
ippTools/share/stacktool_tosum.sql (modified) (1 diff)
-
ippTools/src/magictool.c (modified) (21 diffs)
-
ippTools/src/magictool.h (modified) (1 diff)
-
ippTools/src/magictoolConfig.c (modified) (5 diffs)
-
ippTools/src/pxwarp.c (modified) (2 diffs)
-
psModules/src/imcombine/pmPSFEnvelope.c (modified) (3 diffs)
-
psModules/src/imcombine/pmStackReject.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branch_20080706/ippTools/share/Makefile.am
r18497 r18530 80 80 magictool_find_unmagiced.sql \ 81 81 magictool_inputskyfile.sql \ 82 magictool_totree.sql \ 82 83 magictool_tomask.sql \ 83 84 magictool_toprocess_inputs.sql \ 84 85 magictool_toprocess_tree.sql \ 85 86 magictool_toskyfilemask.sql \ 87 magictool_inputs.sql \ 88 magictool_addmask.sql \ 89 magictool_mask.sql \ 86 90 pstamptool_addjob_otherjob.sql \ 87 91 pstamptool_addjob_stampjob.sql \ -
branches/eam_branch_20080706/ippTools/share/magictool_toprocess_inputs.sql
r15336 r18530 3 3 -- convert magic_id into a boolean value (1 or 0) 4 4 -- note that the type stays a 64 bit int 5 magicNodeResult.magic_id IS TRUE as done, 6 diffSkyfile.uri 5 magicNodeResult.magic_id IS TRUE as done 7 6 FROM magicTree 8 7 JOIN magicRun -
branches/eam_branch_20080706/ippTools/share/magictool_toprocess_tree.sql
r15272 r18530 3 3 -- convert magic_id into a boolean value (1 or 0) 4 4 -- note that the type stays a 64 bit int 5 magicNodeResult.magic_id IS TRUE as done, 6 magicNodeResult.uri 5 magicNodeResult.magic_id IS TRUE as done 7 6 FROM magicTree 8 7 JOIN magicRun -
branches/eam_branch_20080706/ippTools/share/pxadmin_create_tables.sql
r18029 r18530 719 719 CREATE TABLE diffInputSkyfile (diff_id BIGINT, template TINYINT, stack_id BIGINT, warp_id BIGINT, skycell_id VARCHAR(64), tess_id VARCHAR(64), kind VARCHAR(64), PRIMARY KEY(diff_id, template), KEY(stack_id), KEY(warp_id), KEY(skycell_id), KEY(tess_id), KEY(kind), FOREIGN KEY (diff_id) REFERENCES diffRun(diff_id), FOREIGN KEY (stack_id) REFERENCES stackSumSkyfile(stack_id), FOREIGN KEY (warp_id, skycell_id, tess_id) REFERENCES warpSkyfile(warp_id, skycell_id, tess_id)) ENGINE=innodb DEFAULT CHARSET=latin1; 720 720 CREATE TABLE diffSkyfile (diff_id BIGINT, uri VARCHAR(255), path_base VARCHAR(255), bg DOUBLE, bg_stdev DOUBLE, stamps_num INT, stamps_rms FLOAT, sources INT, dtime_diff FLOAT, hostname VARCHAR(64), good_frac FLOAT, fault SMALLINT, PRIMARY KEY(diff_id), KEY(good_frac), KEY(fault), FOREIGN KEY (diff_id) REFERENCES diffRun(diff_id)) ENGINE=innodb DEFAULT CHARSET=latin1; 721 CREATE TABLE magicRun (magic_id BIGINT AUTO_INCREMENT, state VARCHAR(64), workdir VARCHAR(255), workdir_state VARCHAR(255), label VARCHAR(64), dvodb VARCHAR(255), registered DATETIME, PRIMARY KEY(magic_id), KEY(magic_id), KEY(state), KEY(workdir_state), KEY(label)) ENGINE=innodb DEFAULT CHARSET=latin1; 722 CREATE TABLE magicInputSkyfile (magic_id BIGINT, diff_id BIGINT, node VARCHAR(64), PRIMARY KEY(magic_id, diff_id), FOREIGN KEY (magic_id) REFERENCES magicRun(magic_id), FOREIGN KEY (diff_id) REFERENCES diffRun(diff_id)) ENGINE=innodb DEFAULT CHARSET=latin1; 723 CREATE TABLE magicTree (magic_id BIGINT, node VARCHAR(64), dep VARCHAR(64), KEY(magic_id), KEY(node), KEY(dep), INDEX(magic_id, node), FOREIGN KEY (magic_id) REFERENCES magicRun(magic_id)) ENGINE=innodb DEFAULT CHARSET=latin1; 724 CREATE TABLE magicNodeResult (magic_id BIGINT, node VARCHAR(64), uri VARCHAR(255), PRIMARY KEY(magic_id, node), FOREIGN KEY (magic_id) REFERENCES magicRun(magic_id), FOREIGN KEY (magic_id, node) REFERENCES magicTree(magic_id, node)) ENGINE=innodb DEFAULT CHARSET=latin1; 725 CREATE TABLE magicMask (magic_id BIGINT, uri VARCHAR(255), PRIMARY KEY(magic_id), FOREIGN KEY (magic_id) REFERENCES magicRun(magic_id)) ENGINE=innodb DEFAULT CHARSET=latin1; 726 CREATE TABLE magicSkyfileMask (magic_id BIGINT, diff_id BIGINT, uri VARCHAR(255), PRIMARY KEY(magic_id, diff_id), KEY(uri), FOREIGN KEY (magic_id) REFERENCES magicRun(magic_id), FOREIGN KEY (magic_id, diff_id) REFERENCES magicInputSkyfile(magic_id, diff_id), FOREIGN KEY (magic_id) REFERENCES magicMask(magic_id)) ENGINE=innodb DEFAULT CHARSET=latin1; 721 722 CREATE TABLE magicRun ( 723 magic_id BIGINT AUTO_INCREMENT, 724 state VARCHAR(64), 725 workdir VARCHAR(255), 726 workdir_state VARCHAR(255), 727 label VARCHAR(64), 728 dvodb VARCHAR(255), 729 registered DATETIME, 730 fault SMALLINT, 731 PRIMARY KEY(magic_id), 732 KEY(magic_id), 733 KEY(state), 734 KEY(workdir_state), 735 KEY(label), 736 KEY(fault) 737 ) ENGINE=innodb DEFAULT CHARSET=latin1; 738 739 CREATE TABLE magicInputSkyfile ( 740 magic_id BIGINT, 741 diff_id BIGINT, 742 node VARCHAR(64), 743 PRIMARY KEY(magic_id, diff_id), 744 FOREIGN KEY (magic_id) REFERENCES magicRun(magic_id), 745 FOREIGN KEY (diff_id) REFERENCES diffRun(diff_id) 746 ) ENGINE=innodb DEFAULT CHARSET=latin1; 747 748 CREATE TABLE magicTree ( 749 magic_id BIGINT, 750 node VARCHAR(64), 751 dep VARCHAR(64), 752 KEY(magic_id), 753 KEY(node), 754 KEY(dep), 755 INDEX(magic_id, node), 756 FOREIGN KEY (magic_id) REFERENCES magicRun(magic_id) 757 ) ENGINE=innodb DEFAULT CHARSET=latin1; 758 759 CREATE TABLE magicNodeResult ( 760 magic_id BIGINT, 761 node VARCHAR(64), 762 uri VARCHAR(255), 763 fault SMALLINT, 764 PRIMARY KEY(magic_id, node), 765 FOREIGN KEY (magic_id) REFERENCES magicRun(magic_id), 766 FOREIGN KEY (magic_id, node) REFERENCES magicTree(magic_id, node), 767 KEY(fault) 768 ) ENGINE=innodb DEFAULT CHARSET=latin1; 769 770 CREATE TABLE magicMask ( 771 magic_id BIGINT, 772 uri VARCHAR(255), 773 streaks INT, 774 fault SMALLINT, 775 PRIMARY KEY(magic_id), 776 FOREIGN KEY (magic_id) REFERENCES magicRun(magic_id), 777 KEY(fault) 778 ) ENGINE=innodb DEFAULT CHARSET=latin1; 779 727 780 CREATE TABLE calDB (cal_id BIGINT AUTO_INCREMENT, dvodb VARCHAR(64), state VARCHAR(64), PRIMARY KEY(cal_id), KEY(cal_id)) ENGINE=innodb DEFAULT CHARSET=latin1; 728 781 CREATE TABLE calRun (cal_id BIGINT AUTO_INCREMENT, region VARCHAR(64), last_step VARCHAR(64), state VARCHAR(64), PRIMARY KEY(cal_id), KEY(cal_id), KEY(last_step), FOREIGN KEY (cal_id) REFERENCES calDB(cal_id)) ENGINE=innodb DEFAULT CHARSET=latin1; -
branches/eam_branch_20080706/ippTools/share/stacktool_tosum.sql
r16942 r18530 1 SELECT 1 SELECT DISTINCT 2 2 stackRun.stack_id, 3 3 stackRun.tess_id, 4 4 stackRun.skycell_id, 5 stackRun.workdir 5 stackRun.workdir, 6 rawExp.camera 6 7 FROM stackRun 8 JOIN stackInputSkyfile 9 USING(stack_id) 10 JOIN warpSkyfile 11 ON stackInputSkyfile.warp_id = warpSkyfile.warp_id 12 AND stackRun.skycell_id = warpSkyfile.skycell_id 13 AND stackRun.tess_id = warpSkyfile.tess_id 14 JOIN warpRun 15 ON warpRun.warp_id = warpSkyfile.warp_id 16 JOIN fakeRun 17 USING(fake_id) 18 JOIN camRun 19 USING(cam_id) 20 JOIN chipRun 21 USING(chip_id) 22 JOIN rawExp 23 USING(exp_id) 7 24 LEFT JOIN stackSumSkyfile 8 25 USING(stack_id) -
branches/eam_branch_20080706/ippTools/src/magictool.c
r18496 r18530 36 36 static bool addinputskyfileMode(pxConfig *config); 37 37 static bool inputskyfileMode(pxConfig *config); 38 static bool totreeMode(pxConfig *config); 38 39 static bool inputtreeMode(pxConfig *config); 39 40 static bool toprocessMode(pxConfig *config); 40 41 static bool addresultMode(pxConfig *config); 42 static bool inputsMode(pxConfig *config); 41 43 static bool tomaskMode(pxConfig *config); 42 44 static bool addmaskMode(pxConfig *config); 43 static bool toskyfilemaskMode(pxConfig *config); 44 static bool addskyfilemaskMode(pxConfig *config); 45 static bool maskMode(pxConfig *config); 45 46 46 47 static bool setmagicRunState(pxConfig *config, psS64 magic_id, const char *state); … … 65 66 66 67 switch (config->mode) { 67 MODECASE(MAGICTOOL_MODE_DEFINEBYQUERY, definebyqueryMode);68 MODECASE(MAGICTOOL_MODE_DEFINEBYQUERY, definebyqueryMode); 68 69 MODECASE(MAGICTOOL_MODE_DEFINERUN, definerunMode); 69 70 MODECASE(MAGICTOOL_MODE_UPDATERUN, updaterunMode); 70 71 MODECASE(MAGICTOOL_MODE_ADDINPUTSKYFILE,addinputskyfileMode); 71 72 MODECASE(MAGICTOOL_MODE_INPUTSKYFILE, inputskyfileMode); 73 MODECASE(MAGICTOOL_MODE_TOTREE, totreeMode); 72 74 MODECASE(MAGICTOOL_MODE_INPUTTREE, inputtreeMode); 73 75 MODECASE(MAGICTOOL_MODE_TOPROCESS, toprocessMode); 74 76 MODECASE(MAGICTOOL_MODE_ADDRESULT, addresultMode); 77 MODECASE(MAGICTOOL_MODE_INPUTS, inputsMode); 75 78 MODECASE(MAGICTOOL_MODE_TOMASK, tomaskMode); 76 79 MODECASE(MAGICTOOL_MODE_ADDMASK, addmaskMode); 77 MODECASE(MAGICTOOL_MODE_TOSKYFILEMASK, toskyfilemaskMode); 78 MODECASE(MAGICTOOL_MODE_ADDSKYFILEMASK, addskyfilemaskMode); 80 MODECASE(MAGICTOOL_MODE_MASK, maskMode); 79 81 default: 80 82 psAbort("invalid option (this should not happen)"); … … 212 214 NULL, // label 213 215 NULL, // dvodb 214 NULL // registered 216 NULL, // registered 217 0 // fault 215 218 ); 216 219 if (!run) { … … 263 266 PS_ASSERT_PTR_NON_NULL(config, false); 264 267 265 // required 268 // required 266 269 PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", true, false); 267 270 … … 279 282 label, 280 283 dvodb, 281 registered 284 registered, 285 0 282 286 ); 283 psFree(registered); 287 284 288 if (!run) { 285 289 psError(PS_ERR_UNKNOWN, false, "failed to alloc magicRun object"); 286 return true;290 return false; 287 291 } 288 292 if (!magicRunInsertObject(config->dbh, run)) { 289 293 psError(PS_ERR_UNKNOWN, false, "database error"); 290 294 psFree(run); 291 return true;295 return false; 292 296 } 293 297 … … 400 404 } 401 405 if (!psArrayLength(output)) { 402 psTrace(" warptool", PS_LOG_INFO, "no rows found");406 psTrace("magictool", PS_LOG_INFO, "no rows found"); 403 407 psFree(output); 404 408 return true; … … 420 424 421 425 422 static bool inputtreeMode(pxConfig *config) 423 { 424 PS_ASSERT_PTR_NON_NULL(config, false); 425 426 // required 427 PXOPT_LOOKUP_STR(magic_id, config->args, "-magic_id", true, false); 428 PXOPT_LOOKUP_STR(dep_file, config->args, "-dep_file", true, false); 429 430 if (!parseAndInsertNodeDeps(config, (psS64)atoll(magic_id), dep_file)) { 431 psError(PS_ERR_UNKNOWN, false, "failed to parse file"); 432 return false; 433 } 434 435 return true; 436 } 437 438 439 bool findBaseNodes(void *arg, pxNode *node) 440 { 441 bool status = false; 442 psS64 done = psMetadataLookupS64(&status, node->data, "done"); 443 if (!status) { 444 psAbort("failed to lookup value for done column"); 445 } 446 447 if ((!pxNodeHasChildren(node)) && (!done)) { 448 // if this node has no child and it's not 'done', then push it's data 449 // onto the void *array 450 psArrayAdd((psArray *)arg, 0, node->data); 451 return false; 452 } 453 454 return true; 455 } 456 457 458 bool findReadyNodes(void *arg, pxNode *node) 459 { 460 461 if (pxNodeHasChildren(node)) { 462 psListIterator *iter = psListIteratorAlloc(node->children, 0, false); 463 psMetadata *work = psMetadataCopy(NULL, node->data); 464 psMetadataRemoveKey(work, "dep"); 465 psMetadataRemoveKey(work, "done"); 466 psMetadataRemoveKey(work, "uri"); 467 pxNode *child = NULL; 468 while ((child = psListGetAndIncrement(iter))) { 469 psMetadata *data = child->data; 470 471 bool status = false; 472 psS32 done = psMetadataLookupS32(&status, data, "done"); 473 if (!status) { 474 psAbort("failed to lookup value for done column"); 475 } 476 477 if (!done) { 478 // if a child isn't "done", give up on this node and continue 479 // to crawl the tree 480 psFree(iter); 481 psFree(work); 482 return true; 483 } 484 485 char *uri = psMetadataLookupStr(&status, data, "uri"); 486 if (!status) { 487 psAbort("failed to lookup value for uri column"); 488 } 489 490 psMetadataAddStr(work, PS_LIST_TAIL, "uri", PS_META_DUPLICATE_OK, NULL, uri); 491 492 } 493 psFree(iter); 494 // if all this nodes children are done, then push it's data onto the 495 // void *array 496 psArrayAdd((psArray *)arg, 0, work); 497 psFree(work); 498 return false; 499 } 500 501 return true; 502 } 503 504 505 static bool toprocessMode(pxConfig *config) 426 static bool totreeMode(pxConfig *config) 506 427 { 507 428 PS_ASSERT_PTR_NON_NULL(config, false); … … 510 431 PXOPT_COPY_STR(config->args, where, "-magic_id", "magic_id", "=="); 511 432 512 psString whereClause = NULL; 513 if (psListLength(where->list)) { 514 whereClause = psDBGenerateWhereSQL(where, NULL); 515 } 516 psFree(where); 517 433 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 518 434 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 519 435 520 436 // look for "inputs" that need to processed 521 psString query = pxDataGet("magictool_to process_inputs.sql");437 psString query = pxDataGet("magictool_totree.sql"); 522 438 if (!query) { 523 439 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); … … 525 441 } 526 442 527 if (whereClause) { 528 psStringAppend(&query, " %s", whereClause); 443 XXX : add where test 444 445 // treat limit == 0 as "no limit" 446 if (limit) { 447 psString limitString = psDBGenerateLimitSQL(limit); 448 psStringAppend(&query, " %s", limitString); 449 psFree(limitString); 529 450 } 530 451 … … 552 473 if (!psArrayLength(output)) { 553 474 psTrace("magictool", PS_LOG_INFO, "no rows found"); 554 // psFree(output); 555 // return true; 556 } 557 558 // look for tree nodes that need to be processed 559 query = pxDataGet("magictool_toprocess_tree.sql"); 560 if (!query) { 561 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 562 return false; 563 } 564 565 if (whereClause) { 566 psStringAppend(&query, " %s", whereClause); 567 } 568 569 if (!p_psDBRunQuery(config->dbh, query)) { 570 psError(PS_ERR_UNKNOWN, false, "database error"); 571 psFree(query); 572 return false; 573 } 574 psFree(query); 575 576 psArray *magicTree = p_psDBFetchResult(config->dbh); 577 if (!output) { 578 psErrorCode err = psErrorCodeLast(); 579 switch (err) { 580 case PS_ERR_DB_CLIENT: 581 psError(PXTOOLS_ERR_SYS, false, "database error"); 582 case PS_ERR_DB_SERVER: 583 psError(PXTOOLS_ERR_PROG, false, "database error"); 584 default: 585 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 586 } 587 588 return false; 589 } 590 if (!psArrayLength(magicTree)) { 591 psTrace("magictool", PS_LOG_INFO, "no rows found"); 592 psFree(magicTree); 475 psFree(output); 593 476 return true; 594 477 } 595 596 psHash *forest = psHashAlloc(psArrayLength(magicTree));597 598 // convert the array of metadata into a pxTree structure599 for (long i = 0; i < psArrayLength(magicTree); i++) {600 bool status;601 psString node = psMetadataLookupStr(&status, magicTree->data[i], "node");602 if (!status) {603 psAbort("failed to lookup value for node column");604 }605 606 psString dep = psMetadataLookupStr(&status, magicTree->data[i], "dep");607 if (!status) {608 psAbort("failed to lookup value for dep column");609 }610 611 pxTreeBuilder(forest, node, dep, magicTree->data[i]);612 613 }614 psFree(magicTree);615 616 // find the root of the tree617 pxNode *root = psHashLookup(forest, "root");618 psFree(forest);619 // pxTreePrint(stdout, root);620 621 // crawl through the tree and looking for nodes with children that are all622 // "done"623 pxTreeCrawl(root, findReadyNodes, output);624 psFree(root);625 478 626 479 if (psArrayLength(output)) { 627 480 // negative simple so the default is true 628 if (!ippdbPrintMetadatas(stdout, output, " magicMe", !simple)) {481 if (!ippdbPrintMetadatas(stdout, output, "totree", !simple)) { 629 482 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 630 483 psFree(output); … … 634 487 635 488 psFree(output); 636 psFree(whereClause); 637 638 return true; 639 } 640 641 642 static bool addresultMode(pxConfig *config) 489 490 return true; 491 } 492 493 494 static bool inputtreeMode(pxConfig *config) 643 495 { 644 496 PS_ASSERT_PTR_NON_NULL(config, false); … … 646 498 // required 647 499 PXOPT_LOOKUP_STR(magic_id, config->args, "-magic_id", true, false); 648 PXOPT_LOOKUP_STR(node, config->args, "-node", true, false); 649 PXOPT_LOOKUP_STR(uri, config->args, "-uri", true, false); 650 651 if (!magicNodeResultInsert(config->dbh, 652 (psS64)atoll(magic_id), 653 node, 654 uri 655 )) { 656 psError(PS_ERR_UNKNOWN, false, "database error"); 657 return false; 658 } 659 660 return true; 661 } 662 663 664 static bool tomaskMode(pxConfig *config) 665 { 666 PS_ASSERT_PTR_NON_NULL(config, false); 667 668 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 500 PXOPT_LOOKUP_STR(dep_file, config->args, "-dep_file", true, false); 501 502 if (!parseAndInsertNodeDeps(config, (psS64)atoll(magic_id), dep_file)) { 503 psError(PS_ERR_UNKNOWN, false, "failed to parse file"); 504 return false; 505 } 506 507 return true; 508 } 509 510 511 bool findBaseNodes(void *arg, pxNode *node) 512 { 513 bool status = false; 514 psS64 done = psMetadataLookupS64(&status, node->data, "done"); 515 if (!status) { 516 psAbort("failed to lookup value for done column"); 517 } 518 519 if ((!pxNodeHasChildren(node)) && (!done)) { 520 // if this node has no child and it's not 'done', then push it's data 521 // onto the void *array 522 psArrayAdd((psArray *)arg, 0, node->data); 523 return false; 524 } 525 526 return true; 527 } 528 529 530 bool findReadyNodes(void *arg, pxNode *node) 531 { 532 if (psMetadataLookupBool(NULL, node->data, "done")) { 533 // It's already done 534 return true; 535 } 536 537 if (pxNodeHasChildren(node)) { 538 psListIterator *iter = psListIteratorAlloc(node->children, 0, false); 539 psMetadata *work = psMetadataCopy(NULL, node->data); 540 psMetadataRemoveKey(work, "dep"); 541 psMetadataRemoveKey(work, "done"); 542 #if 0 543 psMetadataRemoveKey(work, "uri"); 544 #endif 545 pxNode *child = NULL; 546 while ((child = psListGetAndIncrement(iter))) { 547 psMetadata *data = child->data; 548 549 bool status = false; 550 psS32 done = psMetadataLookupS32(&status, data, "done"); 551 if (!status) { 552 psAbort("failed to lookup value for done column"); 553 } 554 555 if (!done) { 556 // if a child isn't "done", give up on this node and continue 557 // to crawl the tree 558 psFree(iter); 559 psFree(work); 560 return true; 561 } 562 #if 0 563 char *uri = psMetadataLookupStr(&status, data, "uri"); 564 if (!status) { 565 psAbort("failed to lookup value for uri column"); 566 } 567 568 psMetadataAddStr(work, PS_LIST_TAIL, "uri", PS_META_DUPLICATE_OK, NULL, uri); 569 #endif 570 } 571 psFree(iter); 572 // if all this nodes children are done, then push it's data onto the 573 // void *array 574 psArrayAdd((psArray *)arg, 0, work); 575 psFree(work); 576 return false; 577 } 578 579 return true; 580 } 581 582 583 static bool toprocessMode(pxConfig *config) 584 { 585 PS_ASSERT_PTR_NON_NULL(config, false); 586 587 psMetadata *where = psMetadataAlloc(); 588 PXOPT_COPY_STR(config->args, where, "-magic_id", "magic_id", "=="); 589 590 psString whereClause = NULL; 591 if (psListLength(where->list)) { 592 whereClause = psDBGenerateWhereSQL(where, NULL); 593 } 594 psFree(where); 595 669 596 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 670 597 671 598 // look for "inputs" that need to processed 672 psString query = pxDataGet("magictool_to mask.sql");599 psString query = pxDataGet("magictool_toprocess_inputs.sql"); 673 600 if (!query) { 674 601 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); … … 676 603 } 677 604 678 // treat limit == 0 as "no limit" 679 if (limit) { 680 psString limitString = psDBGenerateLimitSQL(limit); 681 psStringAppend(&query, " %s", limitString); 682 psFree(limitString); 605 if (whereClause) { 606 psStringAppend(&query, " %s", whereClause); 683 607 } 684 608 … … 706 630 if (!psArrayLength(output)) { 707 631 psTrace("magictool", PS_LOG_INFO, "no rows found"); 708 psFree(output); 632 // psFree(output); 633 // return true; 634 } 635 636 // look for tree nodes that need to be processed 637 query = pxDataGet("magictool_toprocess_tree.sql"); 638 if (!query) { 639 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 640 return false; 641 } 642 643 if (whereClause) { 644 psStringAppend(&query, " %s", whereClause); 645 } 646 647 if (!p_psDBRunQuery(config->dbh, query)) { 648 psError(PS_ERR_UNKNOWN, false, "database error"); 649 psFree(query); 650 return false; 651 } 652 psFree(query); 653 654 psArray *magicTree = p_psDBFetchResult(config->dbh); 655 if (!magicTree) { 656 psErrorCode err = psErrorCodeLast(); 657 switch (err) { 658 case PS_ERR_DB_CLIENT: 659 psError(PXTOOLS_ERR_SYS, false, "database error"); 660 case PS_ERR_DB_SERVER: 661 psError(PXTOOLS_ERR_PROG, false, "database error"); 662 default: 663 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 664 } 665 666 return false; 667 } 668 if (!psArrayLength(magicTree)) { 669 psTrace("magictool", PS_LOG_INFO, "no rows found"); 670 psFree(magicTree); 709 671 return true; 710 672 } 673 674 psHash *forest = psHashAlloc(psArrayLength(magicTree)); 675 676 // convert the array of metadata into a pxTree structure 677 for (long i = 0; i < psArrayLength(magicTree); i++) { 678 bool status; 679 psString node = psMetadataLookupStr(&status, magicTree->data[i], "node"); 680 if (!status) { 681 psAbort("failed to lookup value for node column"); 682 } 683 684 psString dep = psMetadataLookupStr(&status, magicTree->data[i], "dep"); 685 if (!status) { 686 psAbort("failed to lookup value for dep column"); 687 } 688 689 pxTreeBuilder(forest, node, dep, magicTree->data[i]); 690 691 } 692 psFree(magicTree); 693 694 // find the root of the tree 695 pxNode *root = psHashLookup(forest, "root"); 696 psFree(forest); 697 // pxTreePrint(stdout, root); 698 699 // crawl through the tree and looking for nodes with children that are all 700 // "done" 701 pxTreeCrawl(root, findReadyNodes, output); 702 psFree(root); 711 703 712 704 if (psArrayLength(output)) { 713 705 // negative simple so the default is true 714 if (!ippdbPrintMetadatas(stdout, output, " toprocess", !simple)) {706 if (!ippdbPrintMetadatas(stdout, output, "magicMe", !simple)) { 715 707 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 716 708 psFree(output); … … 720 712 721 713 psFree(output); 722 723 return true; 724 } 725 726 727 static bool addmaskMode(pxConfig *config) 714 psFree(whereClause); 715 716 return true; 717 } 718 719 720 static bool addresultMode(pxConfig *config) 728 721 { 729 722 PS_ASSERT_PTR_NON_NULL(config, false); … … 731 724 // required 732 725 PXOPT_LOOKUP_STR(magic_id, config->args, "-magic_id", true, false); 733 PXOPT_LOOKUP_STR(uri, config->args, "-uri", true, false); 734 735 if (!magicMaskInsert(config->dbh, 736 (psS64)atoll(magic_id), 737 uri 726 PXOPT_LOOKUP_STR(node, config->args, "-node", true, false); 727 728 // optional 729 PXOPT_LOOKUP_STR(uri, config->args, "-uri", false, false); 730 731 // default values 732 PXOPT_LOOKUP_S16(code, config->args, "-code", false, false); 733 734 if (!magicNodeResultInsert(config->dbh, 735 (psS64)atoll(magic_id), 736 node, 737 uri, 738 code 738 739 )) { 739 740 psError(PS_ERR_UNKNOWN, false, "database error"); … … 744 745 } 745 746 746 747 static bool toskyfilemaskMode(pxConfig *config) 748 { 749 PS_ASSERT_PTR_NON_NULL(config, false); 750 751 psMetadata *where = psMetadataAlloc(); 752 PXOPT_COPY_STR(config->args, where, "-magic_id", "magic_id", "=="); 747 static bool inputsMode(pxConfig *config) 748 { 749 PS_ASSERT_PTR_NON_NULL(config, false); 753 750 754 751 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 755 752 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 756 753 757 psString query = pxDataGet("magictool_ toskyfilemask.sql");754 psString query = pxDataGet("magictool_inputs.sql"); 758 755 if (!query) { 759 756 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); … … 761 758 } 762 759 763 if ( psListLength(where->list)) {764 psString whereClause = psDBGenerateWhereConditionSQL( where, "magicRun");760 if (config->where) { 761 psString whereClause = psDBGenerateWhereConditionSQL(config->where, NULL); 765 762 psStringAppend(&query, " AND %s", whereClause); 766 763 psFree(whereClause); 767 764 } 768 psFree(where);769 765 770 766 // treat limit == 0 as "no limit" … … 804 800 if (psArrayLength(output)) { 805 801 // negative simple so the default is true 806 if (!ippdbPrintMetadatas(stdout, output, " toskyfilemask", !simple)) {802 if (!ippdbPrintMetadatas(stdout, output, "magicNode", !simple)) { 807 803 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 808 804 psFree(output); … … 817 813 818 814 819 static bool addskyfilemaskMode(pxConfig *config) 815 static bool tomaskMode(pxConfig *config) 816 { 817 PS_ASSERT_PTR_NON_NULL(config, false); 818 819 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 820 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 821 822 // look for "inputs" that need to processed 823 psString query = pxDataGet("magictool_tomask.sql"); 824 if (!query) { 825 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 826 return false; 827 } 828 829 // treat limit == 0 as "no limit" 830 if (limit) { 831 psString limitString = psDBGenerateLimitSQL(limit); 832 psStringAppend(&query, " %s", limitString); 833 psFree(limitString); 834 } 835 836 if (!p_psDBRunQuery(config->dbh, query)) { 837 psError(PS_ERR_UNKNOWN, false, "database error"); 838 psFree(query); 839 return false; 840 } 841 psFree(query); 842 843 psArray *output = p_psDBFetchResult(config->dbh); 844 if (!output) { 845 psErrorCode err = psErrorCodeLast(); 846 switch (err) { 847 case PS_ERR_DB_CLIENT: 848 psError(PXTOOLS_ERR_SYS, false, "database error"); 849 case PS_ERR_DB_SERVER: 850 psError(PXTOOLS_ERR_PROG, false, "database error"); 851 default: 852 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 853 } 854 855 return false; 856 } 857 if (!psArrayLength(output)) { 858 psTrace("magictool", PS_LOG_INFO, "no rows found"); 859 psFree(output); 860 return true; 861 } 862 863 if (psArrayLength(output)) { 864 // negative simple so the default is true 865 if (!ippdbPrintMetadatas(stdout, output, "toprocess", !simple)) { 866 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 867 psFree(output); 868 return false; 869 } 870 } 871 872 psFree(output); 873 874 return true; 875 } 876 877 878 static bool addmaskMode(pxConfig *config) 820 879 { 821 880 PS_ASSERT_PTR_NON_NULL(config, false); … … 823 882 // required 824 883 PXOPT_LOOKUP_STR(magic_id, config->args, "-magic_id", true, false); 825 PXOPT_LOOKUP_STR(diff_id, config->args, "diff_id", true, false); 826 PXOPT_LOOKUP_STR(uri, config->args, "uri", true, false); 827 828 if (!magicSkyfileMaskInsert(config->dbh, 829 (psS64)atoll(magic_id), 830 (psS64)atoll(diff_id), 831 uri 884 885 // optional 886 PXOPT_LOOKUP_STR(uri, config->args, "-uri", false, false); 887 PXOPT_LOOKUP_S32(streaks, config->args, "-streaks", false, false); 888 889 // default values 890 PXOPT_LOOKUP_S16(code, config->args, "-code", false, false); 891 892 if (!psDBTransaction(config->dbh)) { 893 psError(PS_ERR_UNKNOWN, false, "database error"); 894 return false; 895 } 896 897 if (!magicMaskInsert(config->dbh, 898 (psS64)atoll(magic_id), 899 uri, 900 streaks, 901 code 832 902 )) { 833 903 psError(PS_ERR_UNKNOWN, false, "database error"); 834 904 return false; 835 905 } 906 907 // Set the magicRun state 908 psString query = pxDataGet("magictool_addmask.sql"); 909 if (!query) { 910 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 911 return false; 912 } 913 914 // Add "magic_id = value" 915 psString whereClause = psDBGenerateWhereConditionSQL(config->where, NULL); 916 psStringAppend(&query, " AND %s", whereClause); 917 psFree(whereClause); 918 919 if (!p_psDBRunQuery(config->dbh, query)) { 920 psError(PS_ERR_UNKNOWN, false, "database error"); 921 psFree(query); 922 return false; 923 } 924 psFree(query); 925 926 if (!psDBCommit(config->dbh)) { 927 psError(PS_ERR_UNKNOWN, false, "database error"); 928 return false; 929 } 930 931 return true; 932 } 933 934 935 static bool maskMode(pxConfig *config) 936 { 937 PS_ASSERT_PTR_NON_NULL(config, false); 938 939 psMetadata *where = psMetadataAlloc(); 940 PXOPT_COPY_STR(config->args, where, "-magic_id", "magicRun.magic_id", "=="); 941 942 PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false); 943 PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); 944 945 psString query = pxDataGet("magictool_mask.sql"); 946 if (!query) { 947 psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement"); 948 return false; 949 } 950 951 if (psListLength(where->list)) { 952 psString whereClause = psDBGenerateWhereConditionSQL(where, NULL); 953 psStringAppend(&query, " AND %s", whereClause); 954 psFree(whereClause); 955 } 956 psFree(where); 957 958 // treat limit == 0 as "no limit" 959 if (limit) { 960 psString limitString = psDBGenerateLimitSQL(limit); 961 psStringAppend(&query, " %s", limitString); 962 psFree(limitString); 963 } 964 965 if (!p_psDBRunQuery(config->dbh, query)) { 966 psError(PS_ERR_UNKNOWN, false, "database error"); 967 psFree(query); 968 return false; 969 } 970 psFree(query); 971 972 psArray *output = p_psDBFetchResult(config->dbh); 973 if (!output) { 974 psErrorCode err = psErrorCodeLast(); 975 switch (err) { 976 case PS_ERR_DB_CLIENT: 977 psError(PXTOOLS_ERR_SYS, false, "database error"); 978 case PS_ERR_DB_SERVER: 979 psError(PXTOOLS_ERR_PROG, false, "database error"); 980 default: 981 psError(PXTOOLS_ERR_PROG, false, "unknown error"); 982 } 983 984 return false; 985 } 986 if (!psArrayLength(output)) { 987 psTrace("magictool", PS_LOG_INFO, "no rows found"); 988 psFree(output); 989 return true; 990 } 991 992 if (psArrayLength(output)) { 993 // negative simple so the default is true 994 if (!ippdbPrintMetadatas(stdout, output, "magicNode", !simple)) { 995 psError(PS_ERR_UNKNOWN, false, "failed to print array"); 996 psFree(output); 997 return false; 998 } 999 } 1000 1001 psFree(output); 836 1002 837 1003 return true; -
branches/eam_branch_20080706/ippTools/src/magictool.h
r18093 r18530 30 30 MAGICTOOL_MODE_ADDINPUTSKYFILE, 31 31 MAGICTOOL_MODE_INPUTSKYFILE, 32 MAGICTOOL_MODE_TOTREE, 32 33 MAGICTOOL_MODE_INPUTTREE, 33 34 MAGICTOOL_MODE_TOPROCESS, 35 MAGICTOOL_MODE_INPUTS, 34 36 MAGICTOOL_MODE_ADDRESULT, 35 37 MAGICTOOL_MODE_TOMASK, 36 38 MAGICTOOL_MODE_ADDMASK, 37 MAGICTOOL_MODE_TOSKYFILEMASK, 38 MAGICTOOL_MODE_ADDSKYFILEMASK, 39 MAGICTOOL_MODE_MASK, 39 40 } MAGICtoolMode; 40 41 -
branches/eam_branch_20080706/ippTools/src/magictoolConfig.c
r18496 r18530 77 77 psMetadataAddBool(inputskyfileArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false); 78 78 79 // -totree 80 psMetadata *totreeArgs = psMetadataAlloc(); 81 psMetadataAddStr(totreeArgs, PS_LIST_TAIL, "-magic_id", 0, "search by magic ID", NULL); 82 psMetadataAddU64(totreeArgs, PS_LIST_TAIL, "-limit", 0, "limit result set to N items", 0); 83 psMetadataAddBool(totreeArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false); 84 79 85 // -inputtree 80 86 psMetadata *inputtreeArgs = psMetadataAlloc(); 81 87 psMetadataAddStr(inputtreeArgs, PS_LIST_TAIL, "-magic_id", 0, "define magictool ID (required)", NULL); 82 88 psMetadataAddStr(inputtreeArgs, PS_LIST_TAIL, "-dep_file", 0, "order of operations dep. file (required)", NULL); 89 psMetadataAddS16(inputtreeArgs, PS_LIST_TAIL, "-code", 0, "set fault code", 0); 90 91 // -inputs 92 psMetadata *inputsArgs = psMetadataAlloc(); 93 psMetadataAddStr(inputsArgs, PS_LIST_TAIL, "-magic_id", 0, "search by magictool ID", NULL); 94 psMetadataAddStr(inputsArgs, PS_LIST_TAIL, "-node", 0, "search by symbolic node name", NULL); 95 psMetadataAddU64(inputsArgs, PS_LIST_TAIL, "-limit", 0, "limit result set to N items", 0); 96 psMetadataAddBool(inputsArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false); 83 97 84 98 // -tooprocess … … 93 107 psMetadataAddStr(addresultArgs, PS_LIST_TAIL, "-node", 0, "define symbolic node name (required)", NULL); 94 108 psMetadataAddStr(addresultArgs, PS_LIST_TAIL, "-uri", 0, "define URI (required)", NULL); 109 psMetadataAddS16(addresultArgs, PS_LIST_TAIL, "-code", 0, "set fault code", 0); 95 110 96 111 // -tomask … … 101 116 // -addmask 102 117 psMetadata *addmaskArgs = psMetadataAlloc(); 103 psMetadataAddStr(addmaskArgs, PS_LIST_TAIL, "-magic_id", 0, "define magictool ID (required)", NULL); 104 psMetadataAddStr(addmaskArgs, PS_LIST_TAIL, "-uri", 0, "define URI (required)", NULL); 118 psMetadataAddStr(addmaskArgs, PS_LIST_TAIL, "-magic_id", 0, "define magictool ID (required)", NULL); 119 psMetadataAddStr(addmaskArgs, PS_LIST_TAIL, "-uri", 0, "define URI", NULL); 120 psMetadataAddS32(addmaskArgs, PS_LIST_TAIL, "-streaks", 0, "define number of streaks", 0); 121 psMetadataAddS16(addmaskArgs, PS_LIST_TAIL, "-code", 0, "set fault code", 0); 105 122 123 # if (0) 106 124 // -toskyfilemask 107 125 psMetadata *toskyfilemaskArgs = psMetadataAlloc(); … … 115 133 psMetadataAddStr(addskyfilemaskArgs, PS_LIST_TAIL, "-diff_id", 0, "define difftool ID (required)", NULL); 116 134 psMetadataAddStr(addskyfilemaskArgs, PS_LIST_TAIL, "-uri", 0, "define URI (required)", NULL); 135 # endif 136 137 // -mask 138 psMetadata *maskArgs = psMetadataAlloc(); 139 psMetadataAddStr(maskArgs, PS_LIST_TAIL, "-magic_id", 0, "define magictool ID", NULL); 140 psMetadataAddU64(maskArgs, PS_LIST_TAIL, "-limit", 0, "limit result set to N items", 0); 141 psMetadataAddBool(maskArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false); 117 142 118 143 psFree(now); … … 121 146 psMetadata *modes = psMetadataAlloc(); 122 147 123 PXOPT_ADD_MODE("-definebyquery", "", MAGICTOOL_MODE_DEFINEBYQUERY,queueArgs);148 PXOPT_ADD_MODE("-definebyquery", "", MAGICTOOL_MODE_DEFINEBYQUERY, queueArgs); 124 149 PXOPT_ADD_MODE("-definerun", "", MAGICTOOL_MODE_DEFINERUN, definerunArgs); 125 150 PXOPT_ADD_MODE("-updaterun", "", MAGICTOOL_MODE_UPDATERUN, updaterunArgs); 126 151 PXOPT_ADD_MODE("-addinputskyfile", "", MAGICTOOL_MODE_ADDINPUTSKYFILE, addinputskyfileArgs); 127 152 PXOPT_ADD_MODE("-inputskyfile", "", MAGICTOOL_MODE_INPUTSKYFILE, inputskyfileArgs); 153 PXOPT_ADD_MODE("-totree", "", MAGICTOOL_MODE_TOTREE, totreeArgs); 128 154 PXOPT_ADD_MODE("-inputtree", "", MAGICTOOL_MODE_INPUTTREE, inputtreeArgs); 129 155 PXOPT_ADD_MODE("-toprocess", "", MAGICTOOL_MODE_TOPROCESS, toprocessArgs); 156 PXOPT_ADD_MODE("-inputs", "", MAGICTOOL_MODE_INPUTS, inputsArgs); 130 157 PXOPT_ADD_MODE("-addresult", "", MAGICTOOL_MODE_ADDRESULT, addresultArgs); 131 158 PXOPT_ADD_MODE("-tomask", "", MAGICTOOL_MODE_TOMASK, tomaskArgs); 132 159 PXOPT_ADD_MODE("-addmask", "", MAGICTOOL_MODE_ADDMASK, addmaskArgs); 133 PXOPT_ADD_MODE("-toskyfilemask", "", MAGICTOOL_MODE_TOSKYFILEMASK, toskyfilemaskArgs); 134 PXOPT_ADD_MODE("-addskyfilemask", "", MAGICTOOL_MODE_ADDSKYFILEMASK, addskyfilemaskArgs); 160 PXOPT_ADD_MODE("-mask", "", MAGICTOOL_MODE_MASK, maskArgs); 135 161 136 162 if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) { -
branches/eam_branch_20080706/ippTools/src/pxwarp.c
r18029 r18530 74 74 } 75 75 76 psString query = psStringCopy("UPDATE warpRun JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) SETstate = '%s'");76 psString query = psStringCopy("UPDATE warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) SET warpRun.state = '%s'"); 77 77 78 78 if (where) { 79 79 psString whereClause = psDBGenerateWhereSQL(where, NULL); 80 psStringAppend(&query, " %s", whereClause); 80 if (whereClause && strlen(whereClause) > 0) { 81 psStringAppend(&query, " %s", whereClause); 82 } 81 83 psFree(whereClause); 82 84 } … … 115 117 // note label == NULL should be explicitly allowed 116 118 117 psString query = psStringCopy("UPDATE warpRun JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) SET warpRun.label = '%s'");119 psString query = psStringCopy("UPDATE warpRun JOIN fakeRun USING(fake_id) JOIN camRun USING(cam_id) JOIN chipRun USING(chip_id) JOIN rawExp USING(exp_id) SET warpRun.label = '%s'"); 118 120 119 121 if (where) { -
branches/eam_branch_20080706/psModules/src/imcombine/pmPSFEnvelope.c
r16833 r18530 34 34 #define PEAK_FLUX 1.0e4 // Peak flux for each source 35 35 #define SKY_VALUE 0.0e0 // Sky value for fake image 36 #define WEIGHT_VAL 1.0 // Weighting for image 36 #define WEIGHT_VAL 10.0 // Weighting for image 37 #define WEIGHT_FACTOR 10.0 // Factor to multiply image by to get weighting 37 38 #define PSF_STATS PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV // Statistics options for measuring PSF 38 39 … … 199 200 psFree(envelope); 200 201 201 // XXX This seems the best way to set the weight image so that pixels aren't rejected as "insignificant" 202 readout->weight = (psImage*)psBinaryOp(NULL, readout->image, "*", readout->image); 202 // XXX Setting the weight seems to be an art 203 // Can't set it too high so that pixels are rejected as insignificant 204 // Can't set it too low so that it's hard to get to the minimum 205 // Have also tried: 206 // *** readout->weight = (psImage*)psBinaryOp(NULL, readout->image, "*", readout->image); 207 // *** readout->weight = (psImage*)psBinaryOp(NULL, readout->image, "*", psScalarAlloc(WEIGHT_FACTOR, PS_TYPE_F32)); 208 readout->weight = (psImage*)psBinaryOp(NULL, readout->image, "+", psScalarAlloc(PS_SQR(WEIGHT_VAL), PS_TYPE_F32)); 203 209 readout->mask = psImageAlloc(numCols, numRows, PS_TYPE_MASK); 204 210 psImageInit(readout->mask, 0); … … 258 264 options->psfFieldYo = 0; 259 265 260 pmSourceFitModelInit (15, 0.01, WEIGHT_VAL, options->poissonErrorsPhotLMM);266 pmSourceFitModelInit(50, 0.01, WEIGHT_VAL, false); 261 267 262 268 pmPSFtry *try = pmPSFtryModel(fakes, modelName, options, 0, 0xff); -
branches/eam_branch_20080706/psModules/src/imcombine/pmStackReject.c
r17299 r18530 23 23 PS_ASSERT_ARRAY_NON_NULL(kernels, NULL); 24 24 PS_ASSERT_ARRAYS_SIZE_EQUAL(subRegions, kernels, NULL); 25 26 // Trivial case 27 if (in->n == 0) { 28 return psPixelsAllocEmpty(0); 29 } 25 30 26 31 // Get the original image size
Note:
See TracChangeset
for help on using the changeset viewer.
