ATLAS Offline Software
G4AtlasMTRunManager.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // Hide multi-threading classes from builds without G4MT
6 #include "G4Types.hh"
7 #ifdef G4MULTITHREADED
8 
10 
11 #include "G4StateManager.hh"
12 #include "G4GeometryManager.hh"
13 #include "G4UserRunAction.hh"
14 #include "G4Run.hh"
15 #include "G4LogicalVolumeStore.hh"
16 #include "G4MTRunManagerKernel.hh"
17 
18 #include "G4IonTable.hh"
19 #include "G4ParticleTable.hh"
20 #include "G4CascadeInterface.hh"
21 
22 #include "GaudiKernel/ISvcLocator.h"
23 #include "GaudiKernel/Bootstrap.h"
24 
25 G4AtlasMTRunManager::G4AtlasMTRunManager()
26  : G4MTRunManager()
27  , AthMessaging("G4AtlasMTRunManager")
28  , m_physListSvc("PhysicsListSvc", "G4AtlasMTRunManager")
29 {}
30 
31 
32 G4AtlasMTRunManager* G4AtlasMTRunManager::GetG4AtlasMTRunManager ATLAS_NOT_THREAD_SAFE ()
33 {
34  static G4AtlasMTRunManager* thisManager = nullptr;
35  if (!thisManager) { thisManager = new G4AtlasMTRunManager; }
36  return thisManager;
37 }
38 
39 
41 {
42  ATH_MSG_INFO("Initialize");
43  // Set up geometry and physics in base class.
45  // Construct scoring worlds
46  ConstructScoringWorlds();
47  // Run initialization in G4RunManager.
48  // Normally done in BeamOn.
49  if (m_quietMode) { SetVerboseLevel(0); } // HACK
50  RunInitialization();
51  // Setup physics decay channels.
52  // Normally done in InitializeEventLoop, from DoEventLoop, from BeamOn.
53  GetMTMasterRunManagerKernel()->SetUpDecayChannels();
54  // Setup UI commands
55  PrepareCommandsStack();
56 }
57 
58 
59 void G4AtlasMTRunManager::InitializeGeometry()
60 {
61  ATH_MSG_INFO("InitializeGeometry");
62 
63  // Create/assign detector construction
64  SetUserInitialization(m_detConstruction->GetDetectorConstruction().release());
65  if (userDetector) {
66  G4RunManager::InitializeGeometry();
67  }
68  else {
69  // Shouldn't we abort here?
70  ATH_MSG_WARNING("User Detector not set!!! Geometry NOT initialized!!!");
71  }
72 }
73 
74 void G4AtlasMTRunManager::InitializePhysics()
75 {
76  ATH_MSG_INFO("InitializePhysics");
77  kernel->InitializePhysics();
78 
81  physicsInitialized = true;
82 
83  // Grab the physics list tool and set the extra options
84  if (m_physListSvc.retrieve().isFailure()) {
85  ATH_MSG_ERROR("Could not retrieve the physics list tool");
86  G4ExceptionDescription description;
87  description << "InitializePhysics: Failed to retrieve IPhysicsListSvc.";
88  G4Exception("G4AtlasMTRunManager", "CouldNotRetrievePLTool",
89  FatalException, description);
90  abort(); // to keep Coverity happy
91  }
92  m_physListSvc->SetPhysicsOptions();
93  // TODO: parallel worlds stuff here
94 }
95 
96 
97 // I suspect a lot of this could just be delegated to the base class.
98 // I wonder if something there breaks in Athena..
99 void G4AtlasMTRunManager::RunTermination()
100 {
101  // vanilla G4 calls a different method... why?
102  CleanUpPreviousEvents();
103  previousEvents->clear();
104 
105  if(userRunAction) { userRunAction->EndOfRunAction(currentRun); }
106 
107  delete currentRun;
108  currentRun = nullptr;
109  runIDCounter++;
110 
111  ATH_MSG_INFO( "Changing the state..." );
112  G4StateManager* stateManager = G4StateManager::GetStateManager();
113  stateManager->SetNewState(G4State_Idle);
114 
115  ATH_MSG_INFO( "Opening the geometry back up" );
116  G4GeometryManager::GetInstance()->OpenGeometry();
117 
118  ATH_MSG_INFO( "Terminating the run... State is " <<
119  stateManager->GetStateString( stateManager->GetCurrentState() ) );
120  kernel->RunTermination();
121  ATH_MSG_INFO( "All done..." );
122 
123  userRunAction = nullptr;
124  userEventAction = nullptr;
125  userSteppingAction = nullptr;
126  userStackingAction = nullptr;
127  userTrackingAction = nullptr;
128  // physicsList = nullptr;
129  userDetector = nullptr;
130  userPrimaryGeneratorAction = nullptr;
131 }
132 
133 #endif // G4MULTITHREADED
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
G4AtlasMTRunManager.h
ATLAS_NOT_THREAD_SAFE
#define ATLAS_NOT_THREAD_SAFE
getNoisyStrip() Find noisy strips from hitmaps and write out into xml/db formats
Definition: checker_macros.h:212
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
jobOptions.Initialize
Initialize
Definition: jobOptions.pA.py:28
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
description
std::string description
glabal timer - how long have I taken so far?
Definition: hcg.cxx:88