IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 4, 2008, 5:45:56 PM (18 years ago)
Author:
Paul Price
Message:

Removing use of pmConfig.complete in favour of proper use of what's now called pmConfigFileIngest (used to be metadataItemReadFile). The idea is that configuration files are read in to the metadata item where they are defined. The result is that the .ipprc (pmConfig.user) can be dumped to a file, and will contain all the other stuff as well, so that it can be loaded in (using '-ipprc XXX' on the command-line) and we have a fully defined configuration without having to load anything else (which may have changed). The problem with pmConfig.complete was that it produced multiple unsynchronised versions: you could access and change data in pmConfig.complete without pmConfig.user or pmConfig.system being updated. This check in restores things to the way they used to be, where everything is synchronised.

File:
1 edited

Legend:

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

    r18905 r18908  
    5757    psFree(config->site);
    5858    psFree(config->system);
    59     psFree(config->complete);
    6059    psFree(config->files);
    6160    psFree(config->camera);
     
    139138    config->site = NULL;
    140139    config->system = NULL;
    141     config->complete = NULL;
    142140    config->camera = NULL;
    143141    config->cameraName = NULL;
     
    232230bool pmConfigFileRead(psMetadata **config, const char *name, const char *description)
    233231{
    234     PS_ASSERT_PTR_NON_NULL(config, false);
    235     PS_ASSERT_STRING_NON_EMPTY(name, false);
    236     PS_ASSERT_STRING_NON_EMPTY(description, false);
     232    assert(config);
     233    assert(name);
     234    assert(description);
    237235
    238236    char *realName = NULL;
     
    313311}
    314312
    315 // Read a file into a metadataItem, if required
    316 static bool metadataItemReadFile(psMetadataItem *item, // Item into which to read file
    317                                  const char *description // Description, for error messages
    318     )
    319 {
    320     assert(item);
    321     assert(description);
     313bool pmConfigFileIngest(psMetadataItem *item, const char *description)
     314{
     315    PS_ASSERT_METADATA_ITEM_NON_NULL(item, false);
     316    PS_ASSERT_STRING_NON_EMPTY(description, false);
    322317
    323318    if (item->type == PS_DATA_METADATA) {
     
    357352    psMetadataItem *item;               // Item from iteration
    358353    while ((item = psMetadataGetAndIncrement(iter))) {
    359         if (!metadataItemReadFile(item, description)) {
     354        if (!pmConfigFileIngest(item, description)) {
    360355            psError(PM_ERR_CONFIG, false, "Unable to read %s %s.", description, item->name);
    361356            psFree(iter);
     
    400395    psMetadataItem *darkNorm = psMetadataLookup(camera, "DARK.NORM"); // The dark normalisation calibration
    401396    if (darkNorm) {
    402         if (darkNorm->type == PS_DATA_STRING) {
    403             const char *darkNormName = darkNorm->data.str; // The file name
    404             psTrace("config", 2, "Reading %s dark normalisation: %s\n", cameraName, darkNormName);
    405             psMetadata *new = NULL;         // New metadata
    406             if (!pmConfigFileRead(&new, darkNormName, "Dark normalisation")) {
    407                 psError(PM_ERR_CONFIG, false, "Trouble reading reading %s dark normalisation %s --- "
    408                         "ignored.\n", cameraName, darkNormName);
    409                 psFree(new);
    410                 return false;
    411             }
    412 
    413             // Muck around under the hood to replace the filename with the metadata;
    414             // don't try this at home, kids
    415             darkNorm->type = PS_DATA_METADATA;
    416             psFree(darkNorm->data.str);
    417             darkNorm->data.md = new;
    418         } else if (darkNorm->type != PS_DATA_METADATA) {
    419             psWarning("DARK.NORM in camera %s is not of type STR or METADATA (%x)",
    420                       cameraName, darkNorm->type);
     397        if (!pmConfigFileIngest(darkNorm, "dark normalisation")) {
     398            psWarning("Unable to ingest DARK.NORM in camera %s", cameraName);
    421399        }
    422400    } else {
     
    505483
    506484    // read the SITE file
    507     psString siteFile = psMetadataLookupStr(NULL, config->user, "SITE");
    508     if (!pmConfigFileRead(&config->site, siteFile, "site")) {
     485    psMetadataItem *siteItem = psMetadataLookup(config->user, "SITE");
     486    if (!siteItem) {
     487        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to find SITE in user configuration.");
    509488        psFree(config);
    510489        return NULL;
    511490    }
    512 
    513     // load the SYSTEM file
    514     psString systemFile = psMetadataLookupStr(NULL, config->user, "SYSTEM");
    515     if (!pmConfigFileRead(&config->system, systemFile, "system")) {
     491    if (!pmConfigFileIngest(siteItem, "site configuration")) {
     492        psError(PS_ERR_UNKNOWN, false, "Unable to read site configuration");
    516493        psFree(config);
    517494        return NULL;
    518495    }
    519 
    520     // interpolate USER, SITE and SYSTEM into the config->complete metadata
    521     config->complete = psMetadataCopy (NULL,             config->user);
    522     config->complete = psMetadataCopy (config->complete, config->site);
    523     config->complete = psMetadataCopy (config->complete, config->system);
     496    config->site = psMemIncrRefCounter(siteItem->data.md);
     497
     498    // load the SYSTEM file
     499    psMetadataItem *systemItem = psMetadataLookup(config->user, "SYSTEM");
     500    if (!systemItem) {
     501        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unable to find SYSTEM in user configuration.");
     502        psFree(config);
     503        return NULL;
     504    }
     505    if (!pmConfigFileIngest(systemItem, "system configuration")) {
     506        psError(PS_ERR_UNKNOWN, false, "Unable to read system configuration");
     507        psFree(config);
     508        return NULL;
     509    }
     510    config->system = psMemIncrRefCounter(systemItem->data.md);
    524511
    525512    // Set LOG and TRACE options based on the user configuration.  These must be set AFTER
     
    651638        // Initialise the psLib time handling
    652639        // XXX is this still needed / desired?
    653         psString timeName = psMetadataLookupStr(&mdok, config->complete, "TIME");
    654         if (mdok && timeName)
    655         {
     640        psString timeName = psMetadataLookupStr(&mdok, config->system, "TIME");
     641        if (mdok && timeName) {
    656642            psTrace("psModules.config", 7, "Initialising psTime with file %s\n", timeName);
    657643            psTimeInit(timeName);
     
    671657            char *cameraName = argv[argNum]; // symbolic name of the camera
    672658
    673             // look for the CAMERAS list in config->complete
    674             psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->complete, "CAMERAS");
     659            // look for the CAMERAS list in config->system
     660            psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->system, "CAMERAS");
    675661            if (!cameras) {
    676662                psError(PS_ERR_IO, false, "Unable to find CAMERAS in site configuration.\n");
     
    718704                                  "Camera specified on command line", config->camera);
    719705
    720             if (!pmConfigCameraSkycellVersion(config->complete, cameraName)) {
     706            if (!pmConfigCameraSkycellVersion(config->system, cameraName)) {
    721707                psError(PS_ERR_UNKNOWN, false,
    722708                        "Unable to generate skycell versions of specified camera %s.\n",
     
    726712            }
    727713
    728             if (!pmConfigCameraMosaickedVersions(config->complete, cameraName)) {
     714            if (!pmConfigCameraMosaickedVersions(config->system, cameraName)) {
    729715                psError(PS_ERR_UNKNOWN, false,
    730716                        "Unable to generate mosaicked versions of specified camera %s.\n",
     
    739725    if (!config->camera && readCameraConfig) {
    740726        bool mdok;                      // Status of MD lookup
    741         psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->complete, "CAMERAS"); // List of cameras
     727        psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->system, "CAMERAS"); // List of cameras
    742728        if (!mdok || !cameras) {
    743729            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to find CAMERAS in the system configuration.\n");
     
    773759        psFree(iter);
    774760
    775         if (!pmConfigCameraSkycellVersionsAll(config->complete)) {
     761        if (!pmConfigCameraSkycellVersionsAll(config->system)) {
    776762            psError(PS_ERR_UNKNOWN, false, "Unable to generate skycell versions of cameras.\n");
    777763            psFree(config);
    778764            return NULL;
    779765        }
    780         if (!pmConfigCameraMosaickedVersionsAll(config->complete)) {
     766        if (!pmConfigCameraMosaickedVersionsAll(config->system)) {
    781767            psError(PS_ERR_UNKNOWN, false, "Unable to generate mosaicked versions of cameras.\n");
    782768            psFree(config);
     
    817803        psArgumentRemove(argNum, argc, argv);
    818804
    819         psMetadata *cameras = psMetadataLookupMetadata(NULL, config->complete, "CAMERAS"); // List of cameras
     805        psMetadata *cameras = psMetadataLookupMetadata(NULL, config->system, "CAMERAS"); // List of cameras
    820806        if (!cameras) {
    821807            psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find CAMERAS in the site configuration.\n");
     
    865851        } else {
    866852            char *dbserver = argv[argNum]; // The camera configuration file to read
    867             if (!psMetadataAddStr(config->complete, PS_LIST_TAIL, "DBSERVER", PS_META_REPLACE,
     853            if (!psMetadataAddStr(config->user, PS_LIST_TAIL, "DBSERVER", PS_META_REPLACE,
    868854                                  NULL, dbserver)) {
    869855                psWarning("Failed to overwrite .ipprc DBSERVER value");
     
    881867        } else {
    882868            char *dbname = argv[argNum]; // The camera configuration file to read
    883             if (!psMetadataAddStr(config->complete, PS_LIST_TAIL, "DBNAME", PS_META_REPLACE, NULL, dbname)) {
     869            if (!psMetadataAddStr(config->user, PS_LIST_TAIL, "DBNAME", PS_META_REPLACE, NULL, dbname)) {
    884870                psWarning("Failed to overwrite .ipprc DBNAME value");
    885871            }
     
    896882        } else {
    897883            char *dbuser = argv[argNum]; // The camera configuration file to read
    898             if (!psMetadataAddStr(config->complete, PS_LIST_TAIL, "DBUSER", PS_META_REPLACE, NULL, dbuser)) {
     884            if (!psMetadataAddStr(config->user, PS_LIST_TAIL, "DBUSER", PS_META_REPLACE, NULL, dbuser)) {
    899885                psWarning("Failed to overwrite .ipprc DBUSER value");
    900886            }
     
    911897        } else {
    912898            char *dbpassword = argv[argNum]; // The camera configuration file to read
    913             if (!psMetadataAddStr(config->complete, PS_LIST_TAIL, "DBPASSWORD", PS_META_REPLACE,
     899            if (!psMetadataAddStr(config->user, PS_LIST_TAIL, "DBPASSWORD", PS_META_REPLACE,
    914900                                  NULL, dbpassword)) {
    915901                psWarning("Failed to overwrite .ipprc DBPASSWORD value");
     
    927913        } else {
    928914            char *dbport = argv[argNum]; // The camera configuration file to read
    929             if (!psMetadataAddS32(config->complete, PS_LIST_TAIL, "DBPORT", PS_META_REPLACE, NULL,
     915            if (!psMetadataAddS32(config->user, PS_LIST_TAIL, "DBPORT", PS_META_REPLACE, NULL,
    930916                                  (psS32)atoi(dbport))) {
    931917                psWarning("Failed to overwrite .ipprc DBPORT value");
     
    11131099
    11141100        bool mdok;                      // Metadata lookup status
    1115         psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->complete, "CAMERAS");
     1101        psMetadata *cameras = psMetadataLookupMetadata(&mdok, config->system, "CAMERAS");
    11161102        if (! mdok || !cameras) {
    11171103            psError(PS_ERR_IO, true, "Unable to find CAMERAS in the configuration.");
     
    11831169    char *testName = NULL;
    11841170
    1185     psMetadata *cameras = psMetadataLookupMetadata (NULL, config->complete, "CAMERAS");
     1171    psMetadata *cameras = psMetadataLookupMetadata (NULL, config->system, "CAMERAS");
    11861172    psAssert (cameras, "missing CAMERAS in complete metadata");
    11871173
     
    12631249    PS_ASSERT_STRING_NON_EMPTY(cameraName, NULL);
    12641250
    1265     psMetadata *cameras = psMetadataLookupMetadata(NULL, config->complete, "CAMERAS");
     1251    psMetadata *cameras = psMetadataLookupMetadata(NULL, config->system, "CAMERAS");
    12661252    if (!cameras) {
    12671253        psError(PS_ERR_IO, true, "Unable to find CAMERAS in the configuration.");
     
    12691255    }
    12701256
    1271     char *cameraPath = psMetadataLookupStr(NULL, cameras, cameraName);
    1272     if (!cameraPath) {
    1273         psError(PS_ERR_IO, true, "Unable to find requested CAMERA in the configuration.");
     1257    psMetadataItem *item = psMetadataLookup(cameras, cameraName); // Item with camera of interest
     1258    if (!pmConfigFileIngest(item, "camera configuration")) {
     1259        psError(PS_ERR_UNKNOWN, false, "Unable to ingest camera configuration.");
    12741260        return NULL;
    12751261    }
    12761262
    1277     psMetadata *camera = NULL; // Camera to test against what we've got:
    1278 
    1279     if (!pmConfigFileRead(&camera, cameraPath, cameraName)) {
    1280         psWarning("Trouble reading reading camera configuration %s", cameraName);
    1281         psFree(camera);
    1282         return NULL;
    1283     }
    1284 
    1285     return camera;
     1263    return psMemIncrRefCounter(item->data.md);
    12861264}
    12871265
     
    12891267{
    12901268    PS_ASSERT_PTR_NON_NULL(config, NULL);
    1291     PS_ASSERT_PTR_NON_NULL(config->complete, NULL);
     1269    PS_ASSERT_PTR_NON_NULL(config->user, NULL);
    12921270
    12931271    #ifndef HAVE_PSDB
     
    13101288
    13111289    // XXX leaky strings
    1312     psString dbServer = psMetadataLookupStr(&mdStatus01, config->complete, "DBSERVER");
    1313     psString dbUsername = psMetadataLookupStr(&mdStatus02, config->complete, "DBUSER");
    1314     psString dbPassword = psMetadataLookupStr(&mdStatus03, config->complete, "DBPASSWORD");
    1315     psString dbName = psMetadataLookupStr(&mdStatus04, config->complete, "DBNAME");
    1316     psS32 dbPort = psMetadataLookupS32(&mdStatus05, config->complete, "DBPORT");
     1290    psString dbServer = psMetadataLookupStr(&mdStatus01, config->user, "DBSERVER");
     1291    psString dbUsername = psMetadataLookupStr(&mdStatus02, config->user, "DBUSER");
     1292    psString dbPassword = psMetadataLookupStr(&mdStatus03, config->user, "DBPASSWORD");
     1293    psString dbName = psMetadataLookupStr(&mdStatus04, config->user, "DBNAME");
     1294    psS32 dbPort = psMetadataLookupS32(&mdStatus05, config->user, "DBPORT");
    13171295    if (!mdStatus05) {
    13181296        dbPort = 0;
     
    15271505    // replace path://PATH with matched datapath
    15281506    if (!strncasecmp(filename, "path://", strlen("path://"))) {
    1529         PS_ASSERT_METADATA_NON_NULL(config->complete, NULL);
     1507        PS_ASSERT_METADATA_NON_NULL(config->site, NULL);
    15301508
    15311509        psString newName = psStringCopy(filename);
    15321510
    15331511        // filename should be of the form: path://PATH/rest/of/file
    1534         // replace PATH with matching name from config->complete:DATAPATH
    1535         psMetadata *datapath = psMetadataLookupPtr (NULL, config->complete, "DATAPATH");
     1512        // replace PATH with matching name from config->site:DATAPATH
     1513        psMetadata *datapath = psMetadataLookupPtr (NULL, config->site, "DATAPATH");
    15361514        if (datapath == NULL) {
    15371515            psError(PS_ERR_UNKNOWN, true, "DATAPATH is not defined in config.site");
     
    15861564        // if env isn't set, check the config system
    15871565        if (!neb_server) {
    1588             neb_server = psMetadataLookupStr(&status, config->complete, "NEB_SERVER");
     1566            neb_server = psMetadataLookupStr(&status, config->site, "NEB_SERVER");
    15891567            if (!status) {
    15901568                psError(PM_ERR_CONFIG, true, "failed to lookup config value for NEB_SERVER.");
     
    16621640    }
    16631641
    1664     if (!metadataItemReadFile(item, "file rules ")) {
     1642    if (!pmConfigFileIngest(item, "file rules ")) {
    16651643        psError(PM_ERR_CONFIG, false, "Unable to read file rules for camera.");
    16661644        return NULL;
     
    16951673    }
    16961674
    1697     if (!metadataItemReadFile(item, "FITS Types")) {
     1675    if (!pmConfigFileIngest(item, "FITS Types")) {
    16981676        psError(PM_ERR_CONFIG, false, "Unable to read fits types for camera.");
    16991677        return NULL;
Note: See TracChangeset for help on using the changeset viewer.