ATLAS Offline Software
Loading...
Searching...
No Matches
G4RunTool.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef G4ATLASSERVICES_G4RunTool_H
6#define G4ATLASSERVICES_G4RunTool_H
7
8// Base classes
10
11// Gaudi headers
12#include "GaudiKernel/ServiceHandle.h"
13#include "GaudiKernel/ToolHandle.h"
14
15// Athena headers
25
26// STL headers
27#include <condition_variable>
28#include <memory>
29#include <mutex>
30#include <queue>
31#include <thread>
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;
61 virtual void WaitBeginRun() override;
62
63 // Event queue management
64 virtual size_t Size() const override;
65 virtual void PushEvent(UPEvent ev) override;
66 virtual UPEvent GetEvent() override;
67
68 private:
70 void Geant4main();
72 void commandLog(int returnCode, const std::string& commandString) const;
73
74 ServiceHandle<IPhysicsListSvc> m_physicsListSvc{this, "PhysicsListSvc", "PhysicsListSvc"};
75 ServiceHandle<IUserLimitsSvc> m_userLimitsSvc{this, "UserLimitsSvc", "UserLimitsSvc"};
76 ServiceHandle<G4UA::IUserActionSvc> m_userActionSvc{this, "UserActionSvc", "G4UA::UserActionSvc"};
77
78 ToolHandle<IDetectorConstructionTool> m_detConstruction{this, "DetectorConstruction", "", "Tool handle of the DetectorConstruction"};
79 ToolHandleArray<G4UA::IUserActionTool> m_actionTools{this, "UserActionTools", {}, "User action tools to be added to the G4 Action service."};
80 PublicToolHandleArray<IPhysicsInitializationTool> m_physicsInitializationTools{this, "PhysicsInitializationTools", {}, "Physics initialization happening after Geant4 initialization"};
81
82 Gaudi::Property<bool> m_activateParallelGeometries{this, "ActivateParallelWorlds", false, "Toggle on/off the G4 parallel geometry system"};
83
84 Gaudi::Property<std::string> m_libList{this, "Dll", "", ""};
85 Gaudi::Property<std::string> m_physList{this, "Physics", "", ""};
86 Gaudi::Property<std::string> m_fieldMap{this, "FieldMap", "", ""};
87 Gaudi::Property<std::vector<std::string> > m_g4commands{this, "G4Commands", {}, "Commands to be sent to Geant4 UI at initialization"};
88
89 Gaudi::Property<int> m_nG4threads{this, "NG4threads", 1, "Number of parallel G4 worker threads to launch"};
90 Gaudi::Property<int> m_nG4eventsPerRun{this, "NG4eventsPerRun", 100000, "Number of G4 events foreseen for each Run"};
91
93 {
100 void SetStatus(const Status&);
101 void WaitStatus(const Status&);
103 mutable std::mutex m_mutex;
104 std::condition_variable m_cv;
105 };
106
108 {
109 std::queue<UPEvent> m_events;
110 mutable std::mutex m_mutex;
111 std::condition_variable m_cv;
112 };
113
114 // The Geant4 main thread
115 std::unique_ptr<std::thread> m_thread;
116
117 // Status management
119
120 // Event queue management
122};
123
124#endif
Front-end service for initializing and interacting with the Geant4 run.
Definition G4RunTool.h:48
ServiceHandle< IPhysicsListSvc > m_physicsListSvc
Definition G4RunTool.h:74
virtual StatusCode finalize() override final
Definition G4RunTool.cxx:41
virtual void WaitBeginRun() override
Definition G4RunTool.cxx:73
EventQueueSynchronization m_eventQueueSync
Definition G4RunTool.h:121
std::unique_ptr< std::thread > m_thread
Definition G4RunTool.h:115
void Geant4main()
Geant4 main thread function, this is executed in a separate thread and blocks on BeamOn.
Gaudi::Property< std::vector< std::string > > m_g4commands
Definition G4RunTool.h:87
Gaudi::Property< int > m_nG4threads
Definition G4RunTool.h:89
Gaudi::Property< int > m_nG4eventsPerRun
Definition G4RunTool.h:90
virtual void NotifyBeginRun() override
Notify Athena that Geant4 is ready to start a run.
Definition G4RunTool.cxx:68
ServiceHandle< IUserLimitsSvc > m_userLimitsSvc
Definition G4RunTool.h:75
Gaudi::Property< bool > m_activateParallelGeometries
Definition G4RunTool.h:82
virtual UPEvent GetEvent() override
Get an event from the queue (called from Geant4 threads)
Gaudi::Property< std::string > m_libList
Definition G4RunTool.h:84
ToolHandleArray< G4UA::IUserActionTool > m_actionTools
Definition G4RunTool.h:79
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:24
virtual size_t Size() const override
Definition G4RunTool.cxx:95
virtual void PushEvent(UPEvent ev) override
PublicToolHandleArray< IPhysicsInitializationTool > m_physicsInitializationTools
Definition G4RunTool.h:80
Gaudi::Property< std::string > m_fieldMap
Definition G4RunTool.h:86
ServiceHandle< G4UA::IUserActionSvc > m_userActionSvc
Definition G4RunTool.h:76
StateSynchronization m_statusSync
Definition G4RunTool.h:118
ToolHandle< IDetectorConstructionTool > m_detConstruction
Definition G4RunTool.h:78
void commandLog(int returnCode, const std::string &commandString) const
This command prints a message about a G4Command depending on its returnCode.
Gaudi::Property< std::string > m_physList
Definition G4RunTool.h:85
int ev
Definition globals.cxx:25
std::queue< UPEvent > m_events
Definition G4RunTool.h:109
std::condition_variable m_cv
Definition G4RunTool.h:111
void SetStatus(const Status &)
Definition G4RunTool.cxx:77
std::condition_variable m_cv
Definition G4RunTool.h:104
void WaitStatus(const Status &)
Definition G4RunTool.cxx:85