CLHEP 2.4.6.4
C++ Class Library for High Energy Physics
Loading...
Searching...
No Matches
EngineFactory.cc
Go to the documentation of this file.
1// $Id:
2// -*- C++ -*-
3//
4// -----------------------------------------------------------------------
5// HEP Random
6// --- EngineFactory ---
7// class implementation file
8// -----------------------------------------------------------------------
9//
10// =======================================================================
11// Mark Fischler - Created: Dec. 21, 2004
12// =======================================================================
13
14#include "CLHEP/Random/defs.h"
15#include "CLHEP/Random/EngineFactory.h"
16#include "CLHEP/Random/DRand48Engine.h"
17#include "CLHEP/Random/DualRand.h"
18#include "CLHEP/Random/Hurd160Engine.h"
19#include "CLHEP/Random/Hurd288Engine.h"
20#include "CLHEP/Random/JamesRandom.h"
21#include "CLHEP/Random/JamesRandom.h"
22#include "CLHEP/Random/MixMaxRng.h"
23#include "CLHEP/Random/MTwistEngine.h"
24#include "CLHEP/Random/RandEngine.h"
25#include "CLHEP/Random/RanecuEngine.h"
26#include "CLHEP/Random/Ranlux64Engine.h"
27#include "CLHEP/Random/RanluxppEngine.h"
28#include "CLHEP/Random/RanluxEngine.h"
29#include "CLHEP/Random/RanshiEngine.h"
30#include "CLHEP/Random/TripleRand.h"
31#include "CLHEP/Random/NonRandomEngine.h"
32#include "CLHEP/Random/engineIDulong.h"
33#include <iostream>
34#include <string>
35#include <vector>
36
37namespace CLHEP {
38
39template<class E>
40static HepRandomEngine*
41makeAnEngine (const std::string & tag,
42 std::istream & is) {
43 if ( tag != E::beginTag() ) return 0;
44 HepRandomEngine* eptr = new E;
45 eptr->getState(is);
46 if (!is) return 0;
47 return eptr;
48}
49
50template<class E>
51static HepRandomEngine*
52makeAnEngine (const std::vector<unsigned long> & v) {
53 if ( (v[0] & 0xffffffffUL) != engineIDulong<E>() ) return 0;
54 HepRandomEngine* eptr = new E;
55 bool success = eptr->getState(v);
56 if (!success) return 0;
57 // std::cerr << "makeAnEngine made " << E::engineName() << "\n";
58 return eptr;
59}
60
62 HepRandomEngine* eptr;
63 std::string tag;
64 is >> tag;
65 eptr = makeAnEngine <HepJamesRandom> (tag, is); if (eptr) return eptr;
66 eptr = makeAnEngine <RanecuEngine> (tag, is); if (eptr) return eptr;
67 eptr = makeAnEngine <Ranlux64Engine> (tag, is); if (eptr) return eptr;
68 eptr = makeAnEngine <RanluxppEngine> (tag, is); if (eptr) return eptr;
69 eptr = makeAnEngine <MixMaxRng> (tag, is); if (eptr) return eptr;
70 eptr = makeAnEngine <MTwistEngine> (tag, is); if (eptr) return eptr;
71 eptr = makeAnEngine <DRand48Engine> (tag, is); if (eptr) return eptr;
72 eptr = makeAnEngine <TripleRand> (tag, is); if (eptr) return eptr;
73 eptr = makeAnEngine <DualRand> (tag, is); if (eptr) return eptr;
74 eptr = makeAnEngine <Hurd160Engine> (tag, is); if (eptr) return eptr;
75 eptr = makeAnEngine <Hurd288Engine> (tag, is); if (eptr) return eptr;
76 eptr = makeAnEngine <RandEngine> (tag, is); if (eptr) return eptr;
77 eptr = makeAnEngine <RanluxEngine> (tag, is); if (eptr) return eptr;
78 eptr = makeAnEngine <RanshiEngine> (tag, is); if (eptr) return eptr;
79 eptr = makeAnEngine <NonRandomEngine> (tag, is); if (eptr) return eptr;
80 is.clear(std::ios::badbit | is.rdstate());
81 std::cerr <<
82 "Input mispositioned or bad in reading anonymous engine\n"
83 << "\nBegin-tag read was: " << tag
84 << "\nInput stream is probably fouled up\n";
85 return eptr;
86}
87
89EngineFactory::newEngine(std::vector<unsigned long> const & v) {
90 HepRandomEngine* eptr;
91 eptr = makeAnEngine <HepJamesRandom> (v); if (eptr) return eptr;
92 eptr = makeAnEngine <RanecuEngine> (v); if (eptr) return eptr;
93 eptr = makeAnEngine <Ranlux64Engine> (v); if (eptr) return eptr;
94 eptr = makeAnEngine <RanluxppEngine> (v); if (eptr) return eptr;
95 eptr = makeAnEngine <MixMaxRng> (v); if (eptr) return eptr;
96 eptr = makeAnEngine <MTwistEngine> (v); if (eptr) return eptr;
97 eptr = makeAnEngine <DRand48Engine> (v); if (eptr) return eptr;
98 eptr = makeAnEngine <TripleRand> (v); if (eptr) return eptr;
99 eptr = makeAnEngine <DualRand> (v); if (eptr) return eptr;
100 eptr = makeAnEngine <Hurd160Engine> (v); if (eptr) return eptr;
101 eptr = makeAnEngine <Hurd288Engine> (v); if (eptr) return eptr;
102 eptr = makeAnEngine <RandEngine> (v); if (eptr) return eptr;
103 eptr = makeAnEngine <RanluxEngine> (v); if (eptr) return eptr;
104 eptr = makeAnEngine <RanshiEngine> (v); if (eptr) return eptr;
105 eptr = makeAnEngine <NonRandomEngine> (v); if (eptr) return eptr;
106 std::cerr <<
107 "Cannot correctly get anonymous engine from vector\n"
108 << "First unsigned long was: " << v[0]
109 << " Vector size was: " << v.size() <<"\n";
110 return eptr;
111}
112
113} // namespace CLHEP
114
static HepRandomEngine * newEngine(std::istream &is)
virtual std::istream & getState(std::istream &is)
Definition: RandomEngine.cc:74