IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15499


Ignore:
Timestamp:
Nov 7, 2007, 6:06:07 PM (19 years ago)
Author:
jhoblitt
Message:

add magictool -queue mode

Location:
trunk/ippTools
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/share/Makefile.am

    r15348 r15499  
    4242        magictool_tomask.sql \
    4343        magictool_toskyfilemask.sql \
     44        magictool_find_complete_diffed_exposures.sql \
     45        magictool_find_complete_warpruns.sql \
    4446        pztool_find_completed_exp.sql \
    4547        pztool_pendingimfile.sql \
  • trunk/ippTools/share/magictool_find_complete_warpruns.sql

    r15486 r15499  
    11-- find stopped warp runsthat have had all of their skycell's warped without
    22-- any faults
    3 SELECT
    4     warp_id
     3INSERT INTO warpComplete
     4SELECT
     5    warp_id,
     6    skycell_id,
     7    tess_id
    58FROM (
    69    SELECT
  • trunk/ippTools/share/magictool_find_unmagiced.sql

    r15484 r15499  
    88        warpSkyfile.fault as f1,
    99        diffSkyfile.fault as f2,
    10         warpSkyCellMap.skycell_id as s1,
     10        warpSkyCellMap.skycell_id as wscm_s,
     11        warpSkyfile.skycell_id as wsf_s,
    1112        diffInputSkyfile.skycell_id as s2
    1213    FROM warpRun
     
    2627    LEFT JOIN magicInputSkyfile
    2728        USING(diff_id)
    28     LEFT JOIN magicRun
    29         USING (magic_id)
    3029    WHERE
    3130        warpRun.state = 'stop'
     
    4241    --    warpRun.warp_id, warpSkyCellMap.skycell_id, warpSkyCellMap.tess_id
    4342    HAVING
    44         COUNT(warpSkyCellMap.skycell_id) = COUNT(diffInputSkyfile.skycell_id)
     43        COUNT(warpSkyCellMap.skycell_id) = COUNT(warpSkyfile.skycell_id)
     44        AND COUNT(warpSkyCellMap.skycell_id) = COUNT(diffInputSkyfile.skycell_id)
    4545        AND SUM(warpSkyfile.fault) = 0
    4646        AND SUM(diffSkyfile.fault) = 0
  • trunk/ippTools/src/magictool.c

    r15348 r15499  
    3131#include "magictool.h"
    3232
     33static bool queueMode(pxConfig *config);
    3334static psS64 definerunMode(pxConfig *config);
    3435static bool updaterunMode(pxConfig *config);
     
    6364
    6465    switch (config->mode) {
     66        MODECASE(MAGICTOOL_MODE_QUEUE,          queueMode);
    6567        MODECASE(MAGICTOOL_MODE_DEFINERUN,      definerunMode);
    6668        MODECASE(MAGICTOOL_MODE_UPDATERUN,      updaterunMode);
     
    9294
    9395    exit(exit_status);
     96}
     97
     98static bool queueMode(pxConfig *config)
     99{
     100    PS_ASSERT_PTR_NON_NULL(config, false);
     101
     102    // create warped skycells temp table
     103{
     104    char *query =
     105        "CREATE TEMPORARY TABLE warpComplete\n"
     106        " (warp_id BIGINT, skycell_id VARCHAR(64), tess_id VARCHAR(64),\n"
     107        " PRIMARY KEY(warp_id, skycell_id, tess_id)) ENGINE=MEMORY\n";
     108
     109    if (!p_psDBRunQuery(config->dbh, query)) {
     110        psError(PS_ERR_UNKNOWN, false, "database error");
     111        return false;
     112    }
     113}
     114
     115    // find warped skycells
     116{
     117    psString query = pxDataGet("magictool_find_complete_warpruns.sql");
     118    if (!query) {
     119        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     120        return false;
     121    }
     122
     123    if (!p_psDBRunQuery(config->dbh, query)) {
     124        psError(PS_ERR_UNKNOWN, false, "database error");
     125        psFree(query);
     126        return false;
     127    }
     128    psFree(query);
     129}
     130
     131    // find the diff_id's of the warped skycells
     132{
     133    psString query = pxDataGet("magictool_find_complete_diffed_exposures.sql");
     134    if (!query) {
     135        psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     136        return false;
     137    }
     138
     139    if (!p_psDBRunQuery(config->dbh, query)) {
     140        psError(PS_ERR_UNKNOWN, false, "database error");
     141        psFree(query);
     142        return false;
     143    }
     144    psFree(query);
     145}
     146    psArray *output = p_psDBFetchResult(config->dbh);
     147    if (!output) {
     148        psErrorCode err = psErrorCodeLast();
     149        switch (err) {
     150            case PS_ERR_DB_CLIENT:
     151                psError(PXTOOLS_ERR_SYS, false, "database error");
     152            case PS_ERR_DB_SERVER:
     153                psError(PXTOOLS_ERR_PROG, false, "database error");
     154            default:
     155                psError(PXTOOLS_ERR_PROG, false, "unknown error");
     156        }
     157
     158        return false;
     159    }
     160    if (!psArrayLength(output)) {
     161        psTrace("magictool", PS_LOG_INFO, "no rows found");
     162        psFree(output);
     163        return true;
     164    }
     165
     166    // pre-allocate enough hash buckets for 1 unique warp_id per row
     167    psHash *groups = psHashAlloc(psArrayLength(output));
     168    // iterate over result set, and group by warp_id
     169    for (long i = 0; i < psArrayLength(output); i++) {
     170        // lookup the key we're grouping by
     171        bool status = false;
     172        psS64 warp_id = psMetadataLookupS64(&status, output->data[i], "warp_id");
     173        if (!status) {
     174            psAbort("failed to lookup value for warp_id");
     175        }
     176
     177        psString key = psDBIntToString(warp_id);
     178        // look to see if there is a bin for this key
     179        psArray *groupBin = psHashLookup(groups, key);
     180        if (!groupBin) {
     181            // if not, create one
     182            groupBin = psArrayAlloc(0);
     183            psHashAdd(groups, key, groupBin);
     184        }
     185        psFree(key);
     186
     187        // add this row to the bin
     188        psArrayAdd(groupBin, 0, output->data[i]);
     189        psFree(groupBin);
     190    }
     191    psFree(output);
     192
     193    // create a magic run
     194    psArray *grouped =  psHashToArray(groups);
     195    psFree(groups);
     196
     197    // iterate over array of grouped warp_ids
     198    for (long i = 0; i < psArrayLength(grouped); i++) {
     199        psArray *group = grouped->data[i];
     200
     201        // create a new magicRun for this group
     202        // XXX This need to have options passed through to it
     203
     204        magicRunRow *run = magicRunRowAlloc(
     205                0,          // ID
     206                "reg",      // state
     207                NULL,       // workdir
     208                "dirty",    // workdir_state
     209                NULL,       // label
     210                NULL,       // dvodb
     211                NULL        // registered
     212        );
     213        if (!run) {
     214            psAbort("failed to alloc magicRun object");
     215        }
     216        if (!magicRunInsertObject(config->dbh, run)) {
     217            psError(PS_ERR_UNKNOWN, false, "database error");
     218            psFree(run);
     219            psFree(grouped);
     220            return false;
     221        }
     222
     223        // get the assigned warp_id
     224        psS64 magic_id = psDBLastInsertID(config->dbh);
     225
     226        // insert all rows in this bin into the new magicRun
     227        for (long j = 0; j < psArrayLength(group); j++) {
     228            psMetadata *row = group->data[j];
     229
     230            bool status = false;
     231            psS64 diff_id = psMetadataLookupS64(&status, row, "diff_id");
     232            if (!status) {
     233                psAbort("failed to lookup value for diff_id");
     234            }
     235            psString node = psMetadataLookupStr(&status, row, "skycell_id");
     236            if (!status) {
     237                psAbort("failed to lookup value for diff_id");
     238            }
     239
     240            if (!magicInputSkyfileInsert(config->dbh,
     241                magic_id,
     242                diff_id,
     243                node)) {
     244                psError(PS_ERR_UNKNOWN, false, "database error");
     245                psFree(grouped);
     246                return false;
     247            }
     248        }
     249
     250        // set magicRun.state to 'run'
     251        return setmagicRunState(config, magic_id, "run");
     252    }
     253
     254    return true;
    94255}
    95256
  • trunk/ippTools/src/magictool.h

    r14537 r15499  
    2525typedef enum {
    2626    MAGICTOOL_MODE_NONE           = 0x0,
     27    MAGICTOOL_MODE_QUEUE,
    2728    MAGICTOOL_MODE_DEFINERUN,
    2829    MAGICTOOL_MODE_UPDATERUN,
  • trunk/ippTools/src/magictoolConfig.c

    r15340 r15499  
    4848    psString now = psTimeToISO(time);
    4949    psFree(time);
     50
     51    // -queue
     52    psMetadata *queueArgs = psMetadataAlloc();
    5053
    5154    // -definerun
     
    146149    psMetadata *modes   = psMetadataAlloc();
    147150
     151    PXTOOL_ADD_MODE("-queue",           "", MAGICTOOL_MODE_QUEUE,           queueArgs);
    148152    PXTOOL_ADD_MODE("-definerun",       "", MAGICTOOL_MODE_DEFINERUN,       definerunArgs);
    149153    PXTOOL_ADD_MODE("-updaterun",       "", MAGICTOOL_MODE_UPDATERUN,       updaterunArgs);
Note: See TracChangeset for help on using the changeset viewer.