ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
G4InitTool Class Reference

#include <G4InitTool.h>

Inheritance diagram for G4InitTool:
Collaboration diagram for G4InitTool:

Public Member Functions

 G4InitTool (const std::string &, const std::string &, const IInterface *)
 
virtual void initThread ()
 
virtual void terminateThread ()
 
virtual unsigned int nInit () const
 

Private Attributes

std::atomic_uint m_nInitThreads
 

Detailed Description

Definition at line 14 of file G4InitTool.h.

Constructor & Destructor Documentation

◆ G4InitTool()

G4InitTool::G4InitTool ( const std::string &  type,
const std::string &  name,
const IInterface *  parent 
)

Definition at line 27 of file G4InitTool.cxx.

29  : base_class(type, name, parent),
31 
32 {
33 }

Member Function Documentation

◆ initThread()

void G4InitTool::initThread ( )
virtual

Definition at line 39 of file G4InitTool.cxx.

39  {
40 
41  ATH_MSG_INFO ("==> tbb thread started with id: 0x" << std::hex
42  << pthread_self() << std::dec);
43 
44  // The following code is modeled after G4MTRunManagerKernel::StartThread
45 
46  // Define the G4 worker thread context
47  auto wThreadContext = new G4WorkerThread;
48  G4AutoDelete::Register(wThreadContext);
49 
50  // Assign the thread id
51  // TODO: implement a better solution.
52  // WARNING: not portable!
53 #if defined(__USE_GNU) || defined(__CPPCHECK__)
54  pid_t tid = gettid();
55  wThreadContext->SetThreadId( tid );
56 #else
57  #error "gettid() unavailable on this system"
58 #endif
59  //wThreadContext->SetThreadId( pthread_self() );
60  G4int thisID = wThreadContext->GetThreadId();
61  G4Threading::G4SetThreadId(thisID);
62 
63  // Retrieve the G4AtlasMTRunManager
64  G4MTRunManager* masterRM = G4MTRunManager::GetMasterRunManager();
65  // Worker thread initialization
66  const G4UserWorkerThreadInitialization* workerInitializer = masterRM->GetUserWorkerThreadInitialization();
67 
68  const CLHEP::HepRandomEngine* masterEngine = masterRM->getMasterRandomEngine();
69  workerInitializer->SetupRNGEngine(masterEngine);
70 
71  // Setup up thread-local workspace
72  wThreadContext->BuildGeometryAndPhysicsVector();
73 
74  // Create the thread-local worker run manager (G4AtlasWorkerRunManager)
75  ATH_MSG_INFO("Creating worker RM");
76  G4WorkerRunManager* wrm = workerInitializer->CreateWorkerRunManager();
77  wrm->SetWorkerThread(wThreadContext);
78 
79  // Share detector from master with worker.
80  ATH_MSG_INFO("Assigning detector construction");
81  auto detector ATLAS_THREAD_SAFE = const_cast<G4VUserDetectorConstruction*>
82  (masterRM->GetUserDetectorConstruction());
83  wrm->G4RunManager::SetUserInitialization(detector);
84 
85  // Share physics list from master with worker.
86  auto physicslist ATLAS_THREAD_SAFE = const_cast<G4VUserPhysicsList*>(masterRM->GetUserPhysicsList());
87  wrm->SetUserInitialization(physicslist);
88 
89  // Build thread-local user actions - NOT CURRENTLY USED.
90  if(masterRM->GetUserActionInitialization()) {
91  masterRM->GetNonConstUserActionInitialization()->Build();
92  }
93 
94  // Start user worker initialization
95  if(masterRM->GetUserWorkerInitialization()) {
96  masterRM->GetUserWorkerInitialization()->WorkerStart();
97  }
98 
99  // Initialize the worker run manager
100  ATH_MSG_INFO("Initializing worker RM");
101  wrm->Initialize();
102 
103  // Atomic increment number of initialized threads
104  m_nInitThreads++;
105 
106  ATH_MSG_INFO ("==> tbb thread end of initThread with id: 0x" << std::hex <<
107  pthread_self() << std::dec );
108 
109 }

◆ nInit()

virtual unsigned int G4InitTool::nInit ( ) const
inlinevirtual

Definition at line 22 of file G4InitTool.h.

22 { return m_nInitThreads; }

◆ terminateThread()

void G4InitTool::terminateThread ( )
virtual

Definition at line 114 of file G4InitTool.cxx.

114  {
115 
116  ATH_MSG_INFO ("terminateThread ==> tbb thread 0x"
117  << std::hex << pthread_self() << std::dec );
118 
119  // call the run termination method on the G4 side
120  G4RunManager::GetRunManager()->RunTermination();
121 
122  m_nInitThreads--;
123 
124 }

Member Data Documentation

◆ m_nInitThreads

std::atomic_uint G4InitTool::m_nInitThreads
private

Definition at line 26 of file G4InitTool.h.


The documentation for this class was generated from the following files:
G4InitTool::m_nInitThreads
std::atomic_uint m_nInitThreads
Definition: G4InitTool.h:26
pid_t
int32_t pid_t
Definition: FPGATrackSimTypes.h:19
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
TRTCalib_cfilter.detector
detector
Definition: TRTCalib_cfilter.py:241
test_pyathena.parent
parent
Definition: test_pyathena.py:15
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
ATLAS_THREAD_SAFE
#define ATLAS_THREAD_SAFE
Definition: checker_macros.h:211