ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
Simulation
G4Utilities
G4RunManagement
src
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
9
#include "
AthenaBaseComps/AthAlgTool.h
"
10
11
// Gaudi headers
12
#include "GaudiKernel/ServiceHandle.h"
13
#include "GaudiKernel/ToolHandle.h"
14
15
// Athena headers
16
#include "
G4AtlasInterfaces/IG4RunTool.h
"
17
#include "
G4AtlasInterfaces/IDetectorConstructionTool.h
"
18
#include "
G4AtlasInterfaces/IG4RunTool.h
"
19
#include "
G4AtlasInterfaces/IPhysicsListSvc.h
"
20
#include "
G4AtlasInterfaces/IPhysicsInitialization.h
"
21
#include "
G4AtlasInterfaces/IUserActionSvc.h
"
22
#include "
G4AtlasInterfaces/IUserActionTool.h
"
23
#include "
G4AtlasInterfaces/IUserLimitsSvc.h
"
24
#include "
G4RunManagement/AtlasG4SyncEventUserInfo.h
"
25
26
// STL headers
27
#include <condition_variable>
28
#include <memory>
29
#include <mutex>
30
#include <queue>
31
#include <thread>
32
48
class
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
92
struct
StateSynchronization
93
{
94
enum class
Status
{
95
Created
,
96
BeginRun
,
97
AthenaFinalize
,
98
Size
99
};
100
void
SetStatus
(
const
Status
&);
101
void
WaitStatus
(
const
Status
&);
102
Status
m_status
{
Status::Created
};
103
mutable
std::mutex
m_mutex
;
104
std::condition_variable
m_cv
;
105
};
106
107
struct
EventQueueSynchronization
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
118
StateSynchronization
m_statusSync
;
119
120
// Event queue management
121
EventQueueSynchronization
m_eventQueueSync
;
122
};
123
124
#endif
AthAlgTool.h
AtlasG4SyncEventUserInfo.h
IDetectorConstructionTool.h
IG4RunTool.h
IPhysicsInitialization.h
IPhysicsListSvc.h
IUserActionSvc.h
IUserActionTool.h
IUserLimitsSvc.h
G4RunTool
Front-end service for initializing and interacting with the Geant4 run.
Definition
G4RunTool.h:48
G4RunTool::m_physicsListSvc
ServiceHandle< IPhysicsListSvc > m_physicsListSvc
Definition
G4RunTool.h:74
G4RunTool::finalize
virtual StatusCode finalize() override final
Definition
G4RunTool.cxx:42
G4RunTool::WaitBeginRun
virtual void WaitBeginRun() override
Definition
G4RunTool.cxx:74
G4RunTool::m_eventQueueSync
EventQueueSynchronization m_eventQueueSync
Definition
G4RunTool.h:121
G4RunTool::m_thread
std::unique_ptr< std::thread > m_thread
Definition
G4RunTool.h:115
G4RunTool::Geant4main
void Geant4main()
Geant4 main thread function, this is executed in a separate thread and blocks on BeamOn.
Definition
G4RunTool.cxx:125
G4RunTool::m_g4commands
Gaudi::Property< std::vector< std::string > > m_g4commands
Definition
G4RunTool.h:87
G4RunTool::m_nG4threads
Gaudi::Property< int > m_nG4threads
Definition
G4RunTool.h:89
G4RunTool::m_nG4eventsPerRun
Gaudi::Property< int > m_nG4eventsPerRun
Definition
G4RunTool.h:90
G4RunTool::NotifyBeginRun
virtual void NotifyBeginRun() override
Notify Athena that Geant4 is ready to start a run.
Definition
G4RunTool.cxx:69
G4RunTool::m_userLimitsSvc
ServiceHandle< IUserLimitsSvc > m_userLimitsSvc
Definition
G4RunTool.h:75
G4RunTool::m_activateParallelGeometries
Gaudi::Property< bool > m_activateParallelGeometries
Definition
G4RunTool.h:82
G4RunTool::GetEvent
virtual UPEvent GetEvent() override
Get an event from the queue (called from Geant4 threads).
Definition
G4RunTool.cxx:111
G4RunTool::m_libList
Gaudi::Property< std::string > m_libList
Definition
G4RunTool.h:84
G4RunTool::m_actionTools
ToolHandleArray< G4UA::IUserActionTool > m_actionTools
Definition
G4RunTool.h:79
G4RunTool::initialize
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
G4RunTool::Size
virtual size_t Size() const override
Definition
G4RunTool.cxx:96
G4RunTool::PushEvent
virtual void PushEvent(UPEvent ev) override
Definition
G4RunTool.cxx:102
G4RunTool::m_physicsInitializationTools
PublicToolHandleArray< IPhysicsInitializationTool > m_physicsInitializationTools
Definition
G4RunTool.h:80
G4RunTool::m_fieldMap
Gaudi::Property< std::string > m_fieldMap
Definition
G4RunTool.h:86
G4RunTool::m_userActionSvc
ServiceHandle< G4UA::IUserActionSvc > m_userActionSvc
Definition
G4RunTool.h:76
G4RunTool::m_statusSync
StateSynchronization m_statusSync
Definition
G4RunTool.h:118
G4RunTool::m_detConstruction
ToolHandle< IDetectorConstructionTool > m_detConstruction
Definition
G4RunTool.h:78
G4RunTool::commandLog
void commandLog(int returnCode, const std::string &commandString) const
This command prints a message about a G4Command depending on its returnCode.
Definition
G4RunTool.cxx:245
G4RunTool::m_physList
Gaudi::Property< std::string > m_physList
Definition
G4RunTool.h:85
ServiceHandle
Definition
ClusterMakerTool.h:36
ev
int ev
Definition
globals.cxx:25
G4RunTool::EventQueueSynchronization
Definition
G4RunTool.h:108
G4RunTool::EventQueueSynchronization::m_mutex
std::mutex m_mutex
Definition
G4RunTool.h:110
G4RunTool::EventQueueSynchronization::m_events
std::queue< UPEvent > m_events
Definition
G4RunTool.h:109
G4RunTool::EventQueueSynchronization::m_cv
std::condition_variable m_cv
Definition
G4RunTool.h:111
G4RunTool::StateSynchronization
Definition
G4RunTool.h:93
G4RunTool::StateSynchronization::m_mutex
std::mutex m_mutex
Definition
G4RunTool.h:103
G4RunTool::StateSynchronization::m_status
Status m_status
Definition
G4RunTool.h:102
G4RunTool::StateSynchronization::Status
Status
Definition
G4RunTool.h:94
G4RunTool::StateSynchronization::Status::Created
@ Created
Definition
G4RunTool.h:95
G4RunTool::StateSynchronization::Status::BeginRun
@ BeginRun
Definition
G4RunTool.h:96
G4RunTool::StateSynchronization::Status::AthenaFinalize
@ AthenaFinalize
Definition
G4RunTool.h:97
G4RunTool::StateSynchronization::SetStatus
void SetStatus(const Status &)
Definition
G4RunTool.cxx:78
G4RunTool::StateSynchronization::m_cv
std::condition_variable m_cv
Definition
G4RunTool.h:104
G4RunTool::StateSynchronization::WaitStatus
void WaitStatus(const Status &)
Definition
G4RunTool.cxx:86
Generated on
for ATLAS Offline Software by
1.17.0