Changeset 5104 for trunk/archive/scripts/src/phase2/pmFPA.c
- Timestamp:
- Sep 22, 2005, 4:54:52 PM (21 years ago)
- File:
-
- 1 edited
-
trunk/archive/scripts/src/phase2/pmFPA.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/archive/scripts/src/phase2/pmFPA.c
r4820 r5104 1 1 #include <stdio.h> 2 2 #include <string.h> 3 #include <assert.h> 3 4 #include "pslib.h" 4 5 #include "psAdditionals.h" … … 6 7 #include "pmFPA.h" 7 8 8 9 9 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 10 10 // Allocators 11 11 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 12 12 13 pmFPA *pmFPAAlloc(const psMetadata *camera, // Camera configuration 14 psDB *db // Database 13 p_pmHDU *p_pmHDUAlloc(const char *extname) 14 { 15 p_pmHDU *hdu = psAlloc(sizeof(p_pmHDU)); 16 psMemSetDeallocator(hdu, (psFreeFunc)p_pmHDUFree); 17 18 hdu->extname = extname; 19 hdu->pixels = NULL; 20 hdu->header = NULL; 21 22 return hdu; 23 } 24 25 void p_pmHDUFree(p_pmHDU *hdu) 26 { 27 psFree(hdu->pixels); 28 psFree(hdu->header); 29 } 30 31 pmFPA *pmFPAAlloc(const psMetadata *camera // Camera configuration 15 32 ) 16 33 { 17 34 pmFPA *fpa = psAlloc(sizeof(pmFPA));// The FPA 18 psMemSetDeallocator(fpa, (psFreeF cn)p_pmFPAFree);35 psMemSetDeallocator(fpa, (psFreeFunc)p_pmFPAFree); 19 36 20 37 // Fill in the components … … 23 40 fpa->projection = NULL; 24 41 25 fpa->values = psMetadataAlloc(); 26 // fpa->camera = psMemIncrRefCounter((psPtr)camera); 27 fpa->db = db; 42 fpa->concepts = psMetadataAlloc(); 43 fpa->camera = psMemIncrRefCounter((psPtr)camera); 28 44 fpa->chips = psArrayAlloc(0); 29 45 30 fpa->extname = NULL; 31 fpa->pixels = NULL; 32 fpa->header = NULL; 46 fpa->private = NULL; 33 47 34 48 return fpa; … … 41 55 psFree(fpa->projection); 42 56 43 psFree(fpa-> values);57 psFree(fpa->concepts); 44 58 psFree((psPtr)fpa->camera); 45 psFree(fpa->db);46 59 psFree(fpa->chips); 47 60 48 psFree(fpa->pixels); 49 psFree(fpa->header); 61 psFree(fpa->private); 50 62 } 51 63 … … 55 67 { 56 68 pmChip *chip = psAlloc(sizeof(pmChip)); // The chip 57 psMemSetDeallocator(chip, (psFreeF cn)p_pmChipFree);69 psMemSetDeallocator(chip, (psFreeFunc)p_pmChipFree); 58 70 59 71 // Push onto the array of chips … … 67 79 chip->fromFPA = NULL; 68 80 69 chip->values = psMetadataAlloc(); 70 // chip->parent = psMemIncrRefCounter(fpa); 81 chip->concepts = psMetadataAlloc(); 71 82 chip->cells = psArrayAlloc(0); 72 73 chip->extname = NULL; 74 chip->pixels = NULL; 75 chip->header = NULL; 76 77 psMetadataAddStr(chip->values, PS_LIST_HEAD, "CHIP.NAME", "Chip name added at pmChipAlloc", name); 83 chip->parent = fpa; // We don't increment the reference counter on this --- it's a 84 // "hidden" link. If we increment the reference counter, we get stuck 85 // in a circle. 86 chip->valid = true; 87 88 chip->private = NULL; 89 90 psMetadataAddStr(chip->concepts, PS_LIST_HEAD, "CHIP.NAME", 0, "Chip name added at pmChipAlloc", name); 78 91 79 92 return chip; … … 85 98 psFree(chip->fromFPA); 86 99 87 psFree(chip-> values);100 psFree(chip->concepts); 88 101 psFree(chip->cells); 89 // psFree(chip->parent); 90 91 psFree(chip->pixels); 92 psFree(chip->header); 102 103 psFree(chip->private); 104 105 // We don't free the parent member, since that would generate a circular call. We don't increment the 106 // reference counter when we add it, anyway, so that's OK. 93 107 } 94 108 95 109 pmCell *pmCellAlloc(pmChip *chip, // Chip to which the cell belongs 96 psMetadata * values, // Initial values for concepts110 psMetadata *cameraData, // Camera data 97 111 psString name // Name of cell 98 112 ) 99 113 { 100 114 pmCell *cell = psAlloc(sizeof(pmCell)); // The cell 101 psMemSetDeallocator(cell, (psFreeF cn)p_pmCellFree);115 psMemSetDeallocator(cell, (psFreeFunc)p_pmCellFree); 102 116 103 117 // Push onto the array of chips … … 114 128 cell->toSky = NULL; 115 129 116 cell->values = psMemIncrRefCounter(values); 130 cell->concepts = psMetadataAlloc(); 131 psMetadataAddStr(cell->concepts, PS_LIST_HEAD, "CELL.NAME", 0, "Cell name added at pmCellAlloc", name); 132 cell->camera = psMemIncrRefCounter(cameraData); 133 117 134 cell->readouts = psArrayAlloc(0); 118 // cell->parent = psMemIncrRefCounter(chip); 119 120 cell->extname = NULL; 121 cell->pixels = NULL; 122 cell->header = NULL; 123 124 psMetadataAddStr(cell->values, PS_LIST_HEAD, "CELL.NAME", "Cell name added at pmCellAlloc", name); 135 cell->parent = chip; // We don't increment the reference counter on this --- it's a 136 // "hidden" link. If we increment the reference counter, we get stuck 137 // in a circle. 138 cell->valid = true; 139 140 cell->private = NULL; 125 141 126 142 return cell; … … 135 151 psFree(cell->toSky); 136 152 137 psFree(cell->values); 153 psFree(cell->concepts); 154 psFree(cell->camera); 138 155 psFree(cell->readouts); 139 // psFree(cell->parent); 140 141 psFree(cell->pixels); 142 psFree(cell->header); 156 157 psFree(cell->private); 158 159 // We don't free the parent member, since that would generate a circular call. We don't increment the 160 // reference counter when we add it, anyway, so that's OK. 143 161 } 144 162 145 163 pmReadout *pmReadoutAlloc(pmCell *cell, // Cell to which the readout belongs 146 int readoutNum, // Number of the readout147 164 psImage *image, // The pixels 148 165 psList *overscans, // The overscan images … … 151 168 { 152 169 pmReadout *readout = psAlloc(sizeof(pmReadout)); 153 psMemSetDeallocator(readout, (psFreeFcn)p_pmReadoutFree); 154 psArray *readouts = cell->readouts; 155 if (readoutNum >= readouts->nalloc) { 156 readouts = psArrayRealloc(readouts, readoutNum); 157 cell->readouts = readouts; 158 } 159 readouts->data[readoutNum] = readout; 170 psMemSetDeallocator(readout, (psFreeFunc)p_pmReadoutFree); 171 cell->readouts = psArrayAdd(cell->readouts, 0, readout); 160 172 161 173 // Set the components 162 readout->image = image; 163 readout->overscans = overscans; 174 readout->image = psMemIncrRefCounter(image); 175 readout->mask = NULL; 176 readout->overscans = psMemIncrRefCounter(overscans); 164 177 165 readout->values = psMetadataAlloc();178 //readout->concepts = psMetadataAlloc(); 166 179 167 180 *(int*)&readout->col0 = col0; … … 178 191 { 179 192 psFree(readout->image); 193 psFree(readout->mask); 180 194 psFree(readout->overscans); 181 psFree(readout->values); 182 } 195 //psFree(readout->concepts); 196 } 197 198 199 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 200 // Select and Exclude chips 201 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 202 203 bool pmFPASelectChip(pmFPA *fpa, int chipNum) 204 { 205 assert(fpa); 206 207 if (chipNum < 0 || chipNum > fpa->chips->n) { 208 return false; 209 } 210 psArray *chips = fpa->chips; // Component chips 211 for (int i = 0; i < chips->n; i++) { 212 pmChip *chip = chips->data[i]; // The chip of interest 213 if (i == chipNum) { 214 psTrace(__func__, 5, "Marking chip %d valid.\n", i); 215 chip->valid = true; 216 psArray *cells = chip->cells; // Component cells 217 for (int j = 0; j < cells->n; j++) { 218 pmCell *cell = cells->data[j]; // Cell of interest 219 cell->valid = true; 220 } 221 } else { 222 psTrace(__func__, 5, "Marking chip %d invalid.\n", i); 223 chip->valid = false; 224 psArray *cells = chip->cells; // Component cells 225 for (int j = 0; j < cells->n; j++) { 226 pmCell *cell = cells->data[j]; // Cell of interest 227 cell->valid = false; 228 } 229 } 230 } 231 return true; 232 } 233 234 int pmFPAExcludeChip(pmFPA *fpa, int chipNum) 235 { 236 assert(fpa); 237 238 if (chipNum < 0 || chipNum > fpa->chips->n) { 239 psLogMsg(__func__, PS_LOG_WARN, "Invalid chip number: %d\n", chipNum); 240 } 241 int numValid = 0; // Number of valid chips 242 psArray *chips = fpa->chips; // Component chips 243 for (int i = 0; i < chips->n; i++) { 244 pmChip *chip = chips->data[i]; // The chip of interest 245 if (i == chipNum) { 246 psTrace(__func__, 5, "Marking chip %d invalid.\n", i); 247 chip->valid = false; 248 psArray *cells = chip->cells; // Component cells 249 for (int j = 0; j < cells->n; j++) { 250 pmCell *cell = cells->data[j]; // Cell of interest 251 cell->valid = false; 252 } 253 } else if (chip->valid) { 254 numValid++; 255 } 256 } 257 258 psTrace(__func__, 5, "%d valid chips in fpa.\n", numValid); 259 return numValid; 260 }
Note:
See TracChangeset
for help on using the changeset viewer.
