Changeset 9244 for trunk


Ignore:
Timestamp:
01/23/09 15:28:28 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mjobs/MJob.cc

    r8882 r9244  
    4040
    4141#include "MEnv.h"
     42
    4243#include <TFile.h>
    4344#include <TSystem.h>
     45#include <TRandom.h>
    4446#include <TObjArray.h>
    4547
     
    225227Int_t MJob::GetEnv(const char *name, Int_t dflt) const
    226228{
    227     return GetEnvValue(*fEnv, fEnvPrefix, name, dflt); //    return fEnv->GetValue(Form("%s%s", fEnvPrefix.Data(), name), dflt);
     229    return GetEnvValue2(*fEnv, fEnvPrefix, name, dflt); //    return fEnv->GetValue(Form("%s%s", fEnvPrefix.Data(), name), dflt);
    228230}
    229231
     
    235237Double_t MJob::GetEnv(const char *name, Double_t dflt) const
    236238{
    237     return GetEnvValue(*fEnv, fEnvPrefix, name, dflt); //    return fEnv->GetValue(Form("%s%s", fEnvPrefix.Data(), name), dflt);
     239    return GetEnvValue2(*fEnv, fEnvPrefix, name, dflt); //    return fEnv->GetValue(Form("%s%s", fEnvPrefix.Data(), name), dflt);
    238240}
    239241
     
    245247const char *MJob::GetEnv(const char *name, const char *dflt) const
    246248{
    247     return GetEnvValue(*fEnv, fEnvPrefix, name, dflt); //fEnv->GetValue(Form("%s%s", fEnvPrefix.Data(), name), dflt);
     249    return GetEnvValue2(*fEnv, fEnvPrefix, name, dflt); //fEnv->GetValue(Form("%s%s", fEnvPrefix.Data(), name), dflt);
    248250}
    249251
     
    256258{
    257259    return IsEnvDefined(*fEnv, fEnvPrefix, name, fEnvDebug>2);//fEnv->Lookup(Form("%s%s", fEnvPrefix.Data(), name));
     260}
     261
     262//------------------------------------------------------------------------
     263//
     264// Check fEnv for RadnomNumberGenerator. If it is empty or the
     265// corresponding class does either not exist or not inherit from TRandom,
     266// gRandom remains unchanged. Otherwise gRandom is set to a newly created
     267// instance of this class.
     268//
     269// The second resource which is checked is RandomNumberSeedValue. If it
     270// is empty (not given) the seed keeps unchanged. If a number is given
     271// the seed value of gRandom is set accordingly. (0 means that
     272// the seed value is set accoring to the time, see TRandom::SetSeed())
     273//
     274// If an error occured kFALSE is returned, kTRUE otherwise.
     275//
     276Bool_t MJob::InitRandomNumberGenerator() const
     277{
     278    const TString rng = GetEnv("RandomNumberGenerator", "");
     279    if (!rng.IsNull())
     280    {
     281        TClass *cls = MParContainer::GetClass(rng, &gLog);
     282        if (!cls)
     283            return kFALSE;
     284
     285        if (!cls->InheritsFrom(TRandom::Class()))
     286        {
     287            *fLog << err << "ERROR - RandomNumberGenerator " << rng << " doesn't inherit from TRandom." <<  endl;
     288            return kFALSE;
     289        }
     290
     291        delete gRandom;
     292        gRandom = static_cast<TRandom*>(cls->New());
     293
     294        *fLog << inf << "Random number generator " << rng << " initialized." << endl;
     295    }
     296
     297    // Nothing: Keep seed value, 0 set time as seed value, val set seed
     298    const TString seed = GetEnv("RandomNumberSeedNumber", "");
     299    if (!seed.IsNull())
     300    {
     301        gRandom->SetSeed(seed.Atoi());
     302        *fLog << inf << "Random number seed value set to " << seed.Atoi() << endl;
     303    }
     304
     305    return kTRUE;
    258306}
    259307
     
    266314//   Overwrite
    267315//   EnvDebug
     316//   RandomNumberGenerator
     317//   RandomNumberSeedValue
    268318//
    269319// and call the virtual function CheckEnvLocal
     
    273323    if (!fEnv)
    274324        return kTRUE;
     325
     326    if (!InitRandomNumberGenerator())
     327        return kFALSE;
    275328
    276329    TString p;
Note: See TracChangeset for help on using the changeset viewer.