ATLAS Offline Software
Public Member Functions | List of all members
G4UA::UserActionSvc Class Reference

A service which manages the user actions for G4 simulation. More...

#include <UserActionSvc.h>

Inheritance diagram for G4UA::UserActionSvc:
Collaboration diagram for G4UA::UserActionSvc:

Public Member Functions

 UserActionSvc (const std::string &name, ISvcLocator *pSvcLocator)
 Standard constructor. More...
 
StatusCode initialize () override
 Initialize the service. More...
 
StatusCode initializeActions () override final
 Initialize the user actions for the current thread. More...
 
StatusCode getSecondaryActions (std::vector< G4UserSteppingAction * > &actions) override final
 
StatusCode addActionTool (const ToolHandle< IUserActionTool > &service_tool) override final
 

Private Attributes

Handles to ATLAS action tools
ToolHandleArray< IUserActionToolm_userActionTools
 User action tools. More...
 
ATLAS Geant4 user actions
ThreadActionHolder< G4AtlasRunActionm_runActions
 Thread-local run action. More...
 
ThreadActionHolder< G4AtlasEventActionm_eventActions
 Thread-local event action. More...
 
ThreadActionHolder< G4AtlasStackingActionm_stackingActions
 Thread-local stacking action. More...
 
ThreadActionHolder< G4AtlasTrackingActionm_trackingActions
 Thread-local tracking action. More...
 
ThreadActionHolder< G4AtlasSteppingActionm_steppingActions
 Thread-local stepping action. More...
 

Detailed Description

A service which manages the user actions for G4 simulation.

Author
Steve Farrell Steve.nosp@m.n.Fa.nosp@m.rrell.nosp@m.@cer.nosp@m.n.ch

Definition at line 35 of file UserActionSvc.h.

Constructor & Destructor Documentation

◆ UserActionSvc()

G4UA::UserActionSvc::UserActionSvc ( const std::string &  name,
ISvcLocator *  pSvcLocator 
)

Standard constructor.

Definition at line 23 of file UserActionSvc.cxx.

25  : base_class(name, pSvcLocator)
26  , m_userActionTools(this)
27  {
28  declareProperty("UserActionTools", m_userActionTools);
29  }

Member Function Documentation

◆ addActionTool()

StatusCode G4UA::UserActionSvc::addActionTool ( const ToolHandle< IUserActionTool > &  service_tool)
finaloverride

Definition at line 46 of file UserActionSvc.cxx.

46  {
47 
48  if (!service_tool.isPublic()){
49  ATH_MSG_FATAL("Only public tools are allowed");
50  return StatusCode::FAILURE;
51  }
52  if (service_tool.empty()) {
53  ATH_MSG_FATAL("NO point in adding empty tool handles here.");
54  return StatusCode::FAILURE;
55  }
56  ATH_MSG_INFO(" Add new tool "<<service_tool.name());
57  m_userActionTools.push_back(service_tool);
58  return StatusCode::SUCCESS;
59  }

◆ getSecondaryActions()

StatusCode G4UA::UserActionSvc::getSecondaryActions ( std::vector< G4UserSteppingAction * > &  actions)
finaloverride

Definition at line 178 of file UserActionSvc.cxx.

178  {
179 
180  // Only stepping actions can return secondaries? Maybe turn this into a templated method
181  actions = m_steppingActions.get()->getActions();
182 
183  return StatusCode::SUCCESS;
184  }

◆ initialize()

StatusCode G4UA::UserActionSvc::initialize ( )
override

Initialize the service.

Definition at line 34 of file UserActionSvc.cxx.

35  {
36  ATH_MSG_INFO("Initializing " << m_userActionTools.size() << " user action tools.");
37 
38  for(const auto& action : m_userActionTools) {
39  ATH_MSG_INFO( " -> " << action.name() );
40  }
41 
42  ATH_CHECK( m_userActionTools.retrieve() );
43 
44  return StatusCode::SUCCESS;
45  }

◆ initializeActions()

StatusCode G4UA::UserActionSvc::initializeActions ( )
finaloverride

Initialize the user actions for the current thread.

Definition at line 67 of file UserActionSvc.cxx.

68  {
69  // This method is called concurrently in AthenaMT during initialization.
70  // We conservatively just lock the whole thing to protect MsgStream and
71  // downstream code.
72  static std::mutex userActionMutex;
73  std::lock_guard<std::mutex> userActionLock(userActionMutex);
74 
75  ATH_MSG_DEBUG("initializeActions");
76 
77  // sanity check: this is to make sure there are no other instances of this
78  // svc that have been already initialized, or that nobody else in some other
79  // code has already been registering actions to the run manager, which would
80  // be a major error in the configuration checking the run action is probably
81  // enough fo multiple instances of this service, since all roles are usually
82  // set at the same time. but other code may as well have registered just one
83  // role, so it is safer to do all checks here.
84 
85  if( G4RunManager::GetRunManager()->GetUserRunAction() ||
86  G4RunManager::GetRunManager()->GetUserEventAction() ||
87  G4RunManager::GetRunManager()->GetUserStackingAction() ||
88  G4RunManager::GetRunManager()->GetUserTrackingAction() ||
89  G4RunManager::GetRunManager()->GetUserSteppingAction() )
90  {
91  ATH_MSG_FATAL("UserActionSvc has found that actions were already " <<
92  "registered to the G4RunManager. Check your code/configuration");
93  return StatusCode::FAILURE;
94  }
95 
96  // Retrieve the new user actions
97  G4AtlasUserActions actions;
98  for(auto& tool : m_userActionTools) {
99  ATH_CHECK( tool->fillUserAction(actions) );
100  }
101 
102  // Initialize the ATLAS run action.
103  if(m_runActions.get()) {
104  ATH_MSG_ERROR("Run action already exists for current thread!");
105  return StatusCode::FAILURE;
106  }
107  auto runAction = std::make_unique<G4AtlasRunAction>();
108  // Assign run plugins
109  for(auto* action : actions.runActions)
110  runAction->addRunAction(action);
111  G4RunManager::GetRunManager()->SetUserAction( runAction.get() );
112  m_runActions.set( std::move(runAction) );
113 
114  // Initialize the ATLAS event action.
115  if(m_eventActions.get()) {
116  ATH_MSG_ERROR("Event action already exists for current thread!");
117  return StatusCode::FAILURE;
118  }
119  auto eventAction = std::make_unique<G4AtlasEventAction>();
120  // Assign event plugins
121  for(auto* action : actions.eventActions) {
122  eventAction->addEventAction(action);
123  // set the event manager
124  action->SetEventManager( G4EventManager::GetEventManager() );
125  }
126  G4RunManager::GetRunManager()->SetUserAction( eventAction.get() );
127  m_eventActions.set( std::move(eventAction) );
128 
129  // Initialize the ATLAS stacking action.
130  if(m_stackingActions.get()) {
131  ATH_MSG_ERROR("Stacking action already exists for current thread!");
132  return StatusCode::FAILURE;
133  }
134  auto stackAction = std::make_unique<G4AtlasStackingAction>();
135  // Assign stacking plugins
136  for(auto* action : actions.stackingActions) {
137  stackAction->addAction(action);
138  // set the stack manager
139  action->SetStackManager( G4EventManager::GetEventManager()->GetStackManager() );
140  }
141  G4RunManager::GetRunManager()->SetUserAction( stackAction.get() );
142  m_stackingActions.set( std::move(stackAction) );
143 
144  // Initialize the ATLAS tracking action.
145  if(m_trackingActions.get()) {
146  ATH_MSG_ERROR("Tracking action already exists for current thread!");
147  return StatusCode::FAILURE;
148  }
149  auto trackAction = std::make_unique<G4AtlasTrackingAction>();
150  // Assign tracking plugins
151  for(auto* action : actions.trackingActions) {
152  trackAction->addTrackAction(action);
153  // set the tracking manager
154  action->SetTrackingManagerPointer ( G4EventManager::GetEventManager()->GetTrackingManager() );
155  }
156  G4RunManager::GetRunManager()->SetUserAction( trackAction.get() );
157  m_trackingActions.set( std::move(trackAction) );
158 
159  // Initialize the ATLAS stepping action.
160  if(m_steppingActions.get()) {
161  ATH_MSG_ERROR("Stepping action already exists for current thread!");
162  return StatusCode::FAILURE;
163  }
164  auto stepAction = std::make_unique<G4AtlasSteppingAction>();
165  // Assign stepping plugins
166  for(auto* action : actions.steppingActions) {
167  stepAction->addAction(action);
168  // set the stepping manager
169  action->SetSteppingManagerPointer( G4EventManager::GetEventManager()->GetTrackingManager()->GetSteppingManager() );
170  }
171  G4RunManager::GetRunManager()->SetUserAction( stepAction.get() );
172  m_steppingActions.set( std::move(stepAction) );
173 
174  return StatusCode::SUCCESS;
175  }

Member Data Documentation

◆ m_eventActions

ThreadActionHolder<G4AtlasEventAction> G4UA::UserActionSvc::m_eventActions
private

Thread-local event action.

Definition at line 68 of file UserActionSvc.h.

◆ m_runActions

ThreadActionHolder<G4AtlasRunAction> G4UA::UserActionSvc::m_runActions
private

Thread-local run action.

Definition at line 66 of file UserActionSvc.h.

◆ m_stackingActions

ThreadActionHolder<G4AtlasStackingAction> G4UA::UserActionSvc::m_stackingActions
private

Thread-local stacking action.

Definition at line 70 of file UserActionSvc.h.

◆ m_steppingActions

ThreadActionHolder<G4AtlasSteppingAction> G4UA::UserActionSvc::m_steppingActions
private

Thread-local stepping action.

Definition at line 74 of file UserActionSvc.h.

◆ m_trackingActions

ThreadActionHolder<G4AtlasTrackingAction> G4UA::UserActionSvc::m_trackingActions
private

Thread-local tracking action.

Definition at line 72 of file UserActionSvc.h.

◆ m_userActionTools

ToolHandleArray<IUserActionTool> G4UA::UserActionSvc::m_userActionTools
private

User action tools.

Definition at line 58 of file UserActionSvc.h.


The documentation for this class was generated from the following files:
G4UA::UserActionSvc::m_userActionTools
ToolHandleArray< IUserActionTool > m_userActionTools
User action tools.
Definition: UserActionSvc.h:58
G4UA::UserActionSvc::m_stackingActions
ThreadActionHolder< G4AtlasStackingAction > m_stackingActions
Thread-local stacking action.
Definition: UserActionSvc.h:70
G4UA::UserActionSvc::m_runActions
ThreadActionHolder< G4AtlasRunAction > m_runActions
Thread-local run action.
Definition: UserActionSvc.h:66
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
G4UA::UserActionSvc::m_eventActions
ThreadActionHolder< G4AtlasEventAction > m_eventActions
Thread-local event action.
Definition: UserActionSvc.h:68
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
BeamSpot::mutex
std::mutex mutex
Definition: InDetBeamSpotVertex.cxx:18
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
python.CaloScaleNoiseConfig.action
action
Definition: CaloScaleNoiseConfig.py:77
declareProperty
#define declareProperty(n, p, h)
Definition: BaseFakeBkgTool.cxx:15
G4UA::UserActionSvc::m_trackingActions
ThreadActionHolder< G4AtlasTrackingAction > m_trackingActions
Thread-local tracking action.
Definition: UserActionSvc.h:72
G4UA::UserActionSvc::m_steppingActions
ThreadActionHolder< G4AtlasSteppingAction > m_steppingActions
Thread-local stepping action.
Definition: UserActionSvc.h:74