Changeset 12591 for trunk/psModules/src/config/pmConfigCamera.c
- Timestamp:
- Mar 26, 2007, 4:45:42 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/config/pmConfigCamera.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/config/pmConfigCamera.c
r12564 r12591 70 70 71 71 // Generate a mosaicked version of a camera configuration 72 // XXX EAM : the error states of this function need to be more carefully considered 72 73 static bool mosaickedVersion(psMetadata *oldCameras, // Old list of camera configurations 73 74 psMetadata *newCameras, // New list of camera configurations … … 84 85 psMetadata *camera = psMetadataLookupMetadata(NULL, oldCameras, name); // The camera configuration 85 86 if (!camera) { 87 // XXX is this an error? 88 psError(PS_ERR_UNEXPECTED_NULL, false, "Can't find camera to be mosaicked in camera list."); 86 89 return false; 87 90 } … … 94 97 } 95 98 96 psMetadata *new = psMetadataCopy(NULL, camera); // Copy of the camera 99 psMetadata *new = psMetadataCopy(NULL, camera); // Copy of the camera description 97 100 bool mdok; // Status of MD lookups 98 101 99 // Fix up the contents of the FPA 100 psMetadata *fpa = psMetadataLookupMetadata(&mdok, new, "FPA"); // FPA in the camera configuration 101 if (!mdok || !fpa) { 102 psError(PS_ERR_UNEXPECTED_NULL, true, "Can't find FPA within camera configuration."); 102 // ** Fix up the contents of the FPA description to match the mosaicked camera ** 103 // select the FPA description 104 psMetadata *fpa = psMetadataLookupMetadata(NULL, new, "FPA"); // FPA in the camera configuration 105 if (!fpa) { 106 psError(PS_ERR_UNEXPECTED_NULL, false, "Can't find FPA within camera configuration."); 103 107 psFree(new); 104 return NULL;108 return false; 105 109 } 106 110 switch (mosaicLevel) { 111 // For CHIP mosaic, replace the contents of each chip with a single cell 107 112 case PM_FPA_LEVEL_CHIP: { 108 // Replace the contents of each chip with a single cell109 113 psMetadataIterator *fpaIter = psMetadataIteratorAlloc(fpa, PS_LIST_HEAD, NULL); // Iterator 110 114 psMetadataItem *fpaItem = NULL; // Item from iteration 111 115 while ((fpaItem = psMetadataGetAndIncrement(fpaIter))) { 112 116 if (fpaItem->type != PS_DATA_STRING) { 113 ps Warning("Element %s within FPA in camera configuration is not of type STR.",117 psError(PS_ERR_UNKNOWN, true, "Element %s within FPA in camera configuration is not of type STR.", 114 118 fpaItem->name); 115 continue; 119 psFree(new); 120 return false; 116 121 } 117 122 … … 124 129 break; 125 130 } 131 // For FPA mosaic, replace the contents of the FPA with a single chip containing a single cell 126 132 case PM_FPA_LEVEL_FPA: { 127 // Replace the contents of the FPA with a single chip containing a single cell128 133 while (psListLength(fpa->list) > 0) { 129 134 psMetadataRemoveIndex(fpa, PS_LIST_TAIL); … … 139 144 } 140 145 141 // Update the camera formats appropriately 142 psMetadata *formats = psMetadataLookupMetadata(&mdok, new, "FORMATS"); // FORMATS in the configuration 143 assert(mdok && formats); // It had better be there --- we've already read them in 146 // ** Update the camera formats : add a new (mosaicked) format for each existing camera format ** 147 // select the list of all camera formats 148 psMetadata *formats = psMetadataLookupMetadata(NULL, new, "FORMATS"); // FORMATS in the configuration 149 assert(formats); // It had better be there --- we've already read them in 150 // loop over each of the formats 144 151 psMetadataIterator *formatsIter = psMetadataIteratorAlloc(formats, PS_LIST_HEAD, NULL); // Iterator 145 152 psMetadataItem *formatsItem = NULL; // Item from iteration … … 148 155 psMetadata *format = formatsItem->data.V; // The camera format 149 156 150 // Add a RULE, so that when a mosaic is written to a FITS file, it can be recognised again when read. 151 psMetadata *rule = psMetadataLookupMetadata(&mdok, format, "RULE"); // Way to identify format from PHU 152 if (!mdok || !rule) { 153 psWarning("Couldn't find RULE in the camera format %s.\n", formatsItem->name); 154 continue; 155 } 157 // Add a new RULE which uniquely describes the mosaicked format. this is needed so 158 // that when a mosaic is written to a FITS file, it can be recognised again when read. 159 psMetadata *rule = psMetadataLookupMetadata(NULL, format, "RULE"); // Way to identify format from PHU 160 if (!rule) { 161 // a camera format without a rule is not allowed. 162 psError(PS_ERR_UNKNOWN, false, "Camera format %s has no RULE", formatsItem->name); 163 return false; 164 } 165 166 // the new rule is supplemented by the mosaicLevel 156 167 switch (mosaicLevel) { 157 168 case PM_FPA_LEVEL_CHIP: … … 166 177 167 178 // Fix the FILE information: need to fix the levels for the PHU and EXTENSIONS. 179 // both of these elements are required in the format; we raise an error if they are not found 168 180 // If EXTENSIONS is NONE, then we need to change the CONTENT specifier to point to the chip name. 169 psMetadata *file = psMetadataLookupMetadata( &mdok, format, "FILE"); // File information170 if (! mdok || !file) {171 ps Warning("Couldn't find FILE in the camera format %s.\n", formatsItem->name);172 continue;181 psMetadata *file = psMetadataLookupMetadata(NULL, format, "FILE"); // File information 182 if (!file) { 183 psError(PS_ERR_UNKNOWN, false, "Camera format %s has no FILE", formatsItem->name); 184 return false; 173 185 } 174 186 psMetadataItem *phuItem = psMetadataLookup(file, "PHU"); // PHU level 175 187 if (!phuItem || phuItem->type != PS_DATA_STRING) { 176 psWarning("Couldn't find PHU of type STR in the FILE information in the camera format %s.\n", 177 formatsItem->name); 178 continue; 179 } 180 if (strcasecmp(phuItem->data.str, "CELL") == 0 || 181 (mosaicLevel == PM_FPA_LEVEL_FPA && (strcasecmp(phuItem->data.str, "CHIP") == 0))) { 182 psFree(phuItem->data.str); 183 if (mosaicLevel == PM_FPA_LEVEL_CHIP) { 184 phuItem->data.str = psStringCopy("CHIP"); 185 } else { 186 phuItem->data.str = psStringCopy("FPA"); 187 } 188 psError(PS_ERR_UNKNOWN, false, "Camera format %s is missing PHU in the FILE information", formatsItem->name); 189 return false; 188 190 } 189 191 psMetadataItem *extensionsItem = psMetadataLookup(file, "EXTENSIONS"); // Extensions level 190 192 if (!extensionsItem || extensionsItem->type != PS_DATA_STRING) { 191 psWarning("Couldn't find EXTENSIONS of type STR in the FILE information " 192 "in the camera format %s.\n", formatsItem->name); 193 continue; 194 } 193 psError(PS_ERR_UNKNOWN, false, "Camera format %s is missing EXTENSIONS in the FILE information", formatsItem->name); 194 return false; 195 } 196 197 // mosaicLevel == CHIP: 198 // Case PHU EXTENSIONS Modifications 199 // ==== === ========== =========== 200 // 1. FPA CHIP NONE 201 // 2. FPA CELL EXT->CHIP 202 // 3. FPA NONE NONE 203 // 4. CHIP CELL EXT->NONE 204 // 5. CHIP NONE NONE 205 // 6. CELL NONE PHU->CHIP 206 // possible outcomes: 207 // FPA CHIP 208 // FPA NONE 209 // CHIP NONE 210 211 // mosaicLevel == FPA: 212 // Case PHU EXTENSIONS Modifications 213 // ==== === ========== =========== 214 // 1. FPA CHIP EXT->NONE 215 // 2. FPA CELL EXT->NONE 216 // 3. FPA NONE NONE 217 // 4. CHIP CELL PHU->FPA, EXT->NONE 218 // 5. CHIP NONE PHU->FPA 219 // 6. CELL NONE PHU->FPA 220 // possible outcomes: 221 // FPA NONE 222 223 // modify the values of phuItem and extensionsItem 195 224 switch (mosaicLevel) { 196 225 case PM_FPA_LEVEL_CHIP: 197 if (strcasecmp(phuItem->data.str, "FPA") == 0 && 198 strcasecmp(extensionsItem->data.str, "CELL") == 0) { 226 if (!strcasecmp(phuItem->data.str, "FPA") && !strcasecmp(extensionsItem->data.str, "CHIP")) { 227 break; 228 } 229 if (!strcasecmp(phuItem->data.str, "FPA") && !strcasecmp(extensionsItem->data.str, "CELL")) { 199 230 psFree(extensionsItem->data.str); 200 231 extensionsItem->data.str = psStringCopy("CHIP"); 201 } else { 232 break; 233 } 234 if (!strcasecmp(phuItem->data.str, "FPA") && !strcasecmp(extensionsItem->data.str, "NON")) { 235 break; 236 } 237 if (!strcasecmp(phuItem->data.str, "CHIP") && !strcasecmp(extensionsItem->data.str, "CELL")) { 202 238 psFree(extensionsItem->data.str); 203 239 extensionsItem->data.str = psStringCopy("NONE"); 204 205 if (strcasecmp(phuItem->data.str, "FPA") == 0) { 206 // Don't need a "CONTENT" to identify the content! 207 if (psMetadataLookup(file, "CONTENT")) { 208 psMetadataRemoveKey(file, "CONTENT"); 209 } 210 break; 211 } 212 psMetadataAddStr(file, PS_LIST_TAIL, "CONTENT", PS_META_REPLACE, "Key to CONTENTS menu", 213 "{CHIP.NAME}"); 214 } 240 break; 241 } 242 if (!strcasecmp(phuItem->data.str, "CHIP") && !strcasecmp(extensionsItem->data.str, "NONE")) { 243 break; 244 } 245 if (!strcasecmp(phuItem->data.str, "CELL") && !strcasecmp(extensionsItem->data.str, "NONE")) { 246 psFree(phuItem->data.str); 247 phuItem->data.str = psStringCopy("CHIP"); 248 break; 249 } 250 psAbort ("should not reach here"); 251 252 case PM_FPA_LEVEL_FPA: 253 if (!strcasecmp(phuItem->data.str, "FPA") && !strcasecmp(extensionsItem->data.str, "CHIP")) { 254 psFree(extensionsItem->data.str); 255 extensionsItem->data.str = psStringCopy("NONE"); 256 break; 257 } 258 if (!strcasecmp(phuItem->data.str, "FPA") && !strcasecmp(extensionsItem->data.str, "CELL")) { 259 psFree(extensionsItem->data.str); 260 extensionsItem->data.str = psStringCopy("NONE"); 261 break; 262 } 263 if (!strcasecmp(phuItem->data.str, "FPA") && !strcasecmp(extensionsItem->data.str, "NON")) { 264 break; 265 } 266 if (!strcasecmp(phuItem->data.str, "CHIP") && !strcasecmp(extensionsItem->data.str, "CELL")) { 267 psFree(phuItem->data.str); 268 phuItem->data.str = psStringCopy("FPA"); 269 break; 270 psFree(extensionsItem->data.str); 271 extensionsItem->data.str = psStringCopy("NONE"); 272 break; 273 } 274 if (!strcasecmp(phuItem->data.str, "CHIP") && !strcasecmp(extensionsItem->data.str, "NONE")) { 275 psFree(phuItem->data.str); 276 phuItem->data.str = psStringCopy("FPA"); 277 break; 278 } 279 if (!strcasecmp(phuItem->data.str, "CELL") && !strcasecmp(extensionsItem->data.str, "NONE")) { 280 psFree(phuItem->data.str); 281 phuItem->data.str = psStringCopy("FPA"); 282 break; 283 } 284 psAbort ("should not reach here"); 285 286 default: 287 psAbort("Should never get here.\n"); 288 } 215 289 216 290 #if 0 217 // Don't need CELL.NAME for chip-mosaicked camera 218 if (psMetadataLookup(file, "CELL.NAME")) { 219 psMetadataRemoveKey(file, "CELL.NAME"); 220 } 291 // XXXX when do I need to adjust the value of CONTENT, CELL.NAME, CHIP.NAME? 292 293 // Don't need a "CONTENT" to identify the content! 294 if (psMetadataLookup(file, "CONTENT")) { 295 psMetadataRemoveKey(file, "CONTENT"); 296 } 297 psMetadataAddStr(file, PS_LIST_TAIL, "CONTENT", PS_META_REPLACE, "Key to CONTENTS menu", 298 "{CHIP.NAME}"); 299 // Don't need CELL.NAME for chip-mosaicked camera 300 if (psMetadataLookup(file, "CELL.NAME")) { 301 psMetadataRemoveKey(file, "CELL.NAME"); 302 } 303 // Don't need CHIP.NAME or CELL.NAME for fpa-mosaicked camera 304 if (psMetadataLookup(file, "CHIP.NAME")) { 305 psMetadataRemoveKey(file, "CHIP.NAME"); 306 } 307 if (psMetadataLookup(file, "CELL.NAME")) { 308 psMetadataRemoveKey(file, "CELL.NAME"); 309 } 221 310 #endif 222 break;223 case PM_FPA_LEVEL_FPA:224 psFree(extensionsItem->data.str);225 extensionsItem->data.str = psStringCopy("NONE");226 #if 0227 // Don't need CHIP.NAME or CELL.NAME for fpa-mosaicked camera228 if (psMetadataLookup(file, "CHIP.NAME")) {229 psMetadataRemoveKey(file, "CHIP.NAME");230 }231 if (psMetadataLookup(file, "CELL.NAME")) {232 psMetadataRemoveKey(file, "CELL.NAME");233 }234 #endif235 break;236 default:237 psAbort("Should never get here.\n");238 }239 311 240 312 // Fix up the CONTENTS to contain only the mosaicked cell for each chip … … 245 317 break; 246 318 case PM_FPA_LEVEL_CHIP: 247 if (strcasecmp(phuItem->data.str, "FPA") == 0) { 248 if (strcasecmp(extensionsItem->data.str, "CHIP") == 0) { 249 // List the chipName:chipType for each chip. 250 251 psMetadata *contents = psMetadataAlloc(); // List of contents, with chipName:chipType 252 253 psMetadataIterator *fpaIter = psMetadataIteratorAlloc(fpa, PS_LIST_HEAD, NULL); // Iteratr 254 psMetadataItem *fpaItem; // Item from iteration 255 while ((fpaItem = psMetadataGetAndIncrement(fpaIter))) { 256 if (fpaItem->type != PS_DATA_STRING) { 257 // We've already thrown a warning on this, above. 258 continue; 259 } 260 psString content = NULL; // Content to add 261 psStringAppend(&content, "%s:_mosaicChip ", fpaItem->name); 262 psMetadataAddStr(contents, PS_LIST_TAIL, fpaItem->name, 0, NULL, content); 263 psFree(content); 264 } 265 psFree(fpaIter); 266 psMetadataAddMetadata(format, PS_LIST_TAIL, TABLE_OF_CONTENTS, PS_META_REPLACE, 267 "List of contents", contents); 268 psFree(contents); 269 270 psMetadata *chips = psMetadataAlloc(); // List of chip types, with cellName:cellType 271 psMetadataAddStr(chips, PS_LIST_TAIL, "_mosaicChip", 0, NULL, 272 "MosaickedCell:_mosaic"); 273 psMetadataAddMetadata(format, PS_LIST_TAIL, CHIP_TYPES, PS_META_REPLACE, 274 "List of chip types", chips); 275 psFree(chips); 276 break; 277 } else if (strcasecmp(extensionsItem->data.str, "NONE") == 0) { 278 // List the contents on a single line 279 psString contentsLine = NULL; // Contents of the PHU 280 psMetadataIterator *fpaIter = psMetadataIteratorAlloc(fpa, PS_LIST_HEAD, NULL); // Iteratr 281 psMetadataItem *fpaItem; // Item from iteration 282 while ((fpaItem = psMetadataGetAndIncrement(fpaIter))) { 283 if (fpaItem->type != PS_DATA_STRING) { 284 // We've already thrown a warning on this, above. 285 continue; 286 } 287 psStringAppend(&contentsLine, "%s:MosaickedCell:_mosaic ", fpaItem->name); 288 } 289 psFree(fpaIter); 290 psMetadataAddStr(format, PS_LIST_TAIL, TABLE_OF_CONTENTS, PS_META_REPLACE, 291 NULL, contentsLine); 292 psFree(contentsLine); 293 break; 294 } 295 } 296 // PHU level is CHIP, EXTENSIONS is NONE. 297 298 psMetadata *contents = psMetadataLookupMetadata(&mdok, format, 299 TABLE_OF_CONTENTS); // File contents 300 if (!mdok || !contents) { 301 psWarning("Couldn't find %s in the camera format %s.\n", TABLE_OF_CONTENTS, 302 formatsItem->name); 303 continue; 304 } 305 while (psListLength(contents->list) > 0) { 306 psMetadataRemoveIndex(contents, PS_LIST_TAIL); 307 } 308 309 psMetadataIterator *fpaIter = psMetadataIteratorAlloc(fpa, PS_LIST_HEAD, NULL); // Iterator 310 psMetadataItem *fpaItem; // Item from iteration 311 while ((fpaItem = psMetadataGetAndIncrement(fpaIter))) { 312 if (fpaItem->type != PS_DATA_STRING) { 313 // We've already thrown a warning on this, above. 314 continue; 315 } 316 317 psMetadataAddStr(contents, PS_LIST_TAIL, fpaItem->name, 0, NULL, "_mosaicChip"); 318 } 319 psFree(fpaIter); 320 321 psMetadata *chips = psMetadataAlloc(); // List of chip types, with cellName:cellType 322 psMetadataAddStr(chips, PS_LIST_TAIL, "_mosaicChip", 0, NULL, 323 "MosaickedCell:_mosaic"); 324 psMetadataAddMetadata(format, PS_LIST_TAIL, CHIP_TYPES, PS_META_REPLACE, 325 "List of chip types", chips); 326 psFree(chips); 327 break; 319 if (!strcasecmp(phuItem->data.str, "FPA") && !strcasecmp(extensionsItem->data.str, "CHIP")) { 320 // ensure the value of CONTENT in the FILE section has the right value 321 psMetadataAddStr(file, PS_LIST_TAIL, "CONTENT", PS_META_REPLACE, "Key to CONTENTS menu", "{CHIP.NAME}"); 322 323 // List the chipName:chipType for each chip. 324 psMetadata *contents = psMetadataAlloc(); // List of contents, with chipName:chipType 325 326 psMetadataIterator *fpaIter = psMetadataIteratorAlloc(fpa, PS_LIST_HEAD, NULL); // Iteratr 327 psMetadataItem *fpaItem; // Item from iteration 328 while ((fpaItem = psMetadataGetAndIncrement(fpaIter))) { 329 assert (fpaItem->type == PS_DATA_STRING); 330 psString content = NULL; // Content to add 331 psStringAppend(&content, "%s:_mosaicChip ", fpaItem->name); 332 psMetadataAddStr(contents, PS_LIST_TAIL, fpaItem->name, 0, NULL, content); 333 psFree(content); 334 } 335 psFree(fpaIter); 336 psMetadataAddMetadata(format, PS_LIST_TAIL, TABLE_OF_CONTENTS, PS_META_REPLACE, 337 "List of contents", contents); 338 psFree(contents); 339 340 psMetadata *chips = psMetadataAlloc(); // List of chip types, with cellName:cellType 341 psMetadataAddStr(chips, PS_LIST_TAIL, "_mosaicChip", 0, NULL, 342 "MosaickedCell:_mosaic"); 343 psMetadataAddMetadata(format, PS_LIST_TAIL, CHIP_TYPES, PS_META_REPLACE, 344 "List of chip types", chips); 345 psFree(chips); 346 break; 347 } 348 if (!strcasecmp(phuItem->data.str, "FPA") && !strcasecmp(extensionsItem->data.str, "NONE")) { 349 // List the contents on a single line 350 psString contentsLine = NULL; // Contents of the PHU 351 psMetadataIterator *fpaIter = psMetadataIteratorAlloc(fpa, PS_LIST_HEAD, NULL); // Iteratr 352 psMetadataItem *fpaItem; // Item from iteration 353 while ((fpaItem = psMetadataGetAndIncrement(fpaIter))) { 354 assert (fpaItem->type == PS_DATA_STRING); 355 psStringAppend(&contentsLine, "%s:MosaickedCell:_mosaic ", fpaItem->name); 356 } 357 psFree(fpaIter); 358 psMetadataAddStr(format, PS_LIST_TAIL, TABLE_OF_CONTENTS, PS_META_REPLACE, 359 NULL, contentsLine); 360 psFree(contentsLine); 361 break; 362 } 363 if (!strcasecmp(phuItem->data.str, "CHIP") && !strcasecmp(extensionsItem->data.str, "NONE")) { 364 // XXX recode this to match the structure above (FPA/CHIP)? 365 // select and remove the old contents 366 psMetadata *contents = psMetadataLookupMetadata(NULL, format, TABLE_OF_CONTENTS); // File contents 367 if (!contents) { 368 psError(PS_ERR_UNKNOWN, false, "Couldn't find %s in the camera format %s.\n", 369 TABLE_OF_CONTENTS, formatsItem->name); 370 return false; 371 } 372 while (psListLength(contents->list) > 0) { 373 psMetadataRemoveIndex(contents, PS_LIST_TAIL); 374 } 375 376 // update with the new contents 377 psMetadataIterator *fpaIter = psMetadataIteratorAlloc(fpa, PS_LIST_HEAD, NULL); // Iterator 378 psMetadataItem *fpaItem; // Item from iteration 379 while ((fpaItem = psMetadataGetAndIncrement(fpaIter))) { 380 assert (fpaItem->type == PS_DATA_STRING); 381 psMetadataAddStr(contents, PS_LIST_TAIL, fpaItem->name, 0, NULL, "_mosaicChip"); 382 } 383 psFree(fpaIter); 384 385 psMetadata *chips = psMetadataAlloc(); // List of chip types, with cellName:cellType 386 psMetadataAddStr(chips, PS_LIST_TAIL, "_mosaicChip", 0, NULL, 387 "MosaickedCell:_mosaic"); 388 psMetadataAddMetadata(format, PS_LIST_TAIL, CHIP_TYPES, PS_META_REPLACE, 389 "List of chip types", chips); 390 psFree(chips); 391 break; 392 } 328 393 default: 329 394 psAbort("Should never get here.\n"); … … 331 396 332 397 // Fix the cell type 333 psMetadata *cells = psMetadataLookupMetadata( &mdok, format, CELL_TYPES); // CELLS information334 if (! mdok || !cells) {335 ps Warning("Couldn't find CELLS of type METADATA in the camera format %s.\n", formatsItem->name);336 continue;398 psMetadata *cells = psMetadataLookupMetadata(NULL, format, CELL_TYPES); // CELLS information 399 if (!cells) { 400 psError(PS_ERR_UNKNOWN, false, "Couldn't find CELLS of type METADATA in the camera format %s.\n", formatsItem->name); 401 return false; 337 402 } 338 403 psMetadata *cell = psMetadataAlloc(); // Cell information … … 341 406 psMetadataAddStr(cell, PS_LIST_TAIL, "CELL.TRIMSEC.SOURCE", 0, "Trim section source", "HEADER"); 342 407 psMetadataAddStr(cell, PS_LIST_TAIL, "CELL.BIASSEC.SOURCE", 0, "Bias section source", "HEADER"); 343 psMetadataAddMetadata(cells, PS_LIST_HEAD, "_mosaic", PS_META_REPLACE, 344 "Mosaic cell information", cell); 408 psMetadataAddMetadata(cells, PS_LIST_HEAD, "_mosaic", PS_META_REPLACE, "Mosaic cell information", cell); 345 409 psFree(cell); // Drop reference 346 410 … … 428 492 } 429 493 430 494 // XXX EAM : shouldn't this loop over the unmosaicked camera names, calling the above function? 495 // the operation putting the new entries first is now implemented in mosaickedVersion 431 496 bool pmConfigCameraMosaickedVersionsAll(psMetadata *site) 432 497 {
Note:
See TracChangeset
for help on using the changeset viewer.
