IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 27126


Ignore:
Timestamp:
Mar 1, 2010, 4:48:52 PM (16 years ago)
Author:
Paul Price
Message:

Reworking pswarp to prevent SEGV and/or failed asserts when failures occur in read/write.

Location:
trunk/pswarp/src
Files:
1 added
4 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/pswarp/src/Makefile.am

    r23808 r27126  
    2828        pswarp.c                        \
    2929        pswarpArguments.c               \
    30         pswarpCleanup.c                 \
     30        pswarpExit.c                    \
    3131        pswarpLoop.c                    \
    3232        pswarpDefine.c                  \
     
    4242        pswarpTransformSources.c        \
    4343        pswarpTransformTile.c           \
    44         pswarpVersion.c           
     44        pswarpVersion.c                 \
     45        pswarpFiles.c
    4546
    4647noinst_HEADERS = \
  • trunk/pswarp/src/pswarp.c

    r27098 r27126  
    1111 */
    1212
    13 # include "pswarp.h"
     13#include "pswarp.h"
     14#include "pswarpFileNames.h"
    1415
    1516static void usage (void) {
     
    3031    pmModelClassInit();
    3132    psphotInit();
     33
     34    const char *statsName = NULL;       // Filename for statistics
     35    psMetadata *stats = NULL;           // Container for statistics
     36    FILE *statsFile = NULL;             // File stream for statistics
    3237
    3338    pmConfig *config = pswarpArguments(argc, argv);
     
    5055    }
    5156
     57    // Open the statistics file
     58    bool mdok;                          ///< Status of MD lookup
     59    statsName = psMetadataLookupStr(&mdok, config->arguments, "STATS"); ///< Filename for statistics
     60    if (mdok && statsName && strlen(statsName) > 0) {
     61        psString resolved = pmConfigConvertFilename(statsName, config, true, true);
     62        statsFile = fopen(resolved, "w");
     63        if (!statsFile) {
     64            psError(PS_ERR_IO, true, "Unable to open statistics file %s for writing.\n", resolved);
     65            psFree(resolved);
     66            goto DIE;
     67        }
     68        psFree(resolved);
     69        stats = psMetadataAlloc();
     70        psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", 0, "No problems", 0);
     71    }
     72
    5273    // load and warp
    53     if (!pswarpLoop(config)) {
     74    if (!pswarpLoop(config, stats)) {
    5475        goto DIE;
    5576    }
     
    5879
    5980DIE:
    60     return pswarpCleanup(config);
     81    {
     82        psExit exitValue = pswarpExitCode(PS_EXIT_SUCCESS); // Exit code
     83
     84        // Ensure everything is written out, at every level
     85        pswarpFileActivation(config, detectorFiles, true);
     86        pswarpFileActivation(config, skycellFiles, true);
     87        pswarpFileActivation(config, photFiles, true);
     88        pswarpFileActivation(config, independentFiles, true);
     89        if (!pswarpIOChecksAfter(config)) {
     90            psError(psErrorCodeLast(), false, "Unable to write files.");
     91            exitValue = pswarpExitCode(exitValue);
     92        }
     93
     94        // Write out summary statistics
     95        if (stats) {
     96            psMetadataAddF32(stats, PS_LIST_TAIL, "DT_WARP", 0, "Time for warp completion",
     97                             psTimerMark("pswarp"));
     98
     99            const char *statsMDC = psMetadataConfigFormat(stats);
     100            if (!statsMDC) {
     101                psError(psErrorCodeLast(), false, "Unable to get statistics file.");
     102                exitValue = pswarpExitCode(exitValue);
     103            }
     104            psFree(stats);
     105            if (fprintf(statsFile, "%s", statsMDC) != strlen(statsMDC)) {
     106                psError(PSWARP_ERR_IO, true, "Unable to write statistics file.");
     107                exitValue = pswarpExitCode(exitValue);
     108            }
     109            psFree(statsMDC);
     110            if (fclose(statsFile) == EOF) {
     111                psError(PSWARP_ERR_IO, true, "Unable to close statistics file.");
     112                exitValue = pswarpExitCode(exitValue);
     113            }
     114            pmConfigRunFilenameAddWrite(config, "STATS", statsName);
     115        }
     116
     117        // Dump configuration
     118        psString dump_file = psMetadataLookupStr(&mdok, config->arguments, "DUMP_CONFIG");
     119        if (dump_file) {
     120            if (!pmConfigDump(config, dump_file)) {
     121                psError(psErrorCodeLast(), false, "Unable to dump configuration");
     122                exitValue = pswarpExitCode(exitValue);
     123            }
     124        }
     125
     126        psThreadPoolFinalize();
     127        psMemCheckCorruption(stderr, true);
     128
     129        psFree(config);
     130
     131        psTimerStop();
     132        pmVisualClose();
     133        pmModelClassCleanup();
     134        pmConceptsDone();
     135        pmConfigDone();
     136        psLibFinalize();
     137
     138        exitValue = pswarpExitCode(exitValue);
     139        return exitValue;
     140    }
    61141}
  • trunk/pswarp/src/pswarp.h

    r27096 r27126  
    8080bool pswarpParseCamera (pmConfig *config);
    8181bool pswarpDefine (pmConfig *config);
    82 bool pswarpLoop (pmConfig *config);
    83 psExit pswarpCleanup (pmConfig *config);
     82bool pswarpLoop (pmConfig *config, psMetadata *stats);
     83psExit pswarpExitCode(psExit exitValue);
    8484bool pswarpTransformReadout (pmReadout *output, pmReadout *input, pmConfig *config);
    8585bool pswarpTransformSources(pmReadout *output, pmReadout *input, pmConfig *config);
     
    129129/// Print version information
    130130void pswarpVersionPrint(void);
     131
     132/// Activate a list of files
     133///
     134/// File list must be NULL-terminated
     135void pswarpFileActivation(pmConfig *config, // Configuration
     136                          char **files, // Files to turn on/off
     137                          bool state   // Activation state
     138    );
     139
     140
     141// Run down the FPA hierarchy, checking files
     142bool pswarpIOChecksBefore(pmConfig *config // Configuration
     143    );
     144
     145// Run up the FPA hierarchy, checking files
     146bool pswarpIOChecksAfter(pmConfig *config // Configuration
     147    );
     148
  • trunk/pswarp/src/pswarpExit.c

    r27118 r27126  
    1 /** @file pswarpCleanup.c
     1/** @file pswarpExit.c
    22 *
    33 *  @brief
     
    1313# include "pswarp.h"
    1414
    15 psExit pswarpCleanup (pmConfig *config)
     15
     16psExit pswarpExitCode(psExit exitValue)
    1617{
    17     psExit exitValue = PS_EXIT_SUCCESS;        // Exit value for program
     18    if (exitValue != PS_EXIT_SUCCESS) {
     19        return exitValue;
     20    }
     21
    1822    psErrorCode errorCode = psErrorCodeLast(); // Error code
    1923    if (errorCode != PS_ERR_NONE) {
     
    2226          case PSWARP_ERR_UNKNOWN:
    2327          case PS_ERR_UNKNOWN:
    24             exitValue = PS_EXIT_UNKNOWN_ERROR;
    25             break;
     28            return PS_EXIT_UNKNOWN_ERROR;
    2629          case PS_ERR_IO:
    2730          case PS_ERR_DB_CLIENT:
     
    3033          case PS_ERR_OS_CALL_FAILED:
    3134          case PSWARP_ERR_IO:
    32             exitValue = PS_EXIT_SYS_ERROR;
    33             break;
     35            return PS_EXIT_SYS_ERROR;
    3436          case PS_ERR_BAD_PARAMETER_VALUE:
    3537          case PS_ERR_BAD_PARAMETER_TYPE:
     
    3840          case PSWARP_ERR_ARGUMENTS:
    3941          case PSWARP_ERR_CONFIG:
    40             exitValue = PS_EXIT_CONFIG_ERROR;
    41             break;
     42            return PS_EXIT_CONFIG_ERROR;
    4243          case PSWARP_ERR_DATA:
    4344          case PSWARP_ERR_NO_OVERLAP:
    44             exitValue = PS_EXIT_DATA_ERROR;
    45             break;
     45            return PS_EXIT_DATA_ERROR;
    4646          case PS_ERR_UNEXPECTED_NULL:
    4747          case PS_ERR_PROGRAMMING:
     
    4949          default:
    5050            // It's a programming error if we're not dealing with the error correctly
    51             exitValue = PS_EXIT_PROG_ERROR;
    52             break;
     51            return PS_EXIT_PROG_ERROR;
    5352        }
    5453    }
    5554
    56     psThreadPoolFinalize();
    57     psMemCheckCorruption(stderr, true);
    58 
    59     psFree(config);
    60 
    61     psTimerStop();
    62     pmVisualClose();
    63     pmModelClassCleanup();
    64     pmConceptsDone();
    65     pmConfigDone();
    66     psLibFinalize();
    67 
    6855    return exitValue;
    6956}
     57
  • trunk/pswarp/src/pswarpLoop.c

    r27101 r27126  
    1919
    2020
    21 // XXX these are generic functions which should be moved to psModules
    22 // Activate a list of files
    23 static void fileActivation(pmConfig *config, // Configuration
    24                            char **files, // Files to turn on/off
    25                            bool state   // Activation state
    26     )
    27 {
    28     for (int i = 0; files[i] != NULL; i++) {
    29         pmFPAfileActivate(config->files, state, files[i]);
    30     }
    31     return;
    32 }
    33 
    34 /**
    35  * Run down the FPA hierarchy, checking files
    36  */
    37 static bool ioChecksBefore(pmConfig *config ///< Configuration
    38                            )
    39 {
    40     pmFPAview *view = pmFPAviewAlloc(0); ///< View for checking
    41     if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
    42         psFree(view);
    43         return false;
    44     }
    45     view->chip = 0;
    46     if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
    47         psFree(view);
    48         return false;
    49     }
    50     view->cell = 0;
    51     if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
    52         psFree(view);
    53         return false;
    54     }
    55     psFree(view);
    56     return true;
    57 }
    58 
    59 /**
    60  * Run up the FPA hierarchy, checking files
    61  */
    62 static bool ioChecksAfter(pmConfig *config ///< Configuration
    63                           )
    64 {
    65     pmFPAview *view = pmFPAviewAlloc(0); ///< View for checking
    66     view->chip = view->cell = 0;
    67     if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
    68         psFree(view);
    69         return false;
    70     }
    71     view->cell = -1;
    72     if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
    73         psFree(view);
    74         return false;
    75     }
    76     view->chip = -1;
    77     if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
    78         psFree(view);
    79         return false;
    80     }
    81     psFree(view);
    82     return true;
    83 }
    84 
    85 
    86 /**
    87  * Loop over the inputs, warp them to the output skycell and then write out the output.
    88  */
    89 bool pswarpLoop(pmConfig *config)
     21
     22// Loop over the inputs, warp them to the output skycell and then write out the output.
     23bool pswarpLoop(pmConfig *config, psMetadata *stats)
    9024{
    9125    bool status;
     26    bool mdok;                          // Status of MD lookup
    9227
    9328    const char *skyCamera = psMetadataLookupStr(NULL, config->arguments,
    94                                                 "SKYCELL.CAMERA");  ///< Name of camera for skycell
     29                                                "SKYCELL.CAMERA");  // Name of camera for skycell
    9530    pmConfigCamerasCull(config, skyCamera);
    9631    pmConfigRecipesCull(config, "PSWARP,PPSTATS,PSPHOT,PSASTRO,MASKS,JPEG");
    97 
    9832
    9933    // load the recipe
     
    14377    psFree (view);
    14478
    145     bool mdok;                          ///< Status of MD lookup
    146     const char *statsName = psMetadataLookupStr(&mdok, config->arguments, "STATS"); ///< Filename for statistics
    147     psMetadata *stats = NULL;           ///< Container for statistics
    148     FILE *statsFile = NULL;             ///< File stream for statistics
    149     if (mdok && statsName && strlen(statsName) > 0) {
    150         psString resolved = pmConfigConvertFilename(statsName, config, true, true);
    151         statsFile = fopen(resolved, "w");
    152         if (!statsFile) {
    153             psError(PS_ERR_IO, true, "Unable to open statistics file %s for writing.\n", resolved);
    154             psFree(resolved);
    155             return false;
    156         }
    157         psFree(resolved);
    158         stats = psMetadataAlloc();
    159         psMetadataAddS32(stats, PS_LIST_TAIL, "QUALITY", 0, "No problems", 0);
    160     }
    16179
    16280    // Turn all skycell files on to generate them, and then turn them off for the loop over the input images
    16381    // the input, which is in a different format.
    16482    {
    165         fileActivation(config, detectorFiles, false);
    166         fileActivation(config, photFiles, false);
    167         fileActivation(config, independentFiles, false);
    168         fileActivation(config, skycellFiles, true);
    169         if (!ioChecksBefore(config)) {
     83        pswarpFileActivation(config, detectorFiles, false);
     84        pswarpFileActivation(config, photFiles, false);
     85        pswarpFileActivation(config, independentFiles, false);
     86        pswarpFileActivation(config, skycellFiles, true);
     87        if (!pswarpIOChecksBefore(config)) {
    17088            psError(psErrorCodeLast(), false, "Unable to read files.");
    171             return false;
    172         }
    173         fileActivation(config, skycellFiles, false);
     89            goto DONE;
     90        }
     91        pswarpFileActivation(config, skycellFiles, false);
    17492    }
    17593
     
    183101        if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
    184102            psError(psErrorCodeLast(), false, "Unable to read files.");
    185             return false;
     103            goto DONE;
    186104        }
    187105        while ((chip = pmFPAviewNextChip (view, input->fpa, 1)) != NULL) {
     
    190108            if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
    191109                psError(psErrorCodeLast(), false, "Unable to read files.");
    192                 return false;
     110                goto DONE;
    193111            }
    194112            pmCell *cell;
     
    199117                    !pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) {
    200118                    psError(psErrorCodeLast(), false, "Unable to read files.");
    201                     return false;
     119                    goto DONE;
    202120                }
    203121            }
    204122            if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) {
    205123                psError(psErrorCodeLast(), false, "Unable to write files.");
    206                 return false;
     124                goto DONE;
    207125            }
    208126        }
    209127        if (!pmFPAfileIOChecks (config, view, PM_FPA_AFTER)) {
    210128            psError(psErrorCodeLast(), false, "Unable to write files.");
    211             return false;
    212         }
    213         psFree(view);
    214 
    215         fileActivation(config, detectorFiles, true);
     129            goto DONE;
     130        }
     131        psFree(view);
     132
     133        pswarpFileActivation(config, detectorFiles, true);
    216134        pmFPAfileActivate(config->files, false, "PSWARP.ASTROM");
    217135    }
     
    238156            psFree(view);
    239157            psFree(stats);
    240             return false;
     158            goto DONE;
    241159        }
    242160    }
     
    247165    if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) {
    248166        psError(psErrorCodeLast(), false, "Unable to read files.");
    249         return false;
     167        goto DONE;
    250168    }
    251169
     
    256174        if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) {
    257175            psError(psErrorCodeLast(), false, "Unable to read files.");
    258             return false;
     176            goto DONE;
    259177        }
    260178
     
    266184                psFree(view);
    267185                psFree(stats);
    268                 return false;
     186                goto DONE;
    269187            }
    270188        } else {
     
    274192                psFree(view);
    275193                psFree(stats);
    276                 return false;
     194                goto DONE;
    277195            }
    278196        }
     
    284202            if (!pmFPAfileIOChecks (config, view, PM_FPA_BEFORE)) {
    285203                psError(psErrorCodeLast(), false, "Unable to read files.");
    286                 return false;
     204                goto DONE;
    287205            }
    288206
     
    294212                if (!pmFPAfileIOChecks(config, view, PM_FPA_BEFORE)) {
    295213                    psError(psErrorCodeLast(), false, "Unable to read files.");
    296                     return false;
     214                    goto DONE;
    297215                }
    298216                if (!readout->data_exists) {
     
    312230                if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
    313231                    psError(psErrorCodeLast(), false, "Unable to write files.");
    314                     return false;
     232                    goto DONE;
    315233                }
    316234            }
    317235            if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
    318236                psError(psErrorCodeLast(), false, "Unable to write files.");
    319                 return false;
     237                goto DONE;
    320238            }
    321239        }
    322240        if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
    323241            psError(psErrorCodeLast(), false, "Unable to write files.");
    324             return false;
     242            goto DONE;
    325243        }
    326244    }
     
    346264        psFree(cells);
    347265        psFree(view);
    348         return false;
     266        goto DONE;
    349267    }
    350268
     
    384302        psFree(cells);
    385303        psFree(view);
    386         return false;
     304        goto DONE;
    387305    }
    388306    psFree(cells);
     
    395313        psFree(stats);
    396314        psFree(view);
    397         return false;
     315        goto DONE;
    398316    }
    399317
     
    421339            psError(PSWARP_ERR_DATA, false, "Unable to find skycell HDU.");
    422340            psFree(view);
    423             return false;
     341            goto DONE;
    424342        }
    425343        hdu->header = psMetadataCopy(hdu->header, skyHDU->header);
     
    431349        psError(psErrorCodeLast(), false, "Unable to generate WCS header.");
    432350        psFree(stats);
    433         return false;
     351        goto DONE;
    434352    }
    435353
    436354    if (!pmFPAfileIOChecks(config, view, PM_FPA_AFTER)) {
    437355        psError(psErrorCodeLast(), false, "Unable to write files.");
    438         return false;
     356        goto DONE;
    439357    }
    440358
    441359    // Done with the detector side of things
    442     fileActivation(config, detectorFiles, false);
    443     fileActivation(config, independentFiles, false);
     360    pswarpFileActivation(config, detectorFiles, false);
     361    pswarpFileActivation(config, independentFiles, false);
    444362
    445363    // We need a new PSF model for the warped frame.  It would be good to generate this analytically, but
     
    447365
    448366    if (psMetadataLookupBool(&mdok, recipe, "PSF")) {
    449         fileActivation(config, photFiles, true);
    450         if (!ioChecksBefore(config)) {
     367        pswarpFileActivation(config, photFiles, true);
     368        if (!pswarpIOChecksBefore(config)) {
    451369            psError(psErrorCodeLast(), false, "Unable to read files.");
    452             return false;
     370            goto DONE;
    453371        }
    454372
     
    464382        if (!sources) {
    465383            psError(psErrorCodeLast(), false, "No sources supplied to measure PSF");
    466             return false;
     384            goto DONE;
    467385        }
    468386
     
    533451 DONE:
    534452
    535     // Ensure everything is written out, at every level
    536     fileActivation(config, independentFiles, true);
    537     fileActivation(config, skycellFiles, true);
    538     if (!ioChecksAfter(config)) {
    539         psError(psErrorCodeLast(), false, "Unable to write files.");
    540         return false;
    541     }
    542 
    543     // Write out summary statistics
    544     if (stats) {
    545         psMetadataAddF32(stats, PS_LIST_TAIL, "DT_WARP", 0, "Time for warp completion",
    546                          psTimerMark("pswarp"));
    547 
    548         const char *statsMDC = psMetadataConfigFormat(stats);
    549         if (!statsMDC) {
    550             psError(psErrorCodeLast(), false, "Unable to get statistics file.");
    551             psFree(stats);
    552             fclose(statsFile);
    553             return false;
    554         }
    555         psFree(stats);
    556         if (fprintf(statsFile, "%s", statsMDC) != strlen(statsMDC)) {
    557             psError(PSWARP_ERR_IO, true, "Unable to write statistics file.");
    558             psFree(statsMDC);
    559             return false;
    560         }
    561         psFree(statsMDC);
    562         if (fclose(statsFile) == EOF) {
    563             psError(PSWARP_ERR_IO, true, "Unable to close statistics file.");
    564             return false;
    565         }
    566         pmConfigRunFilenameAddWrite(config, "STATS", statsName);
    567     }
    568 
    569     // Dump configuration
    570     psString dump_file = psMetadataLookupStr(&status, config->arguments, "DUMP_CONFIG");
    571     if (dump_file) {
    572         if (!pmConfigDump(config, dump_file)) {
    573             psError(psErrorCodeLast(), false, "Unable to dump configuration");
    574             return false;
    575         }
    576     }
    577 
    578453    return true;
    579454}
Note: See TracChangeset for help on using the changeset viewer.