11 #include "G4StateManager.hh"
13 #include "G4LogicalVolumeStore.hh"
14 #include "G4GeometryManager.hh"
15 #include "G4MTRunManager.hh"
16 #include "G4TransportationManager.hh"
17 #include "G4VUserDetectorConstruction.hh"
18 #include "G4UImanager.hh"
19 #include "G4HadronicProcessStore.hh"
22 #include "GaudiKernel/ISvcLocator.h"
23 #include "GaudiKernel/Bootstrap.h"
24 #include "GaudiKernel/IMessageSvc.h"
25 #include "GaudiKernel/GaudiException.h"
32 G4AtlasWorkerRunManager::G4AtlasWorkerRunManager()
33 : G4WorkerRunManager()
36 , m_detGeoSvc(
"DetectorGeometrySvc",
"G4AtlasWorkerRunManager")
37 , m_fastSimTool(
"FastSimulationMasterTool")
41 G4AtlasWorkerRunManager* G4AtlasWorkerRunManager::GetG4AtlasWorkerRunManager()
44 auto* wrm = G4RunManager::GetRunManager();
45 if(wrm) {
return static_cast<G4AtlasWorkerRunManager*
>(wrm); }
46 else {
return new G4AtlasWorkerRunManager; }
53 std::lock_guard<std::mutex> lock(workerInitMutex);
56 G4HadronicProcessStore::Instance()->SetVerbose(0);
73 ATH_MSG_DEBUG(
"G4 Command: Trying at the end of Initialize()");
74 const std::string methodName =
"G4AtlasWorkerRunManager::Initialize";
75 G4MTRunManager* masterRM = G4MTRunManager::GetMasterRunManager();
76 std::vector<G4String>
cmds = masterRM->GetCommandStack();
77 G4UImanager* uimgr = G4UImanager::GetUIpointer();
78 for(
const auto&
it :
cmds) {
79 int retVal = uimgr->ApplyCommand(
it);
80 CommandLog(retVal,
it);
81 if(retVal!=fCommandSucceeded) {
82 std::string errMsg{
"Failed to apply command <"};
84 throw GaudiException(errMsg,methodName,StatusCode::FAILURE);
89 ConstructScoringWorlds();
92 if (m_quietMode) { SetVerboseLevel(0); }
96 void G4AtlasWorkerRunManager::InitializeGeometry()
98 const std::string methodName =
"G4AtlasWorkerRunManager::InitializeGeometry";
101 if(G4RunManager::IfGeometryHasBeenDestroyed()) {
102 G4TransportationManager::GetTransportationManager()->ClearParallelWorlds();
106 G4RunManagerKernel* masterKernel = G4MTRunManager::GetMasterRunManagerKernel();
107 G4VPhysicalVolume* worldVol = masterKernel->GetCurrentWorld();
108 kernel->WorkerDefineWorldVolume(worldVol,
false);
110 kernel->SetNumberOfParallelWorld(masterKernel->GetNumberOfParallelWorld());
113 userDetector->ConstructSDandField();
114 userDetector->ConstructParallelSD();
117 geometryInitialized =
true;
120 void G4AtlasWorkerRunManager::InitializePhysics()
122 const std::string methodName =
"G4AtlasWorkerRunManager::InitializePhysics";
125 G4RunManager::InitializePhysics();
128 if(m_fastSimTool.retrieve().isFailure()) {
129 throw GaudiException(
"Could not retrieve FastSims master tool",
130 methodName, StatusCode::FAILURE);
132 if(m_fastSimTool->initializeFastSims().isFailure()) {
133 throw GaudiException(
"Failed to initialize FastSims for worker thread",
134 methodName, StatusCode::FAILURE);
139 bool G4AtlasWorkerRunManager::ProcessEvent(G4Event*
event)
142 G4StateManager* stateManager = G4StateManager::GetStateManager();
143 stateManager->SetNewState(G4State_GeomClosed);
145 currentEvent =
event;
149 eventManager->ProcessOneEvent(currentEvent);
150 if (currentEvent->IsAborted()) {
152 "Event Aborted at Detector Simulation level" );
153 currentEvent =
nullptr;
157 this->AnalyzeEvent(currentEvent);
158 if (currentEvent->IsAborted()) {
160 "Event Aborted at Analysis level" );
161 currentEvent =
nullptr;
165 this->StackPreviousEvent(currentEvent);
166 bool abort = currentEvent->IsAborted();
167 currentEvent =
nullptr;
173 void G4AtlasWorkerRunManager::RunTermination()
177 G4WorkerRunManager::RunTermination();
180 void G4AtlasWorkerRunManager::CommandLog(
int returnCode,
const std::string& commandString)
const
183 case 0: {
ATH_MSG_DEBUG(
"G4 Command: " << commandString <<
" - Command Succeeded"); }
break;
184 case 100: {
ATH_MSG_ERROR(
"G4 Command: " << commandString <<
" - Command Not Found!"); }
break;
186 auto* stateManager = G4StateManager::GetStateManager();
187 ATH_MSG_DEBUG(
"G4 Command: " << commandString <<
" - Illegal Application State (" <<
188 stateManager->GetStateString(stateManager->GetCurrentState()) <<
")!");
190 case 300: {
ATH_MSG_ERROR(
"G4 Command: " << commandString <<
" - Parameter Out of Range!"); }
break;
191 case 400: {
ATH_MSG_ERROR(
"G4 Command: " << commandString <<
" - Parameter Unreadable!"); }
break;
192 case 500: {
ATH_MSG_ERROR(
"G4 Command: " << commandString <<
" - Parameter Out of Candidates!"); }
break;
193 case 600: {
ATH_MSG_ERROR(
"G4 Command: " << commandString <<
" - Alias Not Found!"); }
break;
194 default: {
ATH_MSG_ERROR(
"G4 Command: " << commandString <<
" - Unknown Status!"); }
break;
199 #endif // G4MULTITHREADED