Geant4-11
G4UserTaskThreadInitialization.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26
28#include "G4AutoLock.hh"
30#include "G4UImanager.hh"
32#include "G4VUserPhysicsList.hh"
33#include "G4WorkerRunManager.hh"
35#include "G4WorkerThread.hh"
36#include "globals.hh"
37#include <sstream>
38
39//============================================================================//
40
41namespace
42{
44}
45
46//============================================================================//
47
49{
50 // Note: this method is called by G4MTRunManager, here we are still sequential
51 // Create a new thread/worker structure
52 return nullptr;
53}
54
55//============================================================================//
56
57// Avoid compilation warning in sequential
59{
60 if(aThread)
61 {
62 G4THREADJOIN(*aThread);
63 }
64}
65
66//============================================================================//
67
69
70//============================================================================//
71
73
74//============================================================================//
75
77 const CLHEP::HepRandomEngine* aNewRNG) const
78{
80 // No default available, let's create the instance of random stuff
81 // A Call to this just forces the creation to defaults
82 G4Random::getTheEngine();
83 // Poor man's solution to check which RNG Engine is used in master thread
84 CLHEP::HepRandomEngine* retRNG = nullptr;
85
86 // Need to make these calls thread safe
87 if(dynamic_cast<const CLHEP::HepJamesRandom*>(aNewRNG))
88 retRNG = new CLHEP::HepJamesRandom;
89 if(dynamic_cast<const CLHEP::MixMaxRng*>(aNewRNG))
90 retRNG = new CLHEP::MixMaxRng;
91 if(dynamic_cast<const CLHEP::RanecuEngine*>(aNewRNG))
92 retRNG = new CLHEP::RanecuEngine;
93 if(dynamic_cast<const CLHEP::Ranlux64Engine*>(aNewRNG))
94 retRNG = new CLHEP::Ranlux64Engine;
95 if(dynamic_cast<const CLHEP::RanluxppEngine*>(aNewRNG))
96 retRNG = new CLHEP::RanluxppEngine;
97 if(dynamic_cast<const CLHEP::MTwistEngine*>(aNewRNG))
98 retRNG = new CLHEP::MTwistEngine;
99 if(dynamic_cast<const CLHEP::DualRand*>(aNewRNG))
100 retRNG = new CLHEP::DualRand;
101 if(dynamic_cast<const CLHEP::RanluxEngine*>(aNewRNG))
102 retRNG = new CLHEP::RanluxEngine;
103 if(dynamic_cast<const CLHEP::RanshiEngine*>(aNewRNG))
104 retRNG = new CLHEP::RanshiEngine;
105
106 if(retRNG != nullptr)
107 G4Random::setTheEngine(retRNG);
108 else
109 {
110 // Does a new method, such as aNewRng->newEngine() exist to clone it ?
112 msg << " Unknown type of RNG Engine - " << G4endl
113 << " Can cope only with HepJamesRandom, MixMaxRng, Ranecu, Ranlux64,"
114 << " Ranlux++, MTwistEngine, DualRand, Ranlux or Ranshi." << G4endl
115 << " Cannot clone this type of RNG engine, as required for this thread"
116 << G4endl << " Aborting... " << G4endl;
117 G4Exception("G4UserTaskInitializition::SetupRNGEngine()", "Run0122",
118 FatalException, msg);
119 }
120}
121
122//============================================================================//
123
125 const
126{
127 return new G4WorkerTaskRunManager();
128}
129
130//============================================================================//
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
#define G4THREADJOIN(worker)
Definition: G4Threading.hh:259
std::mutex G4Mutex
Definition: G4Threading.hh:81
#define G4endl
Definition: G4ios.hh:57
virtual G4WorkerRunManager * CreateWorkerRunManager() const
virtual void JoinWorker(G4Thread *aThread)
virtual void SetupRNGEngine(const CLHEP::HepRandomEngine *aRNGEngine) const
virtual G4Thread * CreateAndStartWorker(G4WorkerThread *workerThreadContext)