IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 13640


Ignore:
Timestamp:
Jun 5, 2007, 9:36:41 AM (19 years ago)
Author:
eugene
Message:

improving the error handling: detect data vs config errors

Location:
trunk/ppStats/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppStats/src/ppStats.c

    r8749 r13640  
    1515    )
    1616{
     17    psExit status;
     18
    1719    // Get the options, open the files
    1820    ppStatsData *data = ppStatsSetupFromRecipe(NULL, config);
     
    2931
    3032    // Go through the FPA and do the hard work
    31     out = ppStatsLoop(out, data, config);
     33    psMetadata *result = ppStatsLoop(&status, out, data, config);
     34    if (status != PS_EXIT_SUCCESS) {
     35        psError (PS_ERR_UNKNOWN, false, "trouble getting stats\n");
     36        psFree(result);
     37        psFree(data);
     38        return (NULL);
     39    }
    3240
    3341    psFree(data);
    34 
    35     return out;
     42    return result;
    3643}
  • trunk/ppStats/src/ppStatsLoop.c

    r13607 r13640  
    6868
    6969
    70 static void cellStats(psMetadata *chipResults, // Metadata holding the chip results
    71                       pmCell *cell,     // Cell for which to get statistics
    72                       psFits *fits,     // FITS file handle
    73                       ppStatsData *data,// The data
    74                       const pmConfig *config // Configuration
     70static psExit cellStats(psMetadata *chipResults, // Metadata holding the chip results
     71                        pmCell *cell,     // Cell for which to get statistics
     72                        psFits *fits,     // FITS file handle
     73                        ppStatsData *data,// The data
     74                        const pmConfig *config // Configuration
    7575    )
    7676{
    7777    assert(chipResults);
    7878    assert(cell);
     79    assert(fits);
    7980    assert(data);
    8081    assert(config);
     
    8485    // Check to see if this is a cell of interest
    8586    if (!doThis(data->cells, cellName)) {
    86         return;
     87        return PS_EXIT_SUCCESS;
    8788    }
    8889
     
    9596
    9697    if (psListLength(data->headers) > 0 && cell->hdu) {
    97         if (fits && !pmCellReadHeader(cell, fits)) {
    98             goto cellDone;
     98        if (!pmCellReadHeader(cell, fits)) {
     99            psError (PS_ERR_IO, false, "trouble reading cell header\n");
     100            return PS_EXIT_DATA_ERROR;
    99101        }
    100102        pmHDU *hdu = cell->hdu;     // HDU for headers
     
    102104    }
    103105    if (psListLength(data->concepts) > 0) {
    104         if (fits && !pmCellReadHeader(cell, fits)) {
    105             goto cellDone;
     106        if (!pmCellReadHeader(cell, fits)) {
     107            psError (PS_ERR_IO, false, "trouble reading cell header\n");
     108            return PS_EXIT_DATA_ERROR;
    106109        }
    107110        pmConceptsReadCell(cell, PM_CONCEPT_SOURCE_ALL, false, config->database);
     
    120123    pmHDU *hdu = pmHDUFromCell(cell); // HDU for cell
    121124    if (!hdu || hdu->blankPHU) {
    122         goto cellDone;
    123     }
    124 
    125     if (fits && !pmCellRead(cell, fits, config->database)) {
    126         psLogMsg(__func__, PS_LOG_WARN, "Unable to read cell %s\n", cellName);
    127         goto cellDone;
     125        psError (PS_ERR_UNKNOWN, false, "trouble finding HDU for cell\n");
     126        return PS_EXIT_CONFIG_ERROR;
     127    }
     128
     129    if (!pmCellRead(cell, fits, config->database)) {
     130        psError (PS_ERR_IO, false, "trouble reading cell data\n");
     131        return PS_EXIT_DATA_ERROR;
    128132    }
    129133
    130134    psArray *readouts = cell->readouts; // Array of component readouts
    131135    if (readouts->n == 0) {
     136        psLogMsg(__func__, PS_LOG_WARN, "No readouts present in cell %s --- skipping\n", cellName);
    132137        goto cellDone;
    133138    }
     
    138143    pmReadout *readout = readouts->data[0]; // The readout of interest
    139144    if (!readout->image) {
    140         psLogMsg(__func__, PS_LOG_WARN, "No image associated with readout in cell %s --- "
    141                  "ignored.\n", cellName);
     145        psLogMsg(__func__, PS_LOG_WARN, "No image associated with readout in cell %s --- ignored.\n", cellName);
    142146        goto cellDone;
    143147    }
     
    146150    if (data->sample <= 0.0) {
    147151        if (!psImageStats(data->stats, readout->image, readout->mask, data->maskVal)) {
    148             psLogMsg(__func__, PS_LOG_WARN, "Unable to perform statistics on cell %s --- "
    149                      "ignored.\n", cellName);
     152            psLogMsg(__func__, PS_LOG_WARN, "Unable to perform statistics on cell %s --- ignored.\n", cellName);
    150153            goto statsDone;
    151154        }
     
    216219        }
    217220
    218         if (!get_nSatPixels && !get_fSatPixels) goto cellDone;
     221        if (!get_nSatPixels && !get_fSatPixels) {
     222            goto cellDone;
     223        }
    219224
    220225        // Get the "concepts" of interest
     
    222227        if (!mdok || isnan(saturation)) {
    223228            psLogMsg(__func__, PS_LOG_WARN, "CELL.SATURATION is not set --- unable to measure N_SAT_PIXELS.\n");
     229            if (get_nSatPixels) psMetadataAddS32(cellResults, PS_LIST_TAIL, "SAT_PIXEL_NUM", 0, NULL, 0);
     230            if (get_fSatPixels) psMetadataAddF32(cellResults, PS_LIST_TAIL, "SAT_PIXEL_FRAC", 0, NULL, NAN);
    224231            goto cellDone;
    225232        }
     
    240247    // Add the cell results to the chip
    241248    addToHierarchy(cellResults, chipResults, cellName, "Results for cell");
    242     if (fits) {
    243         pmCellFreeData(cell);
    244     }
    245     return;
    246 }
    247 
    248 static bool chipStats(psMetadata *fpaResults, // Metadata holding the fpa results
    249                       pmChip *chip,     // Chip for which to get statistics
    250                       psFits *fits,     // FITS file handle
    251                       pmFPAview *view,  // View for analysis
    252                       ppStatsData *data,// The data
    253                       const pmConfig *config // Configuration
     249    pmCellFreeData(cell);
     250    return PS_EXIT_SUCCESS;
     251}
     252
     253static psExit chipStats(psMetadata *fpaResults, // Metadata holding the fpa results
     254                        pmChip *chip,     // Chip for which to get statistics
     255                        psFits *fits,     // FITS file handle
     256                        pmFPAview *view,  // View for analysis
     257                        ppStatsData *data,// The data
     258                        const pmConfig *config // Configuration
    254259    )
    255260{
    256261    assert(fpaResults);
    257262    assert(chip);
     263    assert(fits);
    258264    assert(view);
    259265    assert(data);
    260266    assert(config);
    261267
     268    psExit result = PS_EXIT_SUCCESS;
     269
    262270    const char *chipName = psMetadataLookupStr(NULL, chip->concepts, "CHIP.NAME"); // Name of chip
    263271
    264272    // Check to see if this is a chip of interest
    265273    if (!doThis(data->chips, chipName)) {
    266         return true;
     274        return PS_EXIT_SUCCESS;
    267275    }
    268276
     
    271279        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Desired cell view (%d) doesn't match "
    272280                "number of cells (%ld)\n", view->cell, cells->n);
    273         return false;
     281        return PS_EXIT_CONFIG_ERROR;
    274282    }
    275283
     
    282290
    283291    if (psListLength(data->headers) > 0 && chip->hdu) {
    284         if (fits && !pmChipReadHeader(chip, fits)) {
    285             goto chipDone;
     292        if (!pmChipReadHeader(chip, fits)) {
     293            psError (PS_ERR_IO, false, "trouble reading chip header\n");
     294            return PS_EXIT_DATA_ERROR;
    286295        }
    287296        pmHDU *hdu = chip->hdu;     // HDU for headers
     
    289298    }
    290299    if (psListLength(data->concepts) > 0) {
    291         if (fits && !pmChipReadHeader(chip, fits)) {
    292             goto chipDone;
     300        if (!pmChipReadHeader(chip, fits)) {
     301            psError (PS_ERR_IO, false, "trouble reading chip header\n");
     302            return PS_EXIT_DATA_ERROR;
    293303        }
    294304        pmConceptsReadChip(chip, PM_CONCEPT_SOURCE_ALL, false, false, config->database);
     
    298308    if (view->cell >= 0) {
    299309        pmCell *cell = cells->data[view->cell]; // Cell of interest
    300         cellStats(chipResults, cell, fits, data, config);
    301         goto chipDone;
     310        result = cellStats(chipResults, cell, fits, data, config);
     311        if (result != PS_EXIT_SUCCESS) {
     312            psError (PS_ERR_IO, false, "trouble with cell stats for %d\n", view->cell);
     313            pmChipFreeData(chip);
     314            return result;
     315        }
     316        addToHierarchy(chipResults, fpaResults, chipName, "Results for chip");
     317        pmChipFreeData(chip);
     318        return PS_EXIT_SUCCESS;
    302319    }
    303320
     
    305322    for (int i = 0; i < cells->n; i++) {
    306323        pmCell *cell = cells->data[i];  // Cell of interest
    307         cellStats(chipResults, cell, fits, data, config);
    308     }
    309 
    310 chipDone:
     324        result = cellStats(chipResults, cell, fits, data, config);
     325        if (result != PS_EXIT_SUCCESS) {
     326            psError (PS_ERR_IO, false, "trouble with cell stats for %d\n", i);
     327            pmChipFreeData(chip);
     328            return result;
     329        }
     330    }
     331
    311332    addToHierarchy(chipResults, fpaResults, chipName, "Results for chip");
    312     if (fits) {
    313         pmChipFreeData(chip);
    314     }
    315 
    316     return true;
    317 }
    318 
    319 
    320 psMetadata *ppStatsLoop(psMetadata *fpaResults, // Metadata to hold the FPA results
     333    pmChipFreeData(chip);
     334    return PS_EXIT_SUCCESS;
     335}
     336
     337psMetadata *ppStatsLoop(psExit *result,
     338                        psMetadata *fpaResults, // Metadata to hold the FPA results
    321339                        ppStatsData *data, // The data
    322340                        const pmConfig *config // Configuration
     
    327345    psFits *fits = data->fits;          // FITS file handle
    328346    PS_ASSERT_PTR_NON_NULL(fpa, NULL);
    329 
    330     pmFPAview *view = psMemIncrRefCounter(data->view); // View for analysis
    331     if (!view) {
    332         view = pmFPAviewAlloc(0);
    333     }
    334 
    335     if (!fpaResults) {
    336         fpaResults = psMetadataAlloc();
     347    PS_ASSERT_PTR_NON_NULL(fits, NULL);
     348
     349    *result = PS_EXIT_SUCCESS;
     350
     351    // allocate or bump the ref counter (so we can just free below)
     352    pmFPAview *view = (data->view) ? psMemIncrRefCounter(data->view) : pmFPAviewAlloc(0);
     353
     354    // allocate a new one if needed
     355    psMetadata *newResults = psMemIncrRefCounter(fpaResults);
     356    if (!newResults) {
     357        newResults = psMetadataAlloc();
    337358    }
    338359
    339360    // Iterate through the FPA
    340361    if (psListLength(data->headers) > 0 && fpa->hdu) {
    341         if (fits) {
    342             pmFPAReadHeader(fpa, fits);
    343         }
     362        pmFPAReadHeader(fpa, fits);
    344363        pmHDU *hdu = fpa->hdu;          // HDU for headers
    345         getMetadata(fpaResults, hdu->header, data->headers);
     364        getMetadata(newResults, hdu->header, data->headers);
    346365    }
    347366    if (psListLength(data->concepts) > 0) {
    348         if (fits) {
    349             pmFPAReadHeader(fpa, fits);
    350         }
     367        pmFPAReadHeader(fpa, fits);
    351368        pmConceptsReadFPA(fpa, PM_CONCEPT_SOURCE_ALL, false, config->database);
    352         getMetadata(fpaResults, fpa->concepts, data->concepts);
     369        getMetadata(newResults, fpa->concepts, data->concepts);
    353370    }
    354371
     
    356373    if (view->chip >= 0) {
    357374        pmChip *chip = chips->data[view->chip]; // Chip of interest
    358         chipStats(fpaResults, chip, fits, view, data, config);
    359         goto fpaDone;
     375        *result = chipStats(newResults, chip, fits, view, data, config);
     376        if (*result != PS_EXIT_SUCCESS) {
     377            psError(PS_ERR_UNKNOWN, false, "trouble with stats for cell %d\n", view->cell);
     378            psFree (view);
     379            psFree (newResults);
     380            return NULL;
     381        }
     382        pmFPAFreeData(fpa);
     383        psFree(view);
     384        return newResults;
    360385    }
    361386
     
    363388    for (int i = 0; i < chips->n; i++) {
    364389        pmChip *chip = chips->data[i];  // Chip of interest
    365         chipStats(fpaResults, chip, fits, view, data, config);
    366     }
    367 
    368 fpaDone:
    369     if (fits) {
    370         pmFPAFreeData(fpa);
    371     }
     390        *result = chipStats(newResults, chip, fits, view, data, config);
     391        if (*result != PS_EXIT_SUCCESS) {
     392            psError(PS_ERR_UNKNOWN, false, "trouble with stats for chip %d\n", i);
     393            psFree (view);
     394            psFree (newResults);
     395            return NULL;
     396        }
     397    }
     398
     399    pmFPAFreeData(fpa);
    372400    psFree(view);
    373 
    374     return fpaResults;
    375 }
     401    return newResults;
     402}
  • trunk/ppStats/src/ppStatsLoop.h

    r8337 r13640  
    66
    77// Loop over the input image and do all the hard work
    8 psMetadata *ppStatsLoop(psMetadata *fpaResults, // Metadata to hold the FPA results
     8psMetadata *ppStatsLoop(psExit *result,
     9                        psMetadata *fpaResults, // Metadata to hold the FPA results
    910                        ppStatsData *data, // The data
    1011                        const pmConfig *config // Configuration
  • trunk/ppStats/src/ppStatsSetupFromArgs.c

    r13181 r13640  
    151151
    152152    // Open the input file, determine the camera
     153    int result = PS_EXIT_UNKNOWN_ERROR;
    153154    {
    154155        psString resolved = pmConfigConvertFilename(inName, config, false); // Resolved filename
     
    157158            psError(PS_ERR_IO, false, "Unable to open input file %s\n", resolved);
    158159            psFree(resolved);
     160            result = PS_EXIT_DATA_ERROR;
    159161            goto die;
    160162        }
     
    166168            psError(PS_ERR_UNKNOWN, false, "Unable to determine camera format for %s\n", inName);
    167169            psFree(header);
     170            result = PS_EXIT_DATA_ERROR;
    168171            goto die;
    169172        }
     
    173176            psFree(header);
    174177            psFree(format);
     178            result = PS_EXIT_CONFIG_ERROR;
    175179            goto die;
    176180        }
     
    180184        if (!view) {
    181185            psError(PS_ERR_UNKNOWN, false, "Unable to add input file %s to FPA.\n", inName);
     186            result = PS_EXIT_CONFIG_ERROR;
    182187            goto die;
    183188        }
     
    206211    pmConfigDone();
    207212    psLibFinalize();
    208     exit(EXIT_FAILURE);
    209 }
     213    exit(result);
     214}
  • trunk/ppStats/src/ppStatsStandAlone.c

    r13628 r13640  
    5252        } else {
    5353            psErrorStackPrint(stderr, "Unable to open output file %s.\n", resolved);
    54             psFree(resolved);
    55             status = PS_EXIT_CONFIG_ERROR;
    56             goto die;
     54            exit(PS_EXIT_CONFIG_ERROR);
    5755        }
    5856        psFree(resolved);
     
    6058
    6159    // Go through the FPA and do the hard work
    62     psMetadata *results = ppStatsLoop(NULL, data, config);
     60    psMetadata *results = ppStatsLoop(&status, NULL, data, config);
     61    if (status != PS_EXIT_SUCCESS) {
     62        psErrorStackPrint(stderr, "Error in stats loop.\n");
     63        exit (status);
     64    }
    6365    if (psListLength(results->list) == 0) {
    6466        psErrorStackPrint(stderr, "No output.\n");
    65         psFree(results);
    66         status = PS_EXIT_DATA_ERROR;
    67         goto die;
     67        exit (status);
    6868    }
    6969
     
    7878        psErrorStackPrint(stderr, "Unable to generate configuration file with result.\n");
    7979        psFree(results);
    80         status = PS_EXIT_CONFIG_ERROR;
    81         goto die;
     80        exit(PS_EXIT_CONFIG_ERROR);
    8281    }
    8382    fprintf(outFile, "%s", output);
Note: See TracChangeset for help on using the changeset viewer.