IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 17, 2005, 2:48:18 PM (21 years ago)
Author:
Paul Price
Message:

Reading in an FPA seems to be working!

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/archive/scripts/src/papFocalPlane.c

    r4092 r4309  
    11#include <stdio.h>
     2#include <string.h>
    23#include "pslib.h"
    34#include "papFocalPlane.h"
    4 #include "pmRead.h"
     5#include "psAdditionals.h"
     6#include "pmFPARead.h"
    57
    68// I'm sure this code, especially the DB lookup, leaks memory something chronic....
     
    810
    911// Look for a value already cached
    10 static psMetadataItem *getValueFromCache(const psFPA *fpa, // The FPA that contains the chip
    11                                          const psChip *chip, // The chip that contains the cell
    12                                          const psCell *cell, // The cell
     12static psMetadataItem *getValueFromCache(const papFPA *fpa, // The FPA that contains the chip
     13                                         const papChip *chip, // The chip that contains the cell
     14                                         const papCell *cell, // The cell
    1315                                         const char *valueName // Name of value
    1416    )
     
    3133
    3234// Put a value that we've found into the cache
    33 static void setValueInCache(psFPA *fpa, // The FPA that contains the chip
    34                             psChip *chip, // The chip that contains the cell
    35                             psCell *cell, // The cell
     35static void setValueInCache(papFPA *fpa, // The FPA that contains the chip
     36                            papChip *chip, // The chip that contains the cell
     37                            papCell *cell, // The cell
    3638                            const char *valueName, // Name of value
    3739                            const psMetadataItem *value // Item containing the value
     
    5658
    5759
    58 static psMetadataItem *getValueFromHeader(const psFPA *fpa, // The FPA that contains the chip
    59                                           const psChip *chip, // The chip that contains the cell
    60                                           const psCell *cell, // The cell
     60static psMetadataItem *getValueFromHeader(papFPA *fpa, // The FPA that contains the chip
     61                                          papChip *chip, // The chip that contains the cell
     62                                          papCell *cell, // The cell
    6163                                          const char *valueName // Name of value
    6264    )
    6365{
     66    bool mdStatus = true;               // Status of MD lookup
     67
    6468    // Look for how to translate the concept into a FITS header name
    65     const char *header = psMetadataLookupString(fpa->fits, valueName);
     69    const char *header = psMetadataLookupString(&mdStatus, fpa->fits, valueName);
    6670    if (strlen(header) > 0) {
    6771        // We have a FITS header to look up --- search each level
     
    7074            if (cellItem) {
    7175                // XXX: Need to clean up before returning
    72                 setValueInCache(NULL, NULL, cell, cellItem);
     76                setValueInCache(NULL, NULL, cell, valueName, cellItem);
    7377                return cellItem;
    7478            }
     
    7983            if (chipItem) {
    8084                // XXX: Need to clean up before returning
    81                 setValueInCache(NULL, chip, cell, chipItem);
     85                setValueInCache(NULL, chip, cell, valueName, chipItem);
    8286                return chipItem;
    8387            }
     
    8892            if (fpaItem) {
    8993                // XXX: Need to clean up before returning
    90                 setValueInCache(fpa, chip, cell, fpaItem);
     94                setValueInCache(fpa, chip, cell, valueName, fpaItem);
    9195                return fpaItem;
    9296            }
     
    100104
    101105// Look for a default
    102 static psMetadataItem *getValueFromDefault(const psFPA *fpa, // The FPA that contains the chip
    103                                            const psChip *chip, // The chip that contains the cell
    104                                            const psCell *cell, // The cell
     106static psMetadataItem *getValueFromDefault(papFPA *fpa, // The FPA that contains the chip
     107                                           papChip *chip, // The chip that contains the cell
     108                                           papCell *cell, // The cell
    105109                                           const char *valueName // Name of value
    106110    )
    107111{
    108     psMetadataItem *defItem = psMetadataLookup(fpa->defaults, valueName);
     112    psMetadataItem *defItem = psMetadataLookup((psMetadata*)fpa->defaults, valueName);
    109113    if (defItem) {
    110         setValueInCache(fpa, chip, cell, defItem);
     114        setValueInCache(fpa, chip, cell, valueName, defItem);
    111115    }
    112116    return defItem;                     // defItem is either NULL or points to what was desired
     
    115119
    116120// Look for a database lookup
    117 static psMetadataItem *getValueFromDB(const psFPA *fpa, // The FPA that contains the chip
    118                                       const psChip *chip, // The chip that contains the cell
    119                                       const psCell *cell, // The cell
     121static psMetadataItem *getValueFromDB(papFPA *fpa, // The FPA that contains the chip
     122                                      papChip *chip, // The chip that contains the cell
     123                                      papCell *cell, // The cell
    120124                                      const char *valueName // Name of value
    121125    )
     
    123127    if (fpa->db) {
    124128        // The database has been initialised
    125 
    126         psMetadata *dbLookup = psMetadataLookupMD(fpa->database, valueName);
     129        bool mdStatus = true;           // Status of MD lookup
     130        psMetadata *dbLookup = psMetadataLookupMD(&mdStatus, fpa->database, valueName);
    127131        if (dbLookup) {
    128             const char *tableName = psMetadataLookupString(dbLookup, "TABLE"); // Name of the table
    129             const char *colName = psMetadataLookupString(dbLookup, "COLUMN"); // Name of the column
    130             const char *givenCols = psMetadataLookupString(dbLookup, "GIVENDBCOL");     // Name of "where" columns
    131             const char *givenPS = psMetadataLookupString(dbLookup, "GIVENPS"); // Values for "where" columns
     132            const char *tableName = psMetadataLookupString(&mdStatus, dbLookup, "TABLE"); // Name of the table
     133            const char *colName = psMetadataLookupString(&mdStatus, dbLookup, "COLUMN"); // Name of the column
     134            const char *givenCols = psMetadataLookupString(&mdStatus, dbLookup, "GIVENDBCOL");  // Name of "where" columns
     135            const char *givenPS = psMetadataLookupString(&mdStatus, dbLookup, "GIVENPS"); // Values for "where" columns
    132136           
    133137            // Now, need to get the "given"s
     
    135139                psList *cols = papSplit(givenCols, ",;"); // List of column names
    136140                psList *values = papSplit(givenPS, ",;"); // List of value names for the columns
    137                 psMetadata *selection = psMetadataAlloc(NULL); // The stuff to select in the DB
     141                psMetadata *selection = psMetadataAlloc(); // The stuff to select in the DB
    138142                if (cols->size != values->size) {
    139143                    psLogMsg(__func__, PS_LOG_WARN, "The GIVENDBCOL and GIVENPS entries for %s do not have "
     
    159163                            }
    160164                            if (! item) {
    161                                 psLogMsg(__func__, PS_LOG_ERR, "Unable to find the value name %s for DB "
     165                                psLogMsg(__func__, PS_LOG_ERROR, "Unable to find the value name %s for DB "
    162166                                         " lookup on %s --- ignored.\n", name, valueName);
    163167                            } else {
     
    199203}
    200204
    201 psMetadataItem *psCellGetValue(const psFPA *fpa, // The FPA that contains the cell
     205psMetadataItem *psCellGetValue(papFPA *fpa, // The FPA that contains the cell
    202206                               const char *chipName, // The name of the chip
    203207                               const char *cellName, // The name of the cell
     
    205209                               )
    206210{
    207     psChip *chip = psMetadataLookupChip(fpa, chipName); // The chip
    208     psCell *cell = psMetadataLookupCell(chip, cellName); // The cell
     211    bool mdStatus = true;               // Status of MD lookup
     212    papChip *chip = psMetadataLookupChip(&mdStatus, fpa->chips, chipName); // The chip
     213    papCell *cell = psMetadataLookupCell(&mdStatus, chip->cells, cellName); // The cell
    209214
    210215    // Try cache, headers, database, defaults in order
     
    223228}
    224229
    225 float psCellGetValueF32(const psFPA *fpa, // The FPA that contains the cell
     230float psCellGetValueF32(papFPA *fpa, // The FPA that contains the cell
    226231                        const char *chipName, // The name of the chip
    227232                        const char *cellName, // The name of the cell
     
    244249}
    245250
    246 int psCellGetValueS32(const psFPA *fpa, // The FPA that contains the cell
     251int psCellGetValueS32(papFPA *fpa, // The FPA that contains the cell
    247252                      const char *chipName, // The name of the chip
    248253                      const char *cellName, // The name of the cell
     
    250255    )
    251256{
    252     int value = NAN;                    // Result
     257    int value = 0;                      // Result
    253258    psMetadataItem *item = psCellGetValue(fpa, chipName, cellName, valueName); // The item
    254259    if (! item) {
     
    266271
    267272
    268 double psCellGetValueF64(const psFPA *fpa, // The FPA that contains the cell
     273double psCellGetValueF64(papFPA *fpa, // The FPA that contains the cell
    269274                         const char *chipName, // The name of the chip
    270275                         const char *cellName, // The name of the cell
     
    288293
    289294
    290 psString psCellGetValueString(const psFPA *fpa, // The FPA that contains the cell
     295psString psCellGetValueString(papFPA *fpa, // The FPA that contains the cell
    291296                              const char *chipName, // The name of the chip
    292297                              const char *cellName, // The name of the cell
     
    308313    return value;
    309314}
     315
     316//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     317// Allocators
     318//////////////////////////////////////////////////////////////////////////////////////////////////////////////
     319
     320papFPA *papFPAAlloc(psMetadata *fits, // FITS translation info
     321                    psMetadata *database, // Database lookup info
     322                    psMetadata *defaults, // Defaults info
     323                    psDB *db            // Database handle
     324    )
     325{
     326    papFPA *fpa = psAlloc(sizeof(papFPA));// The FPA
     327    psMemSetDeallocator(fpa, (psFreeFcn)p_papFPAFree);
     328
     329    // Fill in the various components
     330    fpa->fits = psMemIncrRefCounter(fits);
     331    fpa->database = psMemIncrRefCounter(database);
     332    fpa->defaults = psMemIncrRefCounter(defaults);
     333
     334    fpa->values = psMetadataAlloc();
     335    fpa->header = NULL;
     336    fpa->db = psMemIncrRefCounter(db);
     337
     338    fpa->chips = psMetadataAlloc();
     339    fpa->images = NULL;
     340
     341    return fpa;
     342}
     343
     344void p_papFPAFree(papFPA *fpa)
     345{
     346    psFree((psPtr)fpa->fits);
     347    psFree((psPtr)fpa->database);
     348    psFree((psPtr)fpa->defaults);
     349
     350    psFree(fpa->values);
     351    psFree(fpa->header);
     352    if (fpa->db) {
     353        psDBCleanup((psDB*)fpa->db);
     354    }
     355
     356    psFree(fpa->chips);
     357    psFree(fpa->images);
     358}
     359
     360papChip *papChipAlloc(papFPA *fpa,              // FPA to which the chip belongs
     361                    const char *name    // Name of the chip
     362    )
     363{
     364    papChip *chip = psAlloc(sizeof(papChip)); // The chip
     365    psMemSetDeallocator(chip, (psFreeFcn)p_papChipFree);
     366    psMetadataAdd(fpa->chips, PS_LIST_TAIL, name, PS_META_CHIP, "Added on allocation of chip", chip);
     367
     368    chip->values = psMetadataAlloc();
     369    chip->header = NULL;
     370
     371    chip->cells = psMetadataAlloc();
     372    chip->images = NULL;
     373
     374    return chip;
     375}
     376
     377void p_papChipFree(papChip *chip)
     378{
     379    psFree(chip->values);
     380    psFree(chip->header);
     381    psFree(chip->cells);
     382    psFree(chip->images);
     383}
     384
     385papCell *papCellAlloc(papChip *chip,    // Chip to which the cell belongs
     386                    const char *name,   // Name of the cell
     387                    int nReadouts       // Number of readouts contained
     388    )
     389{
     390    papCell *cell = psAlloc(sizeof(papCell)); // The cell
     391    psMemSetDeallocator(cell, (psFreeFcn)p_papCellFree);
     392    psMetadataAdd(chip->cells, PS_LIST_TAIL, name, PS_META_CELL, "Added on allocation of cell", cell);
     393
     394    cell->values = psMetadataAlloc();
     395    cell->header = NULL;
     396
     397    cell->readouts = psArrayAlloc(nReadouts);
     398    cell->images = NULL;
     399
     400    return cell;
     401}
     402
     403void p_papCellFree(papCell *cell)
     404{
     405    psFree(cell->values);
     406    psFree(cell->header);
     407    psFree(cell->readouts);
     408    psFree(cell->images);
     409}
     410
     411papReadout *papReadoutAlloc(papCell *cell, // Cell to which the readout belongs
     412                            int readoutNum, // Number of the readout
     413                            psImage *image, // The pixels
     414                            psList *overscans, // The overscan images
     415                            int col0, int row0, int colParity, int rowParity, int colBin, int rowBin // Data
     416    )
     417{
     418    papReadout *readout = psAlloc(sizeof(papReadout));
     419    psMemSetDeallocator(readout, (psFreeFcn)p_papReadoutFree);
     420    psArray *readouts = cell->readouts;
     421    if (readoutNum >= readouts->nalloc) {
     422        readouts = psArrayRealloc(readouts, readoutNum);
     423        cell->readouts = readouts;
     424    }
     425    readouts->data[readoutNum] = readout;
     426   
     427    // Set the components
     428    readout->image = image;
     429    readout->overscans = overscans;
     430   
     431    readout->values = psMetadataAlloc();
     432   
     433    *(int*)&readout->col0 = col0;
     434    *(int*)&readout->row0 = row0;
     435    *(int*)&readout->colParity = colParity;
     436    *(int*)&readout->rowParity = rowParity;
     437    *(int*)&readout->colBins = colBin;
     438    *(int*)&readout->rowBins = rowBin;
     439
     440    return readout;
     441}
     442
     443void p_papReadoutFree(papReadout *readout)
     444{
     445    psFree(readout->image);
     446    psFree(readout->overscans);
     447    psFree(readout->values);
     448}
Note: See TracChangeset for help on using the changeset viewer.