Changeset 10965 for trunk/psModules/src/config/pmConfig.c
- Timestamp:
- Jan 8, 2007, 12:26:06 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/config/pmConfig.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/config/pmConfig.c
r10882 r10965 4 4 * @author EAM (IfA) 5 5 * 6 * @version $Revision: 1. 69$ $Name: not supported by cvs2svn $7 * @date $Date: 2007-01-0 3 02:58:38$6 * @version $Revision: 1.70 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2007-01-08 22:26:06 $ 8 8 * 9 9 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 26 26 #include "pmConfig.h" 27 27 #include "pmConfigRecipes.h" 28 #include "pmConfigCamera.h" 28 29 29 30 #define PS_SITE "PS_SITE" // Name of the environment variable containing the site config file 30 31 #define PS_DEFAULT_SITE ".ipprc" // Default site config file 31 32 33 static bool readCameraConfig = true; // Read the camera config on startup (with pmConfigRead)? 32 34 static psArray *configPath = NULL; // Search path for configuration files 35 36 bool pmConfigReadParamsSet(bool newReadCameraConfig) 37 { 38 bool oldReadCameraConfig = readCameraConfig; 39 readCameraConfig = newReadCameraConfig; 40 return oldReadCameraConfig; 41 } 33 42 34 43 static void configFree(pmConfig *config) … … 38 47 psFree(config->camera); 39 48 psFree(config->cameraName); 49 psFree(config->format); 50 psFree(config->formatName); 40 51 psFree(config->recipes); 41 52 psFree(config->recipeSymbols); … … 53 64 config->camera = NULL; 54 65 config->cameraName = NULL; 66 config->format = NULL; 67 config->formatName = NULL; 55 68 config->recipes = psMetadataAlloc(); 56 69 config->recipesRead = PM_RECIPE_SOURCE_NONE; … … 207 220 208 221 psFree (realName); 222 return true; 223 } 224 225 // Read metadata config files in a metadata 226 // The metadata contains file names, which will be replaced with the metadata that are in the files. 227 static bool metadataReadFiles(psMetadata *source, // Source metadata 228 const char *description // Description, for error messages 229 ) 230 { 231 assert(source); 232 psMetadataIterator *iter = psMetadataIteratorAlloc(source, PS_LIST_HEAD, NULL); // Iterator 233 psMetadataItem *item; // Item from iteration 234 while ((item = psMetadataGetAndIncrement(iter))) { 235 if (item->type == PS_DATA_METADATA) { 236 continue; // We've already read it 237 } 238 if (item->type != PS_DATA_STRING) { 239 psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Element %s in %s metadata is not of type STR.\n", 240 item->name, description); 241 continue; 242 } 243 244 psTrace("config", 2, "Reading %s %s: %s\n", description, item->name, item->data.str); 245 psMetadata *new = NULL; // New metadata 246 if (!pmConfigFileRead(&new, item->data.str, item->name)) { 247 psLogMsg("psModules.config", PS_LOG_WARN, "Trouble reading reading %s %s --- " 248 "ignored.\n", description, item->name); 249 psFree(new); 250 psMetadataRemoveKey(source, item->name); // Take it out, so it will not trouble us again 251 continue; 252 } 253 254 // Muck around under the hood to replace the filename with the metadata; don't try this at home, kids 255 item->type = PS_DATA_METADATA; 256 psFree(item->data.str); 257 item->data.md = new; 258 } 259 psFree(iter); 260 261 return true; 262 } 263 264 // Read the formats for a camera 265 static bool cameraReadFormats(psMetadata *camera, // Camera for which to read the formats 266 const char *name // Name of the camera, for error messages 267 ) 268 { 269 assert(camera); 270 assert(name); 271 272 bool mdok; // Status of MD lookup 273 psMetadata *formats = psMetadataLookupMetadata(&mdok, camera, "FORMATS"); // Formats 274 if (!mdok || !formats) { 275 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find FORMATS in camera configuration %s.\n", name); 276 return false; 277 } 278 if (!metadataReadFiles(formats, "camera format")) { 279 psError(PS_ERR_UNKNOWN, false, "Unable to read formats within camera configuration %s.\n", name); 280 return false; 281 } 282 209 283 return true; 210 284 } … … 274 348 } 275 349 276 277 278 350 // Set options based on the site configuration. 279 351 { … … 437 509 pmConfigFileRead(&config->camera, cameraFile, "camera"); 438 510 psArgumentRemove(argNum, config->argc, config->argv); 511 512 // Read in the formats 513 if (!cameraReadFormats(config->camera, cameraFile)) { 514 psError(PS_ERR_UNKNOWN, false, "Unable to read formats within camera configuration %s.\n", 515 cameraFile); 516 psFree(config); 517 return NULL; 518 } 519 520 psMetadataAddMetadata(cameras, PS_LIST_HEAD, cameraFile, PS_META_REPLACE, 521 "Camera specified on command line", config->camera); 522 523 if (!pmConfigCameraMosaickedVersions(config->site, cameraFile)) { 524 psError(PS_ERR_UNKNOWN, false, 525 "Unable to generate mosaicked versions of specified camera %s.\n", 526 cameraFile); 527 psFree(config); 528 return NULL; 529 } 530 } 531 } 532 533 // Read the camera configurations, if not already defined, and not turned off 534 if (!config->camera && readCameraConfig) { 535 bool mdok; // Status of MD lookup 536 psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->site, "CAMERAS"); // List of cameras 537 if (!mdok || !cameras) { 538 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the site configuration.\n"); 539 return false; 540 } 541 542 if (!metadataReadFiles(cameras, "camera configuration")) { 543 psError(PS_ERR_UNKNOWN, false, "Unable to read cameras within site configuration.\n"); 544 psFree(config); 545 return NULL; 546 } 547 548 // Now fill in the formats 549 psMetadataIterator *iter = psMetadataIteratorAlloc(cameras, PS_LIST_HEAD, NULL); // Iterator 550 psMetadataItem *item; // Item from iteration 551 while ((item = psMetadataGetAndIncrement(iter))) { 552 assert(item->type == PS_DATA_METADATA); 553 if (!cameraReadFormats(item->data.md, item->name)) { 554 psWarning("Unable to read formats for camera %s: removed.\n", item->name); 555 psMetadataRemoveKey(cameras, item->name); 556 } 557 } 558 psFree(iter); 559 560 if (!pmConfigCameraMosaickedVersionsAll(config->site)) { 561 psError(PS_ERR_UNKNOWN, false, "Unable to generate mosaicked versions of cameras.\n"); 562 psFree(config); 563 return NULL; 439 564 } 440 565 } … … 448 573 449 574 // load command-line options of the form -recipe NAME RECIPE 450 pmConfigLoadRecipeArguments (config);575 pmConfigLoadRecipeArguments(config); 451 576 452 577 // read in command-line options to specific recipe values 453 pmConfigLoadRecipeOptions (config, "-D");454 pmConfigLoadRecipeOptions (config, "-Di");455 pmConfigLoadRecipeOptions (config, "-Df");456 pmConfigLoadRecipeOptions (config, "-Db");578 pmConfigLoadRecipeOptions(config, "-D"); 579 pmConfigLoadRecipeOptions(config, "-Di"); 580 pmConfigLoadRecipeOptions(config, "-Df"); 581 pmConfigLoadRecipeOptions(config, "-Db"); 457 582 458 583 … … 589 714 } 590 715 716 591 717 // Given a camera and a header, see if any of the camera formats match the header 592 718 static bool formatFromHeader(psMetadata **format, // Format to return 719 psString *name, // Name to return 593 720 psMetadata *camera, // Camera configuration 594 721 const psMetadata *header, // FITS header … … 610 737 return false; 611 738 } 739 740 if (!metadataReadFiles(formats, "camera format")) { 741 psError(PS_ERR_UNKNOWN, false, "Unable to read cameras formats within camera configuration.\n"); 742 return false; 743 } 744 612 745 // Iterate over the formats 613 746 psMetadataIterator *formatsIter = psMetadataIteratorAlloc(formats, PS_LIST_HEAD, NULL); 614 747 psMetadataItem *formatsItem = NULL; // Item from formats 615 748 while ((formatsItem = psMetadataGetAndIncrement(formatsIter))) { 616 if (formatsItem->type != PS_DATA_STRING) { 617 psError(PS_ERR_UNKNOWN, false, "In camera %s, camera format %s is not of type STR", cameraName, formatsItem->name); 618 return false; 619 } 620 psTrace("psModules.config", 5, "Reading camera format for %s...\n", formatsItem->name); 621 psMetadata *testFormat = NULL; // Format to test against what we've got 622 if (!pmConfigFileRead(&testFormat, formatsItem->data.V, formatsItem->name)) { 623 psError(PS_ERR_UNKNOWN, false, "Trouble reading reading camera format %s", formatsItem->name); 624 psFree(testFormat); 625 return false; 626 } 749 assert(formatsItem->type == PS_DATA_METADATA); // Since we have just read it in or deleted it 750 psMetadata *testFormat = formatsItem->data.md; // Format to test against 627 751 628 752 if (pmConfigValidateCameraFormat(testFormat, header)) { 629 753 if (!*format) { 630 psLogMsg("psModules.config", PS_LOG_INFO, "Camera %s, format %s matches header.\n", cameraName,631 formatsItem->name);754 psLogMsg("psModules.config", PS_LOG_INFO, "Camera %s, format %s matches header.\n", 755 cameraName, formatsItem->name); 632 756 *format = psMemIncrRefCounter(testFormat); 757 *name = psStringCopy(formatsItem->name); 633 758 result = true; 634 759 } else { 635 psLogMsg("psModules.config", PS_LOG_WARN, "Camera %s, format %s also matches header --- ignored.\n", 760 psLogMsg("psModules.config", PS_LOG_WARN, 761 "Camera %s, format %s also matches header --- ignored.\n", 636 762 cameraName, formatsItem->name); 637 763 } … … 639 765 psErr *error = psErrorLast(); 640 766 if (error->code != PS_ERR_NONE) { 641 psError (PS_ERR_UNKNOWN, false, "Error in config scripts for camera %s, format %s\n", cameraName, formatsItem->name); 767 psError (PS_ERR_UNKNOWN, false, "Error in config scripts for camera %s, format %s\n",\ 768 cameraName, formatsItem->name); 642 769 return false; 643 770 } 644 771 psFree(error); 645 772 } 646 psFree(testFormat);647 773 } 648 774 psFree(formatsIter); … … 657 783 PS_ASSERT_PTR_NON_NULL(header, NULL); 658 784 785 659 786 psMetadata *format = NULL; // The winning format 660 bool mdok = false; // Metadata lookup status787 psString name = NULL; // Name of the winning format 661 788 662 789 // If we don't know what sort of camera we have, we try all that we know 663 790 if (! config->camera) { 791 bool mdok; // Metadata lookup status 664 792 psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->site, "CAMERAS"); 665 if (! mdok ) {793 if (! mdok || !cameras) { 666 794 psError(PS_ERR_IO, true, "Unable to find CAMERAS in the configuration."); 667 return false; 795 return NULL; 796 } 797 798 if (!metadataReadFiles(cameras, "camera configuration")) { 799 psError(PS_ERR_UNKNOWN, false, "Unable to read cameras within site configuration.\n"); 800 return NULL; 668 801 } 669 802 … … 675 808 psTrace("psModules.config", 3, "Inspecting camera %s (%s)\n", camerasItem->name, 676 809 camerasItem->comment); 677 if (camerasItem->type != PS_DATA_STRING) { 678 psLogMsg("psModules.config", PS_LOG_WARN, "Camera configuration for %s in CAMERAS is not of type STR " 679 "--- ignored.\n", camerasItem->name); 680 continue; 681 } 682 683 psTrace("psModules.config", 5, "Reading camera configuration for %s...\n", camerasItem->name); 684 psMetadata *testCamera = NULL; // Camera to test against what we've got: 685 686 if (!pmConfigFileRead(&testCamera, camerasItem->data.V, camerasItem->name)) { 687 psLogMsg("psModules.config", PS_LOG_WARN, "Trouble reading reading camera configuration %s --- " 688 "ignored.\n", camerasItem->name); 689 psFree(testCamera); 690 continue; 691 } 692 693 if (formatFromHeader(&format, testCamera, header, camerasItem->name)) { 810 assert(camerasItem->type == PS_DATA_METADATA); // It should be because we've read it in or deleted 811 psMetadata *testCamera = camerasItem->data.md; // Camera to test against what we've got: 812 if (formatFromHeader(&format, &name, testCamera, header, camerasItem->name)) { 694 813 config->camera = psMemIncrRefCounter(testCamera); 695 814 config->cameraName = psStringCopy(camerasItem->name); 815 config->formatName = name; 816 config->format = psMemIncrRefCounter(format); 696 817 } else { 697 818 psErr *error = psErrorLast(); … … 702 823 psFree(error); 703 824 } 704 psFree(testCamera);705 825 } // Done looking at all cameras 706 826 psFree(camerasIter); … … 717 837 718 838 // Otherwise, try the specific camera 719 if (!formatFromHeader(&format, config->camera, header, config->cameraName)) {839 if (!formatFromHeader(&format, &name, config->camera, header, config->cameraName)) { 720 840 psError(PS_ERR_IO, true, "Unable to find a format with the specified camera (%s) that matches the " 721 841 "given header.\n", config->cameraName); 722 842 return NULL; 723 843 } 844 config->formatName = name; 845 config->format = psMemIncrRefCounter(format); 724 846 return format; 725 847 }
Note:
See TracChangeset
for help on using the changeset viewer.
