IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 27, 2008, 11:49:07 AM (18 years ago)
Author:
eugene
Message:

cleanup & fix definebydetrun

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/dettool.c

    r19621 r19771  
    722722   
    723723    // XXX this mode is not well-tested: probably need to specify iteration here
    724     // XXX pass the supplied det_id and iteration as ref_det_id, or get from command line?
    725724    PXOPT_LOOKUP_S64(det_id, config->args, "-det_id", true, false); // required
    726725    PXOPT_LOOKUP_STR(det_type, config->args, "-set_det_type", false, false); // optional
     726
    727727    PXOPT_LOOKUP_STR(mode, config->args, "-set_mode", false, false); // optional
     728    if (!isValidMode(config, mode)) {
     729        psError(PS_ERR_UNKNOWN, false, "invalid mode");
     730        return false;
     731    }
     732
     733    // get -ref_det_id and -ref_iter : required for 'verify' mode / disallowed otherwise
     734    PXOPT_LOOKUP_S64(ref_det_id, config->args, "-ref_det_id", false, false);
     735    PXOPT_LOOKUP_S32(ref_iter, config->args, "-ref_iter", false, false);
     736    if (!strncmp(mode, "verify", 7) && ((ref_det_id == 0) || (ref_iter == -1))) {
     737        psError(PS_ERR_UNKNOWN, false, "verify mode requires both -ref_det_id and -ref_iter");
     738        return false;
     739    }
     740    if (strncmp(mode, "verify", 7) && ((ref_det_id != 0) || (ref_iter != -1))) {
     741        psError(PS_ERR_UNKNOWN, false, "master mode cannot have -ref_det_id or -ref_iter set");
     742        return false;
     743    }
     744
     745    // the new detRun may have different values for these limits:
    728746    PXOPT_LOOKUP_STR(exp_type, config->args, "-set_exp_type", false, false);
    729747    PXOPT_LOOKUP_STR(filelevel, config->args, "-set_filelevel", false, false);
     
    742760    PXOPT_LOOKUP_TIME(registered, config->args, "-set_registered", false, false);
    743761    PXOPT_LOOKUP_TIME(time_begin, config->args, "-set_time_begin", false, false);
    744     PXOPT_LOOKUP_TIME(time_end, config->args, "-set_end", false, false);
    745     PXOPT_LOOKUP_TIME(use_begin, config->args, "-use_begin", false, false);
    746     PXOPT_LOOKUP_TIME(use_end, config->args, "-use_end", false, false);
     762    PXOPT_LOOKUP_TIME(time_end, config->args, "-set_time_end", false, false);
     763    PXOPT_LOOKUP_TIME(use_begin, config->args, "-set_use_begin", false, false);
     764    PXOPT_LOOKUP_TIME(use_end, config->args, "-set_use_end", false, false);
    747765    PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false);
    748766    PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false);
    749767    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false); // optional
    750768
    751     // check mode
    752     if (mode && !isValidMode(config, mode)) {
    753         psError(PS_ERR_UNKNOWN, false, "invalud mode");
    754         return false;
    755     }
     769    // reference iteration to use (otherwise last iteration)
     770    PXOPT_LOOKUP_S32(iteration, config->args, "-iteration", false, false); // for specifying input exp restrictions
    756771
    757772    // lookup the detRun that we will be basing this one on
     
    764779    }
    765780    if (!detRuns) {
    766         psError(PS_ERR_UNKNOWN, false, "database error");
    767         return false;
    768     }
     781        psError(PS_ERR_UNKNOWN, false, "database error: no matching det_id found");
     782        return false;
     783    }
     784
    769785    // sanity check the result... we should have only found one det_id
    770786    if (psArrayLength(detRuns) != 1) {
    771787        psAbort("found more then one detRun matching det_id %" PRId64 " (this should not happen)", det_id);
    772         return false;                   // unreachable
    773788    }
    774789
    775790    // pull the detRun object out the result array
    776     // XXX need to assign or re-assign the ref_det_id and ref_iter values
    777791    detRunRow *detRun = psMemIncrRefCounter(detRuns->data[0]);
    778792
     
    780794    psFree(detRuns);
    781795
    782     // set the det_id to 0/NULL so the database can assign it
    783     detRun->det_id = 0;
    784 
    785     // reset the iteration to 0
    786     detRun->iteration = 0;
     796    if (iteration < 0) {
     797        iteration = detRun->iteration;
     798    }
     799
     800    detRun->det_id = 0; // set the det_id to 0/NULL so the database can assign it
     801    detRun->iteration = 0; // reset the iteration to 0
     802
     803    detRun->ref_det_id = ref_det_id; // not inherited: may only be set for 'verify' run
     804    detRun->ref_iter = ref_iter;  // not inherited: may only be set for 'verify' run
    787805
    788806    // reset the state to "run"
     
    790808    detRun->state = psStringCopy("run");
    791809
    792     // walk through the optional values and update the detRun as required
     810    // walk through the optional values and update the detRun as required.  Otherwise, these
     811    // value are inherited from the specified detRun
    793812    if (det_type) {
    794813        psFree(detRun->det_type);
     
    898917    // create a metadata to restrict detInputExp's be in in the specified range
    899918
    900     psMetadata *time_filter = psMetadataAlloc();
    901 
    902     // XXX: possible mem leak: PXOPT_COPY* will free time_filter but NOTHING
    903     // that has previously been allocated
    904     PXOPT_COPY_TIME(config->args, time_filter, "-set_input_begin", "dateobs", ">=");
    905     PXOPT_COPY_TIME(config->args, time_filter, "-set_input_end", "dateobs", "<");
     919    psMetadata *input_filter = psMetadataAlloc();
     920
     921    // additional restriction on the detInputExp's to be selected
     922    PXOPT_COPY_TIME(config->args, input_filter, "-set_input_begin", "dateobs", ">=");
     923    PXOPT_COPY_TIME(config->args, input_filter, "-set_input_end", "dateobs", "<");
     924
     925    PXOPT_LOOKUP_BOOL(only_accepted, config->args, "-only_accepted", false); // optional
    906926
    907927    // start a transaction so we don't end up with childlessed det_ids
    908928    if (!psDBTransaction(config->dbh)) {
    909929        psError(PS_ERR_UNKNOWN, false, "database error");
    910         psFree(time_filter);
     930        psFree(input_filter);
    911931        psFree(detRun);
    912932        return false;
     
    919939            psError(PS_ERR_UNKNOWN, false, "database error");
    920940        }
    921         psFree(time_filter);
     941        psFree(input_filter);
    922942        psFree(detRun);
    923943        return false;
     
    934954    }
    935955
    936     if (time_filter->list->n) {
    937         psString whereClause = psDBGenerateWhereConditionSQL(time_filter, "rawExp");
     956    if (input_filter->list->n) {
     957        psString whereClause = psDBGenerateWhereConditionSQL(input_filter, "rawExp");
    938958        psStringAppend(&query, " AND %s", whereClause);
    939959        psFree(whereClause);
    940960    }
    941     psFree(time_filter);
    942 
    943     if (!p_psDBRunQuery(config->dbh, query, (long long) newDet_id, (long long) det_id)) {
     961    psFree(input_filter);
     962
     963    if (only_accepted) {
     964        psString whereClause = NULL;
     965        psStringAppend(&whereClause, " AND accept = 1");
     966        psStringAppend(&query, " AND %s", whereClause);
     967        psFree(whereClause);
     968    }
     969
     970    if (!p_psDBRunQuery(config->dbh, query, (long long) newDet_id, (long long) det_id, iteration)) {
    944971        psError(PS_ERR_UNKNOWN, false, "database error");
    945972        psFree(query);
Note: See TracChangeset for help on using the changeset viewer.