IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 23, 2010, 11:20:24 AM (16 years ago)
Author:
bills
Message:

Add -listrun mode.
Fix handling of magicked bits during update.
Various other changes to the 'list' modes to support the postage stamp server

File:
1 edited

Legend:

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

    r27391 r27738  
    6060static bool runstateMode(pxConfig *config);
    6161static bool setimfiletoupdateMode(pxConfig *config);
     62static bool listrunMode(pxConfig *config);
    6263
    6364# define MODECASE(caseName, func) \
     
    103104        MODECASE(CHIPTOOL_MODE_RUNSTATE,                runstateMode);
    104105        MODECASE(CHIPTOOL_MODE_SETIMFILETOUPDATE,       setimfiletoupdateMode);
     106        MODECASE(CHIPTOOL_MODE_LISTRUN,                 listrunMode);
    105107        default:
    106108            psAbort("invalid option (this should not happen)");
     
    699701    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    700702    PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false);
     703    PXOPT_LOOKUP_BOOL(allfiles, config->args, "-allfiles", false);
     704    if (allfiles) {
     705        faulted = false;
     706    }
    701707
    702708    psMetadata *where = psMetadataAlloc();
     
    740746        // list only faulted rows
    741747        psStringAppend(&query, " %s", "AND chipProcessedImfile.fault != 0");
    742     } else {
     748    } else if (!allfiles) {
    743749        // don't list faulted rows
    744750        psStringAppend(&query, " %s", "AND chipProcessedImfile.fault = 0");
     
    14141420    }
    14151421
    1416     char *set_magicked_imfile = "";
    1417     char *set_magicked_run = "";
     1422    psString set_magicked_imfile = psStringCopy("");
     1423    psString set_magicked_run = psStringCopy("");
    14181424    if (!strcmp(data_state, "full")) {
    14191425        // if (chipProcessedImfile.magicked < 0 and rawImfile.magicked = 0) leave magicked unchanged. This will
     
    14211427        // otherwise copy magicked from the rawImfile
    14221428        // Same thing for chipRun/rawExp
    1423         set_magicked_imfile = "\n , chipProcessedImfile.magicked = IF((chipProcessedImfile.magicked < 0 AND rawImfile.magicked = 0), chipProcessedImfile.magicked, rawImfile.magicked)";
    1424         set_magicked_run = "\n , chipRun.magicked = IF((chipRun.magicked < 0 AND rawExp.magicked = 0), chipRun.magicked, rawExp.magicked)";
     1429        psStringAppend(&set_magicked_imfile, "\n , chipProcessedImfile.magicked = IF((chipProcessedImfile.magicked < 0"
     1430                                      " AND rawImfile.magicked = 0), chipProcessedImfile.magicked, rawImfile.magicked)");
     1431        psStringAppend(&set_magicked_run, "\n , chipRun.magicked = IF((chipRun.magicked < 0 AND rawExp.magicked = 0), "
     1432                                      " chipRun.magicked, rawExp.magicked)");
     1433
    14251434    } else if (!strcmp(data_state, "cleaned") || !strcmp(data_state, "purged")) {
    14261435        // if magicked is non-zero set it to -1
    1427         set_magicked_imfile = "\n, chipProcessedImfile.magicked = IF(chipProcessedImfile.magicked = 0, 0, -1)";
    1428         set_magicked_run = "\n, chipRun.magicked = IF(chipRun.magicked = 0, 0, -1)";
     1436        // Once one imfile has been cleaned, the chipRun is no longer 'magicked'
     1437        psStringAppend(&set_magicked_imfile, "\n, chipProcessedImfile.magicked = IF(chipProcessedImfile.magicked = 0, 0, -1),"
     1438                                             " chipRun.magicked = IF(chipRun.magicked = 0, 0, -1)");
    14291439    }
    14301440
     
    14401450    }
    14411451    psFree(query);
     1452    psFree(set_magicked_imfile);
     1453    psFree(set_magicked_run);
    14421454    if (psDBAffectedRows(config->dbh) < 1) {
    14431455        psError(PS_ERR_UNKNOWN, false, "should have affected atleast 1 row");
     
    17571769    return true;
    17581770}
     1771
     1772static bool listrunMode(pxConfig *config)
     1773{
     1774    PS_ASSERT_PTR_NON_NULL(config, NULL);
     1775
     1776    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     1777    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1778    PXOPT_LOOKUP_BOOL(pstamp_order, config->args, "-pstamp_order", false);
     1779
     1780    psMetadata *where = psMetadataAlloc();
     1781    pxchipGetSearchArgs (config, where); // chipRun, chipProcessedImfile, rawExp
     1782    PXOPT_COPY_S64(config->args, where, "-chip_id", "chipRun.chip_id", "==");
     1783    PXOPT_COPY_STR(config->args, where, "-reduction", "chipRun.reduction", "==");
     1784    PXOPT_COPY_STR(config->args, where, "-state", "chipRun.state", "==");
     1785    pxAddLabelSearchArgs (config, where, "-label", "chipRun.label", "LIKE");
     1786    pxAddLabelSearchArgs (config, where, "-data_group", "chipRun.data_group", "LIKE");
     1787    pxAddLabelSearchArgs (config, where, "-dist_group", "chipRun.dist_group", "LIKE");
     1788    PXOPT_COPY_S64(config->args, where, "-magicked", "chipRun.magicked", "==");
     1789
     1790    psString where2 = NULL;
     1791    pxmagicAddWhere(config, &where2, "chipRun");
     1792    // add cuts on ra and decl if supplied
     1793    if (!pxspaceAddWhere(config, &where2, "rawExp")) {
     1794        psError(psErrorCodeLast(), false, "pxSpaceAddWhere failed");
     1795        return false;
     1796    }
     1797
     1798    psString query = pxDataGet("chiptool_listrun.sql");
     1799    if (!query) {
     1800        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     1801        return false;
     1802    }
     1803
     1804    if (psListLength(where->list)) {
     1805        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1806        psStringAppend(&query, " WHERE %s %s", whereClause, where2 ? where2 : "");
     1807        psFree(whereClause);
     1808    } else if (psMetadataLookupBool(NULL, config->args, "-all") || where2) {
     1809        psStringAppend(&query, " WHERE chipRun.chip_id IS NOT NULL %s", where2 ? where2 : "");
     1810    } else {
     1811        psFree(where);
     1812        psError(PXTOOLS_ERR_CONFIG, false, "search parameters (or -all) are required");
     1813        return false;
     1814    }
     1815    psFree(where);
     1816
     1817    if (pstamp_order) {
     1818        // put runs in order of exposure id with newest chip Runs first
     1819        // The postage stamp parser depends on this behavior
     1820        psStringAppend(&query, "\nORDER by exp_id, chip_id DESC");
     1821    }
     1822
     1823    // treat limit == 0 as "no limit"
     1824    if (limit) {
     1825        psString limitString = psDBGenerateLimitSQL(limit);
     1826        psStringAppend(&query, " %s", limitString);
     1827        psFree(limitString);
     1828    }
     1829
     1830    if (!p_psDBRunQuery(config->dbh, query)) {
     1831        psError(PS_ERR_UNKNOWN, false, "database error");
     1832        psFree(query);
     1833        return false;
     1834    }
     1835    psFree(query);
     1836
     1837    psArray *output = p_psDBFetchResult(config->dbh);
     1838    if (!output) {
     1839        psError(PS_ERR_UNKNOWN, false, "database error");
     1840        return false;
     1841    }
     1842    if (!psArrayLength(output)) {
     1843        psTrace("chiptool", PS_LOG_INFO, "no rows found");
     1844        psFree(output);
     1845        return true;
     1846    }
     1847
     1848    // negative simple so the default is true
     1849    if (!ippdbPrintMetadatas(stdout, output, "chipRun", !simple)) {
     1850        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1851        psFree(output);
     1852        return false;
     1853    }
     1854
     1855    psFree(output);
     1856
     1857    return true;
     1858}
Note: See TracChangeset for help on using the changeset viewer.