IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15217


Ignore:
Timestamp:
Oct 4, 2007, 10:15:48 AM (19 years ago)
Author:
Paul Price
Message:

Gene pointed out that the file rules are also read in pmConfig (when the '-F' switch is used on the command-line), and the new ability to read file rules from a separate file wasn't implemented there. I've moved the function that gets a file rule from pmFPAfileDefine.c to pmConfig.c (now named pmConfigFileRule), and now both the pmConfig and pmFPAfileDefine functions use this.

Location:
trunk/psModules/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/camera/pmFPAfileDefine.c

    r15183 r15217  
    2020#include "pmFPAConstruct.h"
    2121
    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     psMetadataItem *item = psMetadataLookup(camera, "FILERULES"); // Item with the file rule of interest
    35     if (!item) {
    36         psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find FILERULES in the camera configuration.");
    37         return NULL;
    38     }
    39 
    40     psMetadata *filerules = NULL;       // File rules from the site configuration
    41     switch (item->type) {
    42       case PS_DATA_METADATA:
    43         // It's what we're after
    44         filerules = item->data.md;
    45         break;
    46       case PS_DATA_STRING: {
    47           // It's the name of a file --- read the file, and store it for future use
    48           if (!pmConfigFileRead(&filerules, item->data.str, "filerules")) {
    49               psError(PM_ERR_CONFIG, false, "Trouble reading reading file rules from %s  --- "
    50                       "ignored.\n", item->data.str);
    51               psFree(filerules);
    52               return NULL;
    53           }
    54 
    55           // Muck around under the hood to replace the filename with the metadata; don't try this at home,
    56           // kids
    57           item->type = PS_DATA_METADATA;
    58           psFree(item->data.str);
    59           item->data.md = filerules;
    60           break;
    61       }
    62       default:
    63         psError(PS_ERR_BAD_PARAMETER_TYPE, true,
    64                 "Unexpected type for %s (%x) in FILERULES in SITE configuration.",
    65                 name, item->type);
    66         return NULL;
    67     }
    68 
    69     // select the name from the FILERULES
    70     // check for alias name (type == STR, name is aliased name)
    71     bool mdok;                          // Status of MD lookup
    72     const char *realname = psMetadataLookupStr(&mdok, filerules, name); // Name of file rule to look up
    73     if (!realname || strlen(realname) == 0) {
    74         realname = name;
    75     }
    76 
    77     return psMetadataLookupMetadata(NULL, filerules, realname);
    78 }
    79 
    8022// Parse an option from a metadata, returning the appropriate integer value
    8123static int parseOptionInt(const psMetadata *md, // Metadata containing the option
     
    10749
    10850    const psMetadata *camera = (fpa ? fpa->camera : config->camera); // Camera configuration for this file
    109     psMetadata *data = getFileRule(config, camera, name); // File rule
     51    psMetadata *data = pmConfigFileRule(config, camera, name); // File rule
    11052    if (!data) {
    11153        psError(PS_ERR_IO, true, "Can't find file rule %s!", name);
     
    198140    }
    199141
    200     psMetadata *data = getFileRule(config, camera, name); // File rule
     142    psMetadata *data = pmConfigFileRule(config, camera, name); // File rule
    201143    if (!data) {
    202144        psError(PS_ERR_IO, true, "Can't find file rule %s!", name);
  • trunk/psModules/src/config/pmConfig.c

    r15180 r15217  
    229229}
    230230
     231// Read a file into a metadataItem, if required
     232static bool metadataItemReadFile(psMetadataItem *item, // Item into which to read file
     233                                 const char *description // Description, for error messages
     234    )
     235{
     236    assert(item);
     237    assert(description);
     238
     239    if (item->type == PS_DATA_METADATA) {
     240        return true;                    // We've already read it
     241    }
     242    if (item->type != PS_DATA_STRING) {
     243        psTrace("config", 2, "Element %s in %s metadata is not of type STR.\n",
     244                item->name, description);
     245        return false;
     246    }
     247
     248    psTrace("config", 2, "Reading %s %s: %s\n", description, item->name, item->data.str);
     249    psMetadata *new = NULL;         // New metadata
     250    if (!pmConfigFileRead(&new, item->data.str, item->name)) {
     251        psError(PM_ERR_CONFIG, false, "Trouble reading reading %s %s.\n",
     252                description, item->name);
     253        psFree(new);
     254        return false;
     255    }
     256
     257    // Muck around under the hood to replace the filename with the metadata; don't try this at home, kids
     258    item->type = PS_DATA_METADATA;
     259    psFree(item->data.str);
     260    item->data.md = new;
     261
     262    return true;
     263}
     264
    231265// Read metadata config files in a metadata
    232266// The metadata contains file names, which will be replaced with the metadata that are in the files.
     
    239273    psMetadataItem *item;               // Item from iteration
    240274    while ((item = psMetadataGetAndIncrement(iter))) {
    241         if (item->type == PS_DATA_METADATA) {
    242             continue;       // We've already read it
    243         }
    244         if (item->type != PS_DATA_STRING) {
    245            psTrace("config", 2, "Element %s in %s metadata is not of type STR.\n",
    246                    item->name, description);
    247            continue;
    248         }
    249 
    250         psTrace("config", 2, "Reading %s %s: %s\n", description, item->name, item->data.str);
    251         psMetadata *new = NULL;         // New metadata
    252         if (!pmConfigFileRead(&new, item->data.str, item->name)) {
    253             psError(PM_ERR_CONFIG, false, "Trouble reading reading %s %s --- "
    254                     "ignored.\n", description, item->name);
    255             psFree(new);
     275        if (!metadataItemReadFile(item, description)) {
     276            psError(PM_ERR_CONFIG, false, "Unable to read %s %s.", description, item->name);
    256277            psFree(iter);
    257278            return false;
    258279        }
    259 
    260         // Muck around under the hood to replace the filename with the metadata; don't try this at home, kids
    261         item->type = PS_DATA_METADATA;
    262         psFree(item->data.str);
    263         item->data.md = new;
    264280    }
    265281    psFree(iter);
     
    694710            }
    695711            psMetadata *camera = cameraItem->data.md; // Camera configuration
     712
     713            psMetadata *newRule = pmConfigFileRule(config, camera, new); // The rule of interest
     714            if (!newRule) {
     715                psWarning("Unable to find filerule %s in camera %s --- ignored.", new, cameraItem->name);
     716                continue;
     717            }
     718
     719            // By calling pmConfigFileRule, we've assured that the FILERULES is now a metadata
    696720            psMetadata *filerules = psMetadataLookupMetadata(NULL, camera, "FILERULES"); // File rules
    697721            if (!filerules) {
     
    700724                continue;
    701725            }
    702             psMetadataItem *newItem = psMetadataLookup(filerules, new); // The rule of interest, or a redir.
    703             if (!newItem) {
    704                 psWarning("Can't find file rule %s in camera %s --- ignored.", new, cameraItem->name);
    705                 continue;
    706             }
    707             psMetadata *newRule;        // New rule (replacement)
    708             switch (newItem->type) {
    709               case PS_DATA_STRING:
    710                 // A redirection
    711                 newRule = psMetadataLookupMetadata(NULL, filerules, newItem->data.str);
    712                 break;
    713               case PS_DATA_METADATA:
    714                 // The rule itself
    715                 newRule = newItem->data.md;
    716                 break;
    717               default:
    718                 psWarning("Unable to find filerule %s of the correct type in camera %s --- ignored.",
    719                           new, cameraItem->name);
    720                 continue;
    721             }
     726
    722727            psMetadataAddMetadata(filerules, PS_LIST_TAIL, old, PS_META_REPLACE,
    723728                                  "Original replaced by -F option", newRule);
     
    14141419    return psStringCopy(filename);
    14151420}
     1421
     1422psMetadata *pmConfigFileRule(const pmConfig *config, const psMetadata *camera, const char *name)
     1423{
     1424    PS_ASSERT_PTR_NON_NULL(config, NULL);
     1425    PS_ASSERT_METADATA_NON_NULL(camera, NULL);
     1426    PS_ASSERT_STRING_NON_EMPTY(name, NULL);
     1427
     1428    psMetadataItem *item = psMetadataLookup(camera, "FILERULES"); // Item with the file rule of interest
     1429    if (!item) {
     1430        psError(PS_ERR_UNEXPECTED_NULL, false, "Unable to find FILERULES in the camera configuration.");
     1431        return NULL;
     1432    }
     1433
     1434    if (!metadataItemReadFile(item, "file rules ")) {
     1435        psError(PM_ERR_CONFIG, false, "Unable to read file rules for camera.");
     1436        return NULL;
     1437    }
     1438
     1439    assert(item->type == PS_DATA_METADATA);
     1440    psMetadata *filerules = item->data.md; // File rules from the camera configuration
     1441
     1442    // select the name from the FILERULES
     1443    // check for alias name (type == STR, name is aliased name)
     1444    bool mdok;                          // Status of MD lookup
     1445    const char *realname = psMetadataLookupStr(&mdok, filerules, name); // Name of file rule to look up
     1446    if (!realname || strlen(realname) == 0) {
     1447        realname = name;
     1448    }
     1449
     1450    return psMetadataLookupMetadata(NULL, filerules, realname);
     1451}
     1452
  • trunk/psModules/src/config/pmConfig.h

    r12916 r15217  
    11/*  @file pmConfig.h
    22 *  @brief Configuration functions
    3  * 
     3 *
    44 *  @author Paul Price, IfA
    55 *  @author Eugene Magnier, IfA
    6  * 
    7  *  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2007-04-19 02:10:12 $
     6 *
     7 *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2007-10-04 20:15:48 $
    99 *  Copyright 2005-2006 Institute for Astronomy, University of Hawaii
    1010 */
     
    5656    int *argc;                          ///< Number of command-line arguments
    5757    char **argv;                        ///< Command-line arguments (raw version)
    58     # endif 
     58    # endif
    5959}
    6060pmConfig;
     
    110110/// configuration.  The accepted format is returned.
    111111psMetadata *pmConfigCameraFormatFromHeader(pmConfig *config, ///< The configuration
    112                                            const psMetadata *header, ///< The FITS header
    113                                            bool readRecipes ///< optionally read the recipes as well as the format
     112                                           const psMetadata *header, ///< The FITS header
     113                                           bool readRecipes ///< optionally read the recipes as well as the format
    114114    );
    115115
     
    170170                          );
    171171
     172/// Get the file rule of interest
     173///
     174/// Look up the name of the set of file rules to use, get that set from the site configuration, and return the
     175/// appropriate rule from the set.
     176psMetadata *pmConfigFileRule(const pmConfig *config, ///< Configuration
     177                             const psMetadata *camera, ///< Camera configuration of interest
     178                             const char *name ///< Name of rule to read
     179    );
     180
    172181/// @}
    173182#endif
Note: See TracChangeset for help on using the changeset viewer.