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.

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.