Changeset 9579
- Timestamp:
- Oct 13, 2006, 5:54:51 PM (20 years ago)
- Location:
- trunk/psModules/src
- Files:
-
- 3 edited
-
camera/pmFPAfileDefine.c (modified) (1 diff)
-
config/pmConfig.c (modified) (24 diffs)
-
config/pmConfig.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/camera/pmFPAfileDefine.c
r9539 r9579 266 266 return NULL; 267 267 } 268 readConfig(&file->format, formatFile, formatName);268 pmConfigFileRead(&file->format, formatFile, formatName); 269 269 psFree (words); 270 270 } -
trunk/psModules/src/config/pmConfig.c
r9539 r9579 1 1 /** @file pmConfig.h 2 2 * 3 * @author PAP, IfA 3 * @author PAP (IfA) 4 * @author EAM (IfA) 4 5 * 5 * @version $Revision: 1.4 7$ $Name: not supported by cvs2svn $6 * @date $Date: 2006-10-1 3 21:15:45$6 * @version $Revision: 1.48 $ $Name: not supported by cvs2svn $ 7 * @date $Date: 2006-10-14 03:54:51 $ 7 8 * 8 9 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 28 29 #define PS_DEFAULT_SITE ".ipprc" // Default site config file 29 30 30 static psArray *configPath = NULL; 31 static psArray *configPath = NULL; // Search path for configuration files 31 32 32 33 static void configFree(pmConfig *config) … … 79 80 } 80 81 81 82 /** readConfig 83 * 84 * This function attempts to open the file specified in the parameter list 85 * parse it into metadata, then return it as a psMetaData table. 86 * 87 */ 88 bool readConfig( 89 psMetadata **config, // Config to output 90 const char *name, // Name of file 91 const char *description) // Description of file 92 { 93 assert(config); 94 assert(name && strlen(name) > 0); 95 assert(description && strlen(description) > 0); 82 bool pmConfigFileRead(psMetadata **config, const char *name, const char *description) 83 { 84 PS_ASSERT_METADATA_NON_NULL(*config, false); 85 PS_ASSERT_STRING_NON_EMPTY(name, false); 86 PS_ASSERT_STRING_NON_EMPTY(description, false); 96 87 97 88 char *realName = NULL; … … 167 158 168 159 169 /****************************************************************************** 170 pmConfigRead(**site, **camera, **recipe, *argc, **argv, char *recipeName) 171 172 XXX: The log/trace command line options (as processed by psArgumentVerbosity) 173 must take precedence override the values set here. This must be, somehow, 174 coded. 175 176 XXX: Must load camera and recipe configuration if specified in the command 177 line. 178 *****************************************************************************/ 179 pmConfig *pmConfigRead( 180 int *argc, 181 char **argv) 160 pmConfig *pmConfigRead(int *argc, char **argv) 182 161 { 183 162 PS_ASSERT_PTR_NON_NULL(argc, NULL); … … 236 215 // 237 216 238 if (! readConfig(&config->site, siteName, "site")) {217 if (!pmConfigFileRead(&config->site, siteName, "site")) { 239 218 psFree(config); 240 219 return NULL; … … 289 268 } 290 269 291 readConfig(&config->camera, cameraFile, "camera");270 pmConfigFileRead(&config->camera, cameraFile, "camera"); 292 271 psArgumentRemove(argNum, config->argc, config->argv); 293 272 } … … 387 366 continue; 388 367 } 389 psTrace("psModules.config", 7, "Setting trace level for %s to %d\n", traceItem->name, traceItem->data.S32); 368 psTrace("psModules.config", 7, "Setting trace level for %s to %d\n", traceItem->name, 369 traceItem->data.S32); 390 370 psTraceSetLevel(traceItem->name, traceItem->data.S32); 391 371 } … … 437 417 438 418 439 bool pmConfigValidateCameraFormat( 440 const psMetadata *cameraFormat, 441 const psMetadata *header) 419 bool pmConfigValidateCameraFormat(const psMetadata *cameraFormat, const psMetadata *header) 442 420 { 443 421 PS_ASSERT_PTR_NON_NULL(cameraFormat, false); … … 478 456 479 457 458 // Given a camera and a header, see if any of the camera formats match the header 480 459 static bool formatFromHeader(psMetadata **format, // Format to return 481 460 psMetadata *camera, // Camera configuration … … 510 489 psTrace("psModules.config", 5, "Reading camera format for %s...\n", formatsItem->name); 511 490 psMetadata *testFormat = NULL; // Format to test against what we've got 512 if (! readConfig(&testFormat, formatsItem->data.V, formatsItem->name)) {491 if (!pmConfigFileRead(&testFormat, formatsItem->data.V, formatsItem->name)) { 513 492 psLogMsg(__func__, PS_LOG_WARN, "Trouble reading reading camera format %s --- ignored.\n", 514 493 formatsItem->name); … … 535 514 } 536 515 537 // Work out what camera we have, based on the FITS header and a set of rules specified in the IPP 538 // configuration; return the camera configuration and format 539 psMetadata *pmConfigCameraFormatFromHeader( 540 pmConfig *config, // The configuration 541 const psMetadata *header // The FITS header 542 ) 516 517 psMetadata *pmConfigCameraFormatFromHeader(pmConfig *config, const psMetadata *header) 543 518 { 544 519 PS_ASSERT_PTR_NON_NULL(config, NULL); … … 561 536 while ((camerasItem = psMetadataGetAndIncrement(camerasIter))) { 562 537 // Open the camera information 563 psTrace("psModules.config", 3, "Inspecting camera %s (%s)\n", camerasItem->name, camerasItem->comment); 538 psTrace("psModules.config", 3, "Inspecting camera %s (%s)\n", camerasItem->name, 539 camerasItem->comment); 564 540 if (camerasItem->type != PS_DATA_STRING) { 565 541 psLogMsg(__func__, PS_LOG_WARN, "Camera configuration for %s in CAMERAS is not of type STR " … … 571 547 psMetadata *testCamera = NULL; // Camera to test against what we've got: 572 548 573 if (! readConfig(&testCamera, camerasItem->data.V, camerasItem->name)) {549 if (!pmConfigFileRead(&testCamera, camerasItem->data.V, camerasItem->name)) { 574 550 psLogMsg(__func__, PS_LOG_WARN, "Trouble reading reading camera configuration %s --- " 575 551 "ignored.\n", camerasItem->name); … … 607 583 608 584 // Return the requested camera configuration 609 psMetadata *pmConfigCameraByName( 610 pmConfig *config, // The configuration 611 const char *cameraName // The camera name header 612 ) 613 { 614 PS_ASSERT_PTR_NON_NULL(cameraName, NULL); 585 psMetadata *pmConfigCameraByName(pmConfig *config, const char *cameraName) 586 { 615 587 PS_ASSERT_PTR_NON_NULL(config, NULL); 588 PS_ASSERT_STRING_NON_EMPTY(cameraName, NULL); 616 589 617 590 psMetadata *cameras = psMetadataLookupMetadata(NULL, config->site, "CAMERAS"); … … 629 602 psMetadata *camera = NULL; // Camera to test against what we've got: 630 603 631 if (! readConfig(&camera, cameraPath, cameraName)) {604 if (!pmConfigFileRead(&camera, cameraPath, cameraName)) { 632 605 psLogMsg(__func__, PS_LOG_WARN, "Trouble reading reading camera configuration %s", cameraName); 633 606 psFree(camera); … … 695 668 // Read the recipe 696 669 psMetadata *recipe = NULL; // Recipe from file 697 if ( readConfig(&recipe, fileItem->data.V, "recipe")) {670 if (pmConfigFileRead(&recipe, fileItem->data.V, "recipe")) { 698 671 psMetadataAdd(config->recipes, PS_LIST_TAIL, fileItem->name, 699 672 PS_DATA_METADATA | PS_META_REPLACE, fileItem->comment, recipe); … … 738 711 739 712 740 bool pmConfigReadRecipes(pmConfig *config 741 ) 713 bool pmConfigReadRecipes(pmConfig *config) 742 714 { 743 715 PS_ASSERT_PTR_NON_NULL(config, false); … … 794 766 795 767 // Is the source a symbolic reference? 796 psMetadata *extant = psMetadataLookupMetadata(&mdok, config->recipes, recipeSource); // Does it exist? 768 psMetadata *extant = psMetadataLookupMetadata(&mdok, config->recipes, 769 recipeSource); // Does it exist? 797 770 if (mdok && extant) { 798 771 psString comment = psStringCopy("Recipe added from command line as symbolic link to "); … … 808 781 // The source is a file 809 782 psMetadata *recipe = NULL; // Recipe from file 810 if ( readConfig(&recipe, recipeSource, "recipe")) {783 if (pmConfigFileRead(&recipe, recipeSource, "recipe")) { 811 784 psString comment = psStringCopy("Recipe added at command line from "); 812 785 psStringAppend(&comment, "%s", recipeSource); … … 837 810 } 838 811 839 /****************************************************************************** 840 pmConfigDB(*site) 841 842 XXX: this should allow the option of having NO database server, if chosen by config 843 XXX: What should we use for the Database namespace in the call to psDBInit()? 844 This is currently NULL. 845 *****************************************************************************/ 846 847 psDB *pmConfigDB( 848 pmConfig *config // Configuration 849 ) 812 813 psDB *pmConfigDB(pmConfig *config) 850 814 { 851 815 PS_ASSERT_PTR_NON_NULL(config, NULL); … … 869 833 psString dbName = psMetadataLookupStr(&mdStatus04, config->site, "DBNAME"); 870 834 psS32 dbPort = psMetadataLookupS32(&mdStatus05, config->site, "DBPORT"); 871 if (!mdStatus05) 835 if (!mdStatus05) { 872 836 dbPort = 0; 873 if (!(mdStatus01 & mdStatus02 & mdStatus03 & mdStatus04)) { 874 psLogMsg(__func__, PS_LOG_WARN, "Could not determine database server name, userID, and password from site metadata.\n"); 875 return(NULL); 876 } 877 878 return(psDBInit(dbServer, dbUsername, dbPassword, dbName, dbPort)); 837 } 838 if (!(mdStatus01 && mdStatus02 && mdStatus03 && mdStatus04)) { 839 psLogMsg(__func__, PS_LOG_WARN, 840 "Could not determine database server, name, user, and password from site metadata.\n"); 841 return NULL; 842 } 843 844 return psDBInit(dbServer, dbUsername, dbPassword, dbName, dbPort); 879 845 #endif 880 846 } 881 847 882 848 883 bool pmConfigConformHeader(psMetadata *header, // Header to conform 884 const psMetadata *format // Camera format 885 ) 849 bool pmConfigConformHeader(psMetadata *header, const psMetadata *format) 886 850 { 887 851 PS_ASSERT_PTR_NON_NULL(header, false); … … 907 871 } 908 872 909 // given the 'file' and 'list' words, find the arguments associated with these words 910 // and interpret them as lists of files. return an array of the resulting filenames. 911 psArray *pmConfigFileSets(pmConfig *config, char *file, char *list) 873 psArray *pmConfigFileSets(pmConfig *config, const char *file, const char *list) 912 874 { 913 875 PS_ASSERT_PTR_NON_NULL(config, NULL); … … 915 877 PS_ASSERT_INT_NONNEGATIVE(*config->argc, NULL); 916 878 PS_ASSERT_PTR_NON_NULL(config->argv, NULL); 917 PS_ASSERT_PTR_NON_NULL(file, NULL); 918 PS_ASSERT_INT_POSITIVE(strlen(file), NULL); 919 PS_ASSERT_PTR_NON_NULL(list, NULL); 920 PS_ASSERT_INT_POSITIVE(strlen(list), NULL); 879 PS_ASSERT_STRING_NON_EMPTY(file, NULL); 880 PS_ASSERT_STRING_NON_EMPTY(list, NULL); 921 881 922 882 int Narg; … … 990 950 } 991 951 992 bool pmConfigFileSetsMD (psMetadata *metadata, pmConfig *config, char *name, char *file, char *list) 952 bool pmConfigFileSetsMD(psMetadata *metadata, pmConfig *config, const char *name, 953 const char *file, const char *list) 993 954 { 994 955 PS_ASSERT_PTR_NON_NULL(metadata, false); 995 956 PS_ASSERT_PTR_NON_NULL(config, false); 996 PS_ASSERT_PTR_NON_NULL(name, false); 997 PS_ASSERT_INT_POSITIVE(strlen(name), false); 998 PS_ASSERT_PTR_NON_NULL(file, false); 999 PS_ASSERT_INT_POSITIVE(strlen(file), false); 1000 PS_ASSERT_PTR_NON_NULL(list, false); 1001 PS_ASSERT_INT_POSITIVE(strlen(list), false); 957 PS_ASSERT_STRING_NON_EMPTY(name, NULL); 958 PS_ASSERT_STRING_NON_EMPTY(file, NULL); 959 PS_ASSERT_STRING_NON_EMPTY(list, NULL); 1002 960 1003 961 psErrorClear(); // pmConfigFileSets may or may not call psError, so -
trunk/psModules/src/config/pmConfig.h
r9411 r9579 1 1 /** @file pmConfig.h 2 2 * 3 * @author P AP, IfA3 * @author Paul Price, IfA 4 4 * 5 * @version $Revision: 1.1 4$ $Name: not supported by cvs2svn $6 * @date $Date: 2006-10- 09 20:19:25$5 * @version $Revision: 1.15 $ $Name: not supported by cvs2svn $ 6 * @date $Date: 2006-10-14 03:54:51 $ 7 7 * 8 8 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 12 12 #define PM_CONFIG_H 13 13 14 #include "pslib.h"14 #include <pslib.h> 15 15 16 // What recipe sources have been read so far? 16 /// Sources for recipes. 17 /// 18 /// Defines what recipe sources have been read. This allows us to read recipes from different sources as they 19 /// become available. For example, we may not have access to the camera configuration until we have read a 20 /// FITS file. We allow symbolic links, which means the user can specify on the command-line the name of a 21 /// recipe that's defined elsewhere, instead of typing the entire filename. This structure is private to 22 /// psModules --- there is no need for the user to know about it. 17 23 typedef enum { 18 P_PM_RECIPE_SOURCE_NONE = 0x00, // None yet19 P_PM_RECIPE_SOURCE_SITE = 0x01, // Site configuration20 P_PM_RECIPE_SOURCE_CAMERA = 0x02, // Camera configuration21 P_PM_RECIPE_SOURCE_CL = 0x04, // Command-line22 P_PM_RECIPE_SOURCE_SYMBOLIC = 0x14, // Symbolic link, specified on command-line23 P_PM_RECIPE_SOURCE_ALL = 0xff // All sources24 P_PM_RECIPE_SOURCE_NONE = 0x00, ///< None yet 25 P_PM_RECIPE_SOURCE_SITE = 0x01, ///< Site configuration 26 P_PM_RECIPE_SOURCE_CAMERA = 0x02, ///< Camera configuration 27 P_PM_RECIPE_SOURCE_CL = 0x04, ///< Command-line 28 P_PM_RECIPE_SOURCE_SYMBOLIC = 0x14, ///< Symbolic link, specified on command-line 29 P_PM_RECIPE_SOURCE_ALL = 0xff ///< All sources 24 30 } p_pmRecipeSource; 25 31 26 // Configuration information 32 /// Configuration information 33 /// 34 /// This structure stores the configuration information: the site, camera and recipe configuration, the 35 /// command-line arguments, the pmFPAfiles used, and the database handle. 27 36 typedef struct 28 37 { 29 psMetadata *site; // Site configuration30 psMetadata *camera; // Camera specification31 const char *cameraName; // Camera name32 psMetadata *recipes; // Recipes for processing33 psMetadata *arguments; // Processed command-line arguments34 psMetadata *files; // pmFPAfiles used for analysis35 psDB *database; // Database handle36 int *argc; // Number of command-line arguments37 char **argv; // Command-line arguments (raw version)38 psMetadata *site; ///< Site configuration 39 psMetadata *camera; ///< Camera specification 40 const char *cameraName; ///< Camera name 41 psMetadata *recipes; ///< Recipes for processing 42 psMetadata *arguments; ///< Processed command-line arguments 43 psMetadata *files; ///< pmFPAfiles used for analysis 44 psDB *database; ///< Database handle 45 int *argc; ///< Number of command-line arguments 46 char **argv; ///< Command-line arguments (raw version) 38 47 // Private members 39 p_pmRecipeSource recipesRead; // Which recipe sources have been read40 psMetadata *recipesSource; // Where each recipe came from48 p_pmRecipeSource recipesRead; ///< Which recipe sources have been read 49 psMetadata *recipesSource; ///< Where each recipe came from 41 50 } 42 51 pmConfig; 43 52 44 pmConfig *pmConfigAlloc(int *argc, // Number of command-line arguments 45 char **argv // Command-line arguments 53 /// Allocator for pmConfig 54 pmConfig *pmConfigAlloc(int *argc, /// Number of command-line arguments 55 char **argv /// Command-line arguments 46 56 ); 47 57 48 void pmConfigSet(const char *path); // set the configPath 58 /// Set configuration information 59 /// 60 /// The search path for the configuration files is a local static variable, set by this function. 61 void pmConfigSet(const char *path ///< Search paths for configuration files; colon-delimited directories 62 ); 49 63 50 // Free static variables64 /// Free memory used in the configuration system 51 65 void pmConfigDone(void); 52 66 53 /** pmConfigRead 54 * 55 * pmConfigRead shall load the site configuration (according to the above rule 56 * for determining the source). The camera configuration shall also be loaded if 57 * it is specified on the command line (argc, argv); otherwise it shall be set to 58 * NULL. The recipe shall also be loaded from the command line (if specified) or, 59 * if the camera configuration has been loaded, from the camera configuration and 60 * recipe specification therein (see below). In dealing with the command line 61 * parameters, the functions shall use the appropriate functions in psLib to 62 * retrieve and remove the relevant options from the argument list; this 63 * simplifies assignment of the mandatory arguments, since all the optional 64 * command line arguments are removed leaving only the mandatory arguments. The 65 * following psLib setups shall also be performed if they are specified in the 66 * site configuration: 67 * 68 */ 69 pmConfig *pmConfigRead( 70 int *argc, 71 char **argv); 67 /// Read configuration information from the command line. 68 /// 69 /// pmConfigRead loads the site configuration (the file name is specified by "-site SITE_FILE" on the 70 /// command-line, the PS_SITE environment variable, or it is $HOME/.ipprc). The camera configuration is 71 /// loaded if it is specified on the command line ("-camera CAMERA_FILE"). Recipes specified on the command 72 /// line ("-recipe RECIPE_NAME RECIPE_SOURCE") are also loaded. These command-line arguments are removed from 73 /// from the command-line, to simplify parsing. The psLib setups are also performed if specified in the site 74 /// configuration. 75 pmConfig *pmConfigRead(int *argc, ///< Number of command-line arguments 76 char **argv ///< Array of command-line arguments 77 ); 72 78 73 /** we need this elsewhere; make it public **/ 74 bool readConfig( 75 psMetadata **config, // Config to output 76 const char *name, // Name of file 77 const char *description // Description of file 78 ); 79 /// Read a configuration file 80 /// 81 /// Read a metadata configuration file into the supplied metadata. Produce an error and return false if 82 /// there's a problem. 83 bool pmConfigFileRead(psMetadata **config, ///< Config to output 84 const char *name, ///< Name of file 85 const char *description ///< Description of file 86 ); 79 87 80 /** pmConfigValidateCamera 81 * 82 * This function, used by pmConfigCameraFromHeader, shall return true if the 83 * FITS header matches the rule contained in the camera configuration (see 84 * x2.2.2.3); otherwise it shall return false. 85 * 86 */ 87 bool pmConfigValidateCameraFormat( 88 const psMetadata *cameraFormat, 89 const psMetadata *header); 88 /// Validate a header against the camera format 89 /// 90 /// Given a FITS header (the PHU header), check it against the RULE metadata contained within the camera 91 /// format; return true if it matches. 92 bool pmConfigValidateCameraFormat(const psMetadata *cameraFormat, ///< Camera format containing the RULE 93 const psMetadata *header // FITS header for the PHU 94 ); 90 95 96 /// Determine the camera format (and camera if unknown) from examining the header 97 /// 98 /// Given a FITS header, check it against all known cameras (unless we already know which camera, from 99 /// pmConfigRead) and all known formats for those cameras in order to identify which is appropriate. The 100 /// first matching format is accepted; further matches produce warnings. The accepted camera is saved in the 101 /// configuration. The accepted format is returned. 102 psMetadata *pmConfigCameraFormatFromHeader(pmConfig *config, ///< The configuration 103 const psMetadata *header ///< The FITS header 104 ); 91 105 92 /** pmConfigCameraFromHeader 93 * 94 * pmConfigCameraFromHeader shall load the camera configuration based on the 95 * contents of the FITS header, using the list of known cameras contained in the 96 * site configuration. If more than one camera matches the FITS header, a warning 97 * shall be generated and the first matching camera returned. 98 * 99 */ 100 psMetadata *pmConfigCameraFormatFromHeader( 101 pmConfig *config, // The configuration 102 const psMetadata *header // The FITS header 103 ); 106 /// Return the camera configuration specified by name 107 /// 108 /// Given a camera name, returns the camera configuration metadata. 109 psMetadata *pmConfigCameraByName(pmConfig *config, ///< The configuration 110 const char *cameraName ///< The camera name header 111 ); 104 112 105 106 // find the camera given the name 107 psMetadata *pmConfigCameraByName( 108 pmConfig *config, // The configuration 109 const char *cameraName // The camera name header 110 ); 111 112 /** pmConfigRecipeFromCamera 113 * 114 * pmConfigRecipeFromCamera shall load the recipes from the list of known recipes contained in the camera 115 * configuration. 116 * 117 */ 118 bool pmConfigReadRecipes(pmConfig *config // Configuration 113 /// Read recipes 114 /// 115 /// Attempt to read recipes from the sources that are available but have not already been read. 116 bool pmConfigReadRecipes(pmConfig *config ///< Configuration 119 117 ); 120 118 … … 126 124 * 127 125 */ 128 psDB *pmConfigDB( 129 pmConfig *config // Configuration 130 ); 126 /// Setup the database 127 /// 128 /// Initialise the database connection using the DBSERVER, DBNAME, DBUSER, DBPASSWORD values provided in the 129 /// site configuration. Stores the database handle in the configuration, and also returns it. 130 psDB *pmConfigDB(pmConfig *config ///< Configuration 131 ); 131 132 132 133 /** pmConfigConformHeader … … 134 135 * Make the supplied header conform to the nominated camera format. 135 136 */ 136 bool pmConfigConformHeader(psMetadata *header, // Header to conform 137 const psMetadata *format // Camera format 137 138 /// Make the supplied header conform to the nominated camera format. 139 /// 140 /// Given a FITS header, make it conform to the RULE in the specified camera format. This is useful for 141 /// switching between formats, or generating fake data that must be recognised by 142 /// pmConfigCameraFormatFromHeader. 143 bool pmConfigConformHeader(psMetadata *header, ///< Header to conform 144 const psMetadata *format ///< Camera format 138 145 ); 139 146 147 /// Read the command-line for files (or a text file containing a list of files) 148 /// 149 /// Given the 'file' and 'list' arguments (e.g., "-file" and "-list"), find the arguments associated with 150 /// these words and interpret them as lists of files. Return an array of the resulting filenames. 151 psArray *pmConfigFileSets(pmConfig *config, ///< Configuration, containing command-line arguments 152 const char *file, ///< CL argument specifying a filename 153 const char *list ///< CL argument specifying a text file with a list of filenames 154 ); 140 155 141 psArray *pmConfigFileSets(pmConfig *config, char *file, char *list); 142 bool pmConfigFileSetsMD (psMetadata *metadata, pmConfig *config, char *name, char *file, char *list); 156 /// Stuff associated files from the command-line into a metadata 157 /// 158 /// Calls pmConfigFileSets to parse the command line for filenames (or a list which provides filenames), and 159 /// stuffs the array of filenames into the metadata under "name". 160 bool pmConfigFileSetsMD(psMetadata *metadata, ///< Metadata into which to stuff the array 161 pmConfig *config, ///< Configuration (which command-line arguments) 162 const char *name, ///< Name for array in the metadata 163 const char *file, ///< CL argument specifying a filename 164 const char *list ///< CL argument specifying a text file with a list of filenames 165 ); 143 166 144 167
Note:
See TracChangeset
for help on using the changeset viewer.
