IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 18, 2010, 12:49:05 PM (16 years ago)
Author:
eugene
Message:

merging changes from trunk into branches/pap

Location:
branches/pap
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/pap

  • branches/pap/ippTools/src/chiptool.c

    r27391 r28003  
    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)");
     
    420422    PXOPT_COPY_S64(config->args,  where, "-chip_id", "chipRun.chip_id", "==");
    421423    // we only allow a single label to match (do not use pxAddLabelSearchArgs here)
    422     PXOPT_COPY_STR(config->args,  where, "-label",   "chipRun.label",   "==");
     424    PXOPT_COPY_STR(config->args,  where, "-label",   "chipRun.label",   "LIKE");
    423425    PXOPT_COPY_STR(config->args,  where, "-state",   "chipRun.state",   "==");
    424     PXOPT_COPY_STR(config->args,  where, "-data_group", "chipRun.data_group",   "==");
    425     PXOPT_COPY_STR(config->args,  where, "-dist_group", "chipRun.dist_group",   "==");
     426    PXOPT_COPY_STR(config->args,  where, "-data_group", "chipRun.data_group",   "LIKE");
     427    PXOPT_COPY_STR(config->args,  where, "-dist_group", "chipRun.dist_group",   "LIKE");
    426428
    427429    if (!psListLength(where->list)) {
     
    469471    }
    470472    psFree(where);
     473
     474    psStringAppend(&query, "\nORDER BY priority DESC, chip_id");
    471475
    472476    // treat limit == 0 as "no limit"
     
    699703    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    700704    PXOPT_LOOKUP_BOOL(faulted, config->args, "-faulted", false);
     705    PXOPT_LOOKUP_BOOL(allfiles, config->args, "-allfiles", false);
     706    if (allfiles) {
     707        faulted = false;
     708    }
    701709
    702710    psMetadata *where = psMetadataAlloc();
     
    740748        // list only faulted rows
    741749        psStringAppend(&query, " %s", "AND chipProcessedImfile.fault != 0");
    742     } else {
     750    } else if (!allfiles) {
    743751        // don't list faulted rows
    744752        psStringAppend(&query, " %s", "AND chipProcessedImfile.fault = 0");
     
    807815        return false;
    808816    }
     817    psString query_update = pxDataGet("chiptool_revertupdatedimfile.sql");
     818    if (!query) {
     819        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     820        psFree(where);
     821        return false;
     822    }
    809823
    810824    if (where && psListLength(where->list)) {
    811825        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    812826        psStringAppend(&query, " AND %s", whereClause);
     827        psStringAppend(&query_update, " AND %s", whereClause);
    813828        psFree(whereClause);
    814829    }
     
    822837    }
    823838    psFree(query);
     839    if (!p_psDBRunQuery(config->dbh, query_update)) {
     840        psError(PS_ERR_UNKNOWN, false, "database error");
     841        psFree(query_update);
     842        return false;
     843    }
     844    psFree(query_update);
    824845
    825846    return true;
     
    14141435    }
    14151436
    1416     char *set_magicked_imfile = "";
    1417     char *set_magicked_run = "";
     1437    psString set_magicked_imfile = psStringCopy("");
     1438    psString set_magicked_run = psStringCopy("");
    14181439    if (!strcmp(data_state, "full")) {
    14191440        // if (chipProcessedImfile.magicked < 0 and rawImfile.magicked = 0) leave magicked unchanged. This will
     
    14211442        // otherwise copy magicked from the rawImfile
    14221443        // 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)";
     1444        psStringAppend(&set_magicked_imfile, "\n , chipProcessedImfile.magicked = IF((chipProcessedImfile.magicked < 0"
     1445                                      " AND rawImfile.magicked = 0), chipProcessedImfile.magicked, rawImfile.magicked)");
     1446        psStringAppend(&set_magicked_run, "\n , chipRun.magicked = IF((chipRun.magicked < 0 AND rawExp.magicked = 0), "
     1447                                      " chipRun.magicked, rawExp.magicked)");
     1448
    14251449    } else if (!strcmp(data_state, "cleaned") || !strcmp(data_state, "purged")) {
    14261450        // 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)";
     1451        // Once one imfile has been cleaned, the chipRun is no longer 'magicked'
     1452        psStringAppend(&set_magicked_imfile, "\n, chipProcessedImfile.magicked = IF(chipProcessedImfile.magicked = 0, 0, -1),"
     1453                                             " chipRun.magicked = IF(chipRun.magicked = 0, 0, -1)");
    14291454    }
    14301455
     
    14401465    }
    14411466    psFree(query);
     1467    psFree(set_magicked_imfile);
     1468    psFree(set_magicked_run);
    14421469    if (psDBAffectedRows(config->dbh) < 1) {
    14431470        psError(PS_ERR_UNKNOWN, false, "should have affected atleast 1 row");
     
    17571784    return true;
    17581785}
     1786
     1787static bool listrunMode(pxConfig *config)
     1788{
     1789    PS_ASSERT_PTR_NON_NULL(config, NULL);
     1790
     1791    PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     1792    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1793    PXOPT_LOOKUP_BOOL(pstamp_order, config->args, "-pstamp_order", false);
     1794
     1795    psMetadata *where = psMetadataAlloc();
     1796    pxchipGetSearchArgs (config, where); // chipRun, chipProcessedImfile, rawExp
     1797    PXOPT_COPY_S64(config->args, where, "-chip_id", "chipRun.chip_id", "==");
     1798    PXOPT_COPY_STR(config->args, where, "-reduction", "chipRun.reduction", "==");
     1799    PXOPT_COPY_STR(config->args, where, "-state", "chipRun.state", "==");
     1800    pxAddLabelSearchArgs (config, where, "-label", "chipRun.label", "LIKE");
     1801    pxAddLabelSearchArgs (config, where, "-data_group", "chipRun.data_group", "LIKE");
     1802    pxAddLabelSearchArgs (config, where, "-dist_group", "chipRun.dist_group", "LIKE");
     1803    PXOPT_COPY_S64(config->args, where, "-magicked", "chipRun.magicked", "==");
     1804
     1805    psString where2 = NULL;
     1806    pxmagicAddWhere(config, &where2, "chipRun");
     1807    // add cuts on ra and decl if supplied
     1808    if (!pxspaceAddWhere(config, &where2, "rawExp")) {
     1809        psError(psErrorCodeLast(), false, "pxSpaceAddWhere failed");
     1810        return false;
     1811    }
     1812
     1813    psString query = pxDataGet("chiptool_listrun.sql");
     1814    if (!query) {
     1815        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     1816        return false;
     1817    }
     1818
     1819    if (psListLength(where->list)) {
     1820        psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1821        psStringAppend(&query, " WHERE %s %s", whereClause, where2 ? where2 : "");
     1822        psFree(whereClause);
     1823    } else if (psMetadataLookupBool(NULL, config->args, "-all") || where2) {
     1824        psStringAppend(&query, " WHERE chipRun.chip_id IS NOT NULL %s", where2 ? where2 : "");
     1825    } else {
     1826        psFree(where);
     1827        psError(PXTOOLS_ERR_CONFIG, false, "search parameters (or -all) are required");
     1828        return false;
     1829    }
     1830    psFree(where);
     1831
     1832    if (pstamp_order) {
     1833        // put runs in order of exposure id with newest chip Runs first
     1834        // The postage stamp parser depends on this behavior
     1835        psStringAppend(&query, "\nORDER by exp_id, chip_id DESC");
     1836    }
     1837
     1838    // treat limit == 0 as "no limit"
     1839    if (limit) {
     1840        psString limitString = psDBGenerateLimitSQL(limit);
     1841        psStringAppend(&query, " %s", limitString);
     1842        psFree(limitString);
     1843    }
     1844
     1845    if (!p_psDBRunQuery(config->dbh, query)) {
     1846        psError(PS_ERR_UNKNOWN, false, "database error");
     1847        psFree(query);
     1848        return false;
     1849    }
     1850    psFree(query);
     1851
     1852    psArray *output = p_psDBFetchResult(config->dbh);
     1853    if (!output) {
     1854        psError(PS_ERR_UNKNOWN, false, "database error");
     1855        return false;
     1856    }
     1857    if (!psArrayLength(output)) {
     1858        psTrace("chiptool", PS_LOG_INFO, "no rows found");
     1859        psFree(output);
     1860        return true;
     1861    }
     1862
     1863    // negative simple so the default is true
     1864    if (!ippdbPrintMetadatas(stdout, output, "chipRun", !simple)) {
     1865        psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1866        psFree(output);
     1867        return false;
     1868    }
     1869
     1870    psFree(output);
     1871
     1872    return true;
     1873}
Note: See TracChangeset for help on using the changeset viewer.