IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 8, 2008, 8:17:12 AM (18 years ago)
Author:
Paul Price
Message:

Fixing following changes to psThread.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ppMerge/src/ppMergeLoop_Threaded.c

    r18862 r18967  
    1212#include "ppMerge.h"
    1313
    14 // XXX this function is now sufficiently different for the major types, it would make sense to just 
     14// XXX this function is now sufficiently different for the major types, it would make sense to just
    1515// split it into three: BASIC, SHUTTER, DARK
    1616
     
    5757    psMaskType markVal;
    5858    if (!pmConfigMaskSetBits (&maskVal, &markVal, config)) {
    59         psError (PS_ERR_UNKNOWN, true, "Unable to define the mask bit values");
    60         return false;
     59        psError (PS_ERR_UNKNOWN, true, "Unable to define the mask bit values");
     60        return false;
    6161    }
    6262
     
    151151            if (type == PPMERGE_TYPE_SHUTTER) {
    152152                shutterRef = pmShutterCorrectionReference(shutters->data[cellNum]);
    153                 pattern = pmReadoutAlloc(NULL);
     153                pattern = pmReadoutAlloc(NULL);
    154154            }
    155155
    156156            pmReadout *outRO = pmReadoutAlloc(outCell);
    157157
    158             // open the input files (we need to do the work ourselves)
     158            // open the input files (we need to do the work ourselves)
    159159            for (int i = 0; i < numFiles; i++) {
    160160                if (!ppMergeFileOpenInput(config, view, i)) {
     
    162162                    goto ERROR;
    163163                }
    164             }
    165 
    166             ppMergeFileGroup *fileGroup = NULL;
    167             psArray *fileGroups = psArrayAlloc (nThreads + 1);
    168 
    169             // generate readouts for each input file in each file group
    170             for (int i = 0; i < fileGroups->n; i++) {
    171                 psArray *readouts = psArrayAlloc(numFiles); // Input readouts
    172                 for (int j = 0; j < numFiles; j++) {
    173                     pmFPAfile *input = pmFPAfileSelectSingle(config->files, "PPMERGE.INPUT", i);
    174                     pmCell *inCell = pmFPAviewThisCell(view, input->fpa); // Input cell
    175                     readouts->data[j] = pmReadoutAlloc(inCell);
    176                 }
    177 
    178                 fileGroup = ppMergeFileGroupAlloc();
    179                 fileGroup->readouts = readouts;
    180                 fileGroup->read = false;
    181                 fileGroup->busy = false;
    182                 fileGroup->lastScan = 0;
    183                 fileGroup->firstScan = 0;
    184                 fileGroups->data[i] = fileGroup;
    185             }
    186 
    187             // call the init functions
    188             switch (type) {
    189               case PPMERGE_TYPE_BIAS:
    190               case PPMERGE_TYPE_FLAT:
    191               case PPMERGE_TYPE_FRINGE:
    192                 psAssert (fileGroups->n > 0, "no valid file groups defined");
    193                 fileGroup = fileGroups->data[0];
    194                 if (!pmReadoutCombinePrepare(outRO, fileGroup->readouts, combination)) {
    195                     goto ERROR;
    196                 }
    197                 break;
    198               case PPMERGE_TYPE_DARK:
    199                 psAssert (fileGroups->n > 0, "no valid file groups defined");
    200                 fileGroup = fileGroups->data[0];
    201                 if (!pmDarkCombinePrepare(outCell, fileGroup->readouts, darkOrdinates, darkNorm)) {
    202                     goto ERROR;
    203                 }
    204                 break;
    205               case PPMERGE_TYPE_SHUTTER:
    206                 psAssert (fileGroups->n > 0, "no valid file groups defined");
    207                 fileGroup = fileGroups->data[0];
    208                 if (!pmShutterCorrectionGeneratePrepare(outRO, pattern, fileGroup->readouts, maskVal)) {
    209                     goto ERROR;
    210                 }
    211                 break;
    212               default:
    213                 fprintf (stderr, "not yet ready");
    214                 goto ERROR;
    215             }
     164            }
     165
     166            ppMergeFileGroup *fileGroup = NULL;
     167            psArray *fileGroups = psArrayAlloc(nThreads + 1);
     168
     169            // Generate readouts for each input file in each file group
     170            for (int i = 0; i < fileGroups->n; i++) {
     171                psArray *readouts = psArrayAlloc(numFiles); // Input readouts
     172                for (int j = 0; j < numFiles; j++) {
     173                    pmFPAfile *input = pmFPAfileSelectSingle(config->files, "PPMERGE.INPUT", i);
     174                    pmCell *inCell = pmFPAviewThisCell(view, input->fpa); // Input cell
     175                    readouts->data[j] = pmReadoutAlloc(inCell);
     176                }
     177
     178                fileGroup = ppMergeFileGroupAlloc();
     179                fileGroup->readouts = readouts;
     180                fileGroup->read = false;
     181                fileGroup->busy = false;
     182                fileGroup->lastScan = 0;
     183                fileGroup->firstScan = 0;
     184                fileGroups->data[i] = fileGroup;
     185            }
     186
     187            // call the init functions
     188            switch (type) {
     189              case PPMERGE_TYPE_BIAS:
     190              case PPMERGE_TYPE_FLAT:
     191              case PPMERGE_TYPE_FRINGE:
     192                psAssert (fileGroups->n > 0, "no valid file groups defined");
     193                fileGroup = fileGroups->data[0];
     194                if (!pmReadoutCombinePrepare(outRO, fileGroup->readouts, combination)) {
     195                    goto ERROR;
     196                }
     197                break;
     198              case PPMERGE_TYPE_DARK:
     199                psAssert (fileGroups->n > 0, "no valid file groups defined");
     200                fileGroup = fileGroups->data[0];
     201                if (!pmDarkCombinePrepare(outCell, fileGroup->readouts, darkOrdinates, darkNorm)) {
     202                    goto ERROR;
     203                }
     204                break;
     205              case PPMERGE_TYPE_SHUTTER:
     206                psAssert (fileGroups->n > 0, "no valid file groups defined");
     207                fileGroup = fileGroups->data[0];
     208                if (!pmShutterCorrectionGeneratePrepare(outRO, pattern, fileGroup->readouts, maskVal)) {
     209                    goto ERROR;
     210                }
     211                break;
     212              default:
     213                psAbort("Should never get here.");
     214            }
    216215
    217216            // Read input data by chunks
    218             psTimerStart ("ppMergeLoop");
     217            psTimerStart("ppMergeLoop");
    219218            for (int numChunk = 0; true; numChunk++) {
    220219
    221                 bool status = false;
    222                 fileGroup = ppMergeReadChunk (&status, fileGroups, config, numChunk);
    223                 if (!status) goto ERROR;
    224                 if (!fileGroup) break;
    225 
    226                 psThreadJob *job = NULL;
    227 
     220                bool status = false;
     221                fileGroup = ppMergeReadChunk(&status, fileGroups, config, numChunk);
     222                if (!status) {
     223                    // Something went wrong
     224                    goto ERROR;
     225                }
     226                if (!fileGroup) {
     227                    // Nothing more to read
     228                    break;
     229                }
     230
     231                // Start a job
    228232                switch (type) {
    229233                  case PPMERGE_TYPE_BIAS:
    230234                  case PPMERGE_TYPE_FLAT:
    231                   case PPMERGE_TYPE_FRINGE:
    232                     // allocate a job
    233                     job = psThreadJobAlloc ("PPMERGE_READOUT_COMBINE");
    234 
    235                     // construct the arguments for this job
    236                     psArrayAdd (job->args, 1, outRO);
    237                     psArrayAdd (job->args, 1, fileGroup);
    238                     psArrayAdd (job->args, 1, zeros);
    239                     psArrayAdd (job->args, 1, scales);
    240                     psArrayAdd (job->args, 1, combination);
    241 
    242                     // call: pmReadoutCombine(outRO, fileGroup->readouts, zeros, scales, combination);
    243                     if (!psThreadJobAddPending (job)) {
    244                         goto ERROR;
    245                     }
    246                     break;
    247                   case PPMERGE_TYPE_DARK:
    248                     // allocate a job
    249                     job = psThreadJobAlloc ("PPMERGE_DARK_COMBINE");
    250 
    251                     // construct the arguments for this job
    252                     psArrayAdd (job->args, 1, outCell);
    253                     psArrayAdd (job->args, 1, fileGroup);
    254                     psArrayAdd (job->args, 1, psScalarAlloc(iter, PS_TYPE_S32));
    255                     psArrayAdd (job->args, 1, psScalarAlloc(rej, PS_TYPE_F32));
    256                     psArrayAdd (job->args, 1, psScalarAlloc(maskVal, PS_TYPE_U8));
    257 
    258                     // call: pmDarkCombine(outCell, fileGroup->readouts, iter, rej, maskVal);
    259                     if (!psThreadJobAddPending (job)) {                 
    260                         goto ERROR;
    261                     }
    262                     break;
    263                   case PPMERGE_TYPE_SHUTTER:
    264                     // allocate a job
    265                     job = psThreadJobAlloc ("PPMERGE_SHUTTER_CORRECTION");
    266 
    267                     // construct the arguments for this job
    268                     psArrayAdd (job->args, 1, outRO);
    269                     psArrayAdd (job->args, 1, pattern);
    270                     psArrayAdd (job->args, 1, fileGroup);
    271                     psArrayAdd (job->args, 1, psScalarAlloc(shutterRef, PS_TYPE_F32));
    272                     psArrayAdd (job->args, 1, shutters->data[cellNum]);
    273                     psArrayAdd (job->args, 1, psScalarAlloc(iter, PS_TYPE_S32));
    274                     psArrayAdd (job->args, 1, psScalarAlloc(rej, PS_TYPE_F32));
    275                     psArrayAdd (job->args, 1, psScalarAlloc(maskVal, PS_TYPE_U8));
    276 
    277                     // call: pmShutterCorrectionGenerate(outRO, pattern, fileGroup->readouts, shutterRef, shutters->data[cellNum], iter, rej, maskVal)
    278                     if (!psThreadJobAddPending (job)) {
    279                         goto ERROR;
    280                     }
    281                     break;
     235                  case PPMERGE_TYPE_FRINGE: {
     236                      psThreadJob *job = psThreadJobAlloc("PPMERGE_READOUT_COMBINE"); // Job to start
     237
     238                      // Construct the arguments for this job
     239                      psArrayAdd(job->args, 1, outRO);
     240                      psArrayAdd(job->args, 1, fileGroup);
     241                      psArrayAdd(job->args, 1, zeros);
     242                      psArrayAdd(job->args, 1, scales);
     243                      psArrayAdd(job->args, 1, combination);
     244
     245                      // call: pmReadoutCombine(outRO, fileGroup->readouts, zeros, scales, combination);
     246                      if (!psThreadJobAddPending(job)) {
     247                          goto ERROR;
     248                      }
     249                      break;
     250                  }
     251                  case PPMERGE_TYPE_DARK: {
     252                      psThreadJob *job = psThreadJobAlloc ("PPMERGE_DARK_COMBINE"); // Job to start
     253
     254                      // construct the arguments for this job
     255                      psArrayAdd(job->args, 1, outCell);
     256                      psArrayAdd(job->args, 1, fileGroup);
     257                      psArrayAdd(job->args, 1, psScalarAlloc(iter, PS_TYPE_S32));
     258                      psArrayAdd(job->args, 1, psScalarAlloc(rej, PS_TYPE_F32));
     259                      psArrayAdd(job->args, 1, psScalarAlloc(maskVal, PS_TYPE_U8));
     260
     261                      // call: pmDarkCombine(outCell, fileGroup->readouts, iter, rej, maskVal);
     262                      if (!psThreadJobAddPending(job)) {
     263                          goto ERROR;
     264                      }
     265                      break;
     266                  }
     267                  case PPMERGE_TYPE_SHUTTER: {
     268                      psThreadJob *job = psThreadJobAlloc ("PPMERGE_SHUTTER_CORRECTION");
     269
     270                      // construct the arguments for this job
     271                      psArrayAdd(job->args, 1, outRO);
     272                      psArrayAdd(job->args, 1, pattern);
     273                      psArrayAdd(job->args, 1, fileGroup);
     274                      psArrayAdd(job->args, 1, psScalarAlloc(shutterRef, PS_TYPE_F32));
     275                      psArrayAdd(job->args, 1, shutters->data[cellNum]);
     276                      psArrayAdd(job->args, 1, psScalarAlloc(iter, PS_TYPE_S32));
     277                      psArrayAdd(job->args, 1, psScalarAlloc(rej, PS_TYPE_F32));
     278                      psArrayAdd(job->args, 1, psScalarAlloc(maskVal, PS_TYPE_U8));
     279
     280                      // call: pmShutterCorrectionGenerate(outRO, pattern, fileGroup->readouts, shutterRef,
     281                      //                                   shutters->data[cellNum], iter, rej, maskVal);
     282                      if (!psThreadJobAddPending (job)) {
     283                          goto ERROR;
     284                      }
     285                      break;
     286                  }
    282287                  default:
    283288                    psAbort("Should never get here.");
     
    285290            }
    286291
    287             // wait for the threads to finish and manage results
    288             if (!psThreadPoolWait ()) {
    289                 psError(PS_ERR_UNKNOWN, false, "Unable to combine images.");
    290                 return false;
    291             }
    292 
    293             // we don't care about the results, just dump the done queue jobs
    294             psThreadJob *job = NULL;
    295             while ((job = psThreadJobGetDone()) != NULL) {
    296                 psFree (job);
    297             }
     292            // Wait for the threads to finish and manage results
     293            if (!psThreadPoolWait(false)) {
     294                psError(PS_ERR_UNKNOWN, false, "Unable to combine images.");
     295                return false;
     296            }
     297
     298            // we don't care about the results, just dump the done queue jobs
     299            psThreadJob *job = NULL;    // Job to dump
     300            while ((job = psThreadJobGetDone())) {
     301                psFree (job);
     302            }
    298303
    299304            psFree(fileGroups);
    300305
    301             // XXX eventually need to keep both the shutter and the pattern, as we do with dark
     306            // XXX eventually need to keep both the shutter and the pattern, as we do with dark
    302307            psFree(pattern);
    303308
     
    305310            psList *inCells = psListAlloc(NULL); // List of cells
    306311            for (int i = 0; i < numFiles; i++) {
    307                 pmFPAfile *input = pmFPAfileSelectSingle(config->files, "PPMERGE.INPUT", i);
    308                 pmCell *inCell = pmFPAviewThisCell(view, input->fpa); // Input cell
     312                pmFPAfile *input = pmFPAfileSelectSingle(config->files, "PPMERGE.INPUT", i);
     313                pmCell *inCell = pmFPAviewThisCell(view, input->fpa); // Input cell
    309314                psListAdd(inCells, PS_LIST_TAIL, inCell);
    310315            }
     
    316321            }
    317322            psFree(inCells);
    318             fprintf (stdout, "done ppMergeLoop for cell : %f\n", psTimerMark ("ppMergeLoop"));
    319323
    320324            // Plug supplementary images into their own FPAs
     
    364368            }
    365369
    366             if (!ppStatsFPA(stats, outFPA, view, maskVal, config)) {
     370            if (stats && !ppStatsFPA(stats, outFPA, view, maskVal, config)) {
    367371                psError(PS_ERR_UNKNOWN, true, "Unable to generate stats for image.");
    368372                goto ERROR;
Note: See TracChangeset for help on using the changeset viewer.