IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14079


Ignore:
Timestamp:
Jul 9, 2007, 10:52:11 AM (19 years ago)
Author:
jhoblitt
Message:

factor startNewIteration() function out of updatedetrunMode()
more consistently handle det_id as a psS64

File:
1 edited

Legend:

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

    r14078 r14079  
    8282static detInputExpRow *rawDetrenTodetInputExpRow(rawExpRow *rawExp, psS64 det_id, psS32 iteration);
    8383static psArray *searchRawImfiles(pxConfig *config, psMetadata *where);
    84 static psS32 incrementIteration(pxConfig *config, const char *det_id);
    85 static bool setDetRunState(pxConfig *config, const char *det_id, const char *state);
     84static bool startNewIteration(pxConfig *config, psS64 det_id);
     85static psS32 incrementIteration(pxConfig *config, psS64 det_id);
     86static bool setDetRunState(pxConfig *config, psS64 det_id, const char *state);
    8687static bool isValidMode(pxConfig *config, const char *mode);
    8788
     
    58045805    if (state) {
    58055806        // set detRun.state to state
    5806         return setDetRunState(config, det_id, state);
     5807        return setDetRunState(config, (psS64)atoll(det_id), state);
    58075808    }
    58085809
    58095810    // else
    58105811    // -again
    5811 
    5812     // select detRun.det_id
    5813     // select detRun.iteration
    5814     // select detInputExp.exp_id
    5815     // select detResidExp.accept
    5816     // by:
    5817     // find the current iteration bassed on det_id
    5818     // find all exp_ids in the current det_id/iteration from detInputExp
    5819     // find all exp_ids in the current det_id/iteration from detResidExp
    5820     // compare the counts of exp_ids
    5821 
    5822     psString query = psStringCopy(
    5823         "SELECT DISTINCT"
    5824         "   detRun.det_id AS det_id,"
    5825         "   detRun.iteration,"
    5826         "   detInputExp.exp_id,"
    5827         "   detResidExp.accept"
    5828         " FROM detRun"
    5829         " JOIN detInputExp"
    5830         "   ON detRun.det_id = detInputExp.det_id"
    5831         "   AND detRun.iteration = detInputExp.iteration"
    5832         " JOIN detResidExp"
    5833         "   ON detRun.det_id = detResidExp.det_id"
    5834         "   AND detRun.iteration = detResidExp.iteration"
    5835         "   AND detInputExp.exp_id = detResidExp.exp_id"
    5836         " WHERE"
    5837         "   detRun.state = 'run'"
    5838         "   AND detRun.mode = 'master'"
    5839     );
     5812    if (!startNewIteration(config, (psS64)atoll(det_id))) {
     5813        psError(PS_ERR_UNKNOWN, false, "failed to start new iteration");
     5814        return false;
     5815    }
     5816
     5817    return true;
     5818}
     5819
     5820static bool startNewIteration(pxConfig *config, psS64 det_id)
     5821{
     5822    PS_ASSERT_PTR_NON_NULL(config, false);
     5823
     5824    psString query = pxDataGet("dettool_start_new_iteration.sql");
     5825    if (!query) {
     5826        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     5827        return false;
     5828    }
    58405829
    58415830    // XXX this query was not restricted by det_id, resulting
    58425831    // in an inconsistent UPDATE below.  I added this AND clause
    58435832    // though there may be a cleaner method (EAM 2006.10.08)
    5844     psStringAppend (
    5845         &query,
    5846         "  AND detRun.det_id = '%s'", det_id);
    5847 
    5848     psStringAppend (
    5849         &query,
    5850         " GROUP BY"
    5851         "   detRun.det_id,"
    5852         "   detRun.iteration,"
    5853         "   detInputExp.exp_id"
    5854         " HAVING"
    5855         "   COUNT(detResidExp.exp_id) = COUNT(detInputExp.exp_id)"
    5856         );
     5833    psStringAppend(&query, " WHERE detRun.det_id = %" PRId64 , det_id);
    58575834
    58585835    if (!p_psDBRunQuery(config->dbh, query)) {
     
    58695846    }
    58705847    if (!psArrayLength(output)) {
    5871         psTrace("dettool", PS_LOG_INFO, "no rows found");
     5848        psError(PS_ERR_UNKNOWN, false, "det_id %" PRId64 " not found", det_id);
    58725849        psFree(output);
    5873         return true;
     5850        return false;
    58745851    }
    58755852
     
    58985875    for (long i = 0; i < psArrayLength(output); i++) {
    58995876        psMetadata *row = output->data[i];
     5877        bool status = false;
    59005878        psS64 exp_id = psMetadataLookupS64(&status, row, "exp_id");
    59015879        if (!status) {
     
    59225900        if (!detInputExpInsert(
    59235901                    config->dbh,
    5924                     (psS64)atoll(det_id),
     5902                    det_id,
    59255903                    newIteration,
    59265904                    exp_id,
     
    60466024
    60476025    // up the detRuns iteration count
    6048     psS32 newIteration = incrementIteration(config, det_id);
     6026    psS32 newIteration = incrementIteration(config, (psS64)atoll(det_id));
    60496027    if (!newIteration) {
    60506028        // rollback
     
    65756553}
    65766554
    6577 static psS32 incrementIteration(pxConfig *config, const char *det_id)
     6555static psS32 incrementIteration(pxConfig *config, psS64 det_id)
    65786556{
    65796557    // this function returns zero on error
    65806558    PS_ASSERT_PTR_NON_NULL(config, 0);
    6581     PS_ASSERT_PTR_NON_NULL(det_id, 0);
    6582 
    6583     char *query = "UPDATE detRun SET iteration = iteration + 1 WHERE det_id = '%s'";
     6559
     6560    char *query = "UPDATE detRun SET iteration = iteration + 1 WHERE det_id = %" PRId64;
    65846561    if (!p_psDBRunQuery(config->dbh, query, det_id)) {
    65856562        psError(PS_ERR_UNKNOWN, false,
    6586                 "failed to increment iteration for det_id %s", det_id);
     6563                "failed to increment iteration for det_id %" PRId64, det_id);
    65876564        return 0;
    65886565    }
    65896566
    65906567    psMetadata *where = psMetadataAlloc();
    6591     if (!psMetadataAddS32(where, PS_LIST_TAIL, "det_id", 0, "==",
    6592                 (psS32)atoll(det_id))) {
     6568    if (!psMetadataAddS64(where, PS_LIST_TAIL, "det_id", 0, "==", det_id)) {
    65936569        psError(PS_ERR_UNKNOWN, false, "failed to add item det_id");
    65946570        psFree(where);
     
    66156591}
    66166592
    6617 static bool setDetRunState(pxConfig *config, const char *det_id, const char *state)
     6593static bool setDetRunState(pxConfig *config, psS64 det_id, const char *state)
    66186594{
    6619     PS_ASSERT_PTR_NON_NULL(det_id, false);
     6595    PS_ASSERT_PTR_NON_NULL(config, false);
    66206596    PS_ASSERT_PTR_NON_NULL(state, false);
    66216597
     
    66336609    }
    66346610
    6635     char *query = "UPDATE detRun SET state = '%s' WHERE det_id = '%s'";
     6611    char *query = "UPDATE detRun SET state = '%s' WHERE det_id = %" PRId64;
    66366612    if (!p_psDBRunQuery(config->dbh, query, state, det_id)) {
    66376613        psError(PS_ERR_UNKNOWN, false,
    6638                 "failed to change state for det_id %s", det_id);
     6614                "failed to change state for det_id %" PRId64, det_id);
    66396615        return false;
    66406616    }
Note: See TracChangeset for help on using the changeset viewer.