IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 28, 2010, 3:09:59 PM (16 years ago)
Author:
watersc1
Message:

JPEG work should be done. Transitioning to try to pick up stackAssociation concept in this branch as well.

Location:
branches/czw_branch/20100519
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/czw_branch/20100519

  • branches/czw_branch/20100519/ippTools/src

    • Property svn:ignore
      •  

        old new  
        2020flatcorr
        2121guidetool
         22labeltool
        2223magicdstool
        2324magictool
         
        3738stamp-h1
        3839warptool
         40
  • branches/czw_branch/20100519/ippTools/src/warptool.c

    r28043 r28164  
    4848static bool maskedMode(pxConfig *config);
    4949static bool unblockMode(pxConfig *config);
     50static bool tosummaryMode(pxConfig *config);
     51static bool addsummaryMode(pxConfig *config);
    5052static bool pendingcleanuprunMode(pxConfig *config);
    5153static bool pendingcleanupwarpMode(pxConfig *config);
     
    101103        MODECASE(WARPTOOL_MODE_MASKED,             maskedMode);
    102104        MODECASE(WARPTOOL_MODE_UNBLOCK,            unblockMode);
     105        MODECASE(WARPTOOL_MODE_TOSUMMARY,          tosummaryMode);
     106        MODECASE(WARPTOOL_MODE_ADDSUMMARY,         addsummaryMode);
    103107        MODECASE(WARPTOOL_MODE_PENDINGCLEANUPRUN,  pendingcleanuprunMode);
    104108        MODECASE(WARPTOOL_MODE_PENDINGCLEANUPSKYFILE, pendingcleanupwarpMode);
     
    408412    PXOPT_COPY_STR(config->args, where, "-reduction", "warpRun.reduction", "==");
    409413    PXOPT_COPY_STR(config->args, where, "-state",     "warpRun.state",     "==");
    410     PXOPT_COPY_STR(config->args, where, "-data_group","warpRun.data_group","==");
    411     PXOPT_COPY_STR(config->args, where, "-dist_group","warpRun.dist_group","==");
    412     pxAddLabelSearchArgs(config,  where, "-label",    "warpRun.label",     "==");
     414    PXOPT_COPY_STR(config->args, where, "-data_group","warpRun.data_group","LIKE");
     415    PXOPT_COPY_STR(config->args, where, "-dist_group","warpRun.dist_group","LIKE");
     416    pxAddLabelSearchArgs(config,  where, "-label",    "warpRun.label",     "LIKE");
    413417
    414418    PXOPT_COPY_TIME(config->args, where, "-registered_begin", "warpRun.registered",  ">=");
     
    940944
    941945    // treat limit == 0 as "no limit"
    942     psString limitString = psStringCopy("\n");
     946    psString limitString = psStringCopy("\nORDER BY priority DESC, warp_id");
    943947    if (limit) {
    944         // We apply the limit to both sides of the UNION
    945         // to avoid slow queries and to the query itself
    946         // to satisfy the user's requested limit
     948        // We apply the limit to both sides of the UNION to avoid slow queries
     949        // and to the query itself to satisfy the user's requested limit
    947950        psStringAppend(&limitString, "%s", psDBGenerateLimitSQL(limit));
    948951        psStringAppend(&query, " %s", limitString);
    949952    }
    950953
    951 #define TWO_WHERES
    952 #ifdef TWO_WHERES
    953954    if (!p_psDBRunQueryF(config->dbh, query, whereStr, limitString, whereStr,  limitString)) {
    954955        psError(PS_ERR_UNKNOWN, false, "database error");
     
    956957        return false;
    957958    }
    958 #else
    959     if (!p_psDBRunQueryF(config->dbh, query, whereStr)) {
    960         psError(PS_ERR_UNKNOWN, false, "database error");
    961         psFree(query);
    962         return false;
    963     }
    964 #endif
    965959    psFree(limitString);
    966960    psFree(whereStr);
     
    11631157
    11641158        psString software_ver = NULL;
    1165         psS32 maskfrac_npix = 0;
     1159        psS64 maskfrac_npix = 0;
    11661160        psF32 maskfrac_static = 0;
    11671161        psF32 maskfrac_dynamic = 0;
     
    11811175          return(false);
    11821176        }
    1183         // Set warpRun.software_ver to the appropriate value
    1184         if (!pxSetRunSoftware(config, "warpRun", "warp_id", warp_id, software_ver)) {
    1185           psError(PS_ERR_UNKNOWN, false, "failed to set warpRun.software_ver for warp_id: %" PRId64,
    1186                   warp_id);
    1187           psFree(output);
    1188           if (!psDBRollback(config->dbh)) {
    1189             psError(PS_ERR_UNKNOWN, false, "database error");
     1177        // Set warpRun.software_ver to the appropriate value    if (
     1178        if (software_ver) {
     1179          if (!pxSetRunSoftware(config, "warpRun", "warp_id", warp_id, software_ver)) {
     1180            psError(PS_ERR_UNKNOWN, false, "failed to set warpRun.software_ver for warp_id: %" PRId64,
     1181                    warp_id);
     1182            psFree(output);
     1183            if (!psDBRollback(config->dbh)) {
     1184              psError(PS_ERR_UNKNOWN, false, "database error");
     1185            }
     1186            return(false);
    11901187          }
    1191           return(false);
    11921188        }
    11931189        // Set warpRun.maskfrac* to the appropriate values.
    1194         if (!pxSetRunMaskfrac(config, "warpRun", "warp_id", warp_id, maskfrac_npix, maskfrac_static,
    1195                               maskfrac_dynamic, maskfrac_magic, maskfrac_advisory)) {
    1196           psError(PS_ERR_UNKNOWN, false, "failed to set warpRun.software_ver for warp_id: %" PRId64,
    1197                   warp_id);
    1198           psFree(output);
    1199           if (!psDBRollback(config->dbh)) {
    1200             psError(PS_ERR_UNKNOWN, false, "database error");
     1190        if (maskfrac_npix) {
     1191          if (!pxSetRunMaskfrac(config, "warpRun", "warp_id", warp_id, maskfrac_npix, maskfrac_static,
     1192                                maskfrac_dynamic, maskfrac_magic, maskfrac_advisory)) {
     1193            psError(PS_ERR_UNKNOWN, false, "failed to set warpRun.software_ver for warp_id: %" PRId64,
     1194                    warp_id);
     1195            psFree(output);
     1196            if (!psDBRollback(config->dbh)) {
     1197              psError(PS_ERR_UNKNOWN, false, "database error");
     1198            }
     1199            return(false);
    12011200          }
    1202           return(false);
    1203         }       
     1201        }
    12041202
    12051203       
     
    15541552}
    15551553
     1554static bool tosummaryMode(pxConfig *config) {
     1555  PS_ASSERT_PTR_NON_NULL(config, NULL);
     1556 
     1557  psMetadata *where = psMetadataAlloc();
     1558  PXOPT_COPY_S64(config->args, where, "-warp_id",    "warpSkyfile.warp_id", "==");
     1559  PXOPT_COPY_STR(config->args, where, "-tess_id",    "warpSkyfile.tess_id", "==");
     1560  PXOPT_COPY_STR(config->args, where, "-state",      "warpRun.state", "==");
     1561  PXOPT_COPY_S64(config->args, where, "-exp_id",     "rawExp.exp_id", "==");
     1562  PXOPT_COPY_STR(config->args, where, "-exp_name",   "rawExp.exp_name", "==");
     1563  PXOPT_COPY_S64(config->args, where, "-fake_id",    "fakeRun.fake_id", "==");
     1564  PXOPT_COPY_TIME(config->args, where, "-dateobs_begin", "rawExp.dateobs",  ">=");
     1565  PXOPT_COPY_TIME(config->args, where, "-dateobs_end",   "rawExp.dateobs",  "<=");
     1566  PXOPT_COPY_STR(config->args, where, "-filter",    "rawExp.filter", "LIKE");
     1567  PXOPT_COPY_S64(config->args, where, "-magicked", "warpSkyfile.magicked", "==");
     1568  pxAddLabelSearchArgs (config, where, "-label",   "warpRun.label", "LIKE");
     1569  pxAddLabelSearchArgs (config, where, "-data_group",   "warpRun.data_group", "LIKE");
     1570
     1571  PXOPT_LOOKUP_BOOL(all, config->args, "-all", false);
     1572
     1573  PXOPT_LOOKUP_U64(limit, config->args, "-limit", false, false);
     1574  PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1575 
     1576  // find all rawImfiles matching the default query
     1577  psString query = pxDataGet("warptool_tosummary.sql");
     1578  if (!query) {
     1579    psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     1580    return false;
     1581  }
     1582
     1583  // generate where strings for arguments that require extra processing
     1584  // beyond PXOPT_COPY*
     1585  psString where2 = NULL;
     1586  if (!pxmagicAddWhere(config, &where2, "warpSkyfile")) {
     1587    psError(psErrorCodeLast(), false, "pxMagicAddWhere failed");
     1588    return false;
     1589  }
     1590 
     1591  if (psListLength(where->list)) {
     1592    psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     1593    psStringAppend(&query, " AND %s", whereClause);
     1594    psFree(whereClause);
     1595  } else if (!all && !where2) {
     1596    psError(PXTOOLS_ERR_CONFIG, true, "search parameters or -all are required");
     1597    return false;
     1598  }
     1599 
     1600  if (where2) {
     1601    psStringAppend(&query, " %s", where2);
     1602  }
     1603  psFree(where);
     1604
     1605  // treat limit == 0 as "no limit"
     1606  if (limit) {
     1607    psString limitString = psDBGenerateLimitSQL(limit);
     1608    psStringAppend(&query, " %s", limitString);
     1609    psFree(limitString);
     1610  }
     1611 
     1612  if (!p_psDBRunQuery(config->dbh, query)) {
     1613    psError(PS_ERR_UNKNOWN, false, "database error");
     1614    psFree(query);
     1615    return false;
     1616  }
     1617  psFree(query);
     1618
     1619  psArray *output = p_psDBFetchResult(config->dbh);
     1620  if (!output) {
     1621    psErrorCode err = psErrorCodeLast();
     1622    switch (err) {
     1623    case PS_ERR_DB_CLIENT:
     1624      psError(PXTOOLS_ERR_SYS, false, "database error");
     1625    case PS_ERR_DB_SERVER:
     1626      psError(PXTOOLS_ERR_PROG, false, "database error");
     1627    default:
     1628      psError(PXTOOLS_ERR_PROG, false, "unknown error");
     1629    }
     1630   
     1631    return false;
     1632  }
     1633  if (!psArrayLength(output)) {
     1634    psTrace("warptool", PS_LOG_INFO, "no rows found");
     1635    psFree(output);
     1636    return true;
     1637  }
     1638 
     1639  if (psArrayLength(output)) {
     1640    // negative simple so the default is true
     1641    if (!ippdbPrintMetadatas(stdout, output, "warpRun", !simple)) {
     1642      psError(PS_ERR_UNKNOWN, false, "failed to print array");
     1643      psFree(output);
     1644      return false;
     1645    }
     1646  }
     1647 
     1648  psFree(output);
     1649  return(true);
     1650}
     1651static bool addsummaryMode(pxConfig *config) {
     1652  PS_ASSERT_PTR_NON_NULL(config, NULL);
     1653
     1654  PXOPT_LOOKUP_S64(warp_id, config->args, "-warp_id", true, false);
     1655  PXOPT_LOOKUP_STR(tangent_plane, config->args, "-tangent_plane", true, false);
     1656  PXOPT_LOOKUP_STR(path_base, config->args, "-path_base", true, false);
     1657
     1658  psString query = pxDataGet("warptool_addsummary.sql");
     1659  if (!query) {
     1660    psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     1661    return(false);
     1662  }
     1663  if (!p_psDBRunQueryF(config->dbh, query, warp_id, tangent_plane, path_base)) {
     1664    psError(PS_ERR_UNKNOWN, false, "database error");
     1665    psFree(query);
     1666    return(false);
     1667  }
     1668  psS64 numUpdated = psDBAffectedRows(config->dbh);
     1669 
     1670  if (numUpdated != 1) {
     1671    psError(PS_ERR_UNKNOWN, false, "should have affected 1 row");
     1672    psFree(query);
     1673    return false;
     1674  }
     1675 
     1676  psFree(query);
     1677
     1678  // Print anything here?
     1679 
     1680  return(true);
     1681}
     1682
    15561683static bool pendingcleanuprunMode(pxConfig *config)
    15571684{
Note: See TracChangeset for help on using the changeset viewer.