ATLAS Offline Software
Loading...
Searching...
No Matches
G4RunTool.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef G4ATLASSERVICES_G4RunTool_H
6#define G4ATLASSERVICES_G4RunTool_H
7
10
11// Base classes
13
14// Gaudi headers
15#include "GaudiKernel/ServiceHandle.h"
16#include "GaudiKernel/ToolHandle.h"
17
18// Athena headers
26// STL headers
27#include <memory>
28#include <string>
29#include <thread>
30
31class G4MTRunManager;
32
48class G4RunTool : public extends<AthAlgTool , IG4RunTool> {
49 public:
50
51 // Standard constructor
52 using extends::extends;
53
54 // Gaudi methods
55 virtual StatusCode initialize() override final;
56 virtual StatusCode finalize() override final;
57
58 // Status management
60 virtual void NotifyBeginRun() override;
62 virtual StatusCode WaitBeginRun() override;
63
64 // Event queue management
65 virtual size_t Size() const override;
66 virtual void PushEvent(UPEvent ev) override;
67 virtual UPEvent GetEvent() override;
68
69 private:
71 void Geant4main() noexcept;
73 void Geant4mainImpl(G4MTRunManager& runManager);
75 void commandLog(int returnCode, const std::string& commandString) const;
76
77 ServiceHandle<IPhysicsListSvc> m_physicsListSvc{this, "PhysicsListSvc", "PhysicsListSvc"};
78 ServiceHandle<IUserLimitsSvc> m_userLimitsSvc{this, "UserLimitsSvc", "UserLimitsSvc"};
79 ServiceHandle<G4UA::IUserActionSvc> m_userActionSvc{this, "UserActionSvc", "G4UA::UserActionSvc"};
80
81 ToolHandle<IDetectorConstructionTool> m_detConstruction{this, "DetectorConstruction", "", "Tool handle of the DetectorConstruction"};
82 ToolHandleArray<G4UA::IUserActionTool> m_actionTools{this, "UserActionTools", {}, "User action tools to be added to the G4 Action service."};
83 PublicToolHandleArray<IPhysicsInitializationTool> m_physicsInitializationTools{this, "PhysicsInitializationTools", {}, "Physics initialization happening after Geant4 initialization"};
84
85 Gaudi::Property<bool> m_activateParallelGeometries{this, "ActivateParallelWorlds", false, "Toggle on/off the G4 parallel geometry system"};
86
87 Gaudi::Property<std::string> m_libList{this, "Dll", "", ""};
88 Gaudi::Property<std::string> m_physList{this, "Physics", "", ""};
89 Gaudi::Property<std::string> m_fieldMap{this, "FieldMap", "", ""};
90 Gaudi::Property<std::vector<std::string> > m_g4commands{this, "G4Commands", {}, "Commands to be sent to Geant4 UI at initialization"};
91
92 Gaudi::Property<int> m_nG4threads{this, "NG4threads", 1, "Number of parallel G4 worker threads to launch"};
93 Gaudi::Property<int> m_nG4eventsPerRun{this, "NG4eventsPerRun", 100000, "Number of G4 events foreseen for each Run"};
94
95 // The Geant4 main thread
96 std::unique_ptr<std::thread> m_thread;
97
98 // Status management
100
101 // Event queue management
103};
104
105#endif
Thread-safe event handoff between Athena and the Geant4 worker threads.
Thread-safe lifecycle state shared by the Athena and Geant4 main threads.
Front-end service for initializing and interacting with the Geant4 run.
Definition G4RunTool.h:48
ServiceHandle< IPhysicsListSvc > m_physicsListSvc
Definition G4RunTool.h:77
virtual StatusCode finalize() override final
Definition G4RunTool.cxx:42
std::unique_ptr< std::thread > m_thread
Definition G4RunTool.h:96
Gaudi::Property< std::vector< std::string > > m_g4commands
Definition G4RunTool.h:90
Gaudi::Property< int > m_nG4threads
Definition G4RunTool.h:92
Gaudi::Property< int > m_nG4eventsPerRun
Definition G4RunTool.h:93
virtual void NotifyBeginRun() override
Notify Athena that Geant4 is ready to start a run.
Definition G4RunTool.cxx:71
ServiceHandle< IUserLimitsSvc > m_userLimitsSvc
Definition G4RunTool.h:78
void Geant4mainImpl(G4MTRunManager &runManager)
Implementation called inside the Geant4 main thread exception boundary.
Gaudi::Property< bool > m_activateParallelGeometries
Definition G4RunTool.h:85
void Geant4main() noexcept
Geant4 main thread function, this is executed in a separate thread and blocks on BeamOn.
G4RunToolStateSynchronization m_statusSync
Definition G4RunTool.h:99
virtual UPEvent GetEvent() override
Get an event from the queue (called from Geant4 threads).
Gaudi::Property< std::string > m_libList
Definition G4RunTool.h:87
ToolHandleArray< G4UA::IUserActionTool > m_actionTools
Definition G4RunTool.h:82
virtual StatusCode initialize() override final
Initialize and start the Geant4 main thread, then wait until Geant4 is ready to start the run.
Definition G4RunTool.cxx:25
virtual size_t Size() const override
Definition G4RunTool.cxx:90
virtual void PushEvent(UPEvent ev) override
Definition G4RunTool.cxx:95
PublicToolHandleArray< IPhysicsInitializationTool > m_physicsInitializationTools
Definition G4RunTool.h:83
virtual StatusCode WaitBeginRun() override
Wait for BeginOfRun, or return failure if the Geant4 thread stops first.
Definition G4RunTool.cxx:76
Gaudi::Property< std::string > m_fieldMap
Definition G4RunTool.h:89
ServiceHandle< G4UA::IUserActionSvc > m_userActionSvc
Definition G4RunTool.h:79
ToolHandle< IDetectorConstructionTool > m_detConstruction
Definition G4RunTool.h:81
void commandLog(int returnCode, const std::string &commandString) const
This command prints a message about a G4Command depending on its returnCode.
G4RunToolEventQueue m_eventQueue
Definition G4RunTool.h:102
Gaudi::Property< std::string > m_physList
Definition G4RunTool.h:88
int ev
Definition globals.cxx:25