IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18767


Ignore:
Timestamp:
Jul 29, 2008, 11:40:36 AM (18 years ago)
Author:
eugene
Message:

rework the scan chunk counting so that multiple readout pointers can be used in parallel

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20080719/psModules/src/camera/pmFPARead.c

    r18210 r18767  
    4545
    4646// Return pointer to appropriate value for tracking scans
    47 static int *readoutScansByType(pmReadout *readout, // Readout of interest
    48                                fpaReadType type // Type of image
     47static int readoutGetThisScan(pmReadout *readout, // Readout of interest
     48                              fpaReadType type // Type of image
    4949    )
    5050{
    5151    switch (type) {
    5252      case FPA_READ_TYPE_IMAGE:
    53         return &readout->imageScan;
     53        return readout->thisImageScan;
    5454      case FPA_READ_TYPE_MASK:
    55         return &readout->maskScan;
     55        return readout->thisMaskScan;
    5656      case FPA_READ_TYPE_WEIGHT:
    57         return &readout->weightScan;
     57        return readout->thisWeightScan;
    5858      default:
    5959        psAbort("Unknown read type: %x\n", type);
    6060    }
     61}
     62
     63// Return pointer to appropriate value for tracking scans
     64static int readoutSetLastScan(pmReadout *readout, // Readout of interest
     65                              fpaReadType type,   // Type of image
     66                              int numScans        // requested number of scans
     67    )
     68{
     69    switch (type) {
     70      case FPA_READ_TYPE_IMAGE:
     71        readout->lastImageScan = readout->thisImageScan + numScans;
     72        return readout->lastImageScan;
     73      case FPA_READ_TYPE_MASK:
     74        readout->lastMaskScan = readout->thisMaskScan + numScans;
     75        return readout->lastMaskScan;
     76      case FPA_READ_TYPE_WEIGHT:
     77        readout->lastWeightScan = readout->thisWeightScan + numScans;
     78        return readout->lastWeightScan;
     79      default:
     80        psAbort("Unknown read type: %x\n", type);
     81    }
     82    return false;
    6183}
    6284
     
    134156}
    135157
    136 
    137 // Determine readout scan properties: the next and last scans
    138 // Requires that cellNumReadouts() has been called before (for header and concepts to have been read)
    139 // In the process, adjusts the TRIMSEC
    140 static bool readoutScanProperties(int *next, // Index of next scan
    141                                   int *last, // Index of last scan
    142                                   pmReadout *readout, // Readout of interest
    143                                   int numScans, // Number of scans to read at a time
    144                                   fpaReadType type, // Type of image
    145                                   pmConfig *config // Configuration
     158// Does the current readout, with scans set for a new read, represent any real data, or is it
     159// beyond the end?  Requires that cellNumReadouts() has been called before (for header and
     160// concepts to have been read) In the process, adjusts the TRIMSEC
     161static bool readoutHaveMoreScans(bool *result,   // true : more data to read
     162                             pmReadout *readout, // Readout of interest
     163                             int numScans, // Number of scans to read at a time
     164                             fpaReadType type, // Type of image
     165                             pmConfig *config // Configuration
    146166    )
    147167{
    148     assert(next);
    149     assert(last);
     168    assert(result);
    150169    assert(readout);
    151170
    152     psImage *image = *readoutImageByType(readout, type); // Appropriate image from readout
     171    *result = false;
    153172
    154173    if (!pmConceptsReadCell(readout->parent, PM_CONCEPT_SOURCE_DEFAULTS | PM_CONCEPT_SOURCE_DATABASE,
     
    163182    PS_ASSERT_PTR_NON_NULL(cell, false);
    164183    pmHDU *hdu = pmHDUFromCell(cell);   // HDU for data
     184
    165185    bool mdok = true;                   // Status of MD lookup
    166186    psRegion *trimsec = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.TRIMSEC"); // Trim sections
     
    195215    // Calculate the segment offset and upper limit
    196216    if (numScans == 0) {
    197         *next = (readdir == 1) ? trimsec->y0 : trimsec->x0;
    198     } else {
    199         *next = image ? *readoutScansByType(readout, type) + numScans : 0;
    200     }
    201     *last = (readdir == 1) ? trimsec->y1 : trimsec->x1;
    202 
     217        // in the case of numScans == 0, we never call this funtion unless the data has not yet
     218        // been read.  thus, only if the delta is  should we return false (ie, trimsec defines an empty region)
     219        int thisScan = (readdir == 1) ? trimsec->y0 : trimsec->x0;
     220        int lastScan = (readdir == 1) ? trimsec->y1 : trimsec->x1;
     221        *result = (lastScan > thisScan);
     222        return true;
     223    }
     224
     225    // allow multiple threads to read different segments into different readouts
     226    // this thread may not have read a segment yet; but others have.  trust readout->imageScan
     227
     228    // is the start scan of the read less than the last possible scan?
     229    int thisScan = readoutGetThisScan(readout, type);
     230    int lastScan = (readdir == 1) ? trimsec->y1 : trimsec->x1;
     231
     232    *result = (lastScan > thisScan);
    203233    return true;
     234    // XXX fold this and the above case together
    204235}
    205236
     
    217248    psImage *image = *readoutImageByType(readout, type);
    218249
     250    // XXX this may not be the valid test in a multithread environment. consider a fileGroup of
     251    // N readouts, but numScans set to 0.  only the first should report that it requires data,
     252    // even if all readouts lack the image pointer.
    219253    if (!image) {
    220254        return true;
    221     } else if (numScans == 0) {
    222         // Can only read the entire image once
     255    }
     256
     257    // If we have already read an image, this result implies we are done (no more to read)
     258    if (numScans == 0) {
    223259        return false;
    224260    }
     
    235271    }
    236272
    237     int next;                           // Next position
    238     int last;                           // Last position
    239     if (!readoutScanProperties(&next, &last, readout, numScans, type, config)) {
     273    bool haveData;
     274    if (!readoutHaveMoreScans(&haveData, readout, numScans, type, config)) {
    240275        psError(PS_ERR_UNKNOWN, false, "Unable to determine readout properties.");
    241276        return false;
    242277    }
    243278
    244     return (next < last);
     279    return haveData;
    245280}
    246281
     
    423458    }
    424459
    425     int next;                           // Next position
    426     int last;                           // Last position
    427     if (!readoutScanProperties(&next, &last, readout, numScans, type, config)) {
     460    bool haveData;
     461    if (!readoutHaveMoreScans (&haveData, readout, type, numScans, config)) {
    428462        psError(PS_ERR_UNKNOWN, false, "Unable to determine readout properties.");
    429463        return false;
    430464    }
    431     if (next >= last) {
     465    if (!haveData) {
    432466        psError(PS_ERR_IO, true, "No more of the readout to read.");
    433467        return false;
    434468    }
     469
    435470
    436471    pmHDU *hdu = pmHDUFromCell(cell);   // The HDU
     
    459494    }
    460495
    461 
    462 
    463496    // Check the third dimension
    464497    int naxis = psMetadataLookupS32(&mdok, hdu->header, "NAXIS"); // The number of axes
     
    478511    }
    479512
    480     // Update number of scans read
    481     int *scansTracker = readoutScansByType(readout, type); // Tracker for how many scans have been read
    482     *scansTracker = next;
    483     if (next == 0) {
     513    // Determine the numbe of scans to read
     514    int thisScan = readoutGetThisScan(readout, type);
     515    int lastScan = readoutSetLastScan (readout, type, numScans);
     516    if (thisScan == 0) {
    484517        overlap = 0;
    485518    }
    486     next -= overlap;
     519    thisScan -= overlap;
    487520
    488521    // Calculate limits, adjust readout->row0,col0
     
    491524    if (readdir == 1) {
    492525        // Reading rows
    493         readout->row0 = next;
     526        readout->row0 = thisScan;
    494527        readout->col0 = trimsec->x0;
    495528        if (numScans == 0) {
     
    498531    } else {
    499532        // Reading cols
    500         readout->col0 = next;
     533        readout->col0 = thisScan;
    501534        readout->row0 = trimsec->y0;
    502535        if (numScans == 0) {
     
    504537        }
    505538    }
    506     int upper = next + numScans + overlap;        // Upper limit to next section
    507539
    508540    // Blow away existing data.
     
    510542    psFree(*image);
    511543    *image = NULL;
    512     *image = readoutReadComponent(*image, fits, trimsec, readdir, next, upper, z, bad, pixelTypes[type]);
     544    *image = readoutReadComponent(*image, fits, trimsec, readdir, thisScan, lastScan, z, bad, pixelTypes[type]);
    513545
    514546    // Read overscans only for "image" type --- weights and masks shouldn't record overscans
     
    528560        psRegion *biassec = NULL;           // Bias section from iteration
    529561        while ((biassec = psListGetAndIncrement(biassecsIter))) {
    530             psImage *bias = readoutReadComponent(NULL, fits, biassec, readdir, next, upper, z,
    531                                                  bad, pixelTypes[type]); // The bias
     562            psImage *bias = readoutReadComponent(NULL, fits, biassec, readdir, thisScan, lastScan, z, bad, pixelTypes[type]); // The bias
    532563            psListAdd(readout->bias, PS_LIST_TAIL, bias);
    533564            psFree(bias);                   // Drop reference
Note: See TracChangeset for help on using the changeset viewer.