IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 8, 2007, 12:26:06 PM (19 years ago)
Author:
Paul Price
Message:

Adding facilities to automatically generate mosaicked versions of cameras on the fly. To support this, changed the configuration system to load the camera config and camera format configs so that these remain in memory (replacing the filename with the psMetadata that results from reading the file). New mosaicked cameras have the names _CAMERA-CHIP and _CAMERA-FPA for an unmosaicked camera named CAMERA. These are placed at the top of the camera list, so that they are compared first against FITS headers. pmConfigCameraFormatFromHeader still outputs a warning if called on the header from a mosaicked camera, because the unmosaicked version also matches (the addition of a header, rather than changing a header means that something without that header in the RULE also matches).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/config/pmConfig.c

    r10882 r10965  
    44 *  @author EAM (IfA)
    55 *
    6  *  @version $Revision: 1.69 $ $Name: not supported by cvs2svn $
    7  *  @date $Date: 2007-01-03 02:58:38 $
     6 *  @version $Revision: 1.70 $ $Name: not supported by cvs2svn $
     7 *  @date $Date: 2007-01-08 22:26:06 $
    88 *
    99 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2626#include "pmConfig.h"
    2727#include "pmConfigRecipes.h"
     28#include "pmConfigCamera.h"
    2829
    2930#define PS_SITE "PS_SITE"         // Name of the environment variable containing the site config file
    3031#define PS_DEFAULT_SITE ".ipprc"  // Default site config file
    3132
     33static bool readCameraConfig = true;    // Read the camera config on startup (with pmConfigRead)?
    3234static psArray *configPath = NULL;      // Search path for configuration files
     35
     36bool pmConfigReadParamsSet(bool newReadCameraConfig)
     37{
     38    bool oldReadCameraConfig = readCameraConfig;
     39    readCameraConfig = newReadCameraConfig;
     40    return oldReadCameraConfig;
     41}
    3342
    3443static void configFree(pmConfig *config)
     
    3847    psFree(config->camera);
    3948    psFree(config->cameraName);
     49    psFree(config->format);
     50    psFree(config->formatName);
    4051    psFree(config->recipes);
    4152    psFree(config->recipeSymbols);
     
    5364    config->camera = NULL;
    5465    config->cameraName = NULL;
     66    config->format = NULL;
     67    config->formatName = NULL;
    5568    config->recipes = psMetadataAlloc();
    5669    config->recipesRead = PM_RECIPE_SOURCE_NONE;
     
    207220
    208221    psFree (realName);
     222    return true;
     223}
     224
     225// Read metadata config files in a metadata
     226// The metadata contains file names, which will be replaced with the metadata that are in the files.
     227static bool metadataReadFiles(psMetadata *source, // Source metadata
     228                              const char *description // Description, for error messages
     229                             )
     230{
     231    assert(source);
     232    psMetadataIterator *iter = psMetadataIteratorAlloc(source, PS_LIST_HEAD, NULL); // Iterator
     233    psMetadataItem *item;               // Item from iteration
     234    while ((item = psMetadataGetAndIncrement(iter))) {
     235        if (item->type == PS_DATA_METADATA) {
     236            continue;       // We've already read it
     237        }
     238        if (item->type != PS_DATA_STRING) {
     239            psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Element %s in %s metadata is not of type STR.\n",
     240                    item->name, description);
     241            continue;
     242        }
     243
     244        psTrace("config", 2, "Reading %s %s: %s\n", description, item->name, item->data.str);
     245        psMetadata *new = NULL;         // New metadata
     246        if (!pmConfigFileRead(&new, item->data.str, item->name)) {
     247            psLogMsg("psModules.config", PS_LOG_WARN, "Trouble reading reading %s %s --- "
     248                     "ignored.\n", description, item->name);
     249            psFree(new);
     250            psMetadataRemoveKey(source, item->name); // Take it out, so it will not trouble us again
     251            continue;
     252        }
     253
     254        // Muck around under the hood to replace the filename with the metadata; don't try this at home, kids
     255        item->type = PS_DATA_METADATA;
     256        psFree(item->data.str);
     257        item->data.md = new;
     258    }
     259    psFree(iter);
     260
     261    return true;
     262}
     263
     264// Read the formats for a camera
     265static bool cameraReadFormats(psMetadata *camera, // Camera for which to read the formats
     266                              const char *name // Name of the camera, for error messages
     267                             )
     268{
     269    assert(camera);
     270    assert(name);
     271
     272    bool mdok;                          // Status of MD lookup
     273    psMetadata *formats = psMetadataLookupMetadata(&mdok, camera, "FORMATS"); // Formats
     274    if (!mdok || !formats) {
     275        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find FORMATS in camera configuration %s.\n", name);
     276        return false;
     277    }
     278    if (!metadataReadFiles(formats, "camera format")) {
     279        psError(PS_ERR_UNKNOWN, false, "Unable to read formats within camera configuration %s.\n", name);
     280        return false;
     281    }
     282
    209283    return true;
    210284}
     
    274348    }
    275349
    276 
    277 
    278350    // Set options based on the site configuration.
    279351    {
     
    437509            pmConfigFileRead(&config->camera, cameraFile, "camera");
    438510            psArgumentRemove(argNum, config->argc, config->argv);
     511
     512            // Read in the formats
     513            if (!cameraReadFormats(config->camera, cameraFile)) {
     514                psError(PS_ERR_UNKNOWN, false, "Unable to read formats within camera configuration %s.\n",
     515                        cameraFile);
     516                psFree(config);
     517                return NULL;
     518            }
     519
     520            psMetadataAddMetadata(cameras, PS_LIST_HEAD, cameraFile, PS_META_REPLACE,
     521                                  "Camera specified on command line", config->camera);
     522
     523            if (!pmConfigCameraMosaickedVersions(config->site, cameraFile)) {
     524                psError(PS_ERR_UNKNOWN, false,
     525                        "Unable to generate mosaicked versions of specified camera %s.\n",
     526                        cameraFile);
     527                psFree(config);
     528                return NULL;
     529            }
     530        }
     531    }
     532
     533    // Read the camera configurations, if not already defined, and not turned off
     534    if (!config->camera && readCameraConfig) {
     535        bool mdok;                      // Status of MD lookup
     536        psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->site, "CAMERAS"); // List of cameras
     537        if (!mdok || !cameras) {
     538            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the site configuration.\n");
     539            return false;
     540        }
     541
     542        if (!metadataReadFiles(cameras, "camera configuration")) {
     543            psError(PS_ERR_UNKNOWN, false, "Unable to read cameras within site configuration.\n");
     544            psFree(config);
     545            return NULL;
     546        }
     547
     548        // Now fill in the formats
     549        psMetadataIterator *iter = psMetadataIteratorAlloc(cameras, PS_LIST_HEAD, NULL); // Iterator
     550        psMetadataItem *item;           // Item from iteration
     551        while ((item = psMetadataGetAndIncrement(iter))) {
     552            assert(item->type == PS_DATA_METADATA);
     553            if (!cameraReadFormats(item->data.md, item->name)) {
     554                psWarning("Unable to read formats for camera %s: removed.\n", item->name);
     555                psMetadataRemoveKey(cameras, item->name);
     556            }
     557        }
     558        psFree(iter);
     559
     560        if (!pmConfigCameraMosaickedVersionsAll(config->site)) {
     561            psError(PS_ERR_UNKNOWN, false, "Unable to generate mosaicked versions of cameras.\n");
     562            psFree(config);
     563            return NULL;
    439564        }
    440565    }
     
    448573
    449574    // load command-line options of the form -recipe NAME RECIPE
    450     pmConfigLoadRecipeArguments (config);
     575    pmConfigLoadRecipeArguments(config);
    451576
    452577    // read in command-line options to specific recipe values
    453     pmConfigLoadRecipeOptions (config, "-D");
    454     pmConfigLoadRecipeOptions (config, "-Di");
    455     pmConfigLoadRecipeOptions (config, "-Df");
    456     pmConfigLoadRecipeOptions (config, "-Db");
     578    pmConfigLoadRecipeOptions(config, "-D");
     579    pmConfigLoadRecipeOptions(config, "-Di");
     580    pmConfigLoadRecipeOptions(config, "-Df");
     581    pmConfigLoadRecipeOptions(config, "-Db");
    457582
    458583
     
    589714}
    590715
     716
    591717// Given a camera and a header, see if any of the camera formats match the header
    592718static bool formatFromHeader(psMetadata **format, // Format to return
     719                             psString *name, // Name to return
    593720                             psMetadata *camera, // Camera configuration
    594721                             const psMetadata *header, // FITS header
     
    610737        return false;
    611738    }
     739
     740    if (!metadataReadFiles(formats, "camera format")) {
     741        psError(PS_ERR_UNKNOWN, false, "Unable to read cameras formats within camera configuration.\n");
     742        return false;
     743    }
     744
    612745    // Iterate over the formats
    613746    psMetadataIterator *formatsIter = psMetadataIteratorAlloc(formats, PS_LIST_HEAD, NULL);
    614747    psMetadataItem *formatsItem = NULL; // Item from formats
    615748    while ((formatsItem = psMetadataGetAndIncrement(formatsIter))) {
    616         if (formatsItem->type != PS_DATA_STRING) {
    617             psError(PS_ERR_UNKNOWN, false, "In camera %s, camera format %s is not of type STR", cameraName, formatsItem->name);
    618             return false;
    619         }
    620         psTrace("psModules.config", 5, "Reading camera format for %s...\n", formatsItem->name);
    621         psMetadata *testFormat = NULL;  // Format to test against what we've got
    622         if (!pmConfigFileRead(&testFormat, formatsItem->data.V, formatsItem->name)) {
    623             psError(PS_ERR_UNKNOWN, false, "Trouble reading reading camera format %s", formatsItem->name);
    624             psFree(testFormat);
    625             return false;
    626         }
     749        assert(formatsItem->type == PS_DATA_METADATA); // Since we have just read it in or deleted it
     750        psMetadata *testFormat = formatsItem->data.md; // Format to test against
    627751
    628752        if (pmConfigValidateCameraFormat(testFormat, header)) {
    629753            if (!*format) {
    630                 psLogMsg("psModules.config", PS_LOG_INFO, "Camera %s, format %s matches header.\n", cameraName,
    631                          formatsItem->name);
     754                psLogMsg("psModules.config", PS_LOG_INFO, "Camera %s, format %s matches header.\n",
     755                         cameraName, formatsItem->name);
    632756                *format = psMemIncrRefCounter(testFormat);
     757                *name = psStringCopy(formatsItem->name);
    633758                result = true;
    634759            } else {
    635                 psLogMsg("psModules.config", PS_LOG_WARN, "Camera %s, format %s also matches header --- ignored.\n",
     760                psLogMsg("psModules.config", PS_LOG_WARN,
     761                         "Camera %s, format %s also matches header --- ignored.\n",
    636762                         cameraName, formatsItem->name);
    637763            }
     
    639765            psErr *error = psErrorLast();
    640766            if (error->code != PS_ERR_NONE) {
    641                 psError (PS_ERR_UNKNOWN, false, "Error in config scripts for camera %s, format %s\n", cameraName, formatsItem->name);
     767                psError (PS_ERR_UNKNOWN, false, "Error in config scripts for camera %s, format %s\n",\
     768                         cameraName, formatsItem->name);
    642769                return false;
    643770            }
    644771            psFree(error);
    645772        }
    646         psFree(testFormat);
    647773    }
    648774    psFree(formatsIter);
     
    657783    PS_ASSERT_PTR_NON_NULL(header, NULL);
    658784
     785
    659786    psMetadata *format = NULL;          // The winning format
    660     bool mdok = false;                  // Metadata lookup status
     787    psString name = NULL;               // Name of the winning format
    661788
    662789    // If we don't know what sort of camera we have, we try all that we know
    663790    if (! config->camera) {
     791        bool mdok;                      // Metadata lookup status
    664792        psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->site, "CAMERAS");
    665         if (! mdok) {
     793        if (! mdok || !cameras) {
    666794            psError(PS_ERR_IO, true, "Unable to find CAMERAS in the configuration.");
    667             return false;
     795            return NULL;
     796        }
     797
     798        if (!metadataReadFiles(cameras, "camera configuration")) {
     799            psError(PS_ERR_UNKNOWN, false, "Unable to read cameras within site configuration.\n");
     800            return NULL;
    668801        }
    669802
     
    675808            psTrace("psModules.config", 3, "Inspecting camera %s (%s)\n", camerasItem->name,
    676809                    camerasItem->comment);
    677             if (camerasItem->type != PS_DATA_STRING) {
    678                 psLogMsg("psModules.config", PS_LOG_WARN, "Camera configuration for %s in CAMERAS is not of type STR "
    679                          "--- ignored.\n", camerasItem->name);
    680                 continue;
    681             }
    682 
    683             psTrace("psModules.config", 5, "Reading camera configuration for %s...\n", camerasItem->name);
    684             psMetadata *testCamera = NULL; // Camera to test against what we've got:
    685 
    686             if (!pmConfigFileRead(&testCamera, camerasItem->data.V, camerasItem->name)) {
    687                 psLogMsg("psModules.config", PS_LOG_WARN, "Trouble reading reading camera configuration %s --- "
    688                          "ignored.\n", camerasItem->name);
    689                 psFree(testCamera);
    690                 continue;
    691             }
    692 
    693             if (formatFromHeader(&format, testCamera, header, camerasItem->name)) {
     810            assert(camerasItem->type == PS_DATA_METADATA); // It should be because we've read it in or deleted
     811            psMetadata *testCamera = camerasItem->data.md; // Camera to test against what we've got:
     812            if (formatFromHeader(&format, &name, testCamera, header, camerasItem->name)) {
    694813                config->camera = psMemIncrRefCounter(testCamera);
    695814                config->cameraName = psStringCopy(camerasItem->name);
     815                config->formatName = name;
     816                config->format = psMemIncrRefCounter(format);
    696817            } else {
    697818                psErr *error = psErrorLast();
     
    702823                psFree(error);
    703824            }
    704             psFree(testCamera);
    705825        } // Done looking at all cameras
    706826        psFree(camerasIter);
     
    717837
    718838    // Otherwise, try the specific camera
    719     if (!formatFromHeader(&format, config->camera, header, config->cameraName)) {
     839    if (!formatFromHeader(&format, &name, config->camera, header, config->cameraName)) {
    720840        psError(PS_ERR_IO, true, "Unable to find a format with the specified camera (%s) that matches the "
    721841                "given header.\n", config->cameraName);
    722842        return NULL;
    723843    }
     844    config->formatName = name;
     845    config->format = psMemIncrRefCounter(format);
    724846    return format;
    725847}
Note: See TracChangeset for help on using the changeset viewer.