IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 26, 2010, 11:43:32 AM (16 years ago)
Author:
Paul Price
Message:

Fixing pxCoalesceRunStatus: NULL integer in the database returns PS_MAX_S32, not 0. Ensure mask fractions are finite (even if zero). Reformatting and simplifying. Fixing error codes.

File:
1 edited

Legend:

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

    r28107 r28109  
    4848}
    4949
    50 psString pxMergeCodeVersions(psString version1, psString version2) {
     50psString pxMergeCodeVersions(psString version1, psString version2)
     51{
     52    if (!version1 && !version2) {
     53        return NULL;
     54    }
     55
     56    if (!version1) {
     57        return psStringCopy(version2);
     58    }
     59    if (!version2) {
     60        return psStringCopy(version1);
     61    }
     62
     63    bool mod1 = false, mod2 = false;    // Modified versions?
     64    if (strchr(version1, 'M')) {
     65        psStringSubstitute(&version1, "M", "");
     66        mod1 = true;
     67    }
     68    if (strchr(version2, 'M')) {
     69        psStringSubstitute(&version2, "M", "");
     70        mod2 = true;
     71    }
     72
     73    int num1 = strtol(version1, NULL, 10);
     74    int num2 = strtol(version2, NULL, 10);
     75    int numO = PS_MAX(num1, num2);
     76
    5177    psString out = NULL;
    52 
    53     bool mod1 = false;
    54     bool mod2 = false;
    55 
    56     psS32 num1;
    57     psS32 num2;
    58     psS32 numO;
    59 
    60     if (!version1) {
    61         psStringAppend(&out, "%s", version2);
    62         return(out);
    63     }
    64     if (!version2) {
    65         psStringAppend(&out, "%s", version1);
    66         return(out);
    67     }
    68 
    69     if (strchr(version1,'M')) {
    70         psStringSubstitute(&version1,"M","");
    71         mod1 = true;
    72     }
    73     if (strchr(version2,'M')) {
    74         psStringSubstitute(&version2,"M","");
    75         mod2 = true;
    76     }
    77 
    78     num1 = strtol(version1,NULL,10);
    79     num2 = strtol(version2,NULL,10);
    80 
    81     if (num1 >= num2) {
    82         numO = num1;
    83     }
    84     else {
    85         numO = num2;
    86     }
    87 
    88     psStringAppend(&out,"%" PRId32,numO);
     78    psStringAppend(&out, "%" PRId32, numO);
    8979    if (mod1 || mod2) {
    90         psStringAppend(&out,"M");
    91     }
    92     return(out);
     80        psStringAppend(&out, "M");
     81    }
     82    return out;
    9383}
    9484
    9585bool pxCoalesceRunStatus(pxConfig *config, const psString dbQFile, psS64 stage_id, psString *software_ver,
    9686                         psS64 *maskfrac_npix, psF32 *maskfrac_static, psF32 *maskfrac_dynamic,
    97                          psF32 *maskfrac_magic, psF32 *maskfrac_advisory) {
     87                         psF32 *maskfrac_magic, psF32 *maskfrac_advisory)
     88{
    9889    psString query = pxDataGet(dbQFile);
    99 /*   psString text_id = NULL; */
    100 /*   psStringAppend(&text_id," %" PRId64,stage_id); */
    101 /*   psStringSubstitute(&query,text_id,"@STAGE_ID@"); */
    102 /*   psFree(text_id); */
     90    if (!query) {
     91        psError(psErrorCodeLast(), false, "Unable to read query");
     92        return false;
     93    }
    10394    if (!p_psDBRunQueryF(config->dbh, query, stage_id)) {
    104         psError(PS_ERR_UNKNOWN, false, "database error");
     95        psError(psErrorCodeLast(), false, "database error");
    10596        psFree(query);
    106         return(false);
     97        return false;
    10798    }
    10899    psFree(query);
     100
    109101    psArray *output = p_psDBFetchResult(config->dbh);
    110102    if (!output) {
    111         psError(PS_ERR_UNKNOWN, false, "database error");
    112         return(false);
    113     }
     103        psError(psErrorCodeLast(), false, "database error");
     104        return false;
     105    }
     106
     107    *maskfrac_npix = 0;
     108    *maskfrac_static = 0.0;
     109    *maskfrac_dynamic = 0.0;
     110    *maskfrac_magic = 0.0;
     111    *maskfrac_advisory = 0.0;
    114112
    115113    for (long i = 0; i < psArrayLength(output); i++) {
     
    121119        psF32 this_magic = psMetadataLookupF32(NULL, row, "maskfrac_magic");
    122120        psF32 this_advisory = psMetadataLookupF32(NULL, row, "maskfrac_advisory");
     121
     122        psTrace("pxtools", 3, "Mask stats: %d %f %f %f %f\n",
     123                this_npix, this_static, this_dynamic, this_magic, this_advisory);
     124
     125        if (this_npix == 0 || this_npix == PS_MAX_S32) {
     126            continue;
     127        }
     128        if (!isfinite(this_static) || !isfinite(this_dynamic) ||
     129            !isfinite(this_magic) || !isfinite(this_advisory)) {
     130            continue;
     131        }
     132
    123133        psString this_version = psMetadataLookupStr(NULL, row, "software_ver");
    124 
    125         psTrace("pxtools", 3, "Mask stats: %d %f %f %f %f %s\n",
    126                 this_npix, this_static, this_dynamic, this_magic, this_advisory, this_version);
    127 
    128134        *software_ver = pxMergeCodeVersions(*software_ver,this_version);
    129 /*     printf("%ld : %d %f %f %f %f <-> %ld %f %f %f %f\n",i,this_npix,this_static,this_dynamic,this_magic,this_advisory, */
    130 /*         *maskfrac_npix,*maskfrac_static,*maskfrac_dynamic,*maskfrac_magic,*maskfrac_advisory); */
    131         if (this_npix > 0) {
    132             *maskfrac_static = ((*maskfrac_static * *maskfrac_npix) + (this_npix * this_static)) / (this_npix + *maskfrac_npix);
    133             *maskfrac_dynamic = ((*maskfrac_dynamic * *maskfrac_npix) + (this_npix * this_dynamic)) / (this_npix + *maskfrac_npix);
    134             *maskfrac_magic = ((*maskfrac_magic * *maskfrac_npix) + (this_npix * this_magic)) / (this_npix + *maskfrac_npix);
    135             *maskfrac_advisory = ((*maskfrac_advisory * *maskfrac_npix) + (this_npix * this_advisory)) / (this_npix + *maskfrac_npix);
    136             *maskfrac_npix += this_npix;
    137         }
     135
     136        *maskfrac_npix += this_npix;
     137        *maskfrac_static += this_npix * this_static;
     138        *maskfrac_dynamic += this_npix * this_dynamic;
     139        *maskfrac_magic += this_npix * this_magic;
     140        *maskfrac_advisory += this_npix * this_advisory;
    138141    }
    139142    psFree(output);
    140     return(true);
    141 }
    142 
    143 bool pxSetRunSoftware(pxConfig *config, const psString tableName, const psString stage_id_name, const psS64 stage_id,
    144                       psString software_ver) {
     143
     144    if (*maskfrac_npix > 0) {
     145        *maskfrac_static /= *maskfrac_npix;
     146        *maskfrac_dynamic /= *maskfrac_npix;
     147        *maskfrac_magic /= *maskfrac_npix;
     148        *maskfrac_advisory /= *maskfrac_npix;
     149    }
     150
     151    return true;
     152}
     153
     154bool pxSetRunSoftware(pxConfig *config, const psString tableName, const psString stage_id_name,
     155                      const psS64 stage_id, psString software_ver)
     156{
    145157    char *query = "UPDATE %s SET software_ver = '%s' WHERE %s = %" PRId64;
    146 /*   printf(query,tableName,software_ver,stage_id_name,stage_id); */
    147     if (!p_psDBRunQueryF(config->dbh,query,tableName,software_ver,stage_id_name,stage_id)) {
    148         psError(PS_ERR_UNKNOWN, false,
    149                 "failed to set software version for %s %" PRId64,stage_id_name,stage_id);
    150         return(false);
    151     }
    152 
    153     return(true);
    154 }
    155 
    156 bool pxSetRunMaskfrac(pxConfig *config, const psString tableName, const psString stage_id_name, const psS64 stage_id,
    157                       psS64 maskfrac_npix, psF32 maskfrac_static, psF32 maskfrac_dynamic,
    158                       psF32 maskfrac_magic, psF32 maskfrac_advisory) {
    159     char *query = "UPDATE %s SET maskfrac_npix = %f, maskfrac_static = %f, maskfrac_dynamic = %f, maskfrac_magic = %f, maskfrac_advisory = %f WHERE %s = %" PRId64;
    160     if (!p_psDBRunQueryF(config->dbh,query,tableName,(float) maskfrac_npix,maskfrac_static,
    161                          maskfrac_dynamic, maskfrac_magic,maskfrac_advisory,stage_id_name,stage_id)) {
    162         psError(PS_ERR_UNKNOWN, false,
     158    if (!p_psDBRunQueryF(config->dbh, query, tableName, software_ver, stage_id_name, stage_id)) {
     159        psError(psErrorCodeLast(), false,
     160                "failed to set software version for %s %" PRId64, stage_id_name, stage_id);
     161        return false;
     162    }
     163
     164    return true;
     165}
     166
     167bool pxSetRunMaskfrac(pxConfig *config, const psString tableName, const psString stage_id_name,
     168                      const psS64 stage_id, psS64 maskfrac_npix, psF32 maskfrac_static,
     169                      psF32 maskfrac_dynamic, psF32 maskfrac_magic, psF32 maskfrac_advisory)
     170{
     171    char *query = "UPDATE %s SET maskfrac_npix = %f, maskfrac_static = %f, maskfrac_dynamic = %f, "
     172        "maskfrac_magic = %f, maskfrac_advisory = %f WHERE %s = %" PRId64;
     173    if (!p_psDBRunQueryF(config->dbh, query, tableName, (float)maskfrac_npix, maskfrac_static,
     174                         maskfrac_dynamic, maskfrac_magic, maskfrac_advisory, stage_id_name, stage_id)) {
     175        psError(psErrorCodeLast(), false,
    163176                "failed to set maskfrac stats for %s %" PRId64,stage_id_name,stage_id);
    164         return(false);
    165     }
    166 
    167 
    168 
    169     return(true);
    170 }
    171 
    172 bool pxCamSetRunMaskfrac(pxConfig *config, const psString tableName, const psString stage_id_name, const psS64 stage_id,
     177        return false;
     178    }
     179
     180
     181
     182    return true;
     183}
     184
     185bool pxCamSetRunMaskfrac(pxConfig *config, const psString tableName,
     186                         const psString stage_id_name, const psS64 stage_id,
    173187                         psS64 maskfrac_ref_npix, psF32 maskfrac_ref_static, psF32 maskfrac_ref_dynamic,
    174188                         psF32 maskfrac_ref_magic, psF32 maskfrac_ref_advisory,
    175189                         psS64 maskfrac_max_npix, psF32 maskfrac_max_static, psF32 maskfrac_max_dynamic,
    176190                         psF32 maskfrac_max_magic, psF32 maskfrac_max_advisory) {
    177   char *query = "UPDATE %s SET maskfrac_ref_npix = %f, maskfrac_ref_static = %f, maskfrac_ref_dynamic = %f, maskfrac_ref_magic = %f, maskfrac_ref_advisory = %f, maskfrac_max_npix = %f, maskfrac_max_static = %f, maskfrac_max_dynamic = %f, maskfrac_max_magic = %f, maskfrac_max_advisory = %f WHERE %s = %" PRId64;
    178   if (!p_psDBRunQueryF(config->dbh,query,tableName,(float) maskfrac_ref_npix,maskfrac_ref_static,
    179                        maskfrac_ref_dynamic, maskfrac_ref_magic,maskfrac_ref_advisory,
    180                        (float) maskfrac_max_npix,maskfrac_max_static,
    181                        maskfrac_max_dynamic, maskfrac_max_magic,maskfrac_max_advisory,
    182                        stage_id_name,stage_id)) {
    183     psError(PS_ERR_UNKNOWN, false,
    184             "failed to set maskfrac stats for %s %" PRId64,stage_id_name,stage_id);
    185     return(false);
     191  char *query = "UPDATE %s SET maskfrac_ref_npix = %f, maskfrac_ref_static = %f, maskfrac_ref_dynamic = %f, "
     192      "maskfrac_ref_magic = %f, maskfrac_ref_advisory = %f, maskfrac_max_npix = %f, maskfrac_max_static = %f, "
     193      "maskfrac_max_dynamic = %f, maskfrac_max_magic = %f, maskfrac_max_advisory = %f WHERE %s = %" PRId64;
     194  if (!p_psDBRunQueryF(config->dbh, query, tableName, (float)maskfrac_ref_npix, maskfrac_ref_static,
     195                       maskfrac_ref_dynamic,  maskfrac_ref_magic, maskfrac_ref_advisory,
     196                       (float)maskfrac_max_npix, maskfrac_max_static,
     197                       maskfrac_max_dynamic,  maskfrac_max_magic, maskfrac_max_advisory,
     198                       stage_id_name, stage_id)) {
     199      psError(psErrorCodeLast(), false,
     200              "failed to set maskfrac stats for %s %" PRId64,stage_id_name,stage_id);
     201      return false;
    186202  }
    187203
    188 
    189 
    190   return(true);
     204  return true;
    191205}
    192206
     
    225239    psMetadataItem *item = psMetadataLookup(config->args, name);
    226240    if (!item) {
    227         psError(PS_ERR_UNKNOWN, false, "failed to lookup value for %s", name);
     241        psError(psErrorCodeLast(), false, "failed to lookup value for %s", name);
    228242        return false;
    229243    }
     
    242256            item->comment = psStringCopy (op);
    243257            if (!psMetadataAddItem(where, item, PS_LIST_TAIL, PS_META_DUPLICATE_OK)) {
    244                 psError(PS_ERR_UNKNOWN, false, "failed to add item %s", field);
     258                psError(psErrorCodeLast(), false, "failed to add item %s", field);
    245259                psFree(where);
    246260                return false;
     
    334348
    335349    if (!p_psDBRunQueryF(config->dbh, *pQuery, joinHook)) {
    336         psError(PS_ERR_UNKNOWN, false, "database error");
     350        psError(psErrorCodeLast(), false, "database error");
    337351        return false;
    338352    }
     
    346360
    347361    if (!p_psDBRunQuery(config->dbh, query)) {
    348         psError(PS_ERR_UNKNOWN, false, "database error");
     362        psError(psErrorCodeLast(), false, "database error");
    349363        return false;
    350364    }
     
    352366    psArray *output = p_psDBFetchResult(config->dbh);
    353367    if (!output) {
    354         psError(PS_ERR_UNKNOWN, false, "database error");
     368        psError(psErrorCodeLast(), false, "database error");
    355369        return false;
    356370    }
    357371    if (!psArrayLength(output)) {
    358372        psFree(output);
    359         psError(PS_ERR_UNKNOWN, true, "no rows in dbversion");
     373        psError(PXTOOLS_ERR_PROG, true, "no rows in dbversion");
    360374        return false;
    361375    }
    362376    if (psArrayLength(output) > 1) {
    363         psError(PS_ERR_UNKNOWN, true, "unexpected number of rows found in dbversion: %ld",
     377        psError(PXTOOLS_ERR_PROG, true, "unexpected number of rows found in dbversion: %ld",
    364378                psArrayLength(output));
    365379        return false;
     
    376390    psArray *array = NULL;
    377391    if (!pxLookupVersion(config, &array)) {
    378         psError(PS_ERR_UNKNOWN, false, "pxLookupVersion failed");
     392        psError(psErrorCodeLast(), false, "pxLookupVersion failed");
    379393        return NULL;
    380394    }
    381395    psMetadata *md = array->data[0];
    382396    if (!md) {
    383         psError(PS_ERR_UNKNOWN, true, "output of pxLookupVersion is null");
     397        psError(PXTOOLS_ERR_PROG, true, "output of pxLookupVersion is null");
    384398        return NULL;
    385399    }
     
    397411    psArray *array = NULL;
    398412    if (!pxLookupVersion(config, &array) || !array) {
    399         psError(PS_ERR_UNKNOWN, false, "pxLookupVersion failed");
     413        psError(psErrorCodeLast(), false, "pxLookupVersion failed");
    400414        return false;
    401415    }
    402416    if (!ippdbPrintMetadatas(file, array, "dbversion", true)) {
    403         psError(PS_ERR_UNKNOWN, false, "failed to print array");
     417        psError(psErrorCodeLast(), false, "failed to print array");
    404418        psFree(array);
    405419        return false;
     
    417431    psMetadataItem *multi_item =  psMetadataLookup(input, "dbversion");
    418432    if (!multi_item || (multi_item->type != PS_DATA_METADATA_MULTI)) {
    419         psError(PS_ERR_UNKNOWN, true, "dbversion multi not found in input");
     433        psError(PXTOOLS_ERR_PROG, true, "dbversion multi not found in input");
    420434        return false;
    421435    }
     
    423437    psMetadataItem *dbversion = psListGet(multi_item->data.list, 0);
    424438    if (!dbversion) {
    425         psError(PS_ERR_UNKNOWN, true, "dbversion not found in input");
     439        psError(PXTOOLS_ERR_PROG, true, "dbversion not found in input");
    426440        return false;
    427441    }
     
    432446        psString schema_version = pxGetDBVersion(config);
    433447        if (!schema_version) {
    434             psError(PS_ERR_UNKNOWN, false, "pxGetDBVersion failed");
     448            psError(psErrorCodeLast(), false, "pxGetDBVersion failed");
    435449            return false;
    436450        }
     
    438452        psString import_version = psMetadataLookupStr(NULL, md, "schema_version");
    439453        if (import_version && strcmp(import_version, schema_version)) {
    440             psError(PS_ERR_UNKNOWN, true, "input file schema_version: %s does not match data base: %s",
     454            psError(PXTOOLS_ERR_PROG, true, "input file schema_version: %s does not match data base: %s",
    441455                    import_version, schema_version);
    442456            return false;
    443457        } else if (!import_version) {
    444             psError(PS_ERR_UNKNOWN, true, "input file schema_version is NULL");
     458            psError(PXTOOLS_ERR_PROG, true, "input file schema_version is NULL");
    445459            return false;
    446460        } else {
     
    448462        }
    449463    } else {
    450         psError(PS_ERR_UNKNOWN, true, "Unexpected config dump format");
    451         return false;
    452     }
    453 
    454     return true;
    455 }
     464        psError(PXTOOLS_ERR_PROG, true, "Unexpected config dump format");
     465        return false;
     466    }
     467
     468    return true;
     469}
Note: See TracChangeset for help on using the changeset viewer.