Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
EngineFactory.cc
이 파일의 문서화 페이지로 가기
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 
15 #include "CLHEP/Random/DualRand.h"
17 #include "CLHEP/Random/MixMaxRng.h"
25 #include <iostream>
26 #include <string>
27 
28 namespace CLHEP {
29 
30 template<class E>
31 static HepRandomEngine*
32 makeAnEngine (const std::string & tag,
33  std::istream & is) {
34  if ( tag != E::beginTag() ) return 0;
35  HepRandomEngine* eptr = new E;
36  eptr->getState(is);
37  if (!is) return 0;
38  return eptr;
39 }
40 
41 template<class E>
42 static HepRandomEngine*
43 makeAnEngine (const std::vector<unsigned long> & v) {
44  if ( (v[0] & 0xffffffffUL) != engineIDulong<E>() ) return 0;
45  HepRandomEngine* eptr = new E;
46  bool success = eptr->getState(v);
47  if (!success) return 0;
48  // std::cerr << "makeAnEngine made " << E::engineName() << "\n";
49  return eptr;
50 }
51 
53  HepRandomEngine* eptr;
54  std::string tag;
55  is >> tag;
56  eptr = makeAnEngine <HepJamesRandom> (tag, is); if (eptr) return eptr;
57  eptr = makeAnEngine <RanecuEngine> (tag, is); if (eptr) return eptr;
58  eptr = makeAnEngine <Ranlux64Engine> (tag, is); if (eptr) return eptr;
59  eptr = makeAnEngine <MixMaxRng> (tag, is); if (eptr) return eptr;
60  eptr = makeAnEngine <MTwistEngine> (tag, is); if (eptr) return eptr;
61  eptr = makeAnEngine <DualRand> (tag, is); if (eptr) return eptr;
62  eptr = makeAnEngine <RanluxEngine> (tag, is); if (eptr) return eptr;
63  eptr = makeAnEngine <RanshiEngine> (tag, is); if (eptr) return eptr;
64  eptr = makeAnEngine <NonRandomEngine> (tag, is); if (eptr) return eptr;
65  is.clear(std::ios::badbit | is.rdstate());
66  std::cerr <<
67  "Input mispositioned or bad in reading anonymous engine\n"
68  << "\nBegin-tag read was: " << tag
69  << "\nInput stream is probably fouled up\n";
70  return eptr;
71 }
72 
74 EngineFactory::newEngine(std::vector<unsigned long> const & v) {
75  HepRandomEngine* eptr;
76  eptr = makeAnEngine <HepJamesRandom> (v); if (eptr) return eptr;
77  eptr = makeAnEngine <RanecuEngine> (v); if (eptr) return eptr;
78  eptr = makeAnEngine <Ranlux64Engine> (v); if (eptr) return eptr;
79  eptr = makeAnEngine <MixMaxRng> (v); if (eptr) return eptr;
80  eptr = makeAnEngine <MTwistEngine> (v); if (eptr) return eptr;
81  eptr = makeAnEngine <DualRand> (v); if (eptr) return eptr;
82  eptr = makeAnEngine <RanluxEngine> (v); if (eptr) return eptr;
83  eptr = makeAnEngine <RanshiEngine> (v); if (eptr) return eptr;
84  eptr = makeAnEngine <NonRandomEngine> (v); if (eptr) return eptr;
85  std::cerr <<
86  "Cannot correctly get anonymous engine from vector\n"
87  << "First unsigned long was: " << v[0]
88  << " Vector size was: " << v.size() <<"\n";
89  return eptr;
90 }
91 
92 } // namespace CLHEP
93 
Definition: xmlparse.cc:187
static HepRandomEngine * newEngine(std::istream &is)
virtual std::istream & getState(std::istream &is)
Definition: RandomEngine.cc:70
static HepRandomEngine * makeAnEngine(const std::string &tag, std::istream &is)