10 #include "G4WorkerRunManager.hh"
11 #include "G4UImanager.hh"
12 #include "G4MTRunManager.hh"
13 #include "G4WorkerThread.hh"
14 #include "G4UserWorkerThreadInitialization.hh"
15 #include "G4RunManager.hh"
16 #include "G4VUserActionInitialization.hh"
17 #include "G4UserWorkerInitialization.hh"
18 #include "G4AutoDelete.hh"
22 #include <sys/syscall.h>
28 const std::string&
name,
41 std::hex << pthread_self() << std::dec);
44 auto wThreadContext =
new G4WorkerThread;
45 G4AutoDelete::Register(wThreadContext);
48 static std::atomic_uint tid(0);
49 wThreadContext->SetThreadId( tid++ );
50 G4Threading::G4SetThreadId( wThreadContext->GetThreadId() );
53 wThreadContext->BuildGeometryAndPhysicsVector();
56 G4MTRunManager* masterRM = G4MTRunManager::GetMasterRunManager();
58 const G4UserWorkerThreadInitialization* workerInitializer =
59 masterRM->GetUserWorkerThreadInitialization();
63 const CLHEP::HepRandomEngine* masterEngine = masterRM->getMasterRandomEngine();
64 workerInitializer->SetupRNGEngine(masterEngine);
68 G4WorkerRunManager* wrm = workerInitializer->CreateWorkerRunManager();
69 wrm->SetWorkerThread(wThreadContext);
77 const_cast<G4VUserDetectorConstruction*
> (masterRM->GetUserDetectorConstruction());
78 wrm->G4RunManager::SetUserInitialization (
detector);
82 const_cast<G4VUserPhysicsList*
>(masterRM->GetUserPhysicsList());
83 wrm->SetUserInitialization(physicslist);
86 if(masterRM->GetUserActionInitialization()) {
87 masterRM->GetNonConstUserActionInitialization()->Build();
91 if(masterRM->GetUserWorkerInitialization()) {
92 masterRM->GetUserWorkerInitialization()->WorkerStart();
100 std::vector<G4String>
cmds = masterRM->GetCommandStack();
102 G4UImanager* uimgr = G4UImanager::GetUIpointer();
103 for(
const auto&
it :
cmds) {
105 uimgr->ApplyCommand(
it);
111 ATH_MSG_INFO(
"==> tbb thread end of initThread with id: 0x" <<
112 std::hex << pthread_self() << std::dec);
121 std::hex << pthread_self() << std::dec);
124 auto runMgr = G4RunManager::GetRunManager();
127 runMgr->RunTermination();
128 ATH_MSG_INFO(
"terminateThread ==> safely called G4AtlasWorkerRunManager::RunTermination for tbb thread 0x" <<
129 std::hex << pthread_self() << std::dec);
134 ATH_MSG_WARNING(
"skipping attempt to call terminateThread for tbb thread 0x" <<
135 std::hex << pthread_self() << std::dec <<
136 " without having first called initThread.");