IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 10, 2009, 4:53:42 PM (17 years ago)
Author:
Paul Price
Message:

Changing API for psRandomAlloc() to make it easier to be deterministic. psRandomAlloc() now takes only a single argument, which is the generator type (only PS_RANDOM_TAUS is currently supported; others could easily be added). The seed used by the generator is set by psRandomSeed(). This allows us to use the same seed for the random number generator over multiple calls, which means that we can be deterministic by setting the seed. The old API for psRandomAlloc() is available using psRandomAllocSpecific(). Added to the configuration setup in psModules to include recording the random seed, and setting if desired. Updated all our products to use this API. Some fixes and updates to the configuration run-time information dumping. ppImage now dumps the configuration at the end, allowing the list of files in the run-time information to be set.

Location:
trunk/psModules/src/config
Files:
5 edited

Legend:

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

    r23215 r23259  
    1313
    1414#include <stdio.h>
     15#include <stdlib.h>
    1516#include <string.h>
    1617#include <strings.h>            /* for strn?casecmp */
     
    2425#include <pslib.h>
    2526
    26 #include "pmConfig.h"
    2727#include "pmErrorCodes.h"
    2828#include "pmFPALevel.h"
    2929#include "pmConfigRecipes.h"
    3030#include "pmConfigCamera.h"
     31#include "pmConfigRun.h"
     32
     33#include "pmConfig.h"
    3134
    3235#ifdef HAVE_NEBCLIENT
     
    432435    // variable will contain the name of the configuration file.
    433436
    434     char *configFile = NULL;
    435     //
     437    char *configFile = NULL;            // Name of configuration file
     438
    436439    // First, try command line
    437     //
    438440    psS32 argNum = psArgumentGet(*argc, argv, "-ipprc");
    439441    if (argNum != 0) {
     
    447449        }
    448450    }
    449     //
     451
    450452    // Next, try environment variable
    451     //
    452453    if (!configFile) {
    453454        configFile = getenv(IPPRC_ENV);
    454455        if (configFile) {
    455             configFile = psStringCopy (configFile);
    456         }
    457     }
    458 
    459     //
     456            configFile = psStringCopy(configFile);
     457        }
     458    }
     459
    460460    // Last chance is ~/.ipprc
    461     //
    462461    if (!configFile) {
    463462        char *home = getenv("HOME");
     
    466465    }
    467466
    468     // We have the configuration filename; now we read and parse the config
    469     // file and store in psMetadata struct user.
     467    // Read and parse the config file and store in struct user.
    470468    // XXX move this section to pmConfigReadUser.c ?
    471 
    472469    if (!pmConfigFileRead(&config->user, configFile, "user")) {
    473470        psFree(config);
     
    477474    psFree(configFile);
    478475
    479     // XXX why was this being called here?  Is someone calling pmConfigRead multiple times?
    480     // pmConfigDone();
    481     assert (configPath == NULL);
     476    pmConfigRunCommand(config, *argc, argv);
    482477
    483478    // define the config-file search path (configPath).
     479    psAssert(configPath == NULL, "Configuration path is already defined.");
    484480    psString path = psMetadataLookupStr(NULL, config->user, "PATH");
    485     pmConfigSet (path);
     481    pmConfigSet(path);
    486482
    487483    // read the SITE file
     
    525521            psLogSetLevel(logLevel);
    526522        }
    527 
    528523
    529524        // Set logging format
     
    646641            psTimeInit(timeName);
    647642        }
     643    }
     644
     645    // Set the random number generator seed
     646    {
     647        psU64 seed = 0;                 // RNG seed
     648        int argNum = psArgumentGet(*argc, argv, "-seed"); // Argument number
     649        if (argNum > 0) {
     650            psArgumentRemove(argNum, argc, argv);
     651            if (argNum >= *argc) {
     652                psWarning("-seed command-line switch provided without the required seed value --- ignored.");
     653            } else {
     654                char *end = NULL;       // Pointer to end of consumed string
     655                seed = strtoll(argv[argNum], &end, 0);
     656                if (strlen(end) > 0) {
     657                    psError(PS_ERR_IO, true, "Unable to read random number generator seed: %s", argv[argNum]);
     658                    psFree(config);
     659                    return NULL;
     660                }
     661                psArgumentRemove(argNum, argc, argv);
     662            }
     663        }
     664        pmConfigRunSeed(config, seed);
    648665    }
    649666
  • trunk/psModules/src/config/pmConfigCamera.c

    r22700 r23259  
    213213    psStringAppend(&newName, "_%s-SKYCELL", name);
    214214    if (psMetadataLookup(oldCameras, newName)) {
     215        psFree(newName);
    215216        return true;
    216217    }
     
    469470    psStringAppend(&newName, "_%s-%s", name, mosaicLevel == PM_FPA_LEVEL_CHIP ? "CHIP" : "FPA");
    470471    if (psMetadataLookup(oldCameras, newName)) {
     472        psFree(newName);
    471473        return true;
    472474    }
  • trunk/psModules/src/config/pmConfigRecipes.h

    r12916 r23259  
    11/*  @file pmConfigRecipes.h
    22 *  @brief Configuration Recipe functions
    3  * 
     3 *
    44 *  @author ?, MHPCC
    55 *  @author Paul Price, IfA
    66 *  @author Eugene Magnier, IfA
    7  * 
     7 *
    88 *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    99 *  @date $Date: 2007-04-19 02:10:12 $
     
    1313#ifndef PM_CONFIG_RECIPES_H
    1414#define PM_CONFIG_RECIPES_H
     15
     16#include <pmConfig.h>
    1517
    1618/// @addtogroup Config Configuration System
     
    2628
    2729
    28 bool pmConfigLoadRecipeArguments (int *argc, char **argv, pmConfig *config);
    29 bool pmConfigLoadRecipeOptions (int *argc, char **argv, pmConfig *config, char *flag);
    30 psMetadata *pmConfigRecipeOptions (pmConfig *config, char *recipe);
     30bool pmConfigLoadRecipeArguments(int *argc, char **argv, pmConfig *config);
     31bool pmConfigLoadRecipeOptions(int *argc, char **argv, pmConfig *config, char *flag);
     32psMetadata *pmConfigRecipeOptions(pmConfig *config, char *recipe);
    3133
    3234/// @}
  • trunk/psModules/src/config/pmConfigRun.c

    r23244 r23259  
    7272
    7373
    74 bool pmConfigRunCommand(pmConfig *config, int argc, const char **argv)
     74bool pmConfigRunCommand(pmConfig *config, int argc, char **argv)
    7575{
    7676    PS_ASSERT_PTR_NON_NULL(config, false);
     
    8181    psString command = NULL;
    8282    for (int i = 0; i < argc; i++) {
    83         psStringAppend(&command, "%s", argv[i]);
     83        psStringAppend(&command, "%s ", argv[i]);
    8484    }
    8585
     
    8989    return true;
    9090}
     91
     92
     93bool pmConfigRunSeed(pmConfig *config, psU64 seed)
     94{
     95    PS_ASSERT_PTR_NON_NULL(config, false);
     96
     97    psMetadata *run = configRun(config);// Run-time information
     98    psAssert(run, "Require run-time information");
     99
     100    if (!seed) {
     101        bool mdok;                          // Status of MD lookup
     102        seed = psMetadataLookupU64(&mdok, run, "SEED");
     103    }
     104    if (!seed) {
     105        bool mdok;                          // Status of MD lookup
     106        seed = psMetadataLookupU64(&mdok, config->user, "SEED");
     107    }
     108
     109    // seed may still be zero by this point
     110    seed = psRandomSeed(seed);
     111    return psMetadataAddU64(run, PS_LIST_TAIL, "SEED", PS_META_REPLACE, "Random number generator seed", seed);
     112}
     113
  • trunk/psModules/src/config/pmConfigRun.h

    r23243 r23259  
    44#include <pslib.h>
    55#include <pmConfig.h>
     6#include <pmFPAfile.h>
    67
    78/// Add a file to the list of files used in the run-time information
     
    1213
    1314/// Add the command line to the run-time information
    14 bool pmConfigRunCommand(pmConfig *config, ///< Configuration
    15                         int argc, const char **argv ///< Command line arguments
     15bool pmConfigRunCommand(
     16    pmConfig *config,                   ///< Configuration
     17    int argc, char **argv               ///< Command line arguments
     18    );
     19
     20/// Record the random number generator seed in the run-time information
     21bool pmConfigRunSeed(
     22    pmConfig *config,                   ///< Configuration
     23    psU64 seed                          ///< RNG seed
    1624    );
    1725
Note: See TracChangeset for help on using the changeset viewer.