IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 29561 for trunk/ippTools/src


Ignore:
Timestamp:
Oct 26, 2010, 8:39:32 AM (16 years ago)
Author:
bills
Message:

Change the destreak cleanup to preserve the rows in the magicDSFile table

Location:
trunk/ippTools/src
Files:
3 edited

Legend:

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

    r29358 r29561  
    3939static bool advancerunMode(pxConfig *config);
    4040static bool revertdestreakedfileMode(pxConfig *config);
     41static bool updatedestreakedfileMode(pxConfig *config);
    4142static bool clearstatefaultsMode(pxConfig *config);
    4243static bool getskycellsMode(pxConfig *config);
     
    4546static bool completedrevertMode(pxConfig *config);
    4647static bool tocleanupMode(pxConfig *config);
     48static bool tofullfileMode(pxConfig *config);
     49static bool tocleanedfileMode(pxConfig *config);
     50static bool setfiletoupdateMode(pxConfig *config);
    4751
    4852static bool setmagicDSRunState(pxConfig *config, psS64 magic_id, psString extraSetString, psMetadata *where, const char *state);
     
    7377        MODECASE(MAGICDSTOOL_MODE_ADVANCERUN,          advancerunMode);
    7478        MODECASE(MAGICDSTOOL_MODE_REVERTDESTREAKEDFILE,revertdestreakedfileMode);
     79        MODECASE(MAGICDSTOOL_MODE_UPDATEDESTREAKEDFILE,updatedestreakedfileMode);
    7580        MODECASE(MAGICDSTOOL_MODE_CLEARSTATEFAULTS,    clearstatefaultsMode);
    7681        MODECASE(MAGICDSTOOL_MODE_GETSKYCELLS,         getskycellsMode);
     
    7984        MODECASE(MAGICDSTOOL_MODE_COMPLETEDREVERT,     completedrevertMode);
    8085        MODECASE(MAGICDSTOOL_MODE_TOCLEANUP,           tocleanupMode);
     86        MODECASE(MAGICDSTOOL_MODE_TOFULLFILE,          tofullfileMode);
     87        MODECASE(MAGICDSTOOL_MODE_TOCLEANEDFILE,       tocleanedfileMode);
     88        MODECASE(MAGICDSTOOL_MODE_SETFILETOUPDATE,     setfiletoupdateMode);
    8189        default:
    8290            psAbort("invalid option (this should not happen)");
     
    558566    PXOPT_LOOKUP_STR(state, config->args, "-set_state", true, false);
    559567
     568    if (!strcmp(state, "update")) {
     569        fprintf(stderr, "'-updaterun -set_state update' is not supported. Use -setfiletoupdate");
     570        return false;
     571    }
     572
    560573    // optional
    561574    PXOPT_LOOKUP_STR(set_label, config->args, "-set_label", false, false);
     
    907920        return false;
    908921    }
     922
     923    return true;
     924}
     925static bool updatedestreakedfileMode(pxConfig *config)
     926{
     927    PS_ASSERT_PTR_NON_NULL(config, false);
     928
     929    // required values
     930    PXOPT_LOOKUP_S64(magic_ds_id, config->args, "-magic_ds_id", true, false);
     931    PXOPT_LOOKUP_STR(component, config->args, "-component", true, false);
     932
     933    // default values
     934    PXOPT_LOOKUP_S16(fault, config->args, "-fault", false, false);
     935    PXOPT_LOOKUP_STR(backup_path_base, config->args, "-backup_path_base", false, false);
     936    PXOPT_LOOKUP_STR(recovery_path_base, config->args, "-recovery_path_base", false, false);
     937    PXOPT_LOOKUP_STR(data_state, config->args, "-data_state", false, false);
     938    PXOPT_LOOKUP_F32(streak_frac, config->args, "-streak_frac", false, false);
     939    PXOPT_LOOKUP_F32(nondiff_frac, config->args, "-nondiff_frac", false, false);
     940    PXOPT_LOOKUP_F32(run_time, config->args, "-run_time", false, false);
     941
     942    psString query = psStringCopy("UPDATE magicDSFile");
     943
     944
     945    char *initial_separator = " SET";
     946    char *sep = initial_separator;
     947    if (fault) {
     948        psStringAppend(&query, "%s fault = %d", sep, fault);
     949        sep = ", ";
     950    }
     951    if (backup_path_base) {
     952        psStringAppend(&query, "%s backup_path_base = '%s'", sep, backup_path_base);
     953        sep = ", ";
     954    }
     955    if (recovery_path_base) {
     956        psStringAppend(&query, "%s recovery_path_base = '%s'", sep, recovery_path_base);
     957        sep = ", ";
     958    }
     959    if (data_state) {
     960        psStringAppend(&query, "%s data_state = '%s'", sep, data_state);
     961        sep = ", ";
     962    }
     963    if (streak_frac) {
     964        psStringAppend(&query, "%s streak_frac = '%f'", sep, streak_frac);
     965        sep = ", ";
     966    }
     967    if (nondiff_frac) {
     968        psStringAppend(&query, "%s nondiff_frac = '%f'", sep, nondiff_frac);
     969        sep = ", ";
     970    }
     971    if (run_time) {
     972        psStringAppend(&query, "%s run_time = '%f'", sep, run_time);
     973        sep = ", ";
     974    }
     975    if (sep == initial_separator) {
     976        psFree(query);
     977        psError(PS_ERR_UNKNOWN, true, "must set at least one value");
     978        return false;
     979    }
     980
     981    psStringAppend(&query, "\nWHERE magic_ds_id = %" PRId64 " AND component = '%s'\n", magic_ds_id, component);
     982
     983    if (!p_psDBRunQuery(config->dbh, query)) {
     984        psError(PS_ERR_UNKNOWN, false, "database error");
     985        psFree(query);
     986        return false;
     987    }
     988    psFree(query);
    909989
    910990    return true;
     
    10191099    PXOPT_COPY_S64(config->args, where, "-magic_ds_id", "magicDSRun.magic_ds_id", "==");
    10201100    PXOPT_COPY_STR(config->args, where, "-component", "component", "==");
     1101    PXOPT_COPY_STR(config->args, where, "-state", "state", "==");
    10211102    PXOPT_COPY_S16(config->args, where, "-fault", "fault", "==");
    10221103    pxAddLabelSearchArgs (config, where, "-label", "label", "==");
    10231104
    1024     psString query = pxDataGet("magicdstool_revertdestreakedfile.sql");
     1105    PXOPT_LOOKUP_STR(state, config->args, "-state", false, false);
     1106
     1107    psString queryFile = NULL;
     1108    if (state) {
     1109        if (! strcmp(state, "new") ) {
     1110            queryFile = "magicdstool_revertdestreakedfile.sql";
     1111        } else if (!strcmp(state, "update")) {
     1112            queryFile = "magicdstool_revertupdated.sql";
     1113        } else {
     1114            psError(PXTOOLS_ERR_SYS, true, "%s is not a valid value for state", state);
     1115            return false;
     1116        }
     1117    } else {
     1118        queryFile = "magicdstool_revertdestreakedfile.sql";
     1119    }
     1120    psString query = pxDataGet(queryFile);
     1121    if (!query) {
     1122        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     1123        return false;
     1124    }
    10251125
    10261126    if (psListLength(where->list)) {
     
    12411341          (strcmp(state, "censored") == 0) ||
    12421342          (strcmp(state, "cleaned") == 0) ||
     1343          (strcmp(state, "update") == 0) ||
    12431344          (strcmp(state, "goto_restored") == 0) ||
    12441345          (strcmp(state, "goto_censored") == 0) ||
     
    15201621    return true;
    15211622}
     1623
     1624// update magicDSFile.data_state to given value.
     1625// afterwards, if all files in the magicDSRun have the new state,
     1626// update the state for it as well
     1627// shared code for the modes -tocleanedfile -tofullfile
     1628
     1629static bool change_file_data_state(pxConfig *config, psString data_state)
     1630{
     1631    PS_ASSERT_PTR_NON_NULL(config, false);
     1632
     1633    // magic_id, component
     1634    PXOPT_LOOKUP_S64(magic_ds_id, config->args, "-magic_ds_id", true, false);
     1635    PXOPT_LOOKUP_STR(component, config->args, "-component", true, false);
     1636
     1637    psString query = pxDataGet("magicdstool_change_file_data_state.sql");
     1638
     1639    if (!psDBTransaction(config->dbh)) {
     1640        psError(PS_ERR_UNKNOWN, false, "database error");
     1641        return false;
     1642    }
     1643    if (!strcmp(data_state, "full")) {
     1644        // if -tofullfile optoinally set the magicked value for the component
     1645        PXOPT_LOOKUP_BOOL(setmagicked, config->args, "-setmagicked", false);
     1646        // set the image file's magicked flag
     1647        if (!setMagicked(config, magic_ds_id, component)) {
     1648            psError(PS_ERR_UNKNOWN, false, "setMagicked failed");
     1649            if (!psDBRollback(config->dbh)) {
     1650                psError(PS_ERR_UNKNOWN, false, "database error");
     1651            }
     1652            return false;
     1653        }
     1654    }
     1655
     1656    if (!p_psDBRunQueryF(config->dbh, query, data_state, magic_ds_id, component)) {
     1657        psFree(query);
     1658        psError(PS_ERR_UNKNOWN, false, "database error");
     1659        // rollback
     1660        if (!psDBRollback(config->dbh)) {
     1661            psError(PS_ERR_UNKNOWN, false, "database error");
     1662        }
     1663        psError(PS_ERR_UNKNOWN, false, "database error");
     1664        return false;
     1665    }
     1666    psFree(query);
     1667    if (psDBAffectedRows(config->dbh) < 1) {
     1668        psError(PS_ERR_UNKNOWN, false, "should have affected atleast 1 row");
     1669        return false;
     1670    }
     1671
     1672    query = pxDataGet("magicdstool_change_run_state.sql");
     1673    if (!p_psDBRunQueryF(config->dbh, query, data_state, magic_ds_id, data_state)) {
     1674        psFree(query);
     1675        // rollback
     1676        if (!psDBRollback(config->dbh)) {
     1677            psError(PS_ERR_UNKNOWN, false, "database error");
     1678        }
     1679        psError(PS_ERR_UNKNOWN, false, "database error");
     1680        return false;
     1681    }
     1682    psFree(query);
     1683
     1684    if (!psDBCommit(config->dbh)) {
     1685        psError(PS_ERR_UNKNOWN, false, "database error");
     1686        return false;
     1687    }
     1688
     1689    return true;
     1690}
     1691static bool tocleanedfileMode(pxConfig *config)
     1692{
     1693    return change_file_data_state(config, "cleaned");
     1694}
     1695static bool tofullfileMode(pxConfig *config)
     1696{
     1697    return change_file_data_state(config, "full");
     1698}
     1699/*
     1700static bool topurgedimfileMode(pxConfig *config)
     1701{
     1702    return change_imfile_data_state(config, "purged", "goto_purged");
     1703}
     1704static bool toscrubbedfileMode(pxConfig *config)
     1705{
     1706  return change_file_data_state(config, "scrubbed", "goto_scrubbed");
     1707}
     1708*/
     1709
     1710// a very specfic function to queue a cleaned magicDSFile to be updated
     1711static bool setfiletoupdateMode(pxConfig *config)
     1712{
     1713    PS_ASSERT_PTR_NON_NULL(config, NULL);
     1714
     1715    PXOPT_LOOKUP_S64(magic_ds_id, config->args, "-magic_ds_id", true, false);
     1716    PXOPT_LOOKUP_STR(component, config->args, "-component", false, false);
     1717    PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false);
     1718
     1719    psString query = pxDataGet("magicdstool_setfiletoupdate.sql");
     1720    if (!query) {
     1721        psError(PXTOOLS_ERR_SYS, false, "failed to retreive SQL statement");
     1722        return false;
     1723    }
     1724
     1725    psString setHook = psStringCopy("");
     1726    if (label) {
     1727        psStringAppend(&setHook, "\n , magicDSRun.label = '%s'", label);
     1728    }
     1729
     1730    if (component) {
     1731        psStringAppend(&query, " AND (magicDSFile.component = '%s')", component);
     1732    }
     1733
     1734    if (!p_psDBRunQueryF(config->dbh, query, setHook, magic_ds_id)) {
     1735        psError(PS_ERR_UNKNOWN, false, "database error");
     1736        return false;
     1737    }
     1738
     1739    psFree(setHook);
     1740    psFree(query);
     1741
     1742    return true;
     1743}
     1744
     1745
  • trunk/ippTools/src/magicdstool.h

    r26960 r29561  
    3838    MAGICDSTOOL_MODE_COMPLETEDREVERT,
    3939    MAGICDSTOOL_MODE_TOCLEANUP,
     40    MAGICDSTOOL_MODE_TOCLEANEDFILE,
     41    MAGICDSTOOL_MODE_TOFULLFILE,
     42    MAGICDSTOOL_MODE_SETFILETOUPDATE,
     43    MAGICDSTOOL_MODE_UPDATEDESTREAKEDFILE,
    4044} MAGICDStoolMode;
    4145
  • trunk/ippTools/src/magicdstoolConfig.c

    r28936 r29561  
    137137    psMetadataAddS16(adddestreakedfileArgs, PS_LIST_TAIL, "-fault", 0, "set fault code", 0);
    138138
     139    // -updatedestreakedfile
     140    psMetadata *updatedestreakedfileArgs = psMetadataAlloc();
     141    psMetadataAddS64(updatedestreakedfileArgs, PS_LIST_TAIL, "-magic_ds_id", 0, "define magictool ID (required)", 0);
     142    psMetadataAddStr(updatedestreakedfileArgs, PS_LIST_TAIL, "-component", 0, "define component name (required)", NULL);
     143    psMetadataAddStr(updatedestreakedfileArgs, PS_LIST_TAIL, "-state", 0, "current value for magicDSRun.state", NULL);
     144    psMetadataAddStr(updatedestreakedfileArgs, PS_LIST_TAIL, "-backup_path_base", 0, "define backup URI", NULL);
     145    psMetadataAddStr(updatedestreakedfileArgs, PS_LIST_TAIL, "-recovery_path_base", 0, "define recovery pixels URI", NULL);
     146    psMetadataAddStr(updatedestreakedfileArgs, PS_LIST_TAIL, "-data_state", 0, "change data_state", NULL);
     147    psMetadataAddBool(updatedestreakedfileArgs, PS_LIST_TAIL, "-setmagicked", 0, "update the magicked state of the file", false);
     148    psMetadataAddF32(updatedestreakedfileArgs, PS_LIST_TAIL, "-streak_frac", 0, "set fraction of pixels masked by streaks", 0);
     149    psMetadataAddF32(updatedestreakedfileArgs, PS_LIST_TAIL, "-nondiff_frac", 0, "set fraction of pixels masked because nondiffed", 0);
     150    psMetadataAddF32(updatedestreakedfileArgs, PS_LIST_TAIL, "-run_time", 0, "set the streaksremove run time for component ", 0);
     151    psMetadataAddS16(updatedestreakedfileArgs, PS_LIST_TAIL, "-fault", 0, "set fault code", 0);
     152
    139153    // -revertdestreakedfile
    140154    psMetadata *revertdestreakedfileArgs = psMetadataAlloc();
    141155    psMetadataAddS64(revertdestreakedfileArgs, PS_LIST_TAIL, "-magic_ds_id", 0, "search by magictool de-streak ID", 0);
     156    psMetadataAddStr(revertdestreakedfileArgs, PS_LIST_TAIL, "-state", 0, "current value for magicDSRun.state", NULL);
    142157    psMetadataAddStr(revertdestreakedfileArgs, PS_LIST_TAIL, "-component", 0, "search by component", NULL);
    143158    psMetadataAddS16(revertdestreakedfileArgs, PS_LIST_TAIL, "-fault", 0, "search by fault code", 0);
     
    197212    psMetadataAddU64(tocleanupArgs, PS_LIST_TAIL, "-limit", 0, "limit result set to N items", 0);
    198213    psMetadataAddBool(tocleanupArgs, PS_LIST_TAIL, "-simple", 0, "use the simple output format", false);
     214
     215    // -tocleanedfile
     216    psMetadata *tocleanedfileArgs = psMetadataAlloc();
     217    psMetadataAddS64(tocleanedfileArgs, PS_LIST_TAIL, "-magic_ds_id", 0, "define magic_ds_id", 0);
     218    psMetadataAddStr(tocleanedfileArgs, PS_LIST_TAIL, "-component", 0, "define component", NULL);
     219
     220    // -tofullfile
     221    psMetadata *tofullfileArgs = psMetadataAlloc();
     222    psMetadataAddS64(tofullfileArgs, PS_LIST_TAIL, "-magic_ds_id", 0, "define magic_ds_id", 0);
     223    psMetadataAddStr(tofullfileArgs, PS_LIST_TAIL, "-component", 0, "define component", NULL);
     224    psMetadataAddBool(tofullfileArgs, PS_LIST_TAIL, "-setmagicked", 0, "update the magicked state of the file", false);
     225
     226    // -setfiletoupdate
     227    psMetadata *setfiletoupdateArgs = psMetadataAlloc();
     228    psMetadataAddS64(setfiletoupdateArgs, PS_LIST_TAIL, "-magic_ds_id", 0, "define magic_ds_id", 0);
     229    psMetadataAddStr(setfiletoupdateArgs, PS_LIST_TAIL, "-component", 0, "define component", NULL);
     230    psMetadataAddStr(setfiletoupdateArgs, PS_LIST_TAIL, "-set_label", 0, "set new label", NULL);
     231
    199232    psFree(now);
    200233
     
    230263                    MAGICDSTOOL_MODE_TOCLEANUP, tocleanupArgs);
    231264
     265    PXOPT_ADD_MODE("-tofullfile", "set component's data_state to full",
     266                    MAGICDSTOOL_MODE_TOFULLFILE, tofullfileArgs);
     267    PXOPT_ADD_MODE("-tocleanedfile", "set component's data_state to cleaned",
     268                    MAGICDSTOOL_MODE_TOCLEANEDFILE, tocleanedfileArgs);
     269    PXOPT_ADD_MODE("-setfiletoupdate", "set component's data_state to update",
     270                    MAGICDSTOOL_MODE_SETFILETOUPDATE, setfiletoupdateArgs);
     271    PXOPT_ADD_MODE("-updatedestreakedfile", "update parameters of destreaked file",
     272                    MAGICDSTOOL_MODE_UPDATEDESTREAKEDFILE, updatedestreakedfileArgs);
     273
    232274
    233275    if (!pxGetOptions(stderr, argc, argv, config, modes, argSets)) {
Note: See TracChangeset for help on using the changeset viewer.