Changeset 23594 for branches/cnb_branches/cnb_branch_20090301/psModules/src/concepts/pmConceptsWrite.c
- Timestamp:
- Mar 29, 2009, 6:15:31 PM (17 years ago)
- Location:
- branches/cnb_branches/cnb_branch_20090301
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/cnb_branches/cnb_branch_20090301
-
branches/cnb_branches/cnb_branch_20090301/psModules
- Property svn:mergeinfo changed
/trunk/psModules merged: 23354,23358,23370,23374,23378,23404-23405,23428,23432,23447,23450-23452,23476,23487,23498,23535,23574,23576-23577,23587
- Property svn:mergeinfo changed
-
branches/cnb_branches/cnb_branch_20090301/psModules/src/concepts/pmConceptsWrite.c
r22699 r23594 62 62 while ((cItem = psListGetAndIncrement(cIter))) { 63 63 if (cItem->type != PS_DATA_STRING) { 64 psWarning("psMetadataItem from list is of type %x instead of " 65 "%x (PS_DATA_STRING) --- can't interpret.\n", cItem->type, PS_DATA_STRING); 64 psWarning("psMetadataItem from list is of type %x instead of %x (PS_DATA_STRING) --- can't interpret.\n", cItem->type, PS_DATA_STRING); 66 65 psFree(cIter); 67 66 psFree(sIter); … … 183 182 } 184 183 default: 185 psWarning("Type of %s is not suitable for a FITS header --- not added.\n",184 psWarning("Type of %s is not suitable for a FITS header --- not added.\n", 186 185 item->name); 187 186 return false; … … 226 225 } 227 226 227 // Return the camera format appropriate for a focal plane hierarchy 228 static psMetadata *conceptsCameraFormat(const pmFPA *fpa, const pmChip *chip, const pmCell *cell) 229 { 230 pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level 231 if (!hdu) { 232 return NULL; 233 } 234 return hdu->format; 235 } 236 237 // Return the DATABASE metadata from the format 238 static psMetadata *conceptsDatabase(const psMetadata *format) 239 { 240 bool mdok; // Status of MD lookup 241 return psMetadataLookupMetadata(&mdok, format, "DEFAULTS"); 242 } 243 244 // Return the TRANSLATION metadata from the format 245 static psMetadata *conceptsTranslation(const psMetadata *format) 246 { 247 bool mdok; // Status of MD lookup 248 return psMetadataLookupMetadata(&mdok, format, "TRANSLATION"); 249 } 250 251 // Return the DEFAULTS metadata from the format 252 static psMetadata *conceptsDefaults(const psMetadata *format) 253 { 254 bool mdok; // Status of MD lookup 255 return psMetadataLookupMetadata(&mdok, format, "DEFAULTS"); 256 } 257 228 258 229 259 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// … … 231 261 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 232 262 233 bool p_pmConceptsWriteToCells(const psMetadata *specs, const pmCell *cell, const psMetadata *concepts) 234 { 235 PS_ASSERT_PTR_NON_NULL(specs, false); 236 PS_ASSERT_PTR_NON_NULL(concepts, false); 263 bool p_pmConceptWriteToCells(const pmCell *cell, const pmConceptSpec *spec, 264 const psMetadataItem *conceptItem, const psMetadata *format) 265 { 237 266 if (!cell) { 238 267 return false; … … 242 271 } 243 272 244 pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // The HDU at the lowest level 273 if (!format) { 274 format = conceptsCameraFormat(NULL, NULL, cell); 275 if (!format) { 276 return false; 277 } 278 } 279 280 psMetadataItem *cameraItem = psMetadataLookup(cell->config, conceptItem->name); // Version in the config 281 if (!cameraItem) { 282 return false; 283 } 284 285 psString nameSource = NULL; // String with the concept name and ".SOURCE" added 286 psStringAppend(&nameSource, "%s.SOURCE", conceptItem->name); 287 bool mdok = true; // Status of MD lookup 288 psString source = psMetadataLookupStr(&mdok, cell->config, nameSource); // The source 289 if (mdok && strlen(source) > 0) { 290 psTrace("psModules.concepts", 8, "%s is %s\n", nameSource, source); 291 if (strcasecmp(source, "HEADER") == 0) { 292 if (cameraItem->type != PS_DATA_STRING) { 293 psWarning("Concept %s is specified by header, but is not of type STR --- ignored.", 294 conceptItem->name); 295 psFree(nameSource); 296 return false; 297 } 298 299 // Formatted version 300 psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_HEADER, 301 format, NULL, NULL, cell); 302 if (!formatted) { 303 psFree(nameSource); 304 return true; 305 } 306 307 psTrace("psModules.concepts", 8, "Writing %s to header %s\n", 308 conceptItem->name, cameraItem->data.str); 309 pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // Header data unit 310 if (!hdu) { 311 psError(PS_ERR_UNEXPECTED_NULL, false, 312 "Unable to find HDU to write concept %s", conceptItem->name); 313 return false; 314 } 315 writeHeader(hdu, cameraItem->data.V, formatted); 316 psFree(formatted); 317 } else if (strcasecmp(source, "VALUE") == 0) { 318 // Formatted version 319 psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_CELLS, 320 format, NULL, NULL, cell); 321 if (!formatted) { 322 psFree(nameSource); 323 return true; 324 } 325 326 psTrace("psModules.concepts", 8, "Checking %s against camera format.\n", conceptItem->name); 327 if (!compareConcepts(formatted, cameraItem)) { 328 psWarning("Concept %s is specified by value in the camera format, but the values don't match", 329 conceptItem->name); 330 } 331 psFree(formatted); 332 } else { 333 psWarning("Concept source %s isn't HEADER or VALUE --- can't write", nameSource); 334 } 335 } else { 336 // Assume it's specified by value 337 psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_CELLS, 338 format, NULL, NULL, cell); 339 if (!formatted) { 340 psFree(nameSource); 341 return true; 342 } 343 344 if (!compareConcepts(formatted, cameraItem)) { 345 psWarning("Concept %s is specified by value in the camera format, but the values don't match.", 346 conceptItem->name); 347 } 348 psFree(formatted); 349 } 350 psFree(nameSource); 351 352 return true; 353 } 354 355 bool p_pmConceptWriteToDefaults(const pmFPA *fpa, const pmChip *chip, const pmCell *cell, 356 const pmConceptSpec *spec, const psMetadataItem *conceptItem, 357 const psMetadata *format, const psMetadata *defaults) 358 { 359 if (!format) { 360 format = conceptsCameraFormat(fpa, chip, cell); 361 if (!format) { 362 return false; 363 } 364 } 365 if (!defaults) { 366 defaults = conceptsDefaults(format); 367 if (!defaults) { 368 return false; 369 } 370 } 371 372 psMetadataItem *defaultItem = p_pmConceptsReadSingleFromDefaults(conceptItem->name, defaults, 373 fpa, chip, cell); 374 if (!defaultItem) { 375 return false; 376 } 377 psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_DEFAULTS, 378 format, fpa, chip, cell); 379 if (!formatted) { 380 return true; 381 } 382 383 if (strcmp(defaultItem->name, conceptItem->name) != 0) { 384 // Correct the name to match the concept name 385 defaultItem = psMetadataItemCopy(defaultItem); 386 psFree(defaultItem->name); 387 defaultItem->name = psStringCopy(conceptItem->name); 388 } else { 389 psMemIncrRefCounter(defaultItem); 390 } 391 392 if (!compareConcepts(formatted, defaultItem)) { 393 psWarning("Concept %s is specified by the DEFAULTS in the camera format, but the values don't match.", 394 conceptItem->name); 395 } 396 psFree(defaultItem); 397 psFree(formatted); 398 399 return true; 400 } 401 402 403 bool p_pmConceptWriteToHeader(const pmFPA *fpa, const pmChip *chip, const pmCell *cell, 404 const pmConceptSpec *spec, const psMetadataItem *conceptItem, 405 const psMetadata *format, const psMetadata *translation) 406 { 407 if (!format) { 408 format = conceptsCameraFormat(fpa, chip, cell); 409 if (!format) { 410 return false; 411 } 412 } 413 if (!translation) { 414 translation = conceptsTranslation(format); 415 if (!translation) { 416 return false; 417 } 418 } 419 420 psMetadataItem *headerItem = psMetadataLookup(translation, conceptItem->name); // How to format for header 421 if (!headerItem) { 422 return false; 423 } 424 if (headerItem->type == PS_DATA_METADATA) { 425 // This is a menu 426 psTrace("psModules.concepts", 5, "%s is of type METADATA.\n", conceptItem->name); 427 headerItem = p_pmConceptsDepend(conceptItem->name, headerItem->data.md, translation, fpa, chip, cell); 428 if (!headerItem) { 429 return false; 430 } 431 } 432 if (headerItem->type != PS_DATA_STRING) { 433 psWarning("TRANSLATION keyword for concept %s isn't of type STR --- ignored.", conceptItem->name); 434 return false; 435 } 436 psTrace("psModules.concepts", 3, "Writing %s to header %s\n", conceptItem->name, headerItem->data.str); 437 psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_HEADER, 438 format, fpa, chip, cell); 439 if (!formatted) { 440 // Found it, but it doesn't need to be written 441 return true; 442 } 443 444 pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // HDU to which to write 245 445 if (!hdu) { 246 return false; 247 } 248 psMetadata *cameraFormat = hdu->format; // The camera format 249 psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator 250 psMetadataItem *specItem = NULL; // Item from the specs metadata 251 while ((specItem = psMetadataGetAndIncrement(specsIter))) { 252 pmConceptSpec *spec = specItem->data.V; // The specification 253 psString name = specItem->name; // The concept name 254 psMetadataItem *cameraItem = psMetadataLookup(cell->config, name); // The concept from the camera, 255 // or NULL 256 if (cameraItem) { 257 // Grab the concept 258 psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The concept 259 260 psString nameSource = NULL; // String with the concept name and ".SOURCE" added 261 psStringAppend(&nameSource, "%s.SOURCE", name); 262 bool mdok = true; // Status of MD lookup 263 psString source = psMetadataLookupStr(&mdok, cell->config, nameSource); // The source 264 if (mdok && strlen(source) > 0) { 265 psTrace("psModules.concepts", 8, "%s is %s\n", nameSource, source); 266 if (strcasecmp(source, "HEADER") == 0) { 267 if (cameraItem->type != PS_DATA_STRING) { 268 psWarning("Concept %s is specified by header, but is not " 269 "of type STR --- ignored.\n", conceptItem->name); 270 continue; 271 } 272 273 // Formatted version 274 psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_HEADER, 275 cameraFormat, NULL, NULL, cell); 276 if (!formatted) { 277 continue; 278 } 279 280 psTrace("psModules.concepts", 8, "Writing %s to header %s\n", name, cameraItem->data.str); 281 writeHeader(hdu, cameraItem->data.V, formatted); 282 psFree(formatted); 283 } else if (strcasecmp(source, "VALUE") == 0) { 284 // Formatted version 285 psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_CELLS, 286 cameraFormat, NULL, NULL, cell); 287 if (!formatted) { 288 continue; 289 } 290 291 psTrace("psModules.concepts", 8, "Checking %s against camera format.\n", name); 292 if (! compareConcepts(formatted, cameraItem)) { 293 psWarning("Concept %s is specified by value in the camera " 294 "format, but the values don't match.\n", name); 295 } 296 psFree(formatted); 297 } else { 298 psWarning("Concept source %s isn't HEADER or VALUE --- can't " 299 "write\n", nameSource); 300 } 301 } else { 302 // Assume it's specified by value 303 psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_CELLS, 304 cameraFormat, NULL, NULL, cell); 305 if (!formatted) { 306 continue; 307 } 308 309 if (! compareConcepts(formatted, cameraItem)) { 310 psWarning("Concept %s is specified by value in the camera " 311 "format, but the values don't match.\n", name); 312 } 313 psFree(formatted); 314 } 315 psFree(nameSource); 316 } 317 318 } 319 psFree(specsIter); 446 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find HDU to write concept %s", conceptItem->name); 447 return false; 448 } 449 writeHeader(hdu, headerItem->data.V, formatted); 450 psFree(formatted); 451 320 452 return true; 321 453 } 322 454 323 bool p_pmConceptsWriteToDefaults(const psMetadata *specs, const pmFPA *fpa, const pmChip *chip, 324 const pmCell *cell, const psMetadata *concepts) 325 { 326 PS_ASSERT_PTR_NON_NULL(specs, false); 327 PS_ASSERT_PTR_NON_NULL(concepts, false); 328 329 pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level 330 if (!hdu) { 331 return false; 332 } 333 psMetadata *cameraFormat = hdu->format; // The camera format 334 bool mdok = true; // Status of MD lookup 335 psMetadata *defaults = psMetadataLookupMetadata(&mdok, cameraFormat, "DEFAULTS"); // The DEFAULTS spec 336 if (!mdok || !defaults) { 337 return false; 338 } 339 340 psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator 341 psMetadataItem *specItem = NULL; // Item from the specs metadata 342 while ((specItem = psMetadataGetAndIncrement(specsIter))) { 343 pmConceptSpec *spec = specItem->data.V; // The specification 344 psString name = specItem->name; // The concept name 345 346 psMetadataItem *defaultItem = p_pmConceptsReadSingleFromDefaults(name, defaults, fpa, chip, cell); 347 if (!defaultItem) { 348 continue; 349 } 350 psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The item from the concepts 351 psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_DEFAULTS, 352 cameraFormat, fpa, chip, cell); 353 if (!formatted) { 354 continue; 355 } 356 357 if (strcmp(defaultItem->name, name) != 0) { 358 // Correct the name to match the concept name 359 defaultItem = psMetadataItemCopy(defaultItem); 360 psFree(defaultItem->name); 361 defaultItem->name = psStringCopy(name); 362 } else { 363 psMemIncrRefCounter(defaultItem); 364 } 365 366 if (!compareConcepts(formatted, defaultItem)) { 367 psWarning("Concept %s is specified by the DEFAULTS in the camera " 368 "format, but the values don't match.\n", name); 369 } 370 psFree(defaultItem); 371 psFree(formatted); 372 } 373 psFree(specsIter); 455 bool p_pmConceptWriteToDatabase(const pmFPA *fpa, const pmChip *chip, const pmCell *cell, 456 pmConfig *config, const pmConceptSpec *spec, 457 const psMetadataItem *conceptItem, const psMetadata *format, 458 const psMetadata *database) 459 { 460 PS_ASSERT_PTR_NON_NULL(config, false); 461 462 #ifndef HAVE_PSDB 463 return false; 464 #else 465 466 if (!format) { 467 format = conceptsCameraFormat(fpa, chip, cell); 468 if (!format) { 469 return false; 470 } 471 } 472 if (!database) { 473 database = conceptsDatabase(format); 474 if (!database) { 475 return false; 476 } 477 } 478 479 psMetadataItem *dbItem = p_pmConceptsReadSingleFromDatabase(conceptItem->name, database, config, 480 fpa, chip, cell); // Database version 481 if (!dbItem) { 482 return false; 483 } 484 485 psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_DATABASE, 486 format, fpa, chip, cell); 487 if (!formatted) { 488 return false; 489 } 490 491 if (strcmp(dbItem->name, conceptItem->name) != 0) { 492 // Correct the name to match the concept name 493 dbItem = psMetadataItemCopy(dbItem); 494 psFree(dbItem->name); 495 dbItem->name = psStringCopy(conceptItem->name); 496 } else { 497 psMemIncrRefCounter(dbItem); 498 } 499 500 if (!compareConcepts(formatted, dbItem)) { 501 psWarning("Concept %s is specified by the DATABASE in the camera " 502 "format, but the values don't match.\n", conceptItem->name); 503 } 504 psFree(dbItem); 505 psFree(formatted); 506 374 507 return true; 375 } 376 377 378 bool p_pmConceptsWriteToHeader(const psMetadata *specs, const pmFPA *fpa, const pmChip *chip, 379 const pmCell *cell, const psMetadata *concepts) 380 { 381 PS_ASSERT_PTR_NON_NULL(specs, false); 382 PS_ASSERT_PTR_NON_NULL(concepts, false); 383 384 pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level 385 if (!hdu) { 386 return false; 387 } 388 psMetadata *cameraFormat = hdu->format; // The camera format 389 bool mdok = true; // Status of MD lookup 390 psMetadata *translation = psMetadataLookupMetadata(&mdok, cameraFormat, "TRANSLATION"); // The TRANSLATION spec 391 if (!mdok || !translation) { 392 return false; 393 } 394 395 psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator 396 psMetadataItem *specItem = NULL; // Item from the specs metadata 397 while ((specItem = psMetadataGetAndIncrement(specsIter))) { 398 pmConceptSpec *spec = specItem->data.V; // The specification 399 psString name = specItem->name; // The concept name 400 psMetadataItem *headerItem = psMetadataLookup(translation, name); // The item from the TRANSLATION 401 if (!headerItem) { 402 continue; 403 } 404 if (headerItem->type == PS_DATA_METADATA) { 405 // This is a menu 406 psTrace("psModules.concepts", 5, "%s is of type METADATA.\n", name); 407 headerItem = p_pmConceptsDepend(name, headerItem->data.md, translation, fpa, chip, cell); 408 if (!headerItem) { 409 continue; 410 } 411 } 412 if (headerItem->type != PS_DATA_STRING) { 413 psWarning("TRANSLATION keyword for concept %s isn't of type STR --- ignored.", name); 414 continue; 415 } 416 psTrace("psModules.concepts", 3, "Writing %s to header %s\n", name, headerItem->data.str); 417 psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The item from the concepts 418 psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_HEADER, 419 cameraFormat, fpa, chip, cell); 420 if (!formatted) { 421 continue; 422 } 423 writeHeader(hdu, headerItem->data.V, formatted); 424 psFree(formatted); 425 } 426 psFree(specsIter); 508 #endif 509 } 510 511 512 bool pmConceptWriteSingle(const pmFPA *fpa, const pmChip *chip, const pmCell *cell, 513 pmConfig *config, const psMetadataItem *conceptItem) 514 { 515 pmConceptsInit(); 516 517 psMetadata *format = conceptsCameraFormat(fpa, chip, cell); // Camera format 518 if (!format) { 519 psError(PS_ERR_UNKNOWN, false, "Unable to retrieve camera format."); 520 return false; 521 } 522 523 const char *name = conceptItem->name; // Name of concept 524 525 psMetadata *conceptsFPA = pmConceptsSpecs(PM_FPA_LEVEL_FPA); // Concept specifications for FPA 526 bool mdok; // Status of MD lookup 527 pmConceptSpec *spec = psMetadataLookupPtr(&mdok, conceptsFPA, name); // Concept specification of interest 528 if (!spec) { 529 psMetadata *conceptsChip = pmConceptsSpecs(PM_FPA_LEVEL_CHIP); // Concept specifications for Chip 530 spec = psMetadataLookupPtr(&mdok, conceptsChip, name); 531 if (!spec) { 532 psMetadata *conceptsCell = pmConceptsSpecs(PM_FPA_LEVEL_CELL); // Concept specifications for Cell 533 spec = psMetadataLookupPtr(&mdok, conceptsCell, name); 534 if (!spec) { 535 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find specification for concept %s", name); 536 return false; 537 } 538 } 539 } 540 541 if (!p_pmConceptWriteToCells(cell, spec, conceptItem, format) && 542 !p_pmConceptWriteToDefaults(fpa, chip, cell, spec, conceptItem, format, NULL) && 543 !p_pmConceptWriteToHeader(fpa, chip, cell, spec, conceptItem, format, NULL) && 544 !p_pmConceptWriteToDatabase(fpa, chip, cell, config, spec, conceptItem, format, NULL)) { 545 return false; 546 } 427 547 return true; 428 548 } 429 430 // XXX Warning: This code has not been tested at all431 bool p_pmConceptsWriteToDatabase(const psMetadata *specs, const pmFPA *fpa, const pmChip *chip,432 const pmCell *cell, pmConfig *config, const psMetadata *concepts)433 {434 PS_ASSERT_PTR_NON_NULL(specs, false);435 PS_ASSERT_PTR_NON_NULL(concepts, false);436 PS_ASSERT_PTR_NON_NULL(config, false);437 438 #ifndef HAVE_PSDB439 return false;440 #else441 442 pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level443 if (!hdu) {444 return false;445 }446 psMetadata *cameraFormat = hdu->format; // The camera format447 bool mdok = true; // Status of MD lookup448 psMetadata *database = psMetadataLookupMetadata(&mdok, cameraFormat, "DATABASE"); // The DATABASE spec449 if (!mdok || !database) {450 return false;451 }452 psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator453 psMetadataItem *specItem = NULL; // Item from the specs metadata454 while ((specItem = psMetadataGetAndIncrement(specsIter))) {455 pmConceptSpec *spec = specItem->data.V; // The specification456 psString name = specItem->name; // The concept name457 458 psMetadataItem *dbItem = p_pmConceptsReadSingleFromDatabase(name, database, config, fpa, chip, cell);459 if (!dbItem) {460 continue;461 }462 463 psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The item from the concepts464 psMetadataItem *formatted = conceptFormat(spec, conceptItem, PM_CONCEPT_SOURCE_DATABASE,465 cameraFormat, fpa, chip, cell);466 if (!formatted) {467 continue;468 }469 470 if (strcmp(dbItem->name, name) != 0) {471 // Correct the name to match the concept name472 dbItem = psMetadataItemCopy(dbItem);473 psFree(dbItem->name);474 dbItem->name = psStringCopy(name);475 } else {476 psMemIncrRefCounter(dbItem);477 }478 479 if (!compareConcepts(formatted, dbItem)) {480 psWarning("Concept %s is specified by the DATABASE in the camera "481 "format, but the values don't match.\n", name);482 }483 psFree(dbItem);484 psFree(formatted);485 }486 psFree(specsIter);487 return true;488 #endif489 }490 491 492 493 549 494 550 … … 498 554 const pmChip *chip, // The chip 499 555 const pmCell *cell, // The cell 500 pmConceptSource source, // The source of the concepts to write501 556 pmConfig *config, // Configuration 502 557 psMetadata *concepts // The concepts to write out … … 508 563 pmConceptsInit(); 509 564 510 psTrace("psModules.concepts", 3, "Writing concepts (%p %p %p): %d\n", fpa, chip, cell, source); 511 512 if (source & PM_CONCEPT_SOURCE_CELLS) { 513 p_pmConceptsWriteToCells(*specs, cell, concepts); 514 } 515 if (source & PM_CONCEPT_SOURCE_DEFAULTS) { 516 p_pmConceptsWriteToDefaults(*specs, fpa, chip, cell, concepts); 517 } 518 if (source & (PM_CONCEPT_SOURCE_PHU | PM_CONCEPT_SOURCE_HEADER)) { 519 p_pmConceptsWriteToHeader(*specs, fpa, chip, cell, concepts); 520 } 521 if (source & PM_CONCEPT_SOURCE_DATABASE) { 522 p_pmConceptsWriteToDatabase(*specs, fpa, chip, cell, config, concepts); 523 } 565 psTrace("psModules.concepts", 3, "Writing concepts (%p %p %p)\n", fpa, chip, cell); 566 567 psMetadata *format = conceptsCameraFormat(fpa, chip, cell); // Camera format 568 if (!format) { 569 psError(PS_ERR_UNKNOWN, false, "Unable to retrieve camera format."); 570 return false; 571 } 572 573 psMetadata *defaults = conceptsDefaults(format); // DEFAULTS configuration 574 psMetadata *translation = conceptsTranslation(format); // TRANSLATION configuration 575 psMetadata *database = conceptsDatabase(format); // DATABASE configuration 576 577 psMetadataIterator *iter = psMetadataIteratorAlloc(*specs, PS_LIST_HEAD, NULL); // Iterator 578 psMetadataItem *item = NULL; // Item from the specs metadata 579 while ((item = psMetadataGetAndIncrement(iter))) { 580 pmConceptSpec *spec = item->data.V; // The specification 581 psString name = item->name; // The concept name 582 583 psMetadataItem *concept = psMetadataLookup(concepts, name); // Concept to write 584 585 if (!p_pmConceptWriteToCells(cell, spec, concept, format) && 586 !p_pmConceptWriteToDefaults(fpa, chip, cell, spec, concept, format, defaults) && 587 !p_pmConceptWriteToHeader(fpa, chip, cell, spec, concept, format, translation) && 588 !p_pmConceptWriteToDatabase(fpa, chip, cell, config, spec, concept, format, database)) { 589 psTrace("psModules.concepts", 1, "Unable to write concept %s to any output", name); 590 } 591 } 592 psFree(iter); 524 593 525 594 return true; … … 527 596 528 597 529 bool pmConceptsWriteFPA(const pmFPA *fpa, pmConceptSource source,bool propagateDown, pmConfig *config)598 bool pmConceptsWriteFPA(const pmFPA *fpa, bool propagateDown, pmConfig *config) 530 599 { 531 600 PS_ASSERT_PTR_NON_NULL(fpa, false); 532 601 psMetadata *conceptsFPA = pmConceptsSpecs(PM_FPA_LEVEL_FPA); // Concept specifications 533 602 psTrace("psModules.concepts", 5, "Writing FPA concepts: %p %p\n", conceptsFPA, fpa->concepts); 534 bool success = conceptsWrite(&conceptsFPA, fpa, NULL, NULL, source,config, fpa->concepts);603 bool success = conceptsWrite(&conceptsFPA, fpa, NULL, NULL, config, fpa->concepts); 535 604 if (propagateDown) { 536 605 psArray *chips = fpa->chips; // Array of chips … … 538 607 pmChip *chip = chips->data[i]; // Chip of interest 539 608 if (chip && !chip->hdu) { 540 success &= pmConceptsWriteChip(chip, source,false, true, config);609 success &= pmConceptsWriteChip(chip, false, true, config); 541 610 } 542 611 } … … 546 615 547 616 548 bool pmConceptsWriteChip(const pmChip *chip, pmConceptSource source, bool propagateUp, 549 bool propagateDown, pmConfig *config) 617 bool pmConceptsWriteChip(const pmChip *chip, bool propagateUp, bool propagateDown, pmConfig *config) 550 618 { 551 619 PS_ASSERT_PTR_NON_NULL(chip, false); … … 553 621 psTrace("psModules.concepts", 5, "Writing chip concepts: %p %p\n", conceptsChip, chip->concepts); 554 622 pmFPA *fpa = chip->parent; // FPA to which the chip belongs 555 bool success = conceptsWrite(&conceptsChip, fpa, chip, NULL, source,config, chip->concepts);623 bool success = conceptsWrite(&conceptsChip, fpa, chip, NULL, config, chip->concepts); 556 624 if (propagateUp && !fpa->hdu) { 557 625 psMetadata *conceptsFPA = pmConceptsSpecs(PM_FPA_LEVEL_FPA); // Concept specifications 558 success &= conceptsWrite(&conceptsFPA, fpa, chip, NULL, source,config, fpa->concepts);626 success &= conceptsWrite(&conceptsFPA, fpa, chip, NULL, config, fpa->concepts); 559 627 } 560 628 if (propagateDown) { … … 563 631 pmCell *cell = cells->data[i]; // Cell of interest 564 632 if (cell && !cell->hdu) { 565 success &= pmConceptsWriteCell(cell, source,false, config);633 success &= pmConceptsWriteCell(cell, false, config); 566 634 } 567 635 } … … 571 639 572 640 573 bool pmConceptsWriteCell(const pmCell *cell, pmConceptSource source,bool propagateUp, pmConfig *config)641 bool pmConceptsWriteCell(const pmCell *cell, bool propagateUp, pmConfig *config) 574 642 { 575 643 PS_ASSERT_PTR_NON_NULL(cell, false); … … 579 647 pmFPA *fpa = chip->parent; // FPA to which the chip belongs 580 648 581 bool success = conceptsWrite(&conceptsCell, fpa, chip, cell, source,config, cell->concepts);649 bool success = conceptsWrite(&conceptsCell, fpa, chip, cell, config, cell->concepts); 582 650 if (propagateUp) { 583 651 if (!chip->hdu) { 584 652 psMetadata *conceptsChip = pmConceptsSpecs(PM_FPA_LEVEL_CHIP); // Concept specifications 585 success &= conceptsWrite(&conceptsChip, fpa, chip, cell, source,config, chip->concepts);653 success &= conceptsWrite(&conceptsChip, fpa, chip, cell, config, chip->concepts); 586 654 if (!fpa->hdu) { 587 655 psMetadata *conceptsFPA = pmConceptsSpecs(PM_FPA_LEVEL_FPA); // Concept specifications 588 success &= conceptsWrite(&conceptsFPA, fpa, chip, cell, source,config, fpa->concepts);656 success &= conceptsWrite(&conceptsFPA, fpa, chip, cell, config, fpa->concepts); 589 657 } 590 658 }
Note:
See TracChangeset
for help on using the changeset viewer.
