Changeset 18967 for trunk/ppMerge/src/ppMergeLoop_Threaded.c
- Timestamp:
- Aug 8, 2008, 8:17:12 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/ppMerge/src/ppMergeLoop_Threaded.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ppMerge/src/ppMergeLoop_Threaded.c
r18862 r18967 12 12 #include "ppMerge.h" 13 13 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 15 15 // split it into three: BASIC, SHUTTER, DARK 16 16 … … 57 57 psMaskType markVal; 58 58 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; 61 61 } 62 62 … … 151 151 if (type == PPMERGE_TYPE_SHUTTER) { 152 152 shutterRef = pmShutterCorrectionReference(shutters->data[cellNum]); 153 pattern = pmReadoutAlloc(NULL);153 pattern = pmReadoutAlloc(NULL); 154 154 } 155 155 156 156 pmReadout *outRO = pmReadoutAlloc(outCell); 157 157 158 // open the input files (we need to do the work ourselves)158 // open the input files (we need to do the work ourselves) 159 159 for (int i = 0; i < numFiles; i++) { 160 160 if (!ppMergeFileOpenInput(config, view, i)) { … … 162 162 goto ERROR; 163 163 } 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 } 216 215 217 216 // Read input data by chunks 218 psTimerStart("ppMergeLoop");217 psTimerStart("ppMergeLoop"); 219 218 for (int numChunk = 0; true; numChunk++) { 220 219 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 228 232 switch (type) { 229 233 case PPMERGE_TYPE_BIAS: 230 234 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 } 282 287 default: 283 288 psAbort("Should never get here."); … … 285 290 } 286 291 287 // wait for the threads to finish and manage results288 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 jobs294 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 } 298 303 299 304 psFree(fileGroups); 300 305 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 302 307 psFree(pattern); 303 308 … … 305 310 psList *inCells = psListAlloc(NULL); // List of cells 306 311 for (int i = 0; i < numFiles; i++) { 307 pmFPAfile *input = pmFPAfileSelectSingle(config->files, "PPMERGE.INPUT", i);308 pmCell *inCell = pmFPAviewThisCell(view, input->fpa); // Input cell312 pmFPAfile *input = pmFPAfileSelectSingle(config->files, "PPMERGE.INPUT", i); 313 pmCell *inCell = pmFPAviewThisCell(view, input->fpa); // Input cell 309 314 psListAdd(inCells, PS_LIST_TAIL, inCell); 310 315 } … … 316 321 } 317 322 psFree(inCells); 318 fprintf (stdout, "done ppMergeLoop for cell : %f\n", psTimerMark ("ppMergeLoop"));319 323 320 324 // Plug supplementary images into their own FPAs … … 364 368 } 365 369 366 if ( !ppStatsFPA(stats, outFPA, view, maskVal, config)) {370 if (stats && !ppStatsFPA(stats, outFPA, view, maskVal, config)) { 367 371 psError(PS_ERR_UNKNOWN, true, "Unable to generate stats for image."); 368 372 goto ERROR;
Note:
See TracChangeset
for help on using the changeset viewer.
