- Timestamp:
- Mar 13, 2006, 4:23:40 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/rel10_ifa/psModules/src/astrom/pmConceptsWrite.c
r6570 r6575 4 4 5 5 #include "pmFPA.h" 6 #include "pmHDU.h" 7 #include "pmHDUGetLowest.h" 8 #include "pmConcepts.h" 6 9 #include "pmConceptsRead.h" 7 10 #include "psAdditionals.h" … … 89 92 return formatted; 90 93 } 94 return NULL; 91 95 } 92 96 … … 127 131 { 128 132 if (cell) { 129 pmHDU *hdu = getLowestHDU(NULL, NULL, cell); // The HDU at the lowest level133 pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // The HDU at the lowest level 130 134 psMetadata *cameraFormat = hdu->format; // The camera format 131 135 psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator … … 142 146 psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, NULL, NULL, cell); 143 147 psString nameSource = NULL; // String with the concept name and ".SOURCE" added 144 psStringAppend( nameSource, "%s.SOURCE", name);148 psStringAppend(&nameSource, "%s.SOURCE", name); 145 149 bool mdok = true; // Status of MD lookup 146 150 psString source = psMetadataLookupStr(&mdok, cell->config, nameSource); // The source … … 149 153 if (cameraItem->type != PS_DATA_STRING) { 150 154 psLogMsg(__func__, PS_LOG_WARN, "Concept %s is specified by header, but is not " 151 "of type STR --- ignored.\n", conceptItem->name) 155 "of type STR --- ignored.\n", conceptItem->name); 152 156 continue; 153 157 } … … 181 185 182 186 183 bool pmConceptsWriteToDefault(psMetadata *specs, // The concept specifications 184 pmFPA *fpa, // The FPA 185 pmChip *chip, // The chip 186 pmCell *cell, // The cell 187 psMetadata *concepts // The concepts 188 ) 189 { 190 bool mdok = true; // Status of MD lookup 187 bool pmConceptsWriteToDefaults(psMetadata *specs, // The concept specifications 188 pmFPA *fpa, // The FPA 189 pmChip *chip, // The chip 190 pmCell *cell, // The cell 191 psMetadata *concepts // The concepts 192 ) 193 { 194 pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // The HDU at the lowest level 195 psMetadata *cameraFormat = hdu->format; // The camera format 196 bool mdok = true; // Status of MD lookup 191 197 psMetadata *defaults = psMetadataLookupMD(&mdok, cameraFormat, "DEFAULTS"); // The DEFAULTS spec 192 198 if (mdok && defaults) { 193 pmHDU *hdu = getLowestHDU(fpa, chip, cell); // The HDU at the lowest level199 pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level 194 200 psMetadata *cameraFormat = hdu->format; // The camera format 195 201 psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator … … 202 208 psMetadataItem *conceptItem = psMetadataLookup(concepts, name); // The item from the concepts 203 209 psMetadataItem *formatted = conceptFormat(spec, conceptItem, cameraFormat, fpa, chip, cell); 204 if (! compareConcepts( cameraItem, formatted)) {210 if (! compareConcepts(defaultItem, formatted)) { 205 211 psLogMsg(__func__, PS_LOG_WARN, "Concept %s is specified by the DEFAULTS in the camera " 206 212 "format, but the values don't match.\n"); … … 222 228 ) 223 229 { 224 bool mdok = true; // Status of MD lookup 230 pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // The HDU at the lowest level 231 psMetadata *cameraFormat = hdu->format; // The camera format 232 bool mdok = true; // Status of MD lookup 225 233 psMetadata *translation = psMetadataLookupMD(&mdok, cameraFormat, "TRANSLATION"); // The TRANSLATION spec 226 234 if (mdok && translation) { 227 pmHDU *hdu = getLowestHDU(fpa, chip, cell); // The HDU at the lowest level235 pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level 228 236 psMetadata *cameraFormat = hdu->format; // The camera format 229 237 psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator … … 271 279 } 272 280 273 281 // XXX Warning: This code has not been tested at all 274 282 bool pmConceptsWriteToDatabase(psMetadata *specs, // The concept specifications 275 283 pmFPA *fpa, // The FPA … … 280 288 ) 281 289 { 282 bool mdok = true; // Status of MD lookup 290 pmHDU *hdu = pmHDUGetLowest(NULL, NULL, cell); // The HDU at the lowest level 291 psMetadata *cameraFormat = hdu->format; // The camera format 292 bool mdok = true; // Status of MD lookup 283 293 psMetadata *database = psMetadataLookupMD(&mdok, cameraFormat, "DATABASE"); // The DATABASE spec 284 294 if (mdok && database) { 285 pmHDU *hdu = getLowestHDU(fpa, chip, cell); // The HDU at the lowest level295 pmHDU *hdu = pmHDUGetLowest(fpa, chip, cell); // The HDU at the lowest level 286 296 psMetadata *cameraFormat = hdu->format; // The camera format 287 297 psMetadataIterator *specsIter = psMetadataIteratorAlloc(specs, PS_LIST_HEAD, NULL); // Iterator … … 291 301 psString name = specItem->name; // The concept name 292 302 293 psMetadataItem *dbItem = psMetadataLookup( &mdok,database, name); // The item from the DATABASE303 psMetadataItem *dbItem = psMetadataLookup(database, name); // The item from the DATABASE 294 304 if (dbItem) { 295 305 if (dbItem->type != PS_DATA_METADATA) { … … 304 314 psMetadata *dbLookup = dbItem->data.V; // How to look up the value of interest 305 315 // Name of the table 306 const char *tableName = psMetadataLookupStr(&md Status, dbLookup, "TABLE");316 const char *tableName = psMetadataLookupStr(&mdok, dbLookup, "TABLE"); 307 317 // Name of "where" columns 308 const char *givenCols = psMetadataLookupStr(&md Status, dbLookup, "GIVENDBCOL");318 const char *givenCols = psMetadataLookupStr(&mdok, dbLookup, "GIVENDBCOL"); 309 319 // Values for "where" columns 310 const char *givenPS = psMetadataLookupStr(&md Status, dbLookup, "GIVENPS");320 const char *givenPS = psMetadataLookupStr(&mdok, dbLookup, "GIVENPS"); 311 321 312 322 // Now, need to get the "given"s … … 318 328 psLogMsg(__func__, PS_LOG_WARN, 319 329 "The GIVENDBCOL and GIVENPS entries for %s do not have " 320 "the same number of entries --- ignored.\n", concept);330 "the same number of entries --- ignored.\n", name); 321 331 } else { 322 332 // Iterators for the lists … … 325 335 char *column = NULL; // Name of the column 326 336 while ((column = psListGetAndIncrement(colsIter))) { 327 char * name = psListGetAndIncrement(valuesIter); // Name for the value337 char *dependName = psListGetAndIncrement(valuesIter); // Name for the value 328 338 if (!strlen(column) || !strlen(name)) { 329 339 psLogMsg(__func__, PS_LOG_WARN, "One of the columns or value names for %s is " 330 " empty --- ignored.\n", concept);340 " empty --- ignored.\n", name); 331 341 } else { 332 342 // Search for the value name 333 psMetadataItem *item = pmConceptReadFromHeader(fpa, chip, cell, name); 334 if (! item) { 335 item = pmConceptReadFromDefault(fpa, chip, cell, name); 343 psMetadataItem *item = NULL; // The value 344 if (!item && cell) { 345 item = psMetadataLookup(cell->concepts, dependName); 346 } 347 if (!item && chip) { 348 item = psMetadataLookup(chip->concepts, dependName); 349 } 350 if (!item && fpa) { 351 item = psMetadataLookup(fpa->concepts, dependName); 336 352 } 337 353 if (! item) { 338 354 psLogMsg(__func__, PS_LOG_ERROR, 339 355 "Unable to find the value name %s for DB " 340 " lookup on %s --- ignored.\n", name, concept);356 " lookup on %s --- ignored.\n", dependName, name); 341 357 } else { 342 358 // We need to create a new psMetadataItem. I don't think we can't simply … … 346 362 } 347 363 } 348 psFree( name);364 psFree(dependName); 349 365 psFree(column); 350 366 } // Iterating through the columns … … 357 373 if (! dbResult || dbResult->n == 0) { 358 374 psLogMsg(__func__, PS_LOG_WARN, "Unable to find any rows in DB for %s --- " 359 "ignored\n", concept->name);375 "ignored\n", name); 360 376 return false; 361 377 } else { 362 378 if (dbResult->n > 1) { 363 379 psLogMsg(__func__, PS_LOG_WARN, "Multiple rows returned in DB lookup for %s " 364 "--- ignored.\n", concept->name);380 "--- ignored.\n", name); 365 381 } 366 382 // Update the DB 367 383 psMetadata *update = psMetadataAlloc(); 368 psMetadataAddItem(update, concept , PS_LIST_HEAD, 0);384 psMetadataAddItem(update, conceptItem, PS_LIST_HEAD, 0); 369 385 psDBUpdateRows(db, tableName, selection, update); 370 386 psFree(update);
Note:
See TracChangeset
for help on using the changeset viewer.
