IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 20841 for trunk/ippTools/src


Ignore:
Timestamp:
Nov 25, 2008, 5:21:13 PM (17 years ago)
Author:
bills
Message:

Add the stage_id and cam_id to magicDSRun. This vastly reduces the
number of JOINs that we have to do

File:
1 edited

Legend:

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

    r20788 r20841  
    4141static bool setmagicDSRunState(pxConfig *config, psS64 magic_id, const char *state);
    4242static bool magicDSRunComplete(pxConfig *config);
     43static bool magicDSGetIDs(pxConfig *config, psString stage, psS64 magic_id, psS64 *stage_id, psS64 *cam_id);
    4344
    4445#ifdef notdef
     
    344345    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    345346
     347    psS64 stage_id, cam_id;
     348
     349    if (!magicDSGetIDs(config, stage, magic_id, &stage_id, &cam_id)) {
     350        psError(PS_ERR_UNKNOWN, false, "failed to get ids");
     351        return false;
     352    }
     353
    346354    magicDSRunRow *run = magicDSRunRowAlloc(
    347355            0,          // ID
     
    349357            "run",      // state
    350358            stage,
    351             outroot,   
     359            stage_id,
     360            cam_id,
     361            outroot,
    352362            recoveryroot,
    353363            re_place,
     
    517527}
    518528
     529static bool magicDSGetIDs(pxConfig *config, psString stage, psS64 magic_id, psS64 *stage_id, psS64 *cam_id)
     530{
     531    PS_ASSERT_PTR_NON_NULL(config, false);
     532    PS_ASSERT_PTR_NON_NULL(stage, false);
     533    PS_ASSERT_PTR_NON_NULL(stage_id, false);
     534    PS_ASSERT_PTR_NON_NULL(cam_id, false);
     535
     536    if (!strcmp(stage, "diff")) {
     537        // don't need these ids for diff stage
     538        *stage_id = 0;
     539        *cam_id = 0;
     540        return true;
     541    }
     542   
     543    int stageNum;
     544    if (!strcmp(stage, "raw")) {
     545        stageNum = 0;
     546    } else if (!strcmp(stage, "chip")) {
     547        stageNum = 1;
     548    } else if (!strcmp(stage, "warp")) {
     549        stageNum = 2;
     550    } else {
     551        psError(PXTOOLS_ERR_DATA, true, "%s is not a valid value for stage", stage);
     552        return false;
     553    }
     554
     555
     556    psString query = pxDataGet("magicdstool_getrunids.sql");
     557    if (!query) {
     558        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     559        return false;
     560    }
     561
     562    if (!p_psDBRunQuery(config->dbh, query, magic_id)) {
     563        psError(PS_ERR_UNKNOWN, false, "database error");
     564        psFree(query);
     565        return false;
     566    }
     567    psFree(query);
     568
     569    psArray *output = p_psDBFetchResult(config->dbh);
     570    if (!output) {
     571        psError(PS_ERR_UNKNOWN, false, "database error");
     572        return false;
     573    }
     574    if (!psArrayLength(output)) {
     575        psTrace("magicdstool", PS_LOG_INFO, "no rows found");
     576        psFree(output);
     577        return true;
     578    }
     579    if (psArrayLength(output) > 1) {
     580        psError(PS_ERR_UNKNOWN, true, "unexpected number of rows found %ld for magic_id %ld",
     581            psArrayLength(output), magic_id);
     582        return false;
     583    }
     584    psMetadata *row = output->data[0];
     585
     586    *cam_id = psMetadataLookupS64(NULL, row, "cam_id");
     587    if (stageNum == 0) {
     588        *stage_id = psMetadataLookupS64(NULL, row, "exp_id");
     589    } else if (stageNum == 1) {
     590        *stage_id = psMetadataLookupS64(NULL, row, "chip_id");
     591    } else if (stageNum == 2) {
     592        *stage_id = psMetadataLookupS64(NULL, row, "warp_id");
     593    }
     594
     595    return true;
     596}
     597
    519598static bool magicDSRunComplete(pxConfig *config)
    520599{
Note: See TracChangeset for help on using the changeset viewer.