ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EngineFactory.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EngineFactory.cc
1 // -*- C++ -*-
2 //
3 // -----------------------------------------------------------------------
4 // HEP Random
5 // --- EngineFactory ---
6 // class implementation file
7 // -----------------------------------------------------------------------
8 //
9 // =======================================================================
10 // Mark Fischler - Created: Dec. 21, 2004
11 // =======================================================================
12 
14 #include "CLHEP/Random/DualRand.h"
16 #include "CLHEP/Random/MixMaxRng.h"
24 #include <iostream>
25 #include <string>
26 
27 namespace CLHEP {
28 
29 template<class E>
30 static HepRandomEngine*
31 makeAnEngine (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 
40 template<class E>
41 static HepRandomEngine*
42 makeAnEngine (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 <MixMaxRng> (tag, is); if (eptr) return eptr;
59  eptr = makeAnEngine <MTwistEngine> (tag, is); if (eptr) return eptr;
60  eptr = makeAnEngine <DualRand> (tag, is); if (eptr) return eptr;
61  eptr = makeAnEngine <RanluxEngine> (tag, is); if (eptr) return eptr;
62  eptr = makeAnEngine <RanshiEngine> (tag, is); if (eptr) return eptr;
63  eptr = makeAnEngine <NonRandomEngine> (tag, is); if (eptr) return eptr;
64  is.clear(std::ios::badbit | is.rdstate());
65  std::cerr <<
66  "Input mispositioned or bad in reading anonymous engine\n"
67  << "\nBegin-tag read was: " << tag
68  << "\nInput stream is probably fouled up\n";
69  return eptr;
70 }
71 
73 EngineFactory::newEngine(std::vector<unsigned long> const & v) {
74  HepRandomEngine* eptr;
75  eptr = makeAnEngine <HepJamesRandom> (v); if (eptr) return eptr;
76  eptr = makeAnEngine <RanecuEngine> (v); if (eptr) return eptr;
77  eptr = makeAnEngine <Ranlux64Engine> (v); if (eptr) return eptr;
78  eptr = makeAnEngine <MixMaxRng> (v); if (eptr) return eptr;
79  eptr = makeAnEngine <MTwistEngine> (v); if (eptr) return eptr;
80  eptr = makeAnEngine <DualRand> (v); if (eptr) return eptr;
81  eptr = makeAnEngine <RanluxEngine> (v); if (eptr) return eptr;
82  eptr = makeAnEngine <RanshiEngine> (v); if (eptr) return eptr;
83  eptr = makeAnEngine <NonRandomEngine> (v); if (eptr) return eptr;
84  std::cerr <<
85  "Cannot correctly get anonymous engine from vector\n"
86  << "First unsigned long was: " << v[0]
87  << " Vector size was: " << v.size() <<"\n";
88  return eptr;
89 }
90 
91 } // namespace CLHEP
92