00001 /* @file pmConfig.h 00002 * @brief Configuration functions 00003 * 00004 * @author Paul Price, IfA 00005 * @author Eugene Magnier, IfA 00006 * 00007 * @version $Revision: 1.27 $ $Name: $ 00008 * @date $Date: 2007/01/26 00:05:18 $ 00009 * Copyright 2005-2006 Institute for Astronomy, University of Hawaii 00010 */ 00011 00012 #ifndef PM_CONFIG_H 00013 #define PM_CONFIG_H 00014 00015 /// @addtogroup Config Configuration System 00016 /// @{ 00017 00018 /// Sources for recipes. 00019 /// 00020 /// Defines what recipe sources have been read. This allows us to read recipes from different sources as they 00021 /// become available. For example, we may not have access to the camera configuration until we have read a 00022 /// FITS file. We allow symbolic links, which means the user can specify on the command-line the name of a 00023 /// recipe that's defined elsewhere, instead of typing the entire filename. This structure is private to 00024 /// psModules --- there is no need for the user to know about it. 00025 typedef enum { 00026 PM_RECIPE_SOURCE_NONE = 0x00, ///< None yet 00027 PM_RECIPE_SOURCE_SITE = 0x01, ///< Site configuration 00028 PM_RECIPE_SOURCE_CAMERA = 0x02, ///< Camera configuration 00029 PM_RECIPE_SOURCE_CL = 0x04, ///< Command-line 00030 PM_RECIPE_SOURCE_SYMBOLIC = 0x14, ///< Symbolic link, specified on command-line 00031 PM_RECIPE_SOURCE_ALL = 0xff ///< All sources 00032 } pmRecipeSource; 00033 00034 /// Configuration information 00035 /// 00036 /// This structure stores the configuration information: the site, camera and recipe configuration, the 00037 /// command-line arguments, the pmFPAfiles used, and the database handle. 00038 typedef struct 00039 { 00040 psMetadata *site; ///< Site configuration 00041 psMetadata *camera; ///< Camera specification 00042 psString cameraName; ///< Camera name 00043 psMetadata *format; ///< Camera format description 00044 psString formatName; ///< Camera format name 00045 psMetadata *recipes; ///< Recipes for processing 00046 psMetadata *arguments; ///< Processed command-line arguments 00047 psMetadata *files; ///< pmFPAfiles used for analysis 00048 psDB *database; ///< Database handle 00049 int *argc; ///< Number of command-line arguments 00050 char **argv; ///< Command-line arguments (raw version) 00051 const char *defaultRecipe; ///< name of top-level recipe for this program 00052 // Private members 00053 pmRecipeSource recipesRead; ///< Which recipe sources have been read 00054 psMetadata *recipeSymbols; ///< Where each recipe came from 00055 } 00056 pmConfig; 00057 00058 /// Allocator for pmConfig 00059 pmConfig *pmConfigAlloc(int *argc, /// Number of command-line arguments 00060 char **argv /// Command-line arguments 00061 ); 00062 00063 /// Set static configuration information 00064 /// 00065 /// The search path for the configuration files is a local static variable, set by this function. 00066 void pmConfigSet(const char *path ///< Search paths for configuration files; colon-delimited directories 00067 ); 00068 00069 /// Free static memory used in the configuration system 00070 void pmConfigDone(void); 00071 00072 /// Read configuration information from the command line. 00073 /// 00074 /// pmConfigRead loads the site configuration (the file name is specified by "-site SITE_FILE" on the 00075 /// command-line, the PS_SITE environment variable, or it is $HOME/.ipprc). The configuration search path is 00076 /// set. The camera configuration is loaded if it is specified on the command line ("-camera 00077 /// CAMERA_FILE"). Recipes specified on the command line ("-recipe RECIPE_NAME RECIPE_SOURCE") are also 00078 /// loaded. These command-line arguments are removed from from the command-line, to simplify parsing. The 00079 /// psLib log, trace and time setups are also performed if specified in the site configuration. 00080 pmConfig *pmConfigRead(int *argc, ///< Number of command-line arguments 00081 char **argv, ///< Array of command-line arguments 00082 char *defaultRecipe ///< name of top-level recipe for this program 00083 ); 00084 00085 /// Read a configuration file 00086 /// 00087 /// Read a metadata configuration file into the supplied metadata. Produce an error and return false if 00088 /// there's a problem. 00089 bool pmConfigFileRead(psMetadata **config, ///< Config to output 00090 const char *name, ///< Name of file 00091 const char *description ///< Description of file 00092 ); 00093 00094 /// Validate a header against the camera format 00095 /// 00096 /// Given a FITS header (the PHU header), check it against the RULE metadata contained within the camera 00097 /// format; return found = true if it matches. return false on serious errors 00098 bool pmConfigValidateCameraFormat(bool *valid, 00099 const psMetadata *cameraFormat, ///< Camera format containing the RULE 00100 const psMetadata *header // FITS header for the PHU 00101 ); 00102 00103 /// Determine the camera format (and camera if unknown) from examining the header 00104 /// 00105 /// Given a FITS header, check it against all known cameras (unless we already know which camera, from 00106 /// pmConfigRead) and all known formats for those cameras in order to identify which is appropriate. The 00107 /// first matching format is accepted; further matches produce warnings. The accepted camera is saved in the 00108 /// configuration. The accepted format is returned. 00109 psMetadata *pmConfigCameraFormatFromHeader(pmConfig *config, ///< The configuration 00110 const psMetadata *header ///< The FITS header 00111 ); 00112 00113 /// Return the camera configuration specified by name 00114 /// 00115 /// Given a camera name, returns the camera configuration metadata. 00116 psMetadata *pmConfigCameraByName(pmConfig *config, ///< The configuration 00117 const char *cameraName ///< The camera name header 00118 ); 00119 00120 /// Setup the database 00121 /// 00122 /// Initialise the database connection using the DBSERVER, DBNAME, DBUSER, DBPASSWORD values provided in the 00123 /// site configuration. Stores the database handle in the configuration, and also returns it. 00124 psDB *pmConfigDB(pmConfig *config ///< Configuration 00125 ); 00126 00127 /// Make the supplied header conform to the nominated camera format. 00128 /// 00129 /// Given a FITS header, make it conform to the RULE in the specified camera format. This is useful for 00130 /// switching between formats, or generating fake data that must be recognised by 00131 /// pmConfigCameraFormatFromHeader. 00132 bool pmConfigConformHeader(psMetadata *header, ///< Header to conform 00133 const psMetadata *format ///< Camera format 00134 ); 00135 00136 /// Read the command-line for files (or a text file containing a list of files) 00137 /// 00138 /// Given the 'file' and 'list' arguments (e.g., "-file" and "-list"), find the arguments associated with 00139 /// these words and interpret them as lists of files. Return an array of the resulting filenames. 00140 psArray *pmConfigFileSets(pmConfig *config, ///< Configuration, containing command-line arguments 00141 const char *file, ///< CL argument specifying a filename 00142 const char *list ///< CL argument specifying a text file with a list of filenames 00143 ); 00144 00145 /// Stuff associated files from the command-line into a metadata 00146 /// 00147 /// Calls pmConfigFileSets to parse the command line for filenames (or a list which provides filenames), and 00148 /// stuffs the array of filenames into the metadata under "name". 00149 bool pmConfigFileSetsMD(psMetadata *metadata, ///< Metadata into which to stuff the array 00150 pmConfig *config, ///< Configuration (which command-line arguments) 00151 const char *name, ///< Name for array in the metadata 00152 const char *file, ///< CL argument specifying a filename 00153 const char *list ///< CL argument specifying a text file with a list of filenames 00154 ); 00155 00156 /// Convert the supplied name, create a new output psString 00157 psString pmConfigConvertFilename( 00158 const char *filename, ///< file path/URI 00159 const pmConfig *config, ///< configuration 00160 bool create ///< create the file if it doesn't exist 00161 ); 00162 00163 /// Set whether all config parameters are read on startup 00164 bool pmConfigReadParamsSet(bool newReadCameraConfig // Desired mode for camera configuration reading 00165 ); 00166 00167 /// @} 00168 #endif
1.5.1