IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 13, 2008, 10:17:34 AM (17 years ago)
Author:
bills
Message:

Rework the diff stage to process the skycells from an exposure in a single
diffRun

File:
1 edited

Legend:

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

    r20783 r20973  
    128128    PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    129129
    130     // Create temporary table of the best diffs
    131     {
    132         psString query = pxDataGet("magictool_definebyquery_temp_create.sql");
    133         if (!query) {
    134             psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    135             return false;
    136         }
    137 
    138         if (!p_psDBRunQuery(config->dbh, query)) {
    139             psError(PS_ERR_UNKNOWN, false, "database error");
    140             return false;
    141         }
    142         psFree(query);
    143     }
    144 
    145     // Insert list of best diffs into temporary table
    146     {
    147         psString query = pxDataGet("magictool_definebyquery_temp_insert.sql");
    148         if (!query) {
    149             psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
    150             return false;
    151         }
    152 
    153         psMetadata *where = psMetadataAlloc();
    154         PXOPT_COPY_S64(config->args, where, "-exp_id", "exp_id", "==");
    155         PXOPT_COPY_STR(config->args, where, "-diff_label", "diffRun.label", "==");
    156         PXOPT_COPY_F32(config->args, where, "-good_frac", "warpSkyfile.good_frac", ">=");
    157 
    158         psString whereClause = NULL;    // WHERE conditions
    159         if (psListLength(where->list)) {
    160             whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    161             psStringPrepend(&whereClause, "\n AND ");
    162         }
    163         psFree(where);
    164 
    165         if (!p_psDBRunQuery(config->dbh, query, whereClause)) {
    166             psError(PS_ERR_UNKNOWN, false, "database error");
    167             psFree(whereClause);
    168             psFree(query);
    169             return false;
    170         }
    171         psFree(whereClause);
    172         psFree(query);
    173     }
     130    psMetadata *where = psMetadataAlloc();
     131    PXOPT_COPY_S64(config->args, where, "-exp_id", "exp_id", "==");
     132    PXOPT_COPY_STR(config->args, where, "-diff_label", "diffRun.label", "==");
     133
    174134
    175135    // Get list of exposures ready to magic
     
    181141        }
    182142
    183         psString magicSkyCellNumsWhere = NULL;    // WHERE conditions for magicSkyCellNums
    184         {
    185             psMetadata *where = psMetadataAlloc();
    186             PXOPT_COPY_S64(config->args, where, "-exp_id", "exp_id", "==");
    187             PXOPT_COPY_STR(config->args, where, "-diff_label", "diffRun.label", "==");
    188             PXOPT_COPY_F32(config->args, where, "-good_frac", "warpSkyfile.good_frac", ">=");
    189 
    190             if (psListLength(where->list)) {
    191                 magicSkyCellNumsWhere = psDBGenerateWhereConditionSQL(where, NULL);
    192                 psStringPrepend(&magicSkyCellNumsWhere, "\n AND ");
    193             }
    194             psFree(where);
    195         }
    196 
    197         // "available" means only concern ourselves with exposures that have all diffs completed, unless we're
    198         // told to only take what's available.
    199         // "new" means we want a new run even if there's already a magic run defined
     143        // "available" means queue magic run even though the diffRun has skycells that did not complete
     144        // "rerun" means we want a new run even if there's already a magic run defined for the exposure
    200145        PXOPT_LOOKUP_BOOL(available, config->args, "-available", false);
    201         PXOPT_LOOKUP_BOOL(new, config->args, "-new", false);
     146        PXOPT_LOOKUP_BOOL(rerun, config->args, "-rerun", false);
    202147
    203148        psString queryWhere = NULL;     // WHERE conditions for entire query
    204         if (available) {
    205             psStringAppend(&queryWhere, " WHERE num_done = num_todo");
    206         }
    207         if (new) {
     149        if (!available) {
     150            psStringAppend(&queryWhere, " \nWHERE diffRun.state = 'full'");
     151        } else {
     152            // what if no skycells for the diff run completed?
     153        }
     154        if (!rerun) {
    208155            const char *newWhere = " magic_id IS NULL"; // String to add
    209156            if (queryWhere) {
    210157                psStringAppend(&queryWhere, " AND %s", newWhere);
    211158            } else {
    212                 psStringAppend(&queryWhere, " WHERE %s", newWhere);
     159                psStringAppend(&queryWhere, "\nWHERE %s", newWhere);
    213160            }
    214161        }
    215         if (queryWhere) {
    216             psStringAppend(&query, " %s", queryWhere);
     162        // now add the user specified qualifiers
     163        if (psListLength(where->list)) {
     164            psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     165            psStringAppend(&queryWhere, "\n%s %s", queryWhere == NULL ? "WHERE" : "AND", whereClause);
     166            psFree(whereClause);
     167        }
     168        psFree(where);
     169        if (!queryWhere) {
     170            psStringAppend(&queryWhere, " ");
     171        }
     172
     173        if (!p_psDBRunQuery(config->dbh, query, queryWhere)) {
     174            psError(PS_ERR_UNKNOWN, false, "database error");
    217175            psFree(queryWhere);
    218         }
    219 
    220 
    221         if (!p_psDBRunQuery(config->dbh, query, magicSkyCellNumsWhere ? magicSkyCellNumsWhere : "")) {
    222             psError(PS_ERR_UNKNOWN, false, "database error");
    223             psFree(magicSkyCellNumsWhere);
    224176            psFree(query);
    225177            return false;
    226178        }
    227         psFree(magicSkyCellNumsWhere);
     179        psFree(queryWhere);
    228180        psFree(query);
    229181    }
     
    262214        psMetadata *row = output->data[i]; // Row of interest
    263215        psS64 exp_id = psMetadataLookupS64(NULL, row, "exp_id"); // Exposure identifier
     216        psS64 diff_id = psMetadataLookupS64(NULL, row, "diff_id"); // difference identifier
    264217
    265218        // create a new magicRun for this group
    266         magicRunRow *run = magicRunRowAlloc(0, exp_id, "run", workdir, "dirty", label, dvodb, registered, 0);
     219        magicRunRow *run = magicRunRowAlloc(0, exp_id, diff_id, "run", workdir, "dirty", label, dvodb, registered, 0);
    267220        if (!run) {
    268221            psAbort("failed to alloc magicRun object");
     
    297250        {
    298251            psString idString = NULL;
    299             psStringAppend(&idString, "%" PRId64, exp_id);
    300             psStringSubstitute(&thisInsert, idString, "@EXP_ID@");
     252            psStringAppend(&idString, "%" PRId64, diff_id);
     253            psStringSubstitute(&thisInsert, idString, "@DIFF_ID@");
    301254            psFree(idString);
    302255        }
     
    340293    PXOPT_LOOKUP_STR(workdir, config->args, "-workdir", true, false);
    341294    PXOPT_LOOKUP_S64(exp_id, config->args, "-exp_id", true, false);
     295    PXOPT_LOOKUP_S64(diff_id, config->args, "-diff_id", true, false);
    342296
    343297    // optional
     
    350304            0,          // ID
    351305            exp_id,
     306            diff_id,
    352307            "reg",      // state
    353308            workdir,
Note: See TracChangeset for help on using the changeset viewer.