Changeset 13704 for trunk/psModules/src/camera/pmFPAfileDefine.c
- Timestamp:
- Jun 7, 2007, 2:31:50 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/camera/pmFPAfileDefine.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/camera/pmFPAfileDefine.c
r13669 r13704 93 93 } 94 94 95 // define a pmFPAfile, bind to the optional fpa if supplied96 pmFPAfile *pmFPAfileDefineOutput(const pmConfig *config, pmFPA *fpa, const char *name) 97 { 98 PS_ASSERT_PTR_NON_NULL(config, NULL);99 PS_ASSERT_PTR_NON_NULL(config->files, NULL);100 PS_ASSERT_PTR_NON_NULL(config->camera, NULL);101 PS_ASSERT_STRING_NON_EMPTY(name, NULL);102 95 // Define an output pmFPAfile 96 static pmFPAfile *fpaFileDefineOutput(const pmConfig *config, // Configuration 97 pmFPA *fpa, // Optional FPA to bind 98 const char *name, // Name of file rule 99 const char *cameraName, // Name of camera configuration to use 100 const char *formatName // Name of camera format to use 101 ) 102 { 103 103 bool status; 104 104 105 105 // select the FILERULES from the camera config 106 psMetadata *filerules = psMetadataLookupPtr (&status, config->camera, "FILERULES");106 psMetadata *filerules = psMetadataLookupPtr(&status, config->camera, "FILERULES"); 107 107 if (filerules == NULL) { 108 108 psError(PS_ERR_IO, true, "Can't find FILERULES in the CAMERA configuration!"); … … 112 112 // select the name from the FILERULES 113 113 // check for alias name (type == STR, name is aliased name) 114 const char *realname = psMetadataLookupStr (&status, filerules, name);114 const char *realname = psMetadataLookupStr(&status, filerules, name); 115 115 if (!realname || strlen(realname) == 0) { 116 116 realname = name; … … 123 123 } 124 124 125 pmFPAfile *file = pmFPAfileAlloc ();125 pmFPAfile *file = pmFPAfileAlloc(); 126 126 127 127 // save the name of this pmFPAfile 128 file->name = psStringCopy (name);129 130 file->filerule = psMemIncrRefCounter(psMetadataLookupStr (&status, data, "FILENAME.RULE"));131 132 const char *type = psMetadataLookupStr (&status, data, "FILE.TYPE");128 file->name = psStringCopy(name); 129 130 file->filerule = psMemIncrRefCounter(psMetadataLookupStr(&status, data, "FILENAME.RULE")); 131 132 const char *type = psMetadataLookupStr(&status, data, "FILE.TYPE"); 133 133 file->type = pmFPAfileTypeFromString(type); 134 134 if (file->type == PM_FPA_FILE_NONE) { … … 153 153 } 154 154 155 psMetadata *camera; // Camera to use 156 if (fpa && fpa->camera) { 157 camera = (psMetadata*)fpa->camera; // Casting away const, so I can put it in the file 155 // Use the camera we were told to, the camera of the provided FPA, or default to the default camera 156 psMetadata *camera; // Camera configuration 157 if (!cameraName || strlen(cameraName) == 0) { 158 if (fpa && fpa->camera) { 159 camera = (psMetadata*)fpa->camera; // Casting away const, so I can put it in the file 160 } else { 161 camera = config->camera; 162 } 158 163 } else { 159 camera = config->camera; 164 bool mdok; // Status of MD lookup 165 psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->site, "CAMERAS"); // Known cameras 166 if (!mdok || !cameras) { 167 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the site configuration.\n"); 168 return NULL; 169 } 170 camera = psMetadataLookupMetadata(&mdok, cameras, cameraName); // Camera configuration of interest 171 if (!mdok || !camera) { 172 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find automatically generated " 173 "camera configuration %s in site configuration.\n", cameraName); 174 return NULL; 175 } 176 177 if (fpa && fpa->camera && fpa->camera != camera) { 178 psAbort("Camera of bound FPA is not the requested camera --- there is an inconsistency!"); 179 } 160 180 } 161 181 file->camera = psMemIncrRefCounter(camera); 162 182 163 // select the format list from the selected camera 164 const char *formatName = psMetadataLookupStr (&status, data, "FILE.FORMAT"); 165 if (!formatName || strcmp(formatName, "NONE") == 0) { 166 // Try to get by with the default 167 formatName = config->formatName; 183 // Use the format we were told to, the format specified in the file rule, or default to the default format 184 if (!formatName || strlen(formatName) == 0) { 185 // select the format list from the selected camera 186 formatName = psMetadataLookupStr(&status, data, "FILE.FORMAT"); 187 if (!formatName || strcmp(formatName, "NONE") == 0) { 188 // Try to get by with the default 189 formatName = config->formatName; 190 } 168 191 } 169 192 psMetadata *formats = psMetadataLookupMetadata(&status, file->camera, "FORMATS"); // List of formats … … 177 200 file->format = psMemIncrRefCounter(format); 178 201 179 file->fpa = psMemIncrRefCounter(fpa); 202 if (fpa) { 203 file->fpa = psMemIncrRefCounter(fpa); 204 } else { 205 file->fpa = pmFPAConstruct(file->camera); 206 } 180 207 181 208 file->fileLevel = pmFPAPHULevel(format); … … 219 246 } 220 247 248 // define a pmFPAfile, bind to the optional fpa if supplied 249 pmFPAfile *pmFPAfileDefineOutput(const pmConfig *config, pmFPA *fpa, const char *name) 250 { 251 PS_ASSERT_PTR_NON_NULL(config, NULL); 252 PS_ASSERT_PTR_NON_NULL(config->files, NULL); 253 PS_ASSERT_PTR_NON_NULL(config->camera, NULL); 254 PS_ASSERT_STRING_NON_EMPTY(name, NULL); 255 256 return fpaFileDefineOutput(config, fpa, name, NULL, NULL); 257 } 221 258 222 259 // search for argname on the config->argument list … … 245 282 psArray *infiles = psMetadataLookupPtr(&status, config->arguments, argname); 246 283 if (!status) { 247 if (success) *success = true;284 if (success) *success = true; 248 285 return NULL; 249 286 } … … 415 452 if (!status) { 416 453 // this is not an error: this just means no matching argument was supplied 417 if (success) *success = true;454 if (success) *success = true; 418 455 return NULL; 419 456 } … … 545 582 if (!status) { 546 583 psTrace("psModules.camera", 5, "Failed to find %s in argument list", argname); 547 if (success) *success = true;584 if (success) *success = true; 548 585 return NULL; 549 586 } … … 679 716 // don't free the file here: it is left on config->files 680 717 // to be used optionally by pmFPAfileDefineFromDetDB (or others) 681 if (success) *success = true;718 if (success) *success = true; 682 719 return NULL; 683 720 } … … 908 945 } 909 946 947 pmFPAfile *pmFPAfileDefineSkycell(const pmConfig *config, pmFPA *fpa, const char *filename) 948 { 949 PS_ASSERT_PTR_NON_NULL(config, NULL); 950 PS_ASSERT_STRING_NON_EMPTY(filename, NULL); 951 PS_ASSERT_STRING_NON_EMPTY(config->cameraName, NULL); 952 PS_ASSERT_STRING_NON_EMPTY(config->formatName, NULL); 953 954 pmFPAfile *file; // The new file 955 956 if (config->cameraName[0] == '_' && 957 strcmp(config->cameraName + strlen(config->cameraName) - 8, "-SKYCELL") == 0) { 958 // The input camera is already a skycell 959 file = fpaFileDefineOutput(config, fpa, filename, config->cameraName, "SKYCELL"); 960 } else { 961 // Find the correct camera configuration 962 psString cameraName = NULL; // Name of the new (automatically-generated) camera configuration 963 psStringAppend(&cameraName, "_%s-SKYCELL", config->cameraName); 964 965 file = fpaFileDefineOutput(config, fpa, filename, cameraName, "SKYCELL"); 966 psFree(cameraName); 967 } 968 969 // Ensure everything is written out at the appropriate level 970 file->fileLevel = PM_FPA_LEVEL_FPA; 971 file->dataLevel = PM_FPA_LEVEL_FPA; 972 file->freeLevel = PM_FPA_LEVEL_FPA; 973 974 return file; 975 } 976 910 977 pmFPAfile *pmFPAfileDefineChipMosaic(const pmConfig *config, pmFPA *src, const char *filename) 911 978 { … … 916 983 PS_ASSERT_STRING_NON_EMPTY(config->formatName, NULL); 917 984 985 pmFPAfile *file; // The new file 918 986 if (config->cameraName[0] == '_' && 919 987 strcmp(config->cameraName + strlen(config->cameraName) - 5, "-CHIP") == 0) { 920 988 // The input camera has already been mosaicked to this level 921 pmFPAfile *file = pmFPAfileDefineOutput(config, NULL, filename); 922 psFree (file->camera); 923 psFree (file->format); 924 psFree (file->fpa); 925 file->camera = psMemIncrRefCounter(config->camera); 926 file->format = psMemIncrRefCounter(config->format); 927 file->fpa = pmFPAConstruct(file->camera); 928 return file; 929 } 930 931 // Find the correct camera configuration 932 bool mdok; // Status of MD lookup 933 psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->site, "CAMERAS"); // Camera configurations 934 if (!mdok || !cameras) { 935 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the site configuration.\n"); 936 return NULL; 937 } 938 psString name = NULL; // Name of the new (automatically-generated) camera configuration 939 psStringAppend(&name, "_%s-CHIP", config->cameraName); 940 psMetadata *camera = psMetadataLookupMetadata(&mdok, cameras, name); // Camera configuration of interest 941 if (!mdok || !camera) { 942 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find automatically generated " 943 "camera configuration %s in site configuration.\n", name); 944 psFree(name); 945 return NULL; 946 } 947 psFree(name); 948 949 // Need to look up the format of the same name, but under the mosaic camera 950 psMetadata *formats = psMetadataLookupMetadata(&mdok, camera, "FORMATS"); // The FORMATS 951 if (!mdok || !formats) { 952 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find FORMATS in camera configuration %s.\n", 953 config->cameraName); 954 return NULL; 955 } 956 psMetadata *format = psMetadataLookupMetadata(&mdok, formats, config->formatName); // The format 957 if (!mdok || !format) { 958 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find camera format %s within camera %s.\n", 959 config->formatName, config->cameraName); 960 return NULL; 961 } 962 963 pmFPA *fpa = pmFPAConstruct(camera); 964 if (!fpa) { 965 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to generate mosaicked camera.\n"); 966 return NULL; 967 } 968 pmFPAfile *file = pmFPAfileDefineOutput(config, fpa, filename); 969 if (!file) { 970 psErrorStackPrint(stderr, "file %s not defined\n", filename); 971 return NULL; 972 } 989 file = fpaFileDefineOutput(config, NULL, filename, config->cameraName, config->formatName); 990 } else { 991 psString cameraName = NULL; // Name of the new (automatically-generated) camera configuration 992 psStringAppend(&cameraName, "_%s-CHIP", config->cameraName); 993 994 // Find the correct camera configuration 995 file = fpaFileDefineOutput(config, NULL, filename, cameraName, config->formatName); 996 psFree(cameraName); 997 } 998 973 999 file->src = src; // inherit output elements from this source pmFPA 1000 974 1001 file->mosaicLevel = PM_FPA_LEVEL_CHIP; // don't do any I/O on this at a lower level 975 976 psFree (file->format);977 file->format = psMemIncrRefCounter(format);978 979 psFree(fpa);980 1002 981 1003 return file; … … 989 1011 PS_ASSERT_STRING_NON_EMPTY(config->cameraName, NULL); 990 1012 1013 pmFPAfile *file; // The new file 991 1014 if (config->cameraName[0] == '_' && 992 1015 strcmp(config->cameraName + strlen(config->cameraName) - 4 , "-FPA") == 0) { 993 1016 // The input camera has already been mosaicked to this level 994 pmFPAfile *file = pmFPAfileDefineOutput(config, NULL, filename); 995 psFree (file->camera); 996 psFree (file->format); 997 psFree (file->fpa); 998 file->camera = psMemIncrRefCounter(config->camera); 999 file->format = psMemIncrRefCounter(config->format); 1000 file->fpa = pmFPAConstruct(file->camera); 1001 return file; 1002 } 1003 1004 // Find the correct camera configuration 1005 bool mdok; // Status of MD lookup 1006 psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->site, "CAMERAS"); // Camera configurations 1007 if (!mdok || !cameras) { 1008 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the site configuration.\n"); 1009 return NULL; 1010 } 1011 psString original; // Name of the original camera configuration 1012 psString name = NULL; // Name of the new (automatically-generated) camera configuration 1013 if (config->cameraName[0] == '_' && 1017 file = fpaFileDefineOutput(config, NULL, filename, config->cameraName, config->formatName); 1018 } else { 1019 1020 psString original; // Name of the original camera configuration 1021 if (config->cameraName[0] == '_' && 1014 1022 strcmp(config->cameraName + strlen(config->cameraName) - 5 , "-CHIP") == 0) { 1015 // It's a chip mosaic; we need to get the original name 1016 original = psStringNCopy(config->cameraName + 1, strlen(config->cameraName) - 6); 1017 } else { 1018 original = psMemIncrRefCounter(config->cameraName); 1019 } 1020 psStringAppend(&name, "_%s-FPA", original); 1021 psFree(original); 1022 psMetadata *camera = psMetadataLookupMetadata(&mdok, cameras, name); // Camera configuration of interest 1023 if (!mdok || !camera) { 1024 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find automatically generated " 1025 "camera configuration %s in site configuration.\n", name); 1026 psFree(name); 1027 return NULL; 1028 } 1029 psFree(name); 1030 1031 // Need to look up the format of the same name, but under the mosaic camera 1032 psMetadata *formats = psMetadataLookupMetadata(&mdok, camera, "FORMATS"); // The FORMATS 1033 if (!mdok || !formats) { 1034 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find FORMATS in camera configuration %s.\n", 1035 config->cameraName); 1036 return NULL; 1037 } 1038 psMetadata *format = psMetadataLookupMetadata(&mdok, formats, config->formatName); // The format 1039 if (!mdok || !format) { 1040 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find camera format %s within camera %s.\n", 1041 config->formatName, config->cameraName); 1042 return NULL; 1043 } 1044 1045 pmFPA *fpa = pmFPAConstruct(camera); 1046 if (!fpa) { 1047 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to generate mosaicked camera.\n"); 1048 return NULL; 1049 } 1050 pmFPAfile *file = pmFPAfileDefineOutput(config, fpa, filename); 1051 if (!file) { 1052 psErrorStackPrint(stderr, "file %s not defined\n", filename); 1053 return NULL; 1054 } 1023 // It's a chip mosaic; we need to get the original name 1024 original = psStringNCopy(config->cameraName + 1, strlen(config->cameraName) - 6); 1025 } else { 1026 original = psMemIncrRefCounter(config->cameraName); 1027 } 1028 psString cameraName = NULL; 1029 psStringAppend(&cameraName, "_%s-FPA", original); 1030 1031 file = fpaFileDefineOutput(config, NULL, filename, cameraName, config->formatName); 1032 psFree(cameraName); 1033 } 1034 1055 1035 file->src = src; // inherit output elements from this source pmFPA 1036 1056 1037 file->mosaicLevel = PM_FPA_LEVEL_FPA; // don't do any I/O on this at a lower level 1057 psFree (file->format);1058 file->format = psMemIncrRefCounter(format);1059 1060 psFree(fpa);1061 1038 1062 1039 return file;
Note:
See TracChangeset
for help on using the changeset viewer.
