IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 16, 2007, 4:11:52 PM (19 years ago)
Author:
jhoblitt
Message:

add dettool -revertnormalizedimfile

File:
1 edited

Legend:

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

    r14242 r14243  
    6464static bool tonormalizeMode(pxConfig *config);
    6565static bool addnormalizedimfileMode(pxConfig *config);
     66static bool normalizedimfileMode(pxConfig *config);
     67static bool revertnormalizedimfileMode(pxConfig *config);
     68// normalizedexp
    6669static bool tonormalizedexpMode(pxConfig *config);
    6770static bool addnormalizedexpMode(pxConfig *config);
    6871static bool normalizedexpMode(pxConfig *config);
     72
     73// residimfile
    6974static bool toresidimfileMode(pxConfig *config);
    7075static bool addresidimfileMode(pxConfig *config);
    71 static bool normalizedimfileMode(pxConfig *config);
    7276static bool toresidexpMode(pxConfig *config);
    7377static bool residimfileMode(pxConfig *config);
     
    147151        MODECASE(DETTOOL_MODE_ADDNORMALIZEDIMFILE,addnormalizedimfileMode);
    148152        MODECASE(DETTOOL_MODE_NORMALIZEDIMFILE, normalizedimfileMode);
     153        MODECASE(DETTOOL_MODE_REVERTNORMALIZEDIMFILE, revertnormalizedimfileMode);
     154        // normalizedexp
    149155        MODECASE(DETTOOL_MODE_TONORMALIZEDEXP,  tonormalizedexpMode);
    150156        MODECASE(DETTOOL_MODE_ADDNORMALIZEDEXP, addnormalizedexpMode);
     
    39773983}
    39783984
     3985
     3986static bool normalizedimfileMode(pxConfig *config)
     3987{
     3988    PS_ASSERT_PTR_NON_NULL(config, false);
     3989
     3990    bool status = false;
     3991    psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
     3992    if (!status) {
     3993        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit");
     3994        return false;
     3995    }
     3996
     3997    bool faulted = psMetadataLookupU64(&status, config->args, "-faulted");
     3998    if (!status) {
     3999        psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -faulted");
     4000        return false;
     4001    }
     4002
     4003    psString query = psStringCopy(
     4004        "SELECT"
     4005        " detNormalizedImfile.*"
     4006        " FROM detNormalizedImfile"
     4007        " JOIN detRun"
     4008        "   USING(det_id, iteration)"
     4009        " WHERE"
     4010        "   detRun.state = 'run'"
     4011        "   AND detRun.mode = 'master'"
     4012    );
     4013
     4014    if (config->where) {
     4015        bool status;
     4016        int iteration = psMetadataLookupS32 (&status, config->where, "iteration");
     4017        if (status) {
     4018            psMetadataRemoveKey (config->where, "iteration");
     4019            psMetadataAddS32 (config->where, PS_LIST_TAIL, "iteration", 0, "==", iteration);
     4020        }
     4021        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "detNormalizedImfile");
     4022        psStringAppend(&query, " AND %s", whereClause);
     4023        psFree(whereClause);
     4024    }
     4025
     4026    if (faulted) {
     4027        // list only faulted rows
     4028        psStringAppend(&query, " %s", "AND detNormalizedImfile.fault != 0");
     4029    } else {
     4030        // don't list faulted rows
     4031        psStringAppend(&query, " %s", "AND detNormalizedImfile.fault = 0");
     4032    }
     4033
     4034    // treat limit == 0 as "no limit"
     4035    if (limit) {
     4036        psString limitString = psDBGenerateLimitSQL(limit);
     4037        psStringAppend(&query, " %s", limitString);
     4038        psFree(limitString);
     4039    }
     4040
     4041    if (!p_psDBRunQuery(config->dbh, query)) {
     4042        psError(PS_ERR_UNKNOWN, false, "database error");
     4043        psFree(query);
     4044        return false;
     4045    }
     4046    psFree(query);
     4047
     4048    psArray *output = p_psDBFetchResult(config->dbh);
     4049    if (!output) {
     4050        psError(PS_ERR_UNKNOWN, false, "database error");
     4051        return false;
     4052    }
     4053    if (!psArrayLength(output)) {
     4054        psTrace("dettool", PS_LOG_INFO, "no rows found");
     4055        psFree(output);
     4056        return true;
     4057    }
     4058
     4059    bool simple = false;
     4060    {
     4061        bool status = false;
     4062        simple = psMetadataLookupBool(&status, config->args, "-simple");
     4063        if (!status) {
     4064            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
     4065            return false;
     4066        }
     4067    }
     4068
     4069    // negative simple so the default is true
     4070    if (!ippdbPrintMetadatas(stdout, output, "detNormalizedImfile", !simple)) {
     4071        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     4072        psFree(output);
     4073        return false;
     4074    }
     4075
     4076    psFree(output);
     4077
     4078    return true;
     4079}
     4080
     4081
     4082static bool revertnormalizedimfileMode(pxConfig *config)
     4083{
     4084    PS_ASSERT_PTR_NON_NULL(config, false);
     4085
     4086    psString query = pxDataGet("dettool_revertnormalizedimfile.sql");
     4087    if (!query) {
     4088        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     4089        return false;
     4090    }
     4091
     4092    if (config->where) {
     4093        psString whereClause = psDBGenerateWhereConditionSQL(config->where, "detNormalizedImfile");
     4094        psStringAppend(&query, " AND %s", whereClause);
     4095        psFree(whereClause);
     4096    }
     4097
     4098    if (!p_psDBRunQuery(config->dbh, query)) {
     4099        psError(PS_ERR_UNKNOWN, false, "database error");
     4100        psFree(query);
     4101        return false;
     4102    }
     4103    psFree(query);
     4104
     4105    if (psDBAffectedRows(config->dbh) < 1) {
     4106        psError(PS_ERR_UNKNOWN, false, "should have affected atleast 1 row");
     4107        return false;
     4108    }
     4109
     4110    return true;
     4111}
     4112
     4113
    39794114static bool tonormalizedexpMode(pxConfig *config)
    39804115{
     
    44644599}
    44654600
    4466 static bool normalizedimfileMode(pxConfig *config)
    4467 {
    4468     PS_ASSERT_PTR_NON_NULL(config, false);
    4469 
    4470     bool status = false;
    4471     psU64 limit = psMetadataLookupU64(&status, config->args, "-limit");
    4472     if (!status) {
    4473         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -limit");
    4474         return false;
    4475     }
    4476 
    4477     bool faulted = psMetadataLookupU64(&status, config->args, "-faulted");
    4478     if (!status) {
    4479         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -faulted");
    4480         return false;
    4481     }
    4482 
    4483     psString query = psStringCopy(
    4484         "SELECT"
    4485         " detNormalizedImfile.*"
    4486         " FROM detNormalizedImfile"
    4487         " JOIN detRun"
    4488         "   USING(det_id, iteration)"
    4489         " WHERE"
    4490         "   detRun.state = 'run'"
    4491         "   AND detRun.mode = 'master'"
    4492     );
    4493 
    4494     if (config->where) {
    4495         bool status;
    4496         int iteration = psMetadataLookupS32 (&status, config->where, "iteration");
    4497         if (status) {
    4498             psMetadataRemoveKey (config->where, "iteration");
    4499             psMetadataAddS32 (config->where, PS_LIST_TAIL, "iteration", 0, "==", iteration);
    4500         }
    4501         psString whereClause = psDBGenerateWhereConditionSQL(config->where, "detNormalizedImfile");
    4502         psStringAppend(&query, " AND %s", whereClause);
    4503         psFree(whereClause);
    4504     }
    4505 
    4506     if (faulted) {
    4507         // list only faulted rows
    4508         psStringAppend(&query, " %s", "AND detNormalizedImfile.fault != 0");
    4509     } else {
    4510         // don't list faulted rows
    4511         psStringAppend(&query, " %s", "AND detNormalizedImfile.fault = 0");
    4512     }
    4513 
    4514     // treat limit == 0 as "no limit"
    4515     if (limit) {
    4516         psString limitString = psDBGenerateLimitSQL(limit);
    4517         psStringAppend(&query, " %s", limitString);
    4518         psFree(limitString);
    4519     }
    4520 
    4521     if (!p_psDBRunQuery(config->dbh, query)) {
    4522         psError(PS_ERR_UNKNOWN, false, "database error");
    4523         psFree(query);
    4524         return false;
    4525     }
    4526     psFree(query);
    4527 
    4528     psArray *output = p_psDBFetchResult(config->dbh);
    4529     if (!output) {
    4530         psError(PS_ERR_UNKNOWN, false, "database error");
    4531         return false;
    4532     }
    4533     if (!psArrayLength(output)) {
    4534         psTrace("dettool", PS_LOG_INFO, "no rows found");
    4535         psFree(output);
    4536         return true;
    4537     }
    4538 
    4539     bool simple = false;
    4540     {
    4541         bool status = false;
    4542         simple = psMetadataLookupBool(&status, config->args, "-simple");
    4543         if (!status) {
    4544             psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    4545             return false;
    4546         }
    4547     }
    4548 
    4549     // negative simple so the default is true
    4550     if (!ippdbPrintMetadatas(stdout, output, "detNormalizedImfile", !simple)) {
    4551         psError(PS_ERR_UNKNOWN, false, "failed to print array");
    4552         psFree(output);
    4553         return false;
    4554     }
    4555 
    4556     psFree(output);
    4557 
    4558     return true;
    4559 }
    45604601
    45614602static bool addresidimfileMode(pxConfig *config)
Note: See TracChangeset for help on using the changeset viewer.