Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4VModularPhysicsList.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27//
28//
29// ------------------------------------------------------------
30// GEANT 4 class implementation file
31// ------------------------------------------------------------
32// - Add ReplacePhysics 14 Mar 2011 by H.Kurashige
33// - Add RemovePhysics 2 May 2011 by H.Kurashige
34//
36#include "G4StateManager.hh"
37#include <algorithm>
38
39// This macros change the references to fields that are now encapsulated
40// in the class G4VMPLData.
41#define G4MT_physicsVector \
42 ((G4VMPLsubInstanceManager.offset[g4vmplInstanceID]).physicsVector)
43
45
47
50 , verboseLevel(0)
51{
53}
54
56{
57 for(auto itr = G4MT_physicsVector->begin(); itr != G4MT_physicsVector->end();
58 ++itr)
59 {
60 delete(*itr);
61 }
62 G4MT_physicsVector->clear();
63 delete G4MT_physicsVector;
64}
65
67 : G4VUserPhysicsList(right)
68 , verboseLevel(0)
69{
71}
72
74 const G4VModularPhysicsList& right)
75{
76 if(this != &right)
77 {
85 // fDisplayThreshold = static_cast<const
86 // G4VUserPhysicsList&>(right).GetSubInstanceManager().offset[right.GetInstanceID()]._fDisplayThreshold;
88 ._fDisplayThreshold = static_cast<const G4VUserPhysicsList&>(right)
90 .offset[right.GetInstanceID()]
91 ._fDisplayThreshold;
92 // fIsPhysicsTableBuilt = static_cast<const
93 // G4VUserPhysicsList&>(right).GetSubInstanceManager().offset[right.GetInstanceID()]._fIsPhysicsTableBuilt;
95 ._fDisplayThreshold = static_cast<const G4VUserPhysicsList&>(right)
97 .offset[right.GetInstanceID()]
98 ._fIsPhysicsTableBuilt;
99 // fDisplayThreshold = right.fDisplayThreshold;
102
103 if(G4MT_physicsVector != 0)
104 {
105 for(auto itr = G4MT_physicsVector->begin();
106 itr != G4MT_physicsVector->end(); ++itr)
107 {
108 delete(*itr);
109 }
110 G4MT_physicsVector->clear();
111 delete G4MT_physicsVector;
112 }
114 }
115 return *this;
116}
117
119{
120 // create particles
121 for(auto itr = G4MT_physicsVector->begin(); itr != G4MT_physicsVector->end();
122 ++itr)
123 {
124 (*itr)->ConstructParticle();
125 ;
126 }
127}
128
129// Andrea Dotti: May 6 2013
130// Current limitation being debugged: Construction of physics processes
131// needs to be sequential (there is at least one HAD processes creating
132// problems) This is not yet understood and needs to be debugged since we do not
133// want this part to be sequential (imagine when one has 100 threads)
134// TODO: Remove this lock
135#include "G4AutoLock.hh"
136namespace
137{
138 G4Mutex constructProcessMutex = G4MUTEX_INITIALIZER;
139}
140
142{
143 G4AutoLock l(&constructProcessMutex); // Protection to be removed (A.Dotti)
145
146 for(auto itr = G4MT_physicsVector->begin(); itr != G4MT_physicsVector->end();
147 ++itr)
148 {
149 (*itr)->ConstructProcess();
150 }
151}
152
154{
156 G4ApplicationState currentState = stateManager->GetCurrentState();
157 if(!(currentState == G4State_PreInit))
158 {
159 G4Exception("G4VModularPhysicsList::RegisterPhysics", "Run0201",
161 "Geant4 kernel is not PreInit state : Method ignored.");
162 return;
163 }
164
165 G4String pName = fPhysics->GetPhysicsName();
166 G4int pType = fPhysics->GetPhysicsType();
167 // If physics_type is equal to 0,
168 // following duplication check is omitted
169 // This is TEMPORAL treatment.
170 if(pType == 0)
171 {
172 G4MT_physicsVector->push_back(fPhysics);
173#ifdef G4VERBOSE
174 if(verboseLevel > 1)
175 {
176 G4cout << "G4VModularPhysicsList::RegisterPhysics: " << pName
177 << " with type : " << pType << " is added" << G4endl;
178 }
179#endif
180 return;
181 }
182
183 // Check if physics with the physics_type same as one of given physics
184 auto itr = G4MT_physicsVector->begin();
185 for(; itr != G4MT_physicsVector->end(); ++itr)
186 {
187 if(pType == (*itr)->GetPhysicsType())
188 break;
189 }
190 if(itr != G4MT_physicsVector->end())
191 {
192#ifdef G4VERBOSE
193 if(verboseLevel > 0)
194 {
195 G4cout << "G4VModularPhysicsList::RegisterPhysics: "
196 << "a physics with given type already exists " << G4endl;
197 G4cout << " Type = " << pType << " : "
198 << " existing physics is " << (*itr)->GetPhysicsName() << G4endl;
199 G4cout << " New " << pName << " can not be registered " << G4endl;
200 }
201#endif
202 G4String comment = "Duplicate type for ";
203 comment += pName;
204 G4Exception("G4VModularPhysicsList::RegisterPhysics", "Run0202",
205 JustWarning, comment);
206 return;
207 }
208
209 // register
210 G4MT_physicsVector->push_back(fPhysics);
211}
212
214{
216 G4ApplicationState currentState = stateManager->GetCurrentState();
217 if(!(currentState == G4State_PreInit))
218 {
219 G4Exception("G4VModularPhysicsList::ReplacePhysics", "Run0203", JustWarning,
220 "Geant4 kernel is not PreInit state : Method ignored.");
221 return;
222 }
223
224 G4String pName = fPhysics->GetPhysicsName();
225 G4int pType = fPhysics->GetPhysicsType();
226 // If physics_type is equal to 0,
227 // duplication check is omitted and just added.
228 // This is TEMPORAL treatment.
229 if(pType == 0)
230 {
231 // register
232 G4MT_physicsVector->push_back(fPhysics);
233#ifdef G4VERBOSE
234 if(verboseLevel > 0)
235 {
236 G4cout << "G4VModularPhysicsList::ReplacePhysics: " << pName
237 << " with type : " << pType << " is added" << G4endl;
238 }
239#endif
240 return;
241 }
242
243 // Check if physics with the physics_type same as one of given physics
244 auto itr = G4MT_physicsVector->begin();
245 for(itr = G4MT_physicsVector->begin(); itr != G4MT_physicsVector->end();
246 ++itr)
247 {
248 if(pType == (*itr)->GetPhysicsType())
249 break;
250 }
251 if(itr == G4MT_physicsVector->end())
252 {
253 // register
254 G4MT_physicsVector->push_back(fPhysics);
255 }
256 else
257 {
258#ifdef G4VERBOSE
259 if(verboseLevel > 0)
260 {
261 G4cout << "G4VModularPhysicsList::ReplacePhysics: "
262 << (*itr)->GetPhysicsName() << " with type : " << pType
263 << " is replaced with " << pName << G4endl;
264 }
265#endif
266
267 // delete exsiting one
268 delete(*itr);
269 // replace with given one
270 (*itr) = fPhysics;
271 }
272
273 return;
274}
275
277{
279 G4ApplicationState currentState = stateManager->GetCurrentState();
280 if(!(currentState == G4State_PreInit))
281 {
282 G4Exception("G4VModularPhysicsList::RemovePhysics", "Run0204", JustWarning,
283 "Geant4 kernel is not PreInit state : Method ignored.");
284 return;
285 }
286
287 for(auto itr = G4MT_physicsVector->begin(); itr != G4MT_physicsVector->end();)
288 {
289 if(pType == (*itr)->GetPhysicsType())
290 {
291 G4String pName = (*itr)->GetPhysicsName();
292#ifdef G4VERBOSE
293 if(verboseLevel > 0)
294 {
295 G4cout << "G4VModularPhysicsList::RemovePhysics: " << pName
296 << " is removed" << G4endl;
297 }
298#endif
299 G4MT_physicsVector->erase(itr);
300 break;
301 }
302 else
303 {
304 itr++;
305 }
306 }
307}
308
310{
312 G4ApplicationState currentState = stateManager->GetCurrentState();
313 if(!(currentState == G4State_PreInit))
314 {
315 G4Exception("G4VModularPhysicsList::RemovePhysics", "Run0205", JustWarning,
316 "Geant4 kernel is not PreInit state : Method ignored.");
317 return;
318 }
319
320 for(auto itr = G4MT_physicsVector->begin(); itr != G4MT_physicsVector->end();)
321 {
322 if(fPhysics == (*itr))
323 {
324 G4String pName = (*itr)->GetPhysicsName();
325#ifdef G4VERBOSE
326 if(verboseLevel > 0)
327 {
328 G4cout << "G4VModularPhysicsList::RemovePhysics: " << pName
329 << " is removed" << G4endl;
330 }
331#endif
332 G4MT_physicsVector->erase(itr);
333 break;
334 }
335 else
336 {
337 itr++;
338 }
339 }
340}
342{
344 G4ApplicationState currentState = stateManager->GetCurrentState();
345 if(!(currentState == G4State_PreInit))
346 {
347 G4Exception("G4VModularPhysicsList::RemovePhysics", "Run0206", JustWarning,
348 "Geant4 kernel is not PreInit state : Method ignored.");
349 return;
350 }
351
352 for(auto itr = G4MT_physicsVector->begin(); itr != G4MT_physicsVector->end();)
353 {
354 G4String pName = (*itr)->GetPhysicsName();
355 if(name == pName)
356 {
357#ifdef G4VERBOSE
358 if(verboseLevel > 0)
359 {
360 G4cout << "G4VModularPhysicsList::RemovePhysics: " << pName
361 << " is removed" << G4endl;
362 }
363#endif
364 G4MT_physicsVector->erase(itr);
365 break;
366 }
367 else
368 {
369 itr++;
370 }
371 }
372}
373
375{
376 G4int i;
377 auto itr = G4MT_physicsVector->begin();
378 for(i = 0; i < idx && itr != G4MT_physicsVector->end(); ++i)
379 ++itr;
380 if(itr != G4MT_physicsVector->end())
381 return (*itr);
382 else
383 return 0;
384}
385
387 const G4String& name) const
388{
389 auto itr = G4MT_physicsVector->begin();
390 for(; itr != G4MT_physicsVector->end(); ++itr)
391 {
392 if(name == (*itr)->GetPhysicsName())
393 break;
394 }
395 if(itr != G4MT_physicsVector->end())
396 return (*itr);
397 else
398 return 0;
399}
400
402 G4int pType) const
403{
404 auto itr = G4MT_physicsVector->begin();
405 for(; itr != G4MT_physicsVector->end(); ++itr)
406 {
407 if(pType == (*itr)->GetPhysicsType())
408 break;
409 }
410 if(itr != G4MT_physicsVector->end())
411 return (*itr);
412 else
413 return 0;
414}
415
417{
418 verboseLevel = value;
419 // Loop over constructors
420 for(auto itr = G4MT_physicsVector->begin(); itr != G4MT_physicsVector->end();
421 ++itr)
422 {
423 (*itr)->SetVerboseLevel(verboseLevel);
424 }
425}
426
428{
429 // See https://jira-geant4.kek.jp/browse/DEV-284
430 std::for_each(
431 G4MT_physicsVector->begin(), G4MT_physicsVector->end(),
432 [](G4PhysConstVector::value_type el) { el->TerminateWorker(); });
434}
G4ApplicationState
@ G4State_PreInit
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:85
std::mutex G4Mutex
Definition: G4Threading.hh:81
int G4int
Definition: G4Types.hh:85
#define G4MT_physicsVector
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()
std::vector< G4VPhysicsConstructor * > G4PhysConstVectorData
G4PhysConstVectorData * physicsVector
virtual void TerminateWorker() override
virtual void ConstructParticle() override
void SetVerboseLevel(G4int value)
G4VModularPhysicsList & operator=(const G4VModularPhysicsList &)
virtual void ConstructProcess() override
void RegisterPhysics(G4VPhysicsConstructor *)
static G4RUN_DLL G4VMPLManager G4VMPLsubInstanceManager
void RemovePhysics(G4VPhysicsConstructor *)
const G4VPhysicsConstructor * GetPhysicsWithType(G4int physics_type) const
void ReplacePhysics(G4VPhysicsConstructor *)
const G4VPhysicsConstructor * GetPhysics(G4int index) const
const G4String & GetPhysicsName() const
G4RUN_DLL G4ThreadLocalStatic T * offset
G4int CreateSubInstance()
virtual void TerminateWorker()
G4bool fIsCheckedForRetrievePhysicsTable
static G4RUN_DLL G4VUPLManager subInstanceManager
static const G4VUPLManager & GetSubInstanceManager()