IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Oct 18, 2009, 10:23:28 AM (17 years ago)
Author:
eugene
Message:

updated vysos branch from trunk

Location:
branches/eam_branches/20090820
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/20090820

  • branches/eam_branches/20090820/ippTools/src/difftool.c

    r25766 r25870  
    5151
    5252static bool setdiffRunState(pxConfig *config, psS64 diff_id, const char *state, psS64 magicked);
     53static bool change_skyfile_data_state(pxConfig *config, psString data_state, psString run_state);
     54static bool tocleanedskyfileMode(pxConfig *config);
     55static bool topurgedskyfileMode(pxConfig *config);
     56static bool toscrubbedskyfileMode(pxConfig *config);
     57
     58
    5359
    5460# define MODECASE(caseName, func) \
     
    8894        MODECASE(DIFFTOOL_MODE_EXPORTRUN,             exportrunMode);
    8995        MODECASE(DIFFTOOL_MODE_IMPORTRUN,             importrunMode);
     96        MODECASE(DIFFTOOL_MODE_TOCLEANEDSKYFILE,   tocleanedskyfileMode);
     97        MODECASE(DIFFTOOL_MODE_TOPURGEDSKYFILE,    topurgedskyfileMode);
     98        MODECASE(DIFFTOOL_MODE_TOSCRUBBEDSKYFILE,  toscrubbedskyfileMode);
     99
    90100        default:
    91101            psAbort("invalid option (this should not happen)");
     
    115125
    116126    // required options
    117     PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", true, false);
     127    PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", true, false);
    118128    PXOPT_LOOKUP_STR(tess_id, config->args, "-tess_id", true, false);
    119129    PXOPT_LOOKUP_BOOL(bothways, config->args, "-bothways", false);
    120130    PXOPT_LOOKUP_BOOL(exposure, config->args, "-exposure", false);
    121     PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
    122     PXOPT_LOOKUP_STR(reduction, config->args, "-reduction", false, false);
     131    PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false);
     132    PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false);
     133    PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false);
     134    PXOPT_LOOKUP_STR(reduction, config->args, "-rset_eduction", false, false);
     135    PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false);
    123136
    124137    // default
     
    131144            workdir,
    132145            label,
     146            data_group ? data_group : label,
     147            dist_group,
    133148            reduction,
    134149            NULL,       // dvodb
     
    137152            bothways,
    138153            exposure,
    139             false
     154            false,
     155            note
    140156    );
    141157    if (!run) {
     
    168184    PS_ASSERT_PTR_NON_NULL(config, false);
    169185
     186    psMetadata *where = psMetadataAlloc();
     187
     188    PXOPT_COPY_S64(config->args, where, "-diff_id",  "stack_id",   "==");
     189    PXOPT_COPY_STR(config->args, where, "-label",     "label",     "==");
     190    PXOPT_COPY_STR(config->args, where, "-state",     "state",     "==");
     191    if (!psListLength(where->list)) {
     192        psFree(where);
     193        psError(PXTOOLS_ERR_DATA, false, "search parameters are required");
     194        return false;
     195    }
     196
     197    psString query = psStringCopy("UPDATE diffRun");
     198
     199    // pxUpdateRun gets parameters from config->args and updates
     200    bool result = pxUpdateRun(config, where, &query, "diffRun", true);
     201
     202    psFree(query);
     203    psFree(where);
     204
     205    return result;
     206
     207#ifdef notdef
    170208    // required options
    171     PXOPT_LOOKUP_S64(diff_id, config->args, "-diff_id", true, false);
     209    PXOPT_LOOKUP_S64(diff_id, config->args, "-diff_id", false, false);
    172210    PXOPT_LOOKUP_STR(state, config->args, "-state", true, false);
    173 
    174     if (state) {
     211    PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
     212   
     213    // Copy of my hacky work around from stacktool.c
     214    if ((state)&&(diff_id)) {
    175215        // set detRun.state to state
    176216        return setdiffRunState(config, diff_id, state, false);
    177217    }
    178218
    179     return true;
     219    if ((state)&&(label)) {
     220      return setdiffRunStateByLabel(config, label, state);
     221    }
     222
     223    psError(PS_ERR_UNKNOWN, false, "Required options not found.");
     224
     225    return false;
     226#endif
    180227}
    181228
     
    692739    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    693740
    694     PXOPT_LOOKUP_U64(magicked, config->args,        "-magicked", false, false);
    695     PXOPT_LOOKUP_BOOL(destreaked, config->args,     "-destreaked", false);
    696     PXOPT_LOOKUP_BOOL(not_destreaked, config->args, "-not_destreaked", false);
    697 
     741
     742    psString where2 = NULL;
     743    pxmagicAddWhere(config, &where2, "diffSkyfile");
     744    pxspaceAddWhere(config, &where2, template ? "rawTemplate" : "rawInput");
    698745    psString query = pxDataGet("difftool_skyfile.sql");
    699746    if (!query) {
     
    706753        psStringAppend(&query, " WHERE %s", whereClause);
    707754        psFree(whereClause);
     755    } else if (where2) {
     756        psStringAppend(&query, " WHERE diffRun.diff_id is not null %s", where2);
    708757    } else if (!all) {
    709758        psError(PXTOOLS_ERR_DATA, true, "search parameters or -all are required");
     759        return false;
    710760    }
    711761    psFree(where);
    712 
    713     if (not_destreaked) {
    714         if (destreaked) {
    715             psError(PXTOOLS_ERR_DATA, true, "providing -not_destreaked and -destreaked makes no sense");
    716             return false;
    717         }
    718         if (magicked) {
    719             psError(PXTOOLS_ERR_DATA, true, "providing -not_destreaked and -magicked makes no sense");
    720             return false;
    721         }
    722         psStringAppend(&query, " AND diffSkyfile.magicked = 0");
    723     }
    724     if (destreaked) {
    725         psStringAppend(&query, " AND diffSkyfile.magicked != 0");
    726     }
    727 
    728762
    729763    // treat limit == 0 as "no limit"
     
    878912    }
    879913
    880     char *query = "UPDATE diffRun SET state = '%s', magicked = %" PRId64 " WHERE diff_id = %"PRId64;
    881 
    882     if (!p_psDBRunQueryF(config->dbh, query, state, magicked, diff_id)) {
     914    if (magicked) {
     915      char *query = "UPDATE diffRun SET state = '%s', magicked = %" PRId64 " WHERE diff_id = %"PRId64;
     916     
     917      if (!p_psDBRunQueryF(config->dbh, query, state, magicked, diff_id)) {
    883918        psError(PS_ERR_UNKNOWN, false,
    884919                "failed to change state for diff_id %"PRId64, diff_id);
    885920        return false;
    886     }
    887 
     921      }
     922    }
     923    else {
     924      char *query = "UPDATE diffRun SET state = '%s' WHERE diff_id = %"PRId64;
     925     
     926      if (!p_psDBRunQueryF(config->dbh, query, state, diff_id)) {
     927        psError(PS_ERR_UNKNOWN, false,
     928                "failed to change state for diff_id %"PRId64, diff_id);
     929        return false;
     930      }
     931    }
     932   
    888933    return true;
    889934}
     935
     936
     937#ifdef notdef
     938static bool setdiffRunStateByLabel(pxConfig *config, const char *label, const char *state) {
     939  PS_ASSERT_PTR_NON_NULL(state,false);
     940
     941  // check that state is a valid string value
     942  if (!pxIsValidState(state)) {
     943    psError(PS_ERR_UNKNOWN, false, "invalid diffRun state: %s", state);
     944    return false;
     945  }
     946
     947  char *query = "UPDATE diffRun SET state = '%s' WHERE label = '%s'";
     948  if (!p_psDBRunQueryF(config->dbh,query,state,label)) {
     949    psError(PS_ERR_UNKNOWN, false,
     950            "failed to change state for label %s", label);
     951    return(false);
     952  }
     953
     954  return true;
     955}
     956#endif
    890957
    891958// Generate a single populated run
     
    895962                         const char *tess_id, // Tessellation identifier
    896963                         const char *label, // label
     964                         const char *data_group, // data_group
     965                         const char *dist_group, // dist_group
    897966                         const char *reduction, // reduction
     967                         const char *note,      // note
    898968                         psS64 input_warp_id, // Warp identifier for input image, PS_MAX_S64 for none
    899969                         psS64 input_stack_id, // Stack identifier for input image, PS_MAX_S64 for none
     
    926996            workdir,
    927997            label,
     998            data_group ? data_group : label,
     999            dist_group,
    9281000            reduction,
    9291001            NULL,       // dvodb
     
    9321004            false,
    9331005            false,
    934             0       // magicked
     1006            0,       // magicked
     1007            note
    9351008    );
    9361009
     
    10061079    PXOPT_LOOKUP_STR(tess_id, config->args, "-tess_id", true, false); // required options
    10071080    PXOPT_LOOKUP_STR(label, config->args, "-label", false, false);
     1081    PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false);
     1082    PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false);
    10081083    PXOPT_LOOKUP_STR(reduction, config->args, "-reduction", false, false);
    10091084    PXOPT_LOOKUP_S64(template_warp_id, config->args, "-template_warp_id", false, false);
     
    10121087    PXOPT_LOOKUP_S64(input_stack_id, config->args, "-input_stack_id", false, false);
    10131088    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     1089    PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false);
    10141090
    10151091    if (template_stack_id && template_warp_id) {
     
    10351111    psArray *list = psArrayAllocEmpty(16); // List of runs, to print
    10361112
    1037     if (!populatedrun(list, workdir, skycell_id, tess_id, label, reduction,
     1113    if (!populatedrun(list, workdir, skycell_id, tess_id, label, data_group ? data_group : label, dist_group, reduction, note,
    10381114                      input_warp_id ? input_warp_id : PS_MAX_S64,
    10391115                      input_stack_id ? input_stack_id : PS_MAX_S64,
     
    10741150    PXOPT_COPY_STR(config->args, stackWhere, "-stack_label", "stackRun.label", "==");
    10751151
    1076     PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", true, false); // required options
    1077     PXOPT_LOOKUP_STR(reduction, config->args, "-reduction", false, false); // option
    1078     PXOPT_LOOKUP_STR(label, config->args, "-label", false, false); // option
    1079     PXOPT_LOOKUP_TIME(registered, config->args, "-registered", false, false);
     1152    PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", true, false); // required option
     1153    PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false); // option
     1154    PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false); // option
     1155    PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false);
     1156    PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false);
     1157    PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false);
     1158    PXOPT_LOOKUP_TIME(registered, config->args, "-set_registered", false, false);
     1159
    10801160    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    10811161    PXOPT_LOOKUP_BOOL(newTemplates, config->args, "-new-templates", false);
     
    13131393                workdir,
    13141394                label,
     1395                data_group ? data_group : label,
     1396                dist_group,
    13151397                reduction,
    13161398                NULL,       // dvodb
     
    13191401                false,                  // bothways
    13201402                true,                   // exposure
    1321                 0       // magicked
     1403                0,       // magicked
     1404                note
    13221405        );
    13231406
     
    13881471    }
    13891472
    1390     if (!diffRunPrintObjects(stdout, list, !simple)) {
     1473    if (numGood && !diffRunPrintObjects(stdout, list, !simple)) {
    13911474        psError(PS_ERR_UNKNOWN, false, "failed to print object");
    13921475        psFree(list);
     
    14691552
    14701553    // Settings to apply to defined run
    1471     PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", true, false); // required options
    1472     PXOPT_LOOKUP_STR(reduction, config->args, "-reduction", false, false); // option
    1473     PXOPT_LOOKUP_STR(label, config->args, "-label", false, false); // option
    1474     PXOPT_LOOKUP_TIME(registered, config->args, "-registered", false, false);
     1554    PXOPT_LOOKUP_STR(workdir, config->args, "-set_workdir", true, false); // required options
     1555    PXOPT_LOOKUP_STR(reduction, config->args, "-set_reduction", false, false); // option
     1556    PXOPT_LOOKUP_STR(label, config->args, "-set_label", false, false); // option
     1557    PXOPT_LOOKUP_STR(data_group, config->args, "-set_data_group", false, false); // option
     1558    PXOPT_LOOKUP_STR(dist_group, config->args, "-set_dist_group", false, false); // option
     1559    PXOPT_LOOKUP_STR(note, config->args, "-set_note", false, false); // option
     1560    PXOPT_LOOKUP_TIME(registered, config->args, "-set_registered", false, false);
     1561
    14751562    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    14761563    PXOPT_LOOKUP_BOOL(pretend, config->args, "-pretend", false);
     
    16561743        }
    16571744
    1658         diffRunRow *run = diffRunRowAlloc(0, "reg", workdir, label, reduction, NULL, registered,
    1659                                           tess_id, true, true, false); // Run to insert
     1745        diffRunRow *run = diffRunRowAlloc(0, "reg", workdir, label, data_group ? data_group : label, dist_group, reduction, NULL, registered,
     1746                                          tess_id, true, true, false, note); // Run to insert
    16601747        if (!diffRunInsertObject(config->dbh, run)) {
    16611748            psError(PS_ERR_UNKNOWN, false, "database error");
     
    17381825
    17391826    psMetadata *where = psMetadataAlloc();
    1740     pxAddLabelSearchArgs (config, where, "-label", "diffRun.label", "==");
     1827    pxAddLabelSearchArgs (config, where, "-label", "label", "==");
    17411828
    17421829    psString query = pxDataGet("difftool_pendingcleanuprun.sql");
     
    17601847    }
    17611848
     1849    //    fprintf(stderr,"%s",query);
    17621850    if (!p_psDBRunQuery(config->dbh, query)) {
    17631851        psError(PS_ERR_UNKNOWN, false, "database error");
     
    19312019
    19322020    return true;
     2021}
     2022
     2023static bool change_skyfile_data_state(pxConfig *config, psString data_state, psString run_state) {
     2024  PS_ASSERT_PTR_NON_NULL(config, false);
     2025
     2026  // diff_id, skycell_id are required
     2027  PXOPT_LOOKUP_S64(diff_id, config->args, "-diff_id", true, false);
     2028  PXOPT_LOOKUP_STR(skycell_id, config->args, "-skycell_id", true, false);
     2029
     2030  psString query = pxDataGet("difftool_change_skyfile_data_state.sql");
     2031
     2032  if (!psDBTransaction(config->dbh)) {
     2033    psError(PS_ERR_UNKNOWN, false, "database error");
     2034    return(false);
     2035  }
     2036
     2037  // Uses the unconstrained (diffRun.state [NEED NOT EQUAL] run_state) version from warptool.c
     2038
     2039  if (!p_psDBRunQueryF(config->dbh, query, data_state, diff_id, skycell_id)) {
     2040    psError(PS_ERR_UNKNOWN, false, "database error");
     2041    // rollback
     2042    if (!psDBRollback(config->dbh)) {
     2043      psError(PS_ERR_UNKNOWN, false, "database error");
     2044    }
     2045    psError(PS_ERR_UNKNOWN, false, "database error");
     2046    return(false);
     2047  }
     2048  psFree(query);
     2049
     2050  query = pxDataGet("difftool_change_run_state.sql");
     2051  if (!p_psDBRunQueryF(config->dbh, query, data_state, diff_id, data_state)) {
     2052    // rollback
     2053    if (!psDBRollback(config->dbh)) {
     2054      psError(PS_ERR_UNKNOWN, false, "database error");
     2055    }
     2056    psError(PS_ERR_UNKNOWN, false, "database error");
     2057    return(false);
     2058  }
     2059
     2060  if (!psDBCommit(config->dbh)) {
     2061    psError(PS_ERR_UNKNOWN, false, "database error");
     2062    return(false);
     2063  }
     2064 
     2065  return(true);
     2066}
     2067
     2068static bool tocleanedskyfileMode(pxConfig *config) {
     2069  return change_skyfile_data_state(config, "cleaned","goto_cleaned");
     2070}
     2071static bool topurgedskyfileMode(pxConfig *config) {
     2072  return change_skyfile_data_state(config, "purged", "goto_purged");
     2073}
     2074static bool toscrubbedskyfileMode(pxConfig *config) {
     2075  return change_skyfile_data_state(config, "scrubbed", "goto_scrubbed");
    19332076}
    19342077
     
    19562099  }
    19572100
     2101  if (!pxExportVersion(config, f)) {
     2102    psError(PS_ERR_UNKNOWN, false, "failed to write dbversion output file");
     2103    return false;
     2104  }
    19582105  psMetadata *where = psMetadataAlloc();
    19592106  PXOPT_COPY_S64(config->args, where, "-diff_id", "diff_id", "==");
     
    20472194  psMetadata *input = psMetadataConfigRead (NULL, &nFail, infile, false);
    20482195
    2049   fprintf (stdout, "---- input ----\n");
     2196#ifdef notdef
     2197  fprintf (stderr, "---- input ----\n");
    20502198  psMetadataPrint (stderr, input, 1);
    2051 
     2199#endif
     2200
     2201  if (!pxCheckImportVersion(config, input)) {
     2202      psError(PS_ERR_UNKNOWN, false, "pxCheckImportVersion failed");
     2203      return false;
     2204  }
    20522205  psMetadataItem *item = psMetadataLookup (input, "diffRun");
    20532206  psAssert (item, "entry not in input?");
Note: See TracChangeset for help on using the changeset viewer.