IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 2, 2006, 5:27:04 PM (20 years ago)
Author:
jhoblitt
Message:

add -normalize search options
impliment -addnormalizedexp

File:
1 edited

Legend:

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

    r9123 r9137  
    25832583    PS_ASSERT_PTR_NON_NULL(config, false);
    25842584 
    2585     // select detProcessedImfile.det_id
    2586     // select detRun.iteration
    2587     // select detRun.det_type
    2588     // select detProcessedImfile.exp_tag
    2589     // by:
    2590     // find the current iteration bassed on det_id
    2591     // find all exp_tags in the current det_id/iteration from detInputExp
    2592     // find all rawImfiles in the current exp_tags
    2593     // compare to detProcessedImfiles by det_id/exp_tag
    2594     // found how many imfile there are in each class_id
    2595     // and:
    2596     // det_id is not in detProcessedExp;
    2597     // iteration is not in detProcessedExp;
    2598 
    25992585    psString query = psStringCopy(
    26002586        " SELECT DISTINCT"
     
    26792665    psFree(output);
    26802666
    2681 
    26822667    return true;
    26832668}
     
    26862671{
    26872672    PS_ASSERT_PTR_NON_NULL(config, false);
     2673 
     2674    // det_id, recip, -bg, -bg_stdev, & -bg_mean_stdev
     2675    // are required
     2676    bool status = false;
     2677    psString det_id = psMetadataLookupStr(&status, config->args, "-det_id");
     2678    if (!status) {
     2679        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -det_id");
     2680        return false;
     2681    }
     2682    if (!det_id) {
     2683        psError(PS_ERR_UNKNOWN, true, "-det_id is required");
     2684        return false;
     2685    }
     2686    psString recipe = psMetadataLookupStr(&status, config->args, "-recip");
     2687    if (!status) {
     2688        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -recip");
     2689        return false;
     2690    }
     2691    if (!recipe) {
     2692        psError(PS_ERR_UNKNOWN, true, "-recip is required");
     2693        return false;
     2694    }
     2695    psF64 bg = psMetadataLookupF64(&status, config->args, "-bg");
     2696    if (!status) {
     2697        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -bg");
     2698        return false;
     2699    }
     2700    if (isnan(bg)) {
     2701        psError(PS_ERR_UNKNOWN, true, "-bg is required");
     2702        return false;
     2703    }
     2704    psF64 bg_stdev = psMetadataLookupF64(&status, config->args, "-bg_stdev");
     2705    if (!status) {
     2706        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -bg_stdev");
     2707        return false;
     2708    }
     2709    if (isnan(bg_stdev)) {
     2710        psError(PS_ERR_UNKNOWN, true, "-bg_stdev is required");
     2711        return false;
     2712    }
     2713    psF64 bg_mean_stdev = psMetadataLookupF64(&status, config->args, "-bg_mean_stdev");
     2714    if (!status) {
     2715        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -bg_mean_stdev");
     2716        return false;
     2717    }
     2718    if (isnan(bg_mean_stdev)) {
     2719        psError(PS_ERR_UNKNOWN, true, "-bg_mean_stdev is required");
     2720        return false;
     2721    }
     2722    // iteration has a default value
     2723    psS32 iteration = psMetadataLookupS32(&status, config->args, "-iteration");
     2724    if (!status) {
     2725        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -iteration");        return false;
     2726    }
     2727    // optional
     2728    psString b1_uri = psMetadataLookupStr(&status, config->args, "-b1_uri");
     2729    if (!status) {
     2730        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -b1_uri");
     2731        return false;
     2732    }
     2733    psString b2_uri = psMetadataLookupStr(&status, config->args, "-b2_uri");
     2734    if (!status) {
     2735        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -b2_uri");
     2736        return false;
     2737    }
     2738
     2739    psString query = psStringCopy(
     2740        " SELECT DISTINCT"
     2741        "    detRun.position as det_id,"
     2742        "    detRun.iteration,"
     2743        "    detRun.det_type,"
     2744        "    rawDetrendExp.camera,"
     2745        "    rawDetrendExp.telescope,"
     2746        "    rawDetrendExp.exp_type,"
     2747        "    rawDetrendExp.imfiles"
     2748        " FROM detRun"
     2749        " JOIN detInputExp"
     2750        "    ON detRun.position = detInputExp.det_id"
     2751        "    AND detRun.iteration = detInputExp.iteration"
     2752        " JOIN rawDetrendExp"
     2753        "    ON detInputExp.exp_tag = rawDetrendExp.exp_tag"
     2754        " JOIN detNormalizedImfile"
     2755        "    ON detInputExp.det_id = detNormalizedImfile.det_id"
     2756        "    AND detInputExp.iteration = detNormalizedImfile.iteration"
     2757        " LEFT JOIN rawImfile"
     2758        "    ON detInputExp.exp_tag = rawImfile.exp_tag"
     2759        "    AND detNormalizedImfile.class_id = rawImfile.class_id"
     2760        " LEFT JOIN detNormalizedExp"
     2761        "    ON detInputExp.det_id = detNormalizedExp.det_id"
     2762        "    AND detInputExp.iteration = detNormalizedExp.iteration"
     2763        " WHERE"
     2764        "    detNormalizedExp.det_id IS NULL"
     2765        "    AND detNormalizedExp.iteration IS NULL"
     2766        "    AND detInputExp.include = 1"
     2767        "    AND detRun.position = %s"
     2768        "    AND detNormalizedImfile.iteration = %d"
     2769        " GROUP BY"
     2770        "    detNormalizedImfile.iteration,"
     2771        "    detRun.position"
     2772        " HAVING"
     2773        "    COUNT(detNormalizedImfile.class_id) = COUNT(rawImfile.class_id)"
     2774        );
     2775
     2776    if (!p_psDBRunQuery(config->dbh, query, det_id, iteration)) {
     2777        psError(PS_ERR_UNKNOWN, false, "database error");
     2778        psFree(query);
     2779        return false;
     2780    }
     2781    psFree(query);
     2782
     2783    psArray *output = p_psDBFetchResult(config->dbh);
     2784    if (!output) {
     2785        psError(PS_ERR_UNKNOWN, false, "database error");
     2786        psFree(query);
     2787    }
     2788    if (!psArrayLength(output)) {
     2789        // XXX check psError here
     2790        psError(PS_ERR_UNKNOWN, false, "no complete detNormalizedImfile exp found");
     2791        psFree(output);
     2792        return true;
     2793    }
     2794
     2795    // create a new detProcessedImfile object
     2796    detNormalizedExpRow *detRow = detNormalizedExpRowAlloc(
     2797        (psS32)atol(det_id),
     2798        iteration,
     2799        recipe,
     2800        bg,
     2801        bg_stdev,
     2802        bg_mean_stdev,
     2803        b1_uri,
     2804        b2_uri
     2805    );
     2806
     2807    // insert the new row into the detProcessedImfile table
     2808    if (!detNormalizedExpInsertObject(config->dbh, detRow)) {
     2809        psError(PS_ERR_UNKNOWN, false, "database error");
     2810        psFree(detRow);
     2811        return false;
     2812    }
     2813
     2814    psFree(detRow);
    26882815
    26892816    return true;
Note: See TracChangeset for help on using the changeset viewer.