Changeset 18243 for trunk/pstamp/src/pstampparse.c
- Timestamp:
- Jun 20, 2008, 10:27:20 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/pstamp/src/pstampparse.c (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pstamp/src/pstampparse.c
r17456 r18243 72 72 options->mode = parseMode(argv[argnum]); 73 73 psArgumentRemove(argnum, &argc, argv); 74 } else { 75 options->mode = PSP_MODE_LIST_JOB; 74 76 } 75 77 … … 82 84 options->req_id = atol(argv[argnum]); 83 85 psArgumentRemove(argnum, &argc, argv); 86 } 87 88 if ((options->mode == PSP_MODE_QUEUE_JOB) && (options->req_id <= 0)) { 89 psError(PS_ERR_UNKNOWN, true, "need request id in order to queue jobs\n"); 90 return false; 84 91 } 85 92 … … 147 154 // XXX: need to select the database name based on the project name specified in the input 148 155 149 options->config->database = p mConfigDB(options->config);156 options->config->database = psMemIncrRefCounter(pmConfigDB(options->config)); 150 157 151 158 if (!options->config->database) { … … 215 222 // 216 223 // 217 // we return an array containing strin s for the values224 // we return an array containing strings for the values 218 225 219 226 if (!p_psDBRunQuery(options->config->database, query, target, key1, key2)) { … … 264 271 265 272 psStringAppend(&query, "SELECT %%s from %s WHERE %s = %%s", table, id_type); 266 // append class_id unless it is set to the special value " all"267 if (class_id && strcmp(" all", class_id)) {273 // append class_id unless it is set to the special value "null" 274 if (class_id && strcmp("null", class_id)) { 268 275 psStringAppend(&query, "%s", " and class_id = '%s'" ); 269 276 } … … 559 566 bool status = false;; 560 567 psString roiString = NULL; 561 psString ra = psMetadataLookupStr(&status, options->md, "RA"); 562 563 if (ra != NULL) { 564 psString dec = psMetadataLookupStr(&status, options->md, "DEC"); 565 if (dec == NULL) { 566 psError(PS_ERR_UNKNOWN, true, "bad request file: RA specified without DEC"); 567 return NULL; 568 } 569 psStringAppend(&roiString, "-skycenter %s %s", ra, dec); 568 569 psU32 coord_mask = psMetadataLookupU32(&status, options->md, "COORD_MASK"); 570 if (!status) { 571 psError(PS_ERR_UNKNOWN, true, "bad request file: COORD_MASK not specified"); 572 return NULL; 573 } 574 575 psString x = psMetadataLookupStr(&status, options->md, "CENTER_X"); 576 if (x == NULL) { 577 psError(PS_ERR_UNKNOWN, true, "bad request file: CENTER_X not specified"); 578 return NULL; 579 } 580 psString y = psMetadataLookupStr(&status, options->md, "CENTER_Y"); 581 if (y == NULL) { 582 psError(PS_ERR_UNKNOWN, true, "bad request file: CENTER_Y not specified"); 583 return NULL; 584 } 585 586 if (coord_mask & PSTAMP_CENTER_IN_PIXELS) { 587 psStringAppend(&roiString, "-pixcenter %s %s", x, y); 570 588 } else { 571 psString x = psMetadataLookupStr(&status, options->md, "CENTER_X"); 572 if (x == NULL) { 573 psError(PS_ERR_UNKNOWN, true, "bad request file: center not specified"); 574 return NULL; 575 } 576 psString y = psMetadataLookupStr(&status, options->md, "CENTER_Y"); 577 psStringAppend(&roiString, "-pixcenter %s %s", x, y); 578 } 579 580 psString d_ra = psMetadataLookupStr(&status, options->md, "D_RA"); 581 if (d_ra != NULL) { 582 psString d_dec = psMetadataLookupStr(&status, options->md, "D_DEC"); 583 if (d_dec == NULL) { 584 psError(PS_ERR_UNKNOWN, true, "bad request file: D_RA specified without D_DEC"); 585 return NULL; 586 } 587 psStringAppend(&roiString, " -arcrange %s %s", d_ra, d_dec); 589 psStringAppend(&roiString, "-skycenter %s %s", x, y); 590 } 591 592 psString w = psMetadataLookupStr(&status, options->md, "WIDTH"); 593 if (w == NULL) { 594 psError(PS_ERR_UNKNOWN, true, "bad request file: WIDTH not specified"); 595 return NULL; 596 } 597 psString h = psMetadataLookupStr(&status, options->md, "HEIGHT"); 598 if (h == NULL) { 599 psError(PS_ERR_UNKNOWN, true, "bad request file: HEIGHT not specified"); 600 return NULL; 601 } 602 603 if (coord_mask & PSTAMP_RANGE_IN_PIXELS) { 604 psStringAppend(&roiString, " -pixrange %s %s", w, h); 588 605 } else { 589 psString w = psMetadataLookupStr(&status, options->md, "WIDTH"); 590 if (w == NULL) { 591 psError(PS_ERR_UNKNOWN, true, "bad request file: range not specified"); 592 return NULL; 593 } 594 psString h = psMetadataLookupStr(&status, options->md, "HEIGHT"); 595 psStringAppend(&roiString, " -pixrange %s %s", w, h); 606 psStringAppend(&roiString, " -arcrange %s %s", w, h); 596 607 } 597 608 … … 636 647 637 648 static bool 638 queueJobs (pspOptions *options, psString job_type, psArray *uris, psString user_tag, psString commandArgs)649 queueJobs (pspOptions *options, psString job_type, psArray *uris, psString stamp_name, psString commandArgs) 639 650 { 640 651 int numURIs = psArrayLength(uris); … … 643 654 if (numURIs == 1) { 644 655 // use the user tag as the outputBase 645 status = queueOneJob(options, job_type, uris->data[0], user_tag, commandArgs);656 status = queueOneJob(options, job_type, uris->data[0], stamp_name, commandArgs); 646 657 } else { 647 658 for (int i = 0; i< numURIs; i++) { 648 659 psString outputBase = NULL; 649 660 650 // append an integer to the user_tagto get a uniqueu outputBase651 psStringAppend(&outputBase, "%s_%d", user_tag, i);661 // append an integer to the stamp_name to get a uniqueu outputBase 662 psStringAppend(&outputBase, "%s_%d", stamp_name, i); 652 663 653 664 status = queueOneJob(options, job_type, uris->data[i], outputBase, commandArgs); … … 664 675 665 676 static bool 666 turnO ffResultsFile(pspOptions *options)677 turnOnResultsFile(pspOptions *options) 667 678 { 668 679 // turn off the creation of a results file for this request 669 char * query = "UPDATE pstampRequest SET resultsFile = 0WHERE req_id = %" PRId64;680 char * query = "UPDATE pstampRequest SET resultsFile = 1 WHERE req_id = %" PRId64; 670 681 return p_psDBRunQuery(options->config->database, query, options->req_id); 671 682 } … … 678 689 psString img_type = psMetadataLookupStr(NULL, options->md, "IMG_TYPE"); 679 690 691 #ifdef notdef 680 692 if (! turnOffResultsFile(options)) { 681 693 fprintf(stderr, "failed to update resultsFile for request %" PRId64 "\n", options->req_id); 682 694 return false; 683 695 } 696 #endif 684 697 685 698 if (options->outputDirectory == NULL) { … … 716 729 parseRequestTable(pspOptions *options) 717 730 { 718 bool status; 731 bool status = false; 732 719 733 psString job_type = psMetadataLookupStr(&status, options->md, "JOB_TYPE"); 720 721 734 if (job_type == NULL) { 722 // XXX: compatiabilty hack change to error at some point 723 job_type = "stamp"; 724 } 725 726 psString cmd_mode = psMetadataLookupStr(&status, options->md, "CMD_MODE"); 727 728 // if cmd_mode is set on the command line ignore the value in the request file 729 if (options->mode == PSP_MODE_UNKNOWN) { 730 if (cmd_mode != NULL) { 731 options->mode = parseMode(cmd_mode); 732 } else { 733 // default to listing the parameters of the job's that the request would queue 734 options->mode = PSP_MODE_LIST_JOB; 735 } 736 } 737 738 if ((options->mode == PSP_MODE_QUEUE_JOB) && (options->req_id <= 0)) { 739 fprintf(stderr, "need request id in order to queue jobs\n"); 740 return false; 741 } 735 psError(PS_ERR_UNKNOWN, true, "bad request file: JOB_TYPE not specified"); 736 return false; 737 } 738 739 bool isStampJob = (strcmp(job_type, "stamp") == 0); 742 740 743 741 // how are we to select the images ? 744 742 psString req_type = psMetadataLookupStr(&status, options->md, "REQ_TYPE"); 745 746 743 if ( !req_type) { 747 744 psError(PS_ERR_UNKNOWN, true, "request file has no REQ_TYPE"); … … 750 747 751 748 psString roiString = parseROI(options); 749 if (isStampJob && !roiString) { 750 psError(PS_ERR_UNKNOWN, false, "need valid ROI for stamp request"); 751 return false; 752 } 752 753 753 754 psArray *uris = NULL; … … 776 777 777 778 if (uris == NULL) { 778 // mayneed a finer grained status code: did something go wrong with the system779 // XXX we need a finer grained status code: did something go wrong with the system 779 780 // or are there simply no images matching the request 780 781 fprintf(stderr, "No matching images found.\n"); … … 784 785 int numURIs = psArrayLength(uris); 785 786 if (options->mode == PSP_MODE_LIST_URI) { 787 // Just list the images that would have jobs queued for them 786 788 for (int i=0; i<numURIs; i++) { 787 789 fprintf(stdout, "%s\n", (psString) uris->data[i]); … … 790 792 psString commandArgs = roiString; 791 793 psString class_id = psMetadataLookupStr(&status, options->md, "CLASS_ID"); 792 if (class_id) { 794 // We don't check here whether class_id is required. We leave that up to 795 // ppstamp 796 if (class_id && strcmp(class_id, "null")) { 793 797 // TODO: the ppstamp argument needs to change to class_id 794 798 // perhaps allow chip as a synonym 795 799 psStringAppend(&commandArgs, " -chip %s", class_id); 796 800 } 797 psString user_tag = psMetadataLookupStr(&status, options->md, "USER_TAG");801 psString stamp_name = psMetadataLookupStr(&status, options->md, "STAMP_NAME"); 798 802 799 803 if (options->mode == PSP_MODE_LIST_JOB) { 800 804 if (numURIs == 1) { 801 805 printf("%s %s %s %s\n", job_type, (psString) uris->data[0], 802 user_tag ? user_tag: "", commandArgs ? commandArgs : "") ;806 stamp_name ? stamp_name : "", commandArgs ? commandArgs : "") ; 803 807 } else { 804 // add an integer to the user_tag808 // add an integer to the stamp_name 805 809 for (int i = 0; i < numURIs; i++) { 806 printf("%s %s %s_%d %s\n", job_type, (psString) uris->data[i], user_tag, i,810 printf("%s %s %s_%d %s\n", job_type, (psString) uris->data[i], stamp_name, i, 807 811 commandArgs ? commandArgs :""); 808 812 } … … 812 816 if (!strcmp(job_type, "stamp")) { 813 817 // Postage stamp job 814 if ( user_tag== NULL) {815 psError(PS_ERR_UNKNOWN, true, "no user tagin request file");818 if (stamp_name == NULL) { 819 psError(PS_ERR_UNKNOWN, true, "no STAMP_NAME in request file"); 816 820 return false; 817 821 } 818 822 819 if (!queueJobs(options, job_type, uris, user_tag, commandArgs)) { 823 if (!queueJobs(options, job_type, uris, stamp_name, commandArgs)) { 824 return false; 825 } 826 827 // Note: This is a DB operation 828 if (!turnOnResultsFile(options)) { 829 psError(PS_ERR_UNKNOWN, true, "failed to update resultsFile"); 830 831 // TODO: should we unqueue the jobs, set state of request to false?? 832 // Maybe get rid of the column and just use job_type to trigger creation of 833 // results file. so what if the gui doesn't need it? 820 834 return false; 821 835 } 822 836 } else { 823 824 837 return queueGetImageJob(options, uris, req_type); 825 838 } 826 839 827 840 } else { 828 // this error is actually caught by parseMode but we might as well check841 // this error is actually caught by parseMode 829 842 fprintf(stderr, "unknown command mode found: %d\n", options->mode); 830 843 exit(1); … … 848 861 849 862 if (!options) { 863 psErrorStackPrint(stderr, "unable to parse arguments"); 850 864 return 1; 851 865 } 852 866 853 867 if (!readRequestTable(options)) { 868 psErrorStackPrint(stderr, "unable to read request table"); 854 869 return 1; 855 870 } 856 871 857 872 if (!setupDB(options)) { 873 psErrorStackPrint(stderr, "unable to set up data base connection"); 858 874 return 1; 859 875 } … … 864 880 865 881 if (!parseRequestTable(options)) { 866 //psErrorStackPrint(stderr, "unable to parse request table");882 psErrorStackPrint(stderr, "unable to parse request table"); 867 883 return 1; 868 884 }
Note:
See TracChangeset
for help on using the changeset viewer.
