IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 10, 2010, 8:17:41 AM (15 years ago)
Author:
eugene
Message:

re-organize ppStackLoop to make the steps clearer: add separate functions for UpdateHeader, JPEGs, Stats; move cluttered includes into ppStack.h; push DIE section of ppStack.c into ppStackCleanup (like ppImageCleanup); rename old ppStackCleanup to ppStackCleanupFiles; consolidate file cleanup block in ppStackLoop (for unconvolved outputs) into ppStackCleanupFiles; add options for stack type

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20101205/ppStack/src/ppStackCleanup.c

    r30012 r30015  
    1 #ifdef HAVE_CONFIG_H
    2 #include <config.h>
    3 #endif
     1#include "ppStack.h"
    42
    5 #include <stdio.h>
    6 #include <pslib.h>
    7 #include <psmodules.h>
    8 #include <ppStats.h>
    9 
    10 #include "ppStack.h"
    11 #include "ppStackLoop.h"
    12 
    13 // XXX poor name : move jpeg & stats to a separate function?
    143// ppStackCleanupFiles
    15 bool ppStackCleanup(ppStackThreadData *stack, ppStackOptions *options, pmConfig *config)
     4bool ppStackCleanupFiles(ppStackThreadData *stack, ppStackOptions *options, pmConfig *config, ppStackFileList stackFiles, ppStackFileList photFiles, bool closeJPEGs)
    165{
    176    psAssert(stack, "Require stack");
     
    198    psAssert(config, "Require configuration");
    209
    21     psMetadata *recipe = psMetadataLookupMetadata(NULL, config->recipes, PPSTACK_RECIPE); // ppStack recipe
    22     psAssert(recipe, "We've thrown an error on this before.");
    23 
    24     // Generate binned JPEGs
    25     {
    26         int bin1 = psMetadataLookupS32(NULL, recipe, "BIN1"); // First binning level
    27         int bin2 = psMetadataLookupS32(NULL, recipe, "BIN2"); // Second binning level
    28 
    29         // Target cells
    30         pmFPAview *view = pmFPAviewAlloc(0); // View to cells of interest
    31         view->chip = view->cell = 0;
    32         pmCell *cell1 = pmFPAfileThisCell(config->files, view, "PPSTACK.OUTPUT.JPEG1");
    33         pmCell *cell2 = pmFPAfileThisCell(config->files, view, "PPSTACK.OUTPUT.JPEG2");
    34         psImageMaskType maskValue = pmConfigMaskGet("BLANK", config); // Bits to mask
    35         psFree(view);
    36 
    37         pmReadout *ro1 = pmReadoutAlloc(cell1), *ro2 = pmReadoutAlloc(cell2); // Binned readouts
    38         if (!pmReadoutRebin(ro1, options->outRO, maskValue, bin1, bin1) ||
    39             !pmReadoutRebin(ro2, ro1, 0, bin2, bin2)) {
    40             psError(PPSTACK_ERR_DATA, false, "Unable to bin output.");
    41             psFree(ro1);
    42             psFree(ro2);
    43             return false;
    44         }
    45         psFree(ro1);
    46         psFree(ro2);
    47     }
    48 
    49     // Statistics on output
    50     if (options->stats) {
    51         psTrace("ppStack", 1, "Gathering statistics on stacked image....\n");
    52         psString maskBadStr = psMetadataLookupStr(NULL, recipe, "MASK.BAD"); // Name of bits for bad
    53         psImageMaskType maskBad = pmConfigMaskGet(maskBadStr, config); // Bits to mask for bad pixels
    54 
    55         pmFPAview *view = pmFPAviewAlloc(0); // View to readout
    56         view->chip = view->cell = view->readout = 0;
    57 
    58         ppStatsFPA(options->stats, options->outRO->parent->parent->parent, view, maskBad, config);
    59 
    60         psFree(view);
    61     }
    62 
    6310    if (!ppStackFilesIterateUp(config)) {
    6411        psError(psErrorCodeLast(), false, "Unable to close files.");
    6512        return false;
    6613    }
    67     ppStackFileActivation(config, PPSTACK_FILES_STACK, false);
    68     ppStackFileActivation(config, PPSTACK_FILES_PHOT, false);
     14    ppStackFileActivation(config, stackFiles, false);
     15    ppStackFileActivation(config, photFiles, false);
    6916
    7017    // Ensure files are freed
    71     {
    72         options->outRO->data_exists = false;
    73         options->outRO->parent->data_exists = false;
    74         options->outRO->parent->parent->data_exists = false;
    75         psFree(options->outRO);
    76         options->outRO = NULL;
     18    options->outRO->data_exists = false;
     19    options->outRO->parent->data_exists = false;
     20    options->outRO->parent->parent->data_exists = false;
     21    psFree(options->outRO);
     22    options->outRO = NULL;
    7723
    78         options->expRO->data_exists = false;
    79         options->expRO->parent->data_exists = false;
    80         options->expRO->parent->parent->data_exists = false;
    81         psFree(options->expRO);
    82         options->expRO = NULL;
     24    options->expRO->data_exists = false;
     25    options->expRO->parent->data_exists = false;
     26    options->expRO->parent->parent->data_exists = false;
     27    psFree(options->expRO);
     28    options->expRO = NULL;
    8329
     30    for (int i = 0; i < options->num; i++) {
     31        pmCellFreeData(options->cells->data[i]);
     32    }
     33
     34    if (closeJPEGs) {
    8435        // XXX move these close / free operations to the jpeg creation function
    8536        pmFPAview *view = pmFPAviewAlloc(0);// Pointer into FPA hierarchy
     
    10960    return true;
    11061}
     62
     63bool ppStackCleanup (pmConfig *config, ppStackOptions *options) {
     64
     65    psExit exitValue = ppStackExitCode(PS_EXIT_SUCCESS); // Exit code
     66
     67    // Ensure everything closes
     68    if (config) {
     69        ppStackFileActivation(config, PPSTACK_FILES_PREPARE, true);
     70        ppStackFileActivation(config, PPSTACK_FILES_CONVOLVE, true);
     71        ppStackFileActivation(config, PPSTACK_FILES_STACK, true);
     72        ppStackFileActivation(config, PPSTACK_FILES_UNCONV, true);
     73        ppStackFileActivation(config, PPSTACK_FILES_PHOT, true);
     74        if (!ppStackFilesIterateUp(config)) {
     75            psError(psErrorCodeLast(), false, "Unable to close files.");
     76            exitValue = ppStackExitCode(exitValue);
     77            pmFPAfileFreeSetStrict(false);
     78        }
     79    }
     80
     81    // Write out summary statistics
     82    if (options && options->stats) {
     83
     84        psMetadataAddS32(options->stats, PS_LIST_TAIL, "QUALITY", PS_META_REPLACE, "Bad data quality flag", options->quality);
     85        psMetadataAddF32(options->stats, PS_LIST_TAIL, "TIME_STACK", 0, "Total time", psTimerClear("PPSTACK_TOTAL"));
     86
     87        const char *statsMDC = psMetadataConfigFormat(options->stats);
     88        if (!statsMDC || strlen(statsMDC) == 0) {
     89            psError(PS_ERR_IO, false, "Unable to get statistics MDC file.");
     90            exitValue = ppStackExitCode(exitValue);
     91            exit(exitValue);
     92        }
     93        if (fprintf(options->statsFile, "%s", statsMDC) != strlen(statsMDC)) {
     94            psError(PS_ERR_IO, false, "Unable to write statistics MDC file.");
     95            exitValue = ppStackExitCode(exitValue);
     96            exit(exitValue);
     97        }
     98        psFree(statsMDC);
     99        if (fclose(options->statsFile) == EOF) {
     100            psError(PS_ERR_IO, false, "Unable to close statistics MDC file.");
     101            exitValue = ppStackExitCode(exitValue);
     102            exit(exitValue);
     103        }
     104        options->statsFile = NULL;
     105        pmConfigRunFilenameAddWrite(config, "STATS", psMetadataLookupStr(NULL, config->arguments, "STATS"));
     106    }
     107    psFree(options);
     108
     109    // Dump configuration
     110    bool mdok;                                                                    // Status of MD lookup
     111    psString dump = psMetadataLookupStr(&mdok, config->arguments, "DUMP_CONFIG"); // File for config
     112    if (dump && !pmConfigDump(config, dump)) {
     113        psError(psErrorCodeLast(), false, "Unable to dump configuration.");
     114        exitValue = ppStackExitCode(exitValue);
     115    }
     116
     117    psTrace("ppStack", 1, "Finished at %f sec\n", psTimerMark("PPSTACK"));
     118    psTimerStop();
     119
     120    psFree(config);
     121    pmModelClassCleanup();
     122    pmConfigDone();
     123    psLibFinalize();
     124    pmVisualClose();
     125    pmVisualCleanup ();
     126
     127    exitValue = ppStackExitCode(exitValue);
     128    exit(exitValue);
     129}
Note: See TracChangeset for help on using the changeset viewer.