MarlinMT  0.1.0
RandomSeedManager.cc
Go to the documentation of this file.
2 
3 // -- marlinmt headers
4 #include <jenkinsHash.h>
5 #include <marlinmt/Exceptions.h>
6 #include <marlinmt/EventStore.h>
7 
8 
9 namespace marlinmt {
10 
12  _globalSeed( globalSeed ),
13  _generator( _globalSeed ) {
14  /* nop */
15  }
16 
17  //--------------------------------------------------------------------------
18 
20  bool inserted = _entryList.insert( entry ).second ;
21  if ( not inserted ) {
22  throw Exception("RandomSeedManager: Entry '" + std::to_string(entry) + "' already registered !") ;
23  }
24  }
25 
26  //--------------------------------------------------------------------------
27 
29  HashFunction hashf ;
30  addEntry( hashf(arg) ) ;
31  }
32 
33  //--------------------------------------------------------------------------
34 
35  std::unique_ptr<RandomSeedManager::RandomSeedMap>
37  // get hashed seed using jenkins_hash
38  unsigned int seed = 0 ; // initial state
39  // unsigned int eventNumber = evt->getEventNumber() ;
40  // unsigned int runNumber = evt->getRunNumber() ;
41  auto uid = evt->uid() ;
42  unsigned char * c = (unsigned char *) &uid ;
43  // seed = jenkins_hash( c, sizeof eventNumber, seed) ;
44  // c = (unsigned char *) &runNumber ;
45  // seed = jenkins_hash( c, sizeof runNumber, seed) ;
46  // c = (unsigned char *) &uid ;
47  seed = jenkins_hash( c, sizeof _globalSeed, seed) ;
48  // refresh the seed
49  _generator.seed( seed ) ;
50  std::unique_ptr<RandomSeedMap> seedMap( new RandomSeedMap() ) ;
51  // fill map with seeds for each entry using random number generator
52  for (auto iter : _entryList ) {
53  (*seedMap)[iter] = getRandom() ;
54  }
55  return seedMap ;
56  }
57 
58  //--------------------------------------------------------------------------
59 
61  return static_cast<SeedType>(_rdmDistribution(_generator)) ;
62  }
63 
64 }
std::map< HashResult, SeedType > RandomSeedMap
RandomDistribution _rdmDistribution
The random number distribution.
std::size_t uid() const
Get the event unique id.
Definition: EventStore.h:123
unsigned jenkins_hash(unsigned char *k, unsigned length, unsigned initval)
Definition: jenkinsHash.h:94
std::hash< const void * > HashFunction
std::unique_ptr< RandomSeedMap > generateRandomSeeds(const EventStore *const evt)
Generate a random seed map.
void addEntry(HashResult entry)
Add an entry to the random seed manager.
EntryList _entryList
The entry list.
RandomGenerator _generator
The random generator engine.
Exception class.
Definition: Exceptions.h:60
SeedType _globalSeed
The global random seed, if set.
SeedType getRandom()
Get a new random number from the internal generator.
EventStore class.
Definition: EventStore.h:17
RandomSeedManager(const RandomSeedManager &)=delete