IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 17, 2022, 3:30:24 PM (4 years ago)
Author:
eugene
Message:

add fpcamtool support

Location:
branches/eam_branches/ipp-20220316/ippTools/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20220316/ippTools/src

    • Property svn:ignore
      •  

        old new  
        4949fftool
        5050remotetool
        51 
         51fpcamtool
  • branches/eam_branches/ipp-20220316/ippTools/src/fpcamtool.c

    r42197 r42207  
    3333static bool updaterunMode(pxConfig *config);
    3434static bool pendingexpMode(pxConfig *config);
     35static bool inputchipsMode(pxConfig *config);
     36static bool inputastromMode(pxConfig *config);
    3537static bool addprocessedexpMode(pxConfig *config);
    3638static bool processedexpMode(pxConfig *config);
    3739static bool revertprocessedexpMode(pxConfig *config);
    3840static bool updateprocessedexpMode(pxConfig *config);
    39 static bool blockMode(pxConfig *config);
    40 static bool maskedMode(pxConfig *config);
    41 static bool unblockMode(pxConfig *config);
    4241
    4342# define MODECASE(caseName, func) case caseName: if (!func(config)) { goto FAIL; } break;
     
    5756        MODECASE(FPCAMTOOL_MODE_UPDATERUN,            updaterunMode);
    5857        MODECASE(FPCAMTOOL_MODE_PENDINGEXP,           pendingexpMode);
     58        MODECASE(FPCAMTOOL_MODE_INPUTCHIPS,           inputchipsMode);
     59        MODECASE(FPCAMTOOL_MODE_INPUTASTROM,          inputastromMode);
    5960        MODECASE(FPCAMTOOL_MODE_ADDPROCESSEDEXP,      addprocessedexpMode);
    6061        MODECASE(FPCAMTOOL_MODE_PROCESSEDEXP,         processedexpMode);
    6162        MODECASE(FPCAMTOOL_MODE_REVERTPROCESSEDEXP,   revertprocessedexpMode);
    6263        MODECASE(FPCAMTOOL_MODE_UPDATEPROCESSEDEXP,   updateprocessedexpMode);
    63         MODECASE(FPCAMTOOL_MODE_BLOCK,                blockMode);
    64         MODECASE(FPCAMTOOL_MODE_MASKED,               maskedMode);
    65         MODECASE(FPCAMTOOL_MODE_UNBLOCK,              unblockMode);
    6664        default:
    6765            psAbort("invalid option (this should not happen)");
     
    365363}
    366364
     365static bool inputchipsMode(pxConfig *config)
     366{
     367    PS_ASSERT_PTR_NON_NULL(config, false);
     368
     369    PXOPT_LOOKUP_S64(fpcam_id, config->args, "-fpcam_id", true, false);
     370    PXOPT_LOOKUP_U64(limit, config->args,    "-limit", false, false);
     371    PXOPT_LOOKUP_BOOL(simple, config->args,  "-simple", false);
     372
     373    psMetadata *where = psMetadataAlloc();
     374    PXOPT_COPY_S64(config->args, where, "-fpcam_id",  "fpcamRun.fpcam_id", "==");
     375    PXOPT_COPY_STR(config->args, where, "-class_id", "fpcamRun.reduction", "==");
     376
     377    psString query = pxDataGet("fpcamtool_inputchips.sql");
     378    if (!query) {
     379        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement for %d", (int) fpcam_id);
     380        return false;
     381    }
     382
     383    // use psDBGenerateWhereSQL because the SQL yields an intermediate table
     384    if (!psListLength(where->list)) {
     385        psError(PXTOOLS_ERR_SYS, false, "unrestricted query not allowed (-fpcam_id required)");
     386        return false;
     387    }
     388
     389    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     390    psStringAppend(&query, " WHERE %s", whereClause);
     391    psFree(whereClause);
     392    psFree(where);
     393
     394    // treat limit == 0 as "no limit"
     395    if (limit) {
     396        psString limitString = psDBGenerateLimitSQL(limit);
     397        psStringAppend(&query, " %s", limitString);
     398        psFree(limitString);
     399    }
     400
     401    if (!p_psDBRunQuery(config->dbh, query)) {
     402        psError(PS_ERR_UNKNOWN, false, "database error");
     403        psFree(query);
     404        return false;
     405    }
     406    psFree(query);
     407
     408    psArray *output = p_psDBFetchResult(config->dbh);
     409    if (!output) {
     410        psError(PS_ERR_UNKNOWN, false, "database error");
     411        return false;
     412    }
     413    if (!psArrayLength(output)) {
     414        psTrace("fpcamtool", PS_LOG_INFO, "no rows found");
     415        psFree(output);
     416        return true;
     417    }
     418
     419    // negate simple so the default is true
     420    if (!ippdbPrintMetadatas(stdout, output, "fpcamInputChips", !simple)) {
     421        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     422        psFree(output);
     423        return false;
     424    }
     425
     426    psFree(output);
     427
     428    return true;
     429}
     430
     431static bool inputastromMode(pxConfig *config)
     432{
     433    PS_ASSERT_PTR_NON_NULL(config, false);
     434
     435    PXOPT_LOOKUP_S64(fpcam_id, config->args, "-fpcam_id", true, false);
     436    PXOPT_LOOKUP_U64(limit, config->args,    "-limit", false, false);
     437    PXOPT_LOOKUP_BOOL(simple, config->args,  "-simple", false);
     438
     439    psMetadata *where = psMetadataAlloc();
     440    PXOPT_COPY_S64(config->args, where, "-fpcam_id",  "fpcamRun.fpcam_id", "==");
     441
     442    psString query = pxDataGet("fpcamtool_inputastrom.sql");
     443    if (!query) {
     444        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement for %d", (int) fpcam_id);
     445        return false;
     446    }
     447
     448    // use psDBGenerateWhereSQL because the SQL yields an intermediate table
     449    if (!psListLength(where->list)) {
     450        psError(PXTOOLS_ERR_SYS, false, "unrestricted query not allowed (-fpcam_id required)");
     451        return false;
     452    }
     453
     454    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     455    psStringAppend(&query, " WHERE %s", whereClause);
     456    psFree(whereClause);
     457    psFree(where);
     458
     459    // treat limit == 0 as "no limit"
     460    if (limit) {
     461        psString limitString = psDBGenerateLimitSQL(limit);
     462        psStringAppend(&query, " %s", limitString);
     463        psFree(limitString);
     464    }
     465
     466    if (!p_psDBRunQuery(config->dbh, query)) {
     467        psError(PS_ERR_UNKNOWN, false, "database error");
     468        psFree(query);
     469        return false;
     470    }
     471    psFree(query);
     472
     473    psArray *output = p_psDBFetchResult(config->dbh);
     474    if (!output) {
     475        psError(PS_ERR_UNKNOWN, false, "database error");
     476        return false;
     477    }
     478    if (!psArrayLength(output)) {
     479        psTrace("fpcamtool", PS_LOG_INFO, "no rows found");
     480        psFree(output);
     481        return true;
     482    }
     483
     484    // negate simple so the default is true
     485    if (!ippdbPrintMetadatas(stdout, output, "fpcamInputAstrom", !simple)) {
     486        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     487        psFree(output);
     488        return false;
     489    }
     490
     491    psFree(output);
     492
     493    return true;
     494}
     495
    367496static bool addprocessedexpMode(pxConfig *config)
    368497{
     
    392521    PXOPT_LOOKUP_F32(deteff_err, config->args,     "-deteff_inst_err", false, false);
    393522
    394     psF32 deteff = NAN;
     523    psF32 deteff_obs = NAN;
    395524    psF32 deteff_uq = NAN;
    396525    psF32 deteff_lq = NAN;
    397526    if (isfinite(zpt_obs)) {
    398527        if (isfinite(deteff_inst)) {
    399             deteff = deteff_inst + zpt_obs;
     528            deteff_obs = deteff_inst + zpt_obs;
    400529        }
    401530        if (isfinite(deteff_inst_uq)) {
     
    437566        NULL, // XXX : this should be epoch
    438567        software_ver,
    439         deteff,
     568        deteff_obs,
    440569        deteff_err,
    441570        deteff_lq,
     
    700829}
    701830
    702 static bool blockMode(pxConfig *config)
    703 {
    704     PS_ASSERT_PTR_NON_NULL(config, false);
    705 
    706     PXOPT_LOOKUP_STR(label, config->args, "-label", true, false);
    707 
    708     if (!fpcamMaskInsert(config->dbh, label)) {
    709         psError(PS_ERR_UNKNOWN, false, "database error");
    710         return false;
    711     }
    712     return true;
    713 }
    714 
    715 static bool maskedMode(pxConfig *config)
    716 {
    717     PS_ASSERT_PTR_NON_NULL(config, false);
    718 
    719     PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    720 
    721     psString query = psStringCopy("SELECT * FROM fpcamMask");
    722 
    723     if (!p_psDBRunQuery(config->dbh, query)) {
    724         psError(PS_ERR_UNKNOWN, false, "database error");
    725         psFree(query);
    726         return false;
    727     }
    728     psFree(query);
    729 
    730     psArray *output = p_psDBFetchResult(config->dbh);
    731     if (!output) {
    732         psError(PS_ERR_UNKNOWN, false, "database error");
    733         return false;
    734     }
    735     if (!psArrayLength(output)) {
    736         psTrace("fpcamtool", PS_LOG_INFO, "no rows found");
    737         psFree(output);
    738         return true;
    739     }
    740 
    741     // negative simple so the default is true
    742     if (!ippdbPrintMetadatas(stdout, output, "fpcamMask", !simple)) {
    743         psError(PS_ERR_UNKNOWN, false, "failed to print array");
    744         psFree(output);
    745         return false;
    746     }
    747 
    748     psFree(output);
    749     return true;
    750 }
    751 
    752 static bool unblockMode(pxConfig *config)
    753 {
    754     PS_ASSERT_PTR_NON_NULL(config, false);
    755 
    756     PXOPT_LOOKUP_STR(label, config->args, "-label", true, false);
    757 
    758     char *query = "DELETE FROM fpcamMask WHERE label = '%s'";
    759 
    760     if (!p_psDBRunQueryF(config->dbh, query, label)) {
    761         psError(PS_ERR_UNKNOWN, false, "database error");
    762         return false;
    763     }
    764 
    765     return true;
    766 }
    767 
Note: See TracChangeset for help on using the changeset viewer.