9#include "GaudiKernel/ServiceHandle.h"
12#include "G4MTRunManager.hh"
13#include "G4StateManager.hh"
14#include "G4UImanager.hh"
15#include "G4EventManager.hh"
38 ATH_MSG_DEBUG(
"Geant4main thread created, id=" <<
m_thread->get_id() <<
", now waiting for G4 run manager");
39 return StatusCode::SUCCESS;
58 catch(
const std::exception& e) {
59 ATH_MSG_ERROR(
"Failure in G4RunTool::finalize, joining Geant4 main thread:" << e.what());
63 return StatusCode::SUCCESS;
77 std::string failureMessage;
80 return StatusCode::FAILURE;
82 return StatusCode::SUCCESS;
110 std::unique_ptr<G4MTRunManager> runManager;
115 runManager = std::make_unique<G4MTRunManager>();
118 catch(
const std::exception&
error) {
123 m_statusSync.Fail(
"Unknown exception in Geant4 main thread");
138 ATH_MSG_INFO(
"Geant4 main thread starts with id " << std::this_thread::get_id());
141 constexpr int seedFirstEventOnly = 1;
143 runManager.SetSeedOncePerCommunication(seedFirstEventOnly);
147 m_statusSync.Fail(
"Failed to retrieve DetectorGeometryService");
153 m_statusSync.Fail(
"Failed to retrieve PhysicsListService");
159 m_statusSync.Fail(
"Failed to retrieve UserActionService");
171 ATH_MSG_INFO(
"retrieving action tool " + action_tool.name());
173 throw std::runtime_error(
"Failed to add action tool " + action_tool.name());
181 runManager.SetUserInitialization(
m_detConstruction->GetDetectorConstruction().release());
190 runManager.SetUserInitialization(
191 std::make_unique<G4RunToolWorkerThreadInitialization>().
release());
192 runManager.SetUserInitialization(
193 std::make_unique<G4AtlasActionInitialization>(
m_userActionSvc.get()).release());
196 G4UImanager *ui = G4UImanager::GetUIpointer();
200 ATH_MSG_INFO(
"G4AtlasAlg specific libraries requested ");
202 ui->ApplyCommand(temp);
207 std::string temp=
"/Physics/GetPhysicsList "+
m_physList;
208 ui->ApplyCommand(temp);
214 std::string temp=
"/MagneticField/Select "+
m_fieldMap;
215 ui->ApplyCommand(temp);
216 ui->ApplyCommand(
"/MagneticField/Initialize");
220 ATH_MSG_DEBUG(
"G4 Command: Trying at the end of initializeOnce()");
222 int returnCode = ui->ApplyCommand( g4command );
227 runManager.Initialize();
235 if (physicsTool->initializePhysics().isFailure()) {
236 throw std::runtime_error(
"Failed to initialize physics with tool " + physicsTool.name());
241 throw std::runtime_error(
"Could not initialize ATLAS UserLimitsSvc!");
255 case 0: {
ATH_MSG_DEBUG(
"G4 Command: " << commandString <<
" - Command Succeeded"); }
break;
256 case 100: {
ATH_MSG_ERROR(
"G4 Command: " << commandString <<
" - Command Not Found!"); }
break;
258 auto* stateManager = G4StateManager::GetStateManager();
259 ATH_MSG_DEBUG(
"G4 Command: " << commandString <<
" - Illegal Application State (" <<
260 stateManager->GetStateString(stateManager->GetCurrentState()) <<
")!");
262 case 300: {
ATH_MSG_ERROR(
"G4 Command: " << commandString <<
" - Parameter Out of Range!"); }
break;
263 case 400: {
ATH_MSG_ERROR(
"G4 Command: " << commandString <<
" - Parameter Unreadable!"); }
break;
264 case 500: {
ATH_MSG_ERROR(
"G4 Command: " << commandString <<
" - Parameter Out of Candidates!"); }
break;
265 case 600: {
ATH_MSG_ERROR(
"G4 Command: " << commandString <<
" - Alias Not Found!"); }
break;
266 default: {
ATH_MSG_ERROR(
"G4 Command: " << commandString <<
" - Unknown Status!"); }
break;
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_INFO(x,...)
static std::string release