Changeset 14973
- Timestamp:
- Sep 21, 2007, 11:54:48 AM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/pap_branch_070920/psModules/src/camera/pmFPAfileDefine.c
r14954 r14973 8 8 #include <pslib.h> 9 9 10 #include "pmErrorCodes.h" 10 11 #include "pmConfig.h" 11 12 #include "pmDetrendDB.h" … … 19 20 #include "pmFPAConstruct.h" 20 21 22 23 // Get the file rule of interest 24 // Look up the name of the set of file rules to use, get that set from the site configuration, and return the 25 // appropriate rule from the set. 26 static psMetadata *getFileRule(const pmConfig *config, // Configuration 27 const psMetadata *camera, // Camera configuration of interest 28 const char *name // Name of rule to read 29 ) 30 { 31 assert(config); 32 assert(config->site); 33 34 const char *setName = psMetadataLookupStr(NULL, camera, "FILERULES"); // Name of file rules set 35 if (!setName) { 36 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find FILERULES in the camera configuration."); 37 return NULL; 38 } 39 40 psMetadata *fileruleSets = psMetadataLookupMetadata(NULL, config->site, 41 "FILERULES"); // Sets of defined file rules 42 if (!fileruleSets) { 43 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find FILERULES in the site configuration."); 44 return NULL; 45 } 46 47 psMetadataItem *item = psMetadataLookup(fileruleSets, setName); // Item with the file rule of interest 48 if (!item) { 49 psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find FILERULES set %s in the SITE configuration.", 50 setName); 51 return NULL; 52 } 53 54 psMetadata *filerules = NULL; // File rules from the site configuration 55 switch (item->type) { 56 case PS_DATA_METADATA: 57 // It's what we're after 58 filerules = item->data.md; 59 break; 60 case PS_DATA_STRING: { 61 // It's the name of a file --- read the file, and store it for future use 62 if (!pmConfigFileRead(&filerules, item->data.str, "filerules")) { 63 psError(PM_ERR_CONFIG, false, "Trouble reading reading file rules %s --- " 64 "ignored.\n", setName); 65 psFree(filerules); 66 return NULL; 67 } 68 69 // Muck around under the hood to replace the filename with the metadata; don't try this at home, 70 // kids 71 item->type = PS_DATA_METADATA; 72 psFree(item->data.str); 73 item->data.md = filerules; 74 break; 75 } 76 default: 77 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 78 "Unexpected type for %s (%x) in FILERULES in SITE configuration.", 79 name, item->type); 80 return NULL; 81 } 82 83 // select the name from the FILERULES 84 // check for alias name (type == STR, name is aliased name) 85 bool mdok; // Status of MD lookup 86 const char *realname = psMetadataLookupStr(&mdok, filerules, name); // Name of file rule to look up 87 if (!realname || strlen(realname) == 0) { 88 realname = name; 89 } 90 91 return psMetadataLookupMetadata(NULL, filerules, realname); 92 } 93 94 21 95 // define an input-type pmFPAfile, bind to the optional fpa if supplied 22 96 pmFPAfile *pmFPAfileDefineInput(const pmConfig *config, pmFPA *fpa, const char *name) … … 30 104 char *type; 31 105 32 // select the FILERULES from config->camera 33 psMetadata *filerules = psMetadataLookupPtr (&status, config->camera, "FILERULES"); 34 if (filerules == NULL) { 35 psError(PS_ERR_IO, true, "Can't find FILERULES in the CAMERA configuration!"); 36 return NULL; 37 } 38 39 // select the name from the FILERULES 40 // check for alias name (type == STR, name is aliased name) 41 const char *realname = psMetadataLookupStr (&status, filerules, name); 42 if (!realname || strlen(realname) == 0) { 43 realname = name; 44 } 45 46 psMetadata *data = psMetadataLookupPtr (&status, filerules, realname); 47 if (data == NULL) { 106 const psMetadata *camera = (fpa ? fpa->camera : config->camera); // Camera configuration for this file 107 psMetadata *data = getFileRule(config, camera, name); // File rule 108 if (!data) { 48 109 psError(PS_ERR_IO, true, "Can't find file rule %s!", name); 49 110 return NULL; … … 76 137 file->freeLevel = file->dataLevel; 77 138 78 if (fpa != NULL) {139 if (fpa) { 79 140 file->fpa = psMemIncrRefCounter(fpa); 80 141 file->camera = psMemIncrRefCounter((psMetadata *)fpa->camera); 142 file->cameraName = psMemIncrRefCounter(config->cameraName); // XXX Is this the correct thing to do? 143 } else { 144 file->camera = psMemIncrRefCounter(config->camera); 81 145 file->cameraName = psMemIncrRefCounter(config->cameraName); 82 146 } … … 104 168 bool status; 105 169 106 // select the FILERULES from the camera config 107 psMetadata *filerules = psMetadataLookupPtr(&status, config->camera, "FILERULES"); 108 if (filerules == NULL) { 109 psError(PS_ERR_IO, true, "Can't find FILERULES in the CAMERA configuration!"); 110 return NULL; 111 } 112 113 // select the name from the FILERULES 114 // check for alias name (type == STR, name is aliased name) 115 const char *realname = psMetadataLookupStr(&status, filerules, name); 116 if (!realname || strlen(realname) == 0) { 117 realname = name; 118 } 119 120 psMetadata *data = psMetadataLookupPtr (&status, filerules, realname); 121 if (data == NULL) { 170 // Use the camera we were told to, the camera of the provided FPA, or default to the default camera 171 psMetadata *camera; // Camera configuration 172 if (!cameraName || strlen(cameraName) == 0) { 173 if (fpa && fpa->camera) { 174 camera = (psMetadata*)fpa->camera; // Casting away const, so I can put it in the file 175 } else { 176 camera = config->camera; 177 cameraName = config->cameraName; 178 } 179 } else { 180 bool mdok; // Status of MD lookup 181 psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->site, "CAMERAS"); // Known cameras 182 if (!mdok || !cameras) { 183 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the site configuration.\n"); 184 return NULL; 185 } 186 camera = psMetadataLookupMetadata(&mdok, cameras, cameraName); // Camera configuration of interest 187 if (!mdok || !camera) { 188 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find automatically generated " 189 "camera configuration %s in site configuration.\n", cameraName); 190 return NULL; 191 } 192 193 if (fpa && fpa->camera && fpa->camera != camera) { 194 psAbort("Camera of bound FPA is not the requested camera --- there is an inconsistency!"); 195 } 196 } 197 198 psMetadata *data = getFileRule(config, camera, name); // File rule 199 if (!data) { 122 200 psError(PS_ERR_IO, true, "Can't find file rule %s!", name); 123 201 return NULL; … … 158 236 # endif 159 237 160 // Use the camera we were told to, the camera of the provided FPA, or default to the default camera161 psMetadata *camera; // Camera configuration162 if (!cameraName || strlen(cameraName) == 0) {163 if (fpa && fpa->camera) {164 camera = (psMetadata*)fpa->camera; // Casting away const, so I can put it in the file165 } else {166 camera = config->camera;167 cameraName = config->cameraName;168 }169 } else {170 bool mdok; // Status of MD lookup171 psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->site, "CAMERAS"); // Known cameras172 if (!mdok || !cameras) {173 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the site configuration.\n");174 return NULL;175 }176 camera = psMetadataLookupMetadata(&mdok, cameras, cameraName); // Camera configuration of interest177 if (!mdok || !camera) {178 psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find automatically generated "179 "camera configuration %s in site configuration.\n", cameraName);180 return NULL;181 }182 183 if (fpa && fpa->camera && fpa->camera != camera) {184 psAbort("Camera of bound FPA is not the requested camera --- there is an inconsistency!");185 }186 }187 238 file->camera = psMemIncrRefCounter(camera); 188 239 file->cameraName = psMemIncrRefCounter(cameraName);
Note:
See TracChangeset
for help on using the changeset viewer.
