IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.