Changeset 4309 for trunk/archive/scripts/src/papFocalPlane.c
- Timestamp:
- Jun 17, 2005, 2:48:18 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/archive/scripts/src/papFocalPlane.c (modified) (20 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/archive/scripts/src/papFocalPlane.c
r4092 r4309 1 1 #include <stdio.h> 2 #include <string.h> 2 3 #include "pslib.h" 3 4 #include "papFocalPlane.h" 4 #include "pmRead.h" 5 #include "psAdditionals.h" 6 #include "pmFPARead.h" 5 7 6 8 // I'm sure this code, especially the DB lookup, leaks memory something chronic.... … … 8 10 9 11 // Look for a value already cached 10 static psMetadataItem *getValueFromCache(const p sFPA *fpa, // The FPA that contains the chip11 const p sChip *chip, // The chip that contains the cell12 const p sCell *cell, // The cell12 static 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 13 15 const char *valueName // Name of value 14 16 ) … … 31 33 32 34 // Put a value that we've found into the cache 33 static void setValueInCache(p sFPA *fpa, // The FPA that contains the chip34 p sChip *chip, // The chip that contains the cell35 p sCell *cell, // The cell35 static void setValueInCache(papFPA *fpa, // The FPA that contains the chip 36 papChip *chip, // The chip that contains the cell 37 papCell *cell, // The cell 36 38 const char *valueName, // Name of value 37 39 const psMetadataItem *value // Item containing the value … … 56 58 57 59 58 static psMetadataItem *getValueFromHeader( const psFPA *fpa, // The FPA that contains the chip59 const psChip *chip, // The chip that contains the cell60 const psCell *cell, // The cell60 static psMetadataItem *getValueFromHeader(papFPA *fpa, // The FPA that contains the chip 61 papChip *chip, // The chip that contains the cell 62 papCell *cell, // The cell 61 63 const char *valueName // Name of value 62 64 ) 63 65 { 66 bool mdStatus = true; // Status of MD lookup 67 64 68 // 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); 66 70 if (strlen(header) > 0) { 67 71 // We have a FITS header to look up --- search each level … … 70 74 if (cellItem) { 71 75 // XXX: Need to clean up before returning 72 setValueInCache(NULL, NULL, cell, cellItem);76 setValueInCache(NULL, NULL, cell, valueName, cellItem); 73 77 return cellItem; 74 78 } … … 79 83 if (chipItem) { 80 84 // XXX: Need to clean up before returning 81 setValueInCache(NULL, chip, cell, chipItem);85 setValueInCache(NULL, chip, cell, valueName, chipItem); 82 86 return chipItem; 83 87 } … … 88 92 if (fpaItem) { 89 93 // XXX: Need to clean up before returning 90 setValueInCache(fpa, chip, cell, fpaItem);94 setValueInCache(fpa, chip, cell, valueName, fpaItem); 91 95 return fpaItem; 92 96 } … … 100 104 101 105 // Look for a default 102 static psMetadataItem *getValueFromDefault( const psFPA *fpa, // The FPA that contains the chip103 const psChip *chip, // The chip that contains the cell104 const psCell *cell, // The cell106 static psMetadataItem *getValueFromDefault(papFPA *fpa, // The FPA that contains the chip 107 papChip *chip, // The chip that contains the cell 108 papCell *cell, // The cell 105 109 const char *valueName // Name of value 106 110 ) 107 111 { 108 psMetadataItem *defItem = psMetadataLookup( fpa->defaults, valueName);112 psMetadataItem *defItem = psMetadataLookup((psMetadata*)fpa->defaults, valueName); 109 113 if (defItem) { 110 setValueInCache(fpa, chip, cell, defItem);114 setValueInCache(fpa, chip, cell, valueName, defItem); 111 115 } 112 116 return defItem; // defItem is either NULL or points to what was desired … … 115 119 116 120 // Look for a database lookup 117 static psMetadataItem *getValueFromDB( const psFPA *fpa, // The FPA that contains the chip118 const psChip *chip, // The chip that contains the cell119 const psCell *cell, // The cell121 static psMetadataItem *getValueFromDB(papFPA *fpa, // The FPA that contains the chip 122 papChip *chip, // The chip that contains the cell 123 papCell *cell, // The cell 120 124 const char *valueName // Name of value 121 125 ) … … 123 127 if (fpa->db) { 124 128 // 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); 127 131 if (dbLookup) { 128 const char *tableName = psMetadataLookupString( dbLookup, "TABLE"); // Name of the table129 const char *colName = psMetadataLookupString( dbLookup, "COLUMN"); // Name of the column130 const char *givenCols = psMetadataLookupString( dbLookup, "GIVENDBCOL"); // Name of "where" columns131 const char *givenPS = psMetadataLookupString( dbLookup, "GIVENPS"); // Values for "where" columns132 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 132 136 133 137 // Now, need to get the "given"s … … 135 139 psList *cols = papSplit(givenCols, ",;"); // List of column names 136 140 psList *values = papSplit(givenPS, ",;"); // List of value names for the columns 137 psMetadata *selection = psMetadataAlloc( NULL); // The stuff to select in the DB141 psMetadata *selection = psMetadataAlloc(); // The stuff to select in the DB 138 142 if (cols->size != values->size) { 139 143 psLogMsg(__func__, PS_LOG_WARN, "The GIVENDBCOL and GIVENPS entries for %s do not have " … … 159 163 } 160 164 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 " 162 166 " lookup on %s --- ignored.\n", name, valueName); 163 167 } else { … … 199 203 } 200 204 201 psMetadataItem *psCellGetValue( const psFPA *fpa, // The FPA that contains the cell205 psMetadataItem *psCellGetValue(papFPA *fpa, // The FPA that contains the cell 202 206 const char *chipName, // The name of the chip 203 207 const char *cellName, // The name of the cell … … 205 209 ) 206 210 { 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 209 214 210 215 // Try cache, headers, database, defaults in order … … 223 228 } 224 229 225 float psCellGetValueF32( const psFPA *fpa, // The FPA that contains the cell230 float psCellGetValueF32(papFPA *fpa, // The FPA that contains the cell 226 231 const char *chipName, // The name of the chip 227 232 const char *cellName, // The name of the cell … … 244 249 } 245 250 246 int psCellGetValueS32( const psFPA *fpa, // The FPA that contains the cell251 int psCellGetValueS32(papFPA *fpa, // The FPA that contains the cell 247 252 const char *chipName, // The name of the chip 248 253 const char *cellName, // The name of the cell … … 250 255 ) 251 256 { 252 int value = NAN; // Result257 int value = 0; // Result 253 258 psMetadataItem *item = psCellGetValue(fpa, chipName, cellName, valueName); // The item 254 259 if (! item) { … … 266 271 267 272 268 double psCellGetValueF64( const psFPA *fpa, // The FPA that contains the cell273 double psCellGetValueF64(papFPA *fpa, // The FPA that contains the cell 269 274 const char *chipName, // The name of the chip 270 275 const char *cellName, // The name of the cell … … 288 293 289 294 290 psString psCellGetValueString( const psFPA *fpa, // The FPA that contains the cell295 psString psCellGetValueString(papFPA *fpa, // The FPA that contains the cell 291 296 const char *chipName, // The name of the chip 292 297 const char *cellName, // The name of the cell … … 308 313 return value; 309 314 } 315 316 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 317 // Allocators 318 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 319 320 papFPA *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 344 void 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 360 papChip *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 377 void p_papChipFree(papChip *chip) 378 { 379 psFree(chip->values); 380 psFree(chip->header); 381 psFree(chip->cells); 382 psFree(chip->images); 383 } 384 385 papCell *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 403 void p_papCellFree(papCell *cell) 404 { 405 psFree(cell->values); 406 psFree(cell->header); 407 psFree(cell->readouts); 408 psFree(cell->images); 409 } 410 411 papReadout *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 443 void 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.
