IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 20, 2008, 10:27:20 AM (18 years ago)
Author:
bills
Message:

updated postage stamp request file format

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pstamp/src/pstampparse.c

    r17456 r18243  
    7272        options->mode = parseMode(argv[argnum]);
    7373        psArgumentRemove(argnum, &argc, argv);
     74    } else {
     75        options->mode = PSP_MODE_LIST_JOB;
    7476    }
    7577
     
    8284        options->req_id = atol(argv[argnum]);
    8385        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;
    8491    }
    8592
     
    147154    // XXX: need to select the database name based on the project name specified in the input
    148155
    149     options->config->database = pmConfigDB(options->config);
     156    options->config->database = psMemIncrRefCounter(pmConfigDB(options->config));
    150157
    151158    if (!options->config->database) {
     
    215222    //
    216223    //
    217     // we return an array containing strins for the values
     224    // we return an array containing strings for the values
    218225
    219226    if (!p_psDBRunQuery(options->config->database, query, target, key1, key2)) {
     
    264271
    265272    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)) {
    268275        psStringAppend(&query, "%s", " and class_id = '%s'" );
    269276    }
     
    559566    bool status = false;;
    560567    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);
    570588    } 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);
    588605    } 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);
    596607    }
    597608
     
    636647
    637648static bool
    638 queueJobs (pspOptions *options, psString job_type, psArray *uris, psString user_tag, psString commandArgs)
     649queueJobs (pspOptions *options, psString job_type, psArray *uris, psString stamp_name, psString commandArgs)
    639650{
    640651    int numURIs = psArrayLength(uris);
     
    643654    if (numURIs == 1) {
    644655        // 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);
    646657    } else {
    647658        for (int i = 0; i< numURIs; i++) {
    648659            psString outputBase = NULL;
    649660
    650             // append an integer to the user_tag to get a uniqueu outputBase
    651             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);
    652663
    653664            status = queueOneJob(options, job_type, uris->data[i], outputBase, commandArgs);
     
    664675
    665676static bool
    666 turnOffResultsFile(pspOptions *options)
     677turnOnResultsFile(pspOptions *options)
    667678{
    668679    // turn off the creation of a results file for this request
    669     char * query = "UPDATE pstampRequest SET resultsFile = 0 WHERE req_id = %" PRId64;
     680    char * query = "UPDATE pstampRequest SET resultsFile = 1 WHERE req_id = %" PRId64;
    670681    return p_psDBRunQuery(options->config->database, query, options->req_id);
    671682}
     
    678689    psString    img_type = psMetadataLookupStr(NULL, options->md, "IMG_TYPE");
    679690
     691#ifdef notdef
    680692    if (! turnOffResultsFile(options)) {
    681693        fprintf(stderr, "failed to update resultsFile for request %" PRId64 "\n", options->req_id);
    682694        return false;
    683695    }
     696#endif
    684697
    685698    if (options->outputDirectory == NULL) {
     
    716729parseRequestTable(pspOptions *options)
    717730{
    718     bool status;
     731    bool status = false;
     732
    719733    psString job_type = psMetadataLookupStr(&status, options->md, "JOB_TYPE");
    720 
    721734    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);
    742740
    743741    // how are we to select the images ?
    744742    psString req_type = psMetadataLookupStr(&status, options->md, "REQ_TYPE");
    745 
    746743    if ( !req_type) {
    747744        psError(PS_ERR_UNKNOWN, true, "request file has no REQ_TYPE");
     
    750747
    751748    psString roiString = parseROI(options);
     749    if (isStampJob && !roiString) {
     750        psError(PS_ERR_UNKNOWN, false, "need valid ROI for stamp request");
     751        return false;
     752    }
    752753
    753754    psArray *uris = NULL;
     
    776777
    777778    if (uris == NULL) {
    778         // may need a finer grained status code: did something go wrong with the system
     779        // XXX we need a finer grained status code: did something go wrong with the system
    779780        // or are there simply no images matching the request
    780781        fprintf(stderr, "No matching images found.\n");
     
    784785    int numURIs = psArrayLength(uris);
    785786    if (options->mode == PSP_MODE_LIST_URI) {
     787        // Just list the images that would have jobs queued for them
    786788        for (int i=0; i<numURIs; i++) {
    787789            fprintf(stdout, "%s\n", (psString) uris->data[i]);
     
    790792        psString commandArgs = roiString;
    791793        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")) {
    793797            // TODO: the ppstamp argument needs to change to class_id
    794798            // perhaps allow chip as a synonym
    795799            psStringAppend(&commandArgs, " -chip %s", class_id);
    796800        }
    797         psString user_tag = psMetadataLookupStr(&status, options->md, "USER_TAG");
     801        psString stamp_name = psMetadataLookupStr(&status, options->md, "STAMP_NAME");
    798802
    799803        if (options->mode == PSP_MODE_LIST_JOB) {
    800804            if (numURIs == 1) {
    801805                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 : "") ;
    803807            } else {
    804                 // add an integer to the user_tag
     808                // add an integer to the stamp_name
    805809                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,
    807811                        commandArgs ? commandArgs :"");
    808812                }
     
    812816            if (!strcmp(job_type, "stamp")) {
    813817                // Postage stamp job
    814                 if (user_tag == NULL) {
    815                     psError(PS_ERR_UNKNOWN, true, "no user tag in request file");
     818                if (stamp_name == NULL) {
     819                    psError(PS_ERR_UNKNOWN, true, "no STAMP_NAME in request file");
    816820                    return false;
    817821                }
    818822
    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?
    820834                    return false;
    821835                }
    822836            } else {
    823 
    824837                return queueGetImageJob(options, uris, req_type);
    825838            }
    826839
    827840        } else {
    828             // this error is actually caught by parseMode but we might as well check
     841            // this error is actually caught by parseMode
    829842            fprintf(stderr, "unknown command mode found: %d\n", options->mode);
    830843            exit(1);
     
    848861
    849862    if (!options) {
     863        psErrorStackPrint(stderr, "unable to parse arguments");
    850864        return 1;
    851865    }
    852866
    853867    if (!readRequestTable(options)) {
     868        psErrorStackPrint(stderr, "unable to read request table");
    854869        return 1;
    855870    }
    856871
    857872    if (!setupDB(options)) {
     873        psErrorStackPrint(stderr, "unable to set up data base connection");
    858874        return 1;
    859875    }
     
    864880
    865881    if (!parseRequestTable(options)) {
    866         // psErrorStackPrint(stderr, "unable to parse request table");
     882        psErrorStackPrint(stderr, "unable to parse request table");
    867883        return 1;
    868884    }
Note: See TracChangeset for help on using the changeset viewer.