Initialize the user actions for the current thread.
93 std::lock_guard<std::mutex> userActionLock(userActionMutex);
105 if( G4RunManager::GetRunManager()->GetUserRunAction() ||
106 G4RunManager::GetRunManager()->GetUserPrimaryGeneratorAction() ||
107 G4RunManager::GetRunManager()->GetUserEventAction() ||
108 G4RunManager::GetRunManager()->GetUserStackingAction() ||
109 G4RunManager::GetRunManager()->GetUserTrackingAction() ||
110 G4RunManager::GetRunManager()->GetUserSteppingAction() )
112 ATH_MSG_FATAL(
"UserActionSvc has found that actions were already " <<
113 "registered to the G4RunManager. Check your code/configuration");
114 return StatusCode::FAILURE;
118 G4AtlasUserActions actions;
125 ATH_MSG_ERROR(
"Run action already exists for current thread!");
126 return StatusCode::FAILURE;
128 auto runAction = std::make_unique<G4AtlasRunAction>();
130 for(
auto*
action : actions.runActions)
131 runAction->addRunAction(
action);
132 G4RunManager::GetRunManager()->SetUserAction( runAction.get() );
137 ATH_MSG_ERROR(
"Primary generator action already exists for current thread!");
138 return StatusCode::FAILURE;
140 auto primaryGeneratorAction = std::make_unique<G4AtlasPrimaryGeneratorAction>();
142 for(
auto*
action : actions.primaryGeneratorActions)
143 primaryGeneratorAction->addPrimaryGeneratorAction(
action);
144 G4RunManager::GetRunManager()->SetUserAction( primaryGeneratorAction.get() );
149 ATH_MSG_ERROR(
"Event action already exists for current thread!");
150 return StatusCode::FAILURE;
152 auto eventAction = std::make_unique<G4AtlasEventAction>();
154 for(
auto*
action : actions.eventActions) {
155 eventAction->addEventAction(
action);
157 action->SetEventManager( G4EventManager::GetEventManager() );
159 G4RunManager::GetRunManager()->SetUserAction( eventAction.get() );
164 ATH_MSG_ERROR(
"Stacking action already exists for current thread!");
165 return StatusCode::FAILURE;
167 auto stackAction = std::make_unique<G4AtlasStackingAction>();
169 for(
auto*
action : actions.stackingActions) {
170 stackAction->addAction(
action);
172 action->SetStackManager( G4EventManager::GetEventManager()->GetStackManager() );
174 G4RunManager::GetRunManager()->SetUserAction( stackAction.get() );
179 ATH_MSG_ERROR(
"Tracking action already exists for current thread!");
180 return StatusCode::FAILURE;
182 auto trackAction = std::make_unique<G4AtlasTrackingAction>();
184 for(
auto*
action : actions.trackingActions) {
185 trackAction->addTrackAction(
action);
187 action->SetTrackingManagerPointer ( G4EventManager::GetEventManager()->GetTrackingManager() );
189 G4RunManager::GetRunManager()->SetUserAction( trackAction.get() );
194 ATH_MSG_ERROR(
"Stepping action already exists for current thread!");
195 return StatusCode::FAILURE;
197 auto stepAction = std::make_unique<G4AtlasSteppingAction>();
199 for(
auto*
action : actions.steppingActions) {
200 stepAction->addAction(
action);
202 action->SetSteppingManagerPointer( G4EventManager::GetEventManager()->GetTrackingManager()->GetSteppingManager() );
204 G4RunManager::GetRunManager()->SetUserAction( stepAction.get() );
207 return StatusCode::SUCCESS;