IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15149


Ignore:
Timestamp:
Oct 1, 2007, 11:08:44 AM (19 years ago)
Author:
jhoblitt
Message:

update pendingImfileMode() to correctly 'load balance' multiple cameras when -limit is specified

File:
1 edited

Legend:

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

    r15108 r15149  
    3737
    3838static bool copydoneCompleteExp(pxConfig *config);
     39static psArray *pzGetKnownCameras(pxConfig *config);
     40static psArray *pzArrayAddArray(psArray *array, psArray *input);
    3941
    4042# define MODECASE(caseName, func) \
     
    218220    }
    219221
    220     // get a list of cameras we've seen exps for
    221     if (!p_psDBRunQuery(config->dbh, "SELECT DISTINCT camera FROM summitExp")) {
    222         psError(PS_ERR_UNKNOWN, false, "database error");
    223         return false;
    224     }
    225 
    226     psArray *cameras = p_psDBFetchResult(config->dbh);
     222    psArray *cameras = pzGetKnownCameras(config);
    227223    if (!cameras) {
    228         psError(PS_ERR_UNKNOWN, false, "database error");
    229         return false;
    230     }
    231     if (!psArrayLength(cameras)) {
    232         psTrace("pztool", PS_LOG_INFO, "no rows found");
    233         psFree(cameras);
    234         return true;
    235     }
     224        psError(PXTOOLS_ERR_DATA, false, "failed to find any cameras");
     225        return false;
     226    }
     227
     228    // array to hold the aggregate results
     229    psArray *output = psArrayAlloc(0);
    236230
    237231    for (long i = 0; i < psArrayLength(cameras); i++) {
     
    239233        if (!query) {
    240234            psError(PXTOOLS_ERR_DATA, false, "failed to retreive SQL statement");
     235            psFree(output);
    241236            return false;
    242237        }
     
    251246        }
    252247
     248        long camLimit = 0;
     249        // avoid possible div by zero
     250        if (limit) {
     251            // in the case where the limit asked for is less then the number of
     252            // cameras we have, return 1 imfile per camera
     253            if (limit < psArrayLength(cameras)) {
     254                camLimit = 1;
     255            } else {
     256                camLimit = limit / psArrayLength(cameras);
     257                // add the modulous to the first camera in the list
     258                if (i == 0) {
     259                    camLimit += limit % psArrayLength(cameras);
     260                }
     261            }
     262        }
    253263
    254264        // treat limit == 0 as "no limit"
    255         if (limit) {
     265        if (camLimit) {
    256266            // divide limit by the number of cameras
    257             psString limitString = psDBGenerateLimitSQL((limit / psArrayLength(cameras) || 1));
     267            psString limitString = psDBGenerateLimitSQL(camLimit);
    258268            psStringAppend(&query, " %s", limitString);
    259269            psFree(limitString);
     
    263273            psError(PS_ERR_UNKNOWN, false, "database error");
    264274            psFree(query);
     275            psFree(output);
    265276            return false;
    266277        }
    267278        psFree(query);
    268279
    269         psArray *output = p_psDBFetchResult(config->dbh);
    270         if (!output) {
     280        psArray *result = p_psDBFetchResult(config->dbh);
     281        if (!result) {
    271282            psError(PS_ERR_UNKNOWN, false, "database error");
    272             return false;
    273         }
    274         if (!psArrayLength(output)) {
     283            psFree(output);
     284            return false;
     285        }
     286        if (!psArrayLength(result)) {
    275287            psTrace("pztool", PS_LOG_INFO, "no rows found");
     288            psFree(result);
    276289            psFree(output);
    277290            return true;
    278291        }
    279292
    280         bool simple = false;
    281         {
    282             bool status = false;
    283             simple = psMetadataLookupBool(&status, config->args, "-simple");
    284             if (!status) {
    285                 psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    286                 psFree(output);
    287                 return false;
    288             }
    289         }
    290 
    291         // negative simple so the default is true
    292         if (!ippdbPrintMetadatas(stdout, output, "pzPendingImfile", !simple)) {
    293             psError(PS_ERR_UNKNOWN, false, "failed to print array");
     293        // merge this query into the result set
     294        pzArrayAddArray(output, result);
     295        psFree(result);
     296    }
     297
     298    bool simple = false;
     299    {
     300        bool status = false;
     301        simple = psMetadataLookupBool(&status, config->args, "-simple");
     302        if (!status) {
     303            psError(PS_ERR_UNKNOWN, false, "failed to lookup value for -simple");
    294304            psFree(output);
    295305            return false;
    296306        }
    297 
     307    }
     308
     309    // negative simple so the default is true
     310    if (!ippdbPrintMetadatas(stdout, output, "pzPendingImfile", !simple)) {
     311        psError(PS_ERR_UNKNOWN, false, "failed to print array");
    298312        psFree(output);
    299     }
     313        return false;
     314    }
     315
     316    psFree(output);
    300317
    301318    return true;
     
    580597    return true;
    581598}
     599
     600static psArray *pzGetKnownCameras(pxConfig *config)
     601{
     602    // get a list of cameras we've seen exps for
     603    if (!p_psDBRunQuery(config->dbh, "SELECT DISTINCT camera FROM summitExp")) {
     604        psError(PS_ERR_UNKNOWN, false, "database error");
     605        return false;
     606    }
     607
     608    psArray *cameras = p_psDBFetchResult(config->dbh);
     609    if (!cameras) {
     610        psError(PS_ERR_UNKNOWN, false, "database error");
     611        return NULL;
     612    }
     613    if (!psArrayLength(cameras)) {
     614        psTrace("pztool", PS_LOG_INFO, "no rows found");
     615        psFree(cameras);
     616        return psArrayAlloc(0);
     617    }
     618
     619    return cameras;
     620}
     621
     622static psArray *pzArrayAddArray(psArray *array, psArray *input)
     623{
     624    for (long i = 0; i < psArrayLength(input); i++) {
     625        psArrayAdd(array, psArrayLength(input), input->data[i]);
     626    }
     627
     628    return array;
     629}
Note: See TracChangeset for help on using the changeset viewer.