IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 10, 2006, 5:20:10 PM (20 years ago)
Author:
Paul Price
Message:

Changing concepts to only get stuff as the source becomes available; nearly done

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/rel10_ifa/psModules/src/astrom/pmConcepts.c

    r6552 r6570  
    2323
    2424pmConceptSpec *pmConceptSpecAlloc(psMetadataItem *blank, // Blank value; contains the name
    25                                   pmConceptReadFunc read, // Function to call to read the concept
    26                                   pmConceptWriteFunc write // Function to call to write the concept
     25                                  pmConceptParseFunc parse, // Function to call to parse the concept
     26                                  pmConceptFormatFunc format // Function to call to format the concept
    2727                                 )
    2828{
     
    3131
    3232    spec->blank = psMemIncrRefCounter(blank);
    33     spec->read = read;
    34     spec->write = write;
     33    spec->parse = parse;
     34    spec->format = format;
    3535
    3636    return spec;
     
    3939
    4040bool pmConceptRegister(psMetadataItem *blank, // Blank value; contains the name
    41                        pmConceptReadFunc read, // Function to call to read the concept
    42                        pmConceptWriteFunc write, // Function to call to write the concept
     41                       pmConceptParseFunc parse, // Function to call to parse the concept
     42                       pmConceptFormatFunc format, // Function to call to format the concept
    4343                       pmConceptLevel level // Level at which to store concept in the FPA hierarchy
    4444                      )
     
    4949    }
    5050
    51     pmConceptSpec *spec = pmConceptSpecAlloc(blank, read, write); // The concept specification
     51    pmConceptSpec *spec = pmConceptSpecAlloc(blank, parse, format); // The concept specification
    5252    psMetadata **target = NULL;         // The metadata of known concepts to write to
    5353    switch (level) {
     
    7474}
    7575
    76 // This function gets called for the really boring concepts --- where all you have to do is read from a header
    77 // or database and you don't need to muck around with conversions.
    78 // There is no similar "writePlain", since the type is already known.
    79 static psMetadataItem *readPlain(psMetadataItem *blank, // The blank value with name, comment, type
    80                                  pmFPA *fpa, // The FPA of interest
    81                                  pmChip *chip, // The Chip of interest
    82                                  pmCell *cell, // The cell of interest
    83                                  psDB *db // Database handle
    84                                 )
    85 {
    86     switch (blank->type) {
    87     case PS_DATA_STRING: {
    88             psString string = pmConceptReadString(fpa, chip, cell, db, blank->name);
    89             psMetadataItem *item = psMetadataItemAllocStr(blank->name, blank->comment, string);
    90             psFree(string);
    91             return item;
    92         }
    93     case PS_DATA_S32:
    94         return psMetadataItemAllocS32(blank->name, blank->comment,
    95                                       pmConceptReadS32(fpa, chip, cell, db, blank->name));
    96     case PS_DATA_F32:
    97         return psMetadataItemAllocF32(blank->name, blank->comment,
    98                                       pmConceptReadF32(fpa, chip, cell, db, blank->name));
    99     case PS_DATA_F64:
    100         return psMetadataItemAllocF64(blank->name, blank->comment,
    101                                       pmConceptReadF64(fpa, chip, cell, db, blank->name));
    102     default:
    103         psLogMsg(__func__, PS_LOG_WARN, "Concept %s (%s) is not of a standard type (%x)\n",
    104                  blank->name, blank->comment, blank->type);
    105     }
    106     return NULL;
    107 }
    10876
    10977// Set all registered concepts to blank value for the specified level
    110 static bool conceptsBlank(psMetadata **specs,  // One of the concepts specifications
     78static bool conceptsBlank(psMetadata *specs,  // One of the concepts specifications
    11179                          psMetadata *target // Place to install the concepts
    11280                         )
     
    12896}
    12997
     98
     99
    130100// Read all registered concepts for the specified level
    131 static bool conceptsRead(psMetadata **specs, // One of the concepts specifications
     101static bool conceptsRead(psMetadata *specs, // One of the concepts specifications
    132102                         pmFPA *fpa,    // The FPA
    133103                         pmChip *chip,  // The chip
    134104                         pmCell *cell,  // The cell
     105                         pmConceptSource source, // The source of the concepts to read
    135106                         psDB *db,      // Database handle
    136107                         psMetadata *target // Place into which to read the concepts
     
    140111        pmConceptsInit();
    141112    }
    142     psMetadataIterator *specsIter = psMetadataIteratorAlloc(*specs, PS_LIST_HEAD, NULL); // Iterator on specs
    143     psMetadataItem *specItem = NULL;    // Item from the specs metadata
    144     while ((specItem = psMetadataGetAndIncrement(specsIter))) {
    145         pmConceptSpec *spec = specItem->data.V; // The specification
    146         psMetadataItem *conceptItem = NULL; // The item to add to the concepts
    147         if (spec->read) {
    148             conceptItem = spec->read(fpa, chip, cell, db);
    149         } else {
    150             conceptItem = readPlain(spec->blank, fpa, chip, cell, db);
    151             if (conceptItem->type != spec->blank->type) {
    152                 psLogMsg(__func__, PS_LOG_ERROR, "Type of concept %s following read (%x) does not match "
    153                          "blank type (%x).\n", spec->blank->name, conceptItem->type, spec->blank->type);
    154             }
    155         }
    156         if (conceptItem) {
    157             psMetadataAddItem(target, conceptItem, PS_LIST_TAIL, PS_META_REPLACE);
    158             psFree(conceptItem);        // Drop reference
    159         }
    160         // No error if conceptItem is NULL, since that may only mean that the required information isn't
    161         // present yet.
    162     }
    163     psFree(specsIter);
     113
     114    if (source & PM_CONCEPT_SOURCE_CAMERA || source == PM_CONCEPT_SOURCE_ALL) {
     115        pmConceptsReadFromCamera(specs, cell, target);
     116    }
     117    if (source & PM_CONCEPT_SOURCE_DEFAULTS || source == PM_CONCEPT_SOURCE_ALL) {
     118        pmConceptsReadFromDefaults(specs, fpa, chip, cell, target);
     119    }
     120    if (source & PM_CONCEPT_SOURCE_HEADER || source == PM_CONCEPT_SOURCE_ALL) {
     121        pmConceptsReadFromHeader(specs, fpa, chip, cell, target);
     122    }
     123    if (source & PM_CONCEPT_SOURCE_DATABASE || source == PM_CONCEPT_SOURCE_ALL) {
     124        pmConceptsReadFromHeader(specs, fpa, chip, cell, db, target);
     125    }
     126
    164127    return true;
    165128}
    166129
    167130// Write all registered concepts for the specified level
    168 static bool conceptsWrite(psMetadata **specs, // One of the concepts specifications
     131static bool conceptsWrite(psMetadata *specs, // One of the concepts specifications
    169132                          pmFPA *fpa,   // The FPA
    170133                          pmChip *chip, // The chip
    171134                          pmCell *cell, // The cell
     135                          pmConceptSource source, // The source of the concepts to write
    172136                          psDB *db,      // Database handle
    173                           psMetadata *source // The concepts to write out
     137                          psMetadata *concepts // The concepts to write out
    174138                         )
    175139{
     
    177141        pmConceptsInit();
    178142    }
    179     if (! fpa->camera) {
    180         return false;
    181     }
    182     psMetadataIterator *iter = psMetadataIteratorAlloc(source, PS_LIST_HEAD, NULL); // Iterator on concepts
    183     psMetadataItem *item = NULL;    // Item from the concepts
    184     while ((item = psMetadataGetAndIncrement(iter))) {
    185         const char *name = item->name;  // Name of the concept
    186         if (!strcmp(name, "CELL.NAME") || !strcmp(name, "CHIP.NAME")) {
    187             // These concepts are not written out; they are set from things like the FITS extname
    188             continue;
    189         }
    190         psMetadataItem *specItem = psMetadataLookup(*specs, name); // Specification for the concept
    191         if (specItem) {
    192             pmConceptSpec *spec = specItem->data.V; // The specification
    193             if (spec->write) {
    194                 spec->write(fpa, chip, cell, db); // The concept
    195             } else {
    196                 pmConceptWrite(fpa, chip, cell, db, source, spec->blank->name);
    197             }
    198         } else {
    199             psLogMsg(__func__, PS_LOG_WARN, "Unable to find specification to write concept %s in FPA\n",
    200                      name);
    201         }
    202     }
    203     psFree(iter);
     143
     144    if (source & PM_CONCEPT_SOURCE_CAMERA || source == PM_CONCEPT_SOURCE_ALL) {
     145        pmConceptsWriteToCamera(specs, cell, concepts);
     146    }
     147    if (source & PM_CONCEPT_SOURCE_DEFAULTS || source == PM_CONCEPT_SOURCE_ALL) {
     148        pmConceptsWriteToDefaults(specs, fpa, chip, cell, concepts);
     149    }
     150    if (source & PM_CONCEPT_SOURCE_HEADER || source == PM_CONCEPT_SOURCE_ALL) {
     151        pmConceptsWriteToHeader(specs, fpa, chip, cell, concepts);
     152    }
     153    if (source & PM_CONCEPT_SOURCE_DATABASE || source == PM_CONCEPT_SOURCE_ALL) {
     154        pmConceptsWriteToHeader(specs, fpa, chip, cell, db, concepts);
     155    }
    204156
    205157    return true;
    206158}
     159
    207160
    208161// Set the concepts for a given FPA to blanks
     
    211164{
    212165    psTrace("psModule.concepts", 5, "Blanking FPA concepts: %x %x\n", conceptsFPA, fpa->concepts);
    213     return conceptsBlank(&conceptsFPA, fpa->concepts);
     166    return conceptsBlank(conceptsFPA, fpa->concepts);
    214167}
    215168
    216169// Read the concepts for a given FPA
    217170bool pmConceptsReadFPA(pmFPA *fpa,      // FPA for which to read concepts
     171                       pmConceptSource source, // The source of the concepts to read
    218172                       psDB *db         // Database handle
    219173                      )
    220174{
    221175    psTrace("psModule.concepts", 5, "Reading FPA concepts: %x %x\n", conceptsFPA, fpa->concepts);
    222     return conceptsRead(&conceptsFPA, fpa, NULL, NULL, db, fpa->concepts);
     176    return conceptsRead(conceptsFPA, fpa, NULL, NULL, source, db, fpa->concepts);
    223177}
    224178
     
    229183{
    230184    psTrace("psModule.concepts", 5, "Writing FPA concepts: %x %x\n", conceptsFPA, fpa->concepts);
    231     return conceptsWrite(&conceptsFPA, fpa, NULL, NULL, db, fpa->concepts);
     185    return conceptsWrite(conceptsFPA, fpa, NULL, NULL, db, fpa->concepts);
    232186}
    233187
     
    237191{
    238192    psTrace("psModule.concepts", 5, "Blanking chip concepts: %x %x\n", conceptsChip, chip->concepts);
    239     return conceptsBlank(&conceptsChip, chip->concepts);
     193    return conceptsBlank(conceptsChip, chip->concepts);
    240194}
    241195
    242196// Read the concepts for a given FPA
    243197bool pmConceptsReadChip(pmChip *chip,   // Chip for which to read concepts
     198                        pmConceptSource source, // The source of the concepts to read
    244199                        psDB *db        // Database handle
    245200                       )
     
    247202    psTrace("psModule.concepts", 5, "Reading chip concepts: %x %x\n", conceptsChip, chip->concepts);
    248203    pmFPA *fpa = chip->parent;          // FPA to which the chip belongs
    249     return conceptsRead(&conceptsChip, fpa, chip, NULL, db, chip->concepts);
     204    return conceptsRead(conceptsChip, fpa, chip, NULL, source, db, chip->concepts);
    250205}
    251206
     
    257212    psTrace("psModule.concepts", 5, "Writing chip concepts: %x %x\n", conceptsChip, chip->concepts);
    258213    pmFPA *fpa = chip->parent;          // FPA to which the chip belongs
    259     return conceptsWrite(&conceptsChip, fpa, chip, NULL, db, chip->concepts);
     214    return conceptsWrite(conceptsChip, fpa, chip, NULL, db, chip->concepts);
    260215}
    261216
     
    265220{
    266221    psTrace("psModule.concepts", 5, "Blanking cell concepts: %x %x\n", conceptsCell, cell->concepts);
    267     return conceptsBlank(&conceptsCell, cell->concepts);
     222    return conceptsBlank(conceptsCell, cell->concepts);
    268223}
    269224
    270225// Read the concepts for a given FPA
    271226bool pmConceptsReadCell(pmCell *cell,   // Cell for which to read concepts
     227                        pmConceptSource source, // The source of the concepts to read
    272228                        psDB *db        // Database handle
    273229                       )
     
    276232    pmChip *chip = cell->parent;        // Chip to which the cell belongs
    277233    pmFPA *fpa = chip->parent;          // FPA to which the chip belongs
    278     return conceptsRead(&conceptsCell, fpa, chip, cell, db, cell->concepts);
     234    return conceptsRead(conceptsCell, fpa, chip, cell, source, db, cell->concepts);
    279235}
    280236
     
    287243    pmChip *chip = cell->parent;        // Chip to which the cell belongs
    288244    pmFPA *fpa = chip->parent;          // FPA to which the chip belongs
    289     return conceptsWrite(&conceptsCell, fpa, chip, cell, db, cell->concepts);
     245    return conceptsWrite(conceptsCell, fpa, chip, cell, db, cell->concepts);
    290246}
    291247
     
    300256        // Install the standard concepts
    301257
     258        #if 0
    302259        // FPA.NAME
    303260        {
     
    306263            psFree(fpaName);
    307264        }
     265        #endif
    308266
    309267        // FPA.AIRMASS
     
    340298        {
    341299            psMetadataItem *fpaRa = psMetadataItemAllocF64("FPA.RA", "Right Ascension of boresight", NAN);
    342             pmConceptRegister(fpaRa, (pmConceptReadFunc)pmConceptRead_FPA_RA,
    343                               (pmConceptWriteFunc)pmConceptWrite_FPA_RA, PM_CONCEPT_LEVEL_FPA);
     300            pmConceptRegister(fpaRa, (pmConceptParseFunc)pmConceptParse_FPA_Coords,
     301                              (pmConceptFormatFunc)pmConceptFormat_FPA_Coords, PM_CONCEPT_LEVEL_FPA);
    344302            psFree(fpaRa);
    345303        }
     
    348306        {
    349307            psMetadataItem *fpaDec = psMetadataItemAllocF64("FPA.DEC", "Declination of boresight", NAN);
    350             pmConceptRegister(fpaDec, (pmConceptReadFunc)pmConceptRead_FPA_DEC,
    351                               (pmConceptWriteFunc)pmConceptWrite_FPA_DEC, PM_CONCEPT_LEVEL_FPA);
     308            pmConceptRegister(fpaDec, (pmConceptParseFunc)pmConceptParse_FPA_Coords,
     309                              (pmConceptFormatFunc)pmConceptFormat_FPA_Coords, PM_CONCEPT_LEVEL_FPA);
    352310            psFree(fpaDec);
    353311        }
     
    436394
    437395        // CELL.DARKTIME
    438         {
     396        {Read
    439397            psMetadataItem *cellDarktime = psMetadataItemAllocF32("CELL.DARKTIME",
    440398                                           "Time since flush (sec)", NAN);
     
    450408                                          "Trim section", trimsec);
    451409            psFree(trimsec);
    452             pmConceptRegister(cellTrimsec, (pmConceptReadFunc)pmConceptRead_CELL_TRIMSEC,
    453                               (pmConceptWriteFunc)pmConceptWrite_CELL_TRIMSEC, PM_CONCEPT_LEVEL_CELL);
     410            pmConceptRegister(cellTrimsec, (pmConceptParseFunc)pmConceptParse_CELL_TRIMSEC,
     411                              (pmConceptFormatFunc)pmConceptFormat_CELL_TRIMSEC, PM_CONCEPT_LEVEL_CELL);
    454412            psFree(cellTrimsec);
    455413        }
     
    461419                                          "Bias sections", biassecs);
    462420            psFree(biassecs);
    463             pmConceptRegister(cellBiassec, (pmConceptReadFunc)pmConceptRead_CELL_BIASSEC,
    464                               (pmConceptWriteFunc)pmConceptWrite_CELL_BIASSEC, PM_CONCEPT_LEVEL_CELL);
     421            pmConceptRegister(cellBiassec, (pmConceptParseFunc)pmConceptParse_CELL_BIASSEC,
     422                              (pmConceptFormatFunc)pmConceptFormat_CELL_BIASSEC, PM_CONCEPT_LEVEL_CELL);
    465423            psFree(cellBiassec);
    466424        }
     
    469427        {
    470428            psMetadataItem *cellXbin = psMetadataItemAllocS32("CELL.XBIN", "Binning in x", 0);
    471             pmConceptRegister(cellXbin, (pmConceptReadFunc)pmConceptRead_CELL_XBIN,
    472                               (pmConceptWriteFunc)pmConceptWrite_CELL_XBIN, PM_CONCEPT_LEVEL_CELL);
     429            pmConceptRegister(cellXbin, (pmConceptParseFunc)pmConceptParse_CELL_Binning,
     430                              (pmConceptFormatFunc)pmConceptFormat_CELL_Binning, PM_CONCEPT_LEVEL_CELL);
    473431            psFree(cellXbin);
    474432        }
     
    477435        {
    478436            psMetadataItem *cellYbin = psMetadataItemAllocS32("CELL.YBIN", "Binning in y", 0);
    479             pmConceptRegister(cellYbin, (pmConceptReadFunc)pmConceptRead_CELL_YBIN,
    480                               (pmConceptWriteFunc)pmConceptWrite_CELL_YBIN, PM_CONCEPT_LEVEL_CELL);
     437            pmConceptRegister(cellYbin, (pmConceptParseFunc)pmConceptParse_CELL_Binning,
     438                              (pmConceptFormatFunc)pmConceptFormat_CELL_Binning, PM_CONCEPT_LEVEL_CELL);
    481439            psFree(cellYbin);
    482440        }
     
    485443        {
    486444            psMetadataItem *cellTimesys = psMetadataItemAllocS32("CELL.TIMESYS", "Time system", -1);
    487             pmConceptRegister(cellTimesys, (pmConceptReadFunc)pmConceptRead_CELL_TIMESYS,
    488                               (pmConceptWriteFunc)pmConceptWrite_CELL_TIMESYS, PM_CONCEPT_LEVEL_CELL);
     445            pmConceptRegister(cellTimesys, (pmConceptParseFunc)pmConceptParse_CELL_TIMESYS,
     446                              (pmConceptFormatFunc)pmConceptFormat_CELL_TIMESYS, PM_CONCEPT_LEVEL_CELL);
    489447            psFree(cellTimesys);
    490448        }
     
    499457                                       "Time of exposure", time);
    500458            psFree(time);
    501             pmConceptRegister(cellTime, (pmConceptReadFunc)pmConceptRead_CELL_TIME,
    502                               (pmConceptWriteFunc)pmConceptWrite_CELL_TIME, PM_CONCEPT_LEVEL_CELL);
     459            pmConceptRegister(cellTime, (pmConceptParseFunc)pmConceptParse_CELL_TIME,
     460                              (pmConceptFormatFunc)pmConceptFormat_CELL_TIME, PM_CONCEPT_LEVEL_CELL);
    503461            psFree(cellTime);
    504462        }
     
    507465        {
    508466            psMetadataItem *cellX0 = psMetadataItemAllocS32("CELL.X0", "Position of (0,0) on the chip", 0);
    509             pmConceptRegister(cellX0, (pmConceptReadFunc)pmConceptRead_CELL_X0,
    510                               (pmConceptWriteFunc)pmConceptWrite_CELL_X0, PM_CONCEPT_LEVEL_CELL);
     467            pmConceptRegister(cellX0, (pmConceptParseFunc)pmConceptParse_CELL_Positions,
     468                              (pmConceptFormatFunc)pmConceptFormat_CELL_Positions, PM_CONCEPT_LEVEL_CELL);
    511469            psFree(cellX0);
    512470        }
     
    515473        {
    516474            psMetadataItem *cellY0 = psMetadataItemAllocS32("CELL.Y0", "Position of (0,0) on the chip", 0);
    517             pmConceptRegister(cellY0, (pmConceptReadFunc)pmConceptRead_CELL_Y0,
    518                               (pmConceptWriteFunc)pmConceptWrite_CELL_Y0, PM_CONCEPT_LEVEL_CELL);
     475            pmConceptRegister(cellY0, (pmConceptParseFunc)pmConceptParse_CELL_Positions,
     476                              (pmConceptFormatFunc)pmConceptFormat_CELL_Positions, PM_CONCEPT_LEVEL_CELL);
    519477            psFree(cellY0);
    520478        }
Note: See TracChangeset for help on using the changeset viewer.