IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 22, 2013, 4:11:19 PM (13 years ago)
Author:
bills
Message:

add mode stacktool -summary which lists stackSummary objects that match certain search parameters

File:
1 edited

Legend:

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

    r35888 r36009  
    4444static bool tosummaryMode(pxConfig *config);
    4545static bool addsummaryMode(pxConfig *config);
     46static bool summaryMode(pxConfig *config);
    4647static bool pendingcleanuprunMode(pxConfig *config);
    4748static bool pendingcleanupskyfileMode(pxConfig *config);
     
    8485        MODECASE(STACKTOOL_MODE_TOSUMMARY,             tosummaryMode);
    8586        MODECASE(STACKTOOL_MODE_ADDSUMMARY,            addsummaryMode);
     87        MODECASE(STACKTOOL_MODE_SUMMARY,               summaryMode);
    8688        MODECASE(STACKTOOL_MODE_PENDINGCLEANUPRUN,     pendingcleanuprunMode);
    8789        MODECASE(STACKTOOL_MODE_PENDINGCLEANUPSKYFILE, pendingcleanupskyfileMode);
     
    15681570}
    15691571
     1572static bool summaryMode(pxConfig *config)
     1573{
     1574    PS_ASSERT_PTR_NON_NULL(config, false);
     1575
     1576    psMetadata *where = psMetadataAlloc();
     1577    PXOPT_COPY_S64(config->args, where, "-sass_id", "stackSummary.sass_id", "==");
     1578    PXOPT_COPY_STR(config->args, where, "-projection_cell", "stackAssociation.projection_cell", "==");
     1579    PXOPT_COPY_STR(config->args, where, "-tess_id", "stackAssociation.tess_id", "LIKE");
     1580    PXOPT_COPY_STR(config->args, where, "-filter", "stackAssociation.filter", "LIKE");
     1581    PXOPT_COPY_S64(config->args, where, "-stack_id", "stackSumSkyfile.stack_id", "==");
     1582    pxAddLabelSearchArgs(config, where, "-data_group", "stackAssociation.data_group", "LIKE");
     1583    PXOPT_COPY_STR(config->args, where, "-skycell_id", "stackRun.skycell_id", "LIKE");
     1584//    PXOPT_COPY_STR(config->args, where, "-state", "stackRun.state", "==");
     1585    pxAddLabelSearchArgs(config, where, "-label", "stackRun.label", "LIKE");
     1586//    PXOPT_COPY_S16(config->args, where, "-fault", "stackSumSkyfile.fault", "==");
     1587//    PXOPT_COPY_F64(config->args, where, "-mjd_obs_begin", "stackSumSkyfile.mjd_obs", ">=");
     1588//    PXOPT_COPY_F64(config->args, where, "-mjd_obs_end", "stackSumSkyfile.mjd_obs", "<=");
     1589//    PXOPT_COPY_S16(config->args, where, "-background_model","stackSumSkyfile.background_model", "==");
     1590
     1591//    PXOPT_LOOKUP_BOOL(all, config->args, "-all", false);
     1592
     1593    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     1594    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1595
     1596    psString query = pxDataGet("stacktool_summary.sql");
     1597    if (!query) {
     1598        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     1599        return false;
     1600    }
     1601
     1602    if (psListLength(where->list)) {
     1603        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1604        psStringAppend(&query, " WHERE %s", whereClause);
     1605        psFree(whereClause);
     1606    } else {
     1607        psError(PXTOOLS_ERR_CONFIG, true, "search parameters are required");
     1608        return false;
     1609    }
     1610
     1611    psFree(where);
     1612
     1613    // treat limit == 0 as "no limit"
     1614    if (limit) {
     1615        psString limitString = psDBGenerateLimitSQL(limit);
     1616        psStringAppend(&query, " %s", limitString);
     1617        psFree(limitString);
     1618    }
     1619
     1620    if (!p_psDBRunQuery(config->dbh, query)) {
     1621        psError(PS_ERR_UNKNOWN, false, "database error");
     1622        psFree(query);
     1623        return false;
     1624    }
     1625    psFree(query);
     1626
     1627    psArray *output = p_psDBFetchResult(config->dbh);
     1628    if (!output) {
     1629        psErrorCode err = psErrorCodeLast();
     1630        switch (err) {
     1631            case PS_ERR_DB_CLIENT:
     1632                psError(PXTOOLS_ERR_SYS, false, "database error");
     1633            case PS_ERR_DB_SERVER:
     1634                psError(PXTOOLS_ERR_PROG, false, "database error");
     1635            default:
     1636                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     1637        }
     1638
     1639        return false;
     1640    }
     1641    if (!psArrayLength(output)) {
     1642        psTrace("stacktool", PS_LOG_INFO, "no rows found");
     1643        psFree(output);
     1644        return true;
     1645    }
     1646
     1647    if (psArrayLength(output)) {
     1648        if (!ippdbPrintMetadatas(stdout, output, "stackSummary", !simple)) {
     1649            psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1650            psFree(output);
     1651            return false;
     1652        }
     1653    }
     1654
     1655    psFree(output);
     1656
     1657    return true;
     1658}
     1659
    15701660static bool pendingcleanuprunMode(pxConfig *config)
    15711661{
Note: See TracChangeset for help on using the changeset viewer.