Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
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
24#include <iostream>
25#include <string>
26
27namespace CLHEP {
28
29template<class E>
30static HepRandomEngine*
31makeAnEngine (const std::string & tag,
32 std::istream & is) {
33 if ( tag != E::beginTag() ) return 0;
34 HepRandomEngine* eptr = new E;
35 eptr->getState(is);
36 if (!is) return 0;
37 return eptr;
38}
39
40template<class E>
41static HepRandomEngine*
42makeAnEngine (const std::vector<unsigned long> & v) {
43 if ( (v[0] & 0xffffffffUL) != engineIDulong<E>() ) return 0;
44 HepRandomEngine* eptr = new E;
45 bool success = eptr->getState(v);
46 if (!success) return 0;
47 // std::cerr << "makeAnEngine made " << E::engineName() << "\n";
48 return eptr;
49}
50
52 HepRandomEngine* eptr;
53 std::string tag;
54 is >> tag;
55 eptr = makeAnEngine <HepJamesRandom> (tag, is); if (eptr) return eptr;
56 eptr = makeAnEngine <RanecuEngine> (tag, is); if (eptr) return eptr;
57 eptr = makeAnEngine <Ranlux64Engine> (tag, is); if (eptr) return eptr;
58 eptr = makeAnEngine <MTwistEngine> (tag, is); if (eptr) return eptr;
59 eptr = makeAnEngine <DualRand> (tag, is); if (eptr) return eptr;
60 eptr = makeAnEngine <RanluxEngine> (tag, is); if (eptr) return eptr;
61 eptr = makeAnEngine <RanshiEngine> (tag, is); if (eptr) return eptr;
62 eptr = makeAnEngine <NonRandomEngine> (tag, is); if (eptr) return eptr;
63 is.clear(std::ios::badbit | is.rdstate());
64 std::cerr <<
65 "Input mispositioned or bad in reading anonymous engine\n"
66 << "\nBegin-tag read was: " << tag
67 << "\nInput stream is probably fouled up\n";
68 return eptr;
69}
70
72EngineFactory::newEngine(std::vector<unsigned long> const & v) {
73 HepRandomEngine* eptr;
74 eptr = makeAnEngine <HepJamesRandom> (v); if (eptr) return eptr;
75 eptr = makeAnEngine <RanecuEngine> (v); if (eptr) return eptr;
76 eptr = makeAnEngine <Ranlux64Engine> (v); if (eptr) return eptr;
77 eptr = makeAnEngine <MTwistEngine> (v); if (eptr) return eptr;
78 eptr = makeAnEngine <DualRand> (v); if (eptr) return eptr;
79 eptr = makeAnEngine <RanluxEngine> (v); if (eptr) return eptr;
80 eptr = makeAnEngine <RanshiEngine> (v); if (eptr) return eptr;
81 eptr = makeAnEngine <NonRandomEngine> (v); if (eptr) return eptr;
82 std::cerr <<
83 "Cannot correctly get anonymous engine from vector\n"
84 << "First unsigned long was: " << v[0]
85 << " Vector size was: " << v.size() <<"\n";
86 return eptr;
87}
88
89} // namespace CLHEP
90
static HepRandomEngine * newEngine(std::istream &is)
virtual std::istream & getState(std::istream &is)
Definition: RandomEngine.cc:70
Definition: DoubConv.h:17
Definition: xmlparse.cc:179