Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 // $Id: G4VModularPhysicsList.cc 73123 2013-08-19 07:52:00Z gcosmo $
28 //
29 //
30 // ------------------------------------------------------------
31 // GEANT 4 class implementation file
32 // ------------------------------------------------------------
33 // - Add ReplacePhysics 14 Mar 2011 by H.Kurashige
34 // - Add RemovePhysics 2 May 2011 by H.Kurashige
35 //
36 #include "G4VModularPhysicsList.hh"
37 #include "G4StateManager.hh"
38 
39 // This macros change the references to fields that are now encapsulated
40 // in the class G4VMPLData.
41 #define G4MT_physicsVector ((G4VMPLsubInstanceManager.offset[g4vmplInstanceID]).physicsVector)
42 
43 template <class G4VMPLData> G4ThreadLocal
45 
46 template <class G4VMPLData> G4ThreadLocal
48 
50 
52 {
54 }
55 
56 //G4ThreadLocal G4VModularPhysicsList::G4PhysConstVector* G4VModularPhysicsList::physicsVector = 0;
57 
60  verboseLevel(0)
61 {
63 }
64 
66 {
67  G4PhysConstVector::iterator itr;
68  for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
69  delete (*itr);
70  }
71  G4MT_physicsVector->clear();
72  delete G4MT_physicsVector;
73 }
74 
76  verboseLevel(0)
77 {
79 }
80 
82 {
83  if (this != &right) {
91  fDisplayThreshold = static_cast<const G4VUserPhysicsList&>(right).GetSubInstanceManager().offset[right.GetInstanceID()]._fDisplayThreshold;
92  fIsPhysicsTableBuilt = static_cast<const G4VUserPhysicsList&>(right).GetSubInstanceManager().offset[right.GetInstanceID()]._fIsPhysicsTableBuilt;
93  //fDisplayThreshold = right.fDisplayThreshold;
95  verboseLevel = right.verboseLevel;
96 
97  if(G4MT_physicsVector !=0) {
98  G4PhysConstVector::iterator itr;
99  for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
100  delete (*itr);
101  }
102  G4MT_physicsVector->clear();
103  delete G4MT_physicsVector;
104  }
106  }
107  return *this;
108 }
109 
111 {
112  // create particles
113  G4PhysConstVector::iterator itr;
114  for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
115  (*itr)->ConstructParticle();;
116  }
117 }
118 
119 
120 //Andrea Dotti: May 6 2013
121 //Current limitation being debugged: Construction of physics processes
122 //needs to be sequential (there is at least one HAD processes creating problems)
123 //This is not yet understood and needs to be debugged since we do not want
124 //this part to be sequential (imagine when one has 100 threads)
125 //TODO: Remove this lock
126 #include "G4AutoLock.hh"
127 namespace {
128  G4Mutex constructProcessMutex = G4MUTEX_INITIALIZER;
129 }
130 
132 {
133  G4AutoLock l(&constructProcessMutex); //Protection to be removed (A.Dotti)
135 
136  G4PhysConstVector::iterator itr;
137  for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
138  (*itr)->ConstructProcess();
139  }
140 }
141 
142 
143 
145 {
147  G4ApplicationState currentState = stateManager->GetCurrentState();
148  if(!(currentState==G4State_PreInit)){
149  G4Exception("G4VModularPhysicsList::RegisterPhysics",
150  "Run0201", JustWarning,
151  "Geant4 kernel is not PreInit state : Method ignored.");
152  return;
153  }
154 
155  G4String pName = fPhysics->GetPhysicsName();
156  G4int pType = fPhysics->GetPhysicsType();
157  // If physics_type is equal to 0,
158  // following duplication check is omitted
159  // This is TEMPORAL treatment.
160  if (pType == 0) {
161  G4MT_physicsVector->push_back(fPhysics);
162 #ifdef G4VERBOSE
163  if (verboseLevel >1){
164  G4cout << "G4VModularPhysicsList::RegisterPhysics: "
165  << pName << "with type : " << pType
166  << " is added"
167  << G4endl;
168  }
169 #endif
170  return;
171  }
172 
173  // Check if physics with the physics_type same as one of given physics
174  G4PhysConstVector::iterator itr;
175  for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
176  if ( pType == (*itr)->GetPhysicsType()) break;
177  }
178  if (itr!= G4MT_physicsVector->end()) {
179 #ifdef G4VERBOSE
180  if (verboseLevel >0){
181  G4cout << "G4VModularPhysicsList::RegisterPhysics: "
182  << "a physics with given type already exists "
183  << G4endl;
184  G4cout << " Type = " << pType << " : "
185  << " existing physics is " << (*itr)->GetPhysicsName()
186  << G4endl;
187  G4cout << pName << " can not be registered "<<G4endl;
188  }
189 #endif
190  G4String comment ="Duplicate type for ";
191  comment += pName;
192  G4Exception("G4VModularPhysicsList::RegisterPhysics",
193  "Run0202", JustWarning, comment);
194  return;
195  }
196 
197  // register
198  G4MT_physicsVector->push_back(fPhysics);
199 
200 }
201 
203 {
205  G4ApplicationState currentState = stateManager->GetCurrentState();
206  if(!(currentState==G4State_PreInit)){
207  G4Exception("G4VModularPhysicsList::ReplacePhysics",
208  "Run0203", JustWarning,
209  "Geant4 kernel is not PreInit state : Method ignored.");
210  return;
211  }
212 
213  G4String pName = fPhysics->GetPhysicsName();
214  G4int pType = fPhysics->GetPhysicsType();
215  // If physics_type is equal to 0,
216  // duplication check is omitted and just added.
217  // This is TEMPORAL treatment.
218  if (pType == 0) {
219  // register
220  G4MT_physicsVector->push_back(fPhysics);
221 #ifdef G4VERBOSE
222  if (verboseLevel >0){
223  G4cout << "G4VModularPhysicsList::ReplacePhysics: "
224  << pName << "with type : " << pType
225  << " is added"
226  << G4endl;
227  }
228 #endif
229  return;
230  }
231 
232  // Check if physics with the physics_type same as one of given physics
233  G4PhysConstVector::iterator itr= G4MT_physicsVector->begin();
234  for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
235  if ( pType == (*itr)->GetPhysicsType()) break;
236  }
237  if (itr == G4MT_physicsVector->end()) {
238  // register
239  G4MT_physicsVector->push_back(fPhysics);
240  } else {
241 #ifdef G4VERBOSE
242  if (verboseLevel >0){
243  G4cout << "G4VModularPhysicsList::ReplacePhysics: "
244  << (*itr)->GetPhysicsName() << "with type : " << pType
245  << " is replaces with " << pName
246  << G4endl;
247  }
248 #endif
249 
250  // delete exsiting one
251  delete (*itr);
252  // replace with given one
253  (*itr) = fPhysics;
254 
255  }
256 
257  return;
258 }
259 
261 {
263  G4ApplicationState currentState = stateManager->GetCurrentState();
264  if(!(currentState==G4State_PreInit)){
265  G4Exception("G4VModularPhysicsList::RemovePhysics",
266  "Run0204", JustWarning,
267  "Geant4 kernel is not PreInit state : Method ignored.");
268  return;
269  }
270 
271  for (G4PhysConstVector::iterator itr = G4MT_physicsVector->begin();
272  itr!= G4MT_physicsVector->end();) {
273  if ( pType == (*itr)->GetPhysicsType()) {
274  G4String pName = (*itr)->GetPhysicsName();
275 #ifdef G4VERBOSE
276  if (verboseLevel > 0){
277  G4cout << "G4VModularPhysicsList::RemovePhysics: "
278  << pName << " is removed"
279  << G4endl;
280  }
281 #endif
282  G4MT_physicsVector->erase(itr);
283  break;
284  } else {
285  itr++;
286  }
287  }
288 }
289 
291 {
293  G4ApplicationState currentState = stateManager->GetCurrentState();
294  if(!(currentState==G4State_PreInit)){
295  G4Exception("G4VModularPhysicsList::RemovePhysics",
296  "Run0205", JustWarning,
297  "Geant4 kernel is not PreInit state : Method ignored.");
298  return;
299  }
300 
301  for (G4PhysConstVector::iterator itr = G4MT_physicsVector->begin();
302  itr!= G4MT_physicsVector->end();) {
303  if ( fPhysics == (*itr)) {
304  G4String pName = (*itr)->GetPhysicsName();
305 #ifdef G4VERBOSE
306  if (verboseLevel > 0 ){
307  G4cout << "G4VModularPhysicsList::RemovePhysics: "
308  << pName << " is removed"
309  << G4endl;
310  }
311 #endif
312  G4MT_physicsVector->erase(itr);
313  break;
314  } else {
315  itr++;
316  }
317  }
318 }
320 {
322  G4ApplicationState currentState = stateManager->GetCurrentState();
323  if(!(currentState==G4State_PreInit)){
324  G4Exception("G4VModularPhysicsList::RemovePhysics",
325  "Run0206", JustWarning,
326  "Geant4 kernel is not PreInit state : Method ignored.");
327  return;
328  }
329 
330  for (G4PhysConstVector::iterator itr = G4MT_physicsVector->begin();
331  itr!= G4MT_physicsVector->end();) {
332  G4String pName = (*itr)->GetPhysicsName();
333  if ( name == pName) {
334 #ifdef G4VERBOSE
335  if (verboseLevel > 0){
336  G4cout << "G4VModularPhysicsList::RemovePhysics: "
337  << pName << " is removed"
338  << G4endl;
339  }
340 #endif
341  G4MT_physicsVector->erase(itr);
342  break;
343  } else {
344  itr++;
345  }
346  }
347 }
348 
350 {
351  G4int i;
352  G4PhysConstVector::iterator itr= G4MT_physicsVector->begin();
353  for (i=0; i<idx && itr!= G4MT_physicsVector->end() ; ++i) ++itr;
354  if (itr!= G4MT_physicsVector->end()) return (*itr);
355  else return 0;
356 }
357 
359 {
360  G4PhysConstVector::iterator itr;
361  for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
362  if ( name == (*itr)->GetPhysicsName()) break;
363  }
364  if (itr!= G4MT_physicsVector->end()) return (*itr);
365  else return 0;
366 }
367 
369 {
370  G4PhysConstVector::iterator itr;
371  for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
372  if ( pType == (*itr)->GetPhysicsType()) break;
373  }
374  if (itr!= G4MT_physicsVector->end()) return (*itr);
375  else return 0;
376 }
377 
378 
380 {
382 
383  // Loop over constructors
384  G4PhysConstVector::iterator itr;
385  for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
386  (*itr)->SetVerboseLevel(verboseLevel);
387  }
388 
389 }
void RegisterPhysics(G4VPhysicsConstructor *)
#define fDisplayThreshold
G4VModularPhysicsList & operator=(const G4VModularPhysicsList &)
#define fIsPhysicsTableBuilt
static const G4VMPLManager & GetSubInstanceManager()
G4bool fIsCheckedForRetrievePhysicsTable
const XML_Char * name
#define G4ThreadLocal
Definition: tls.hh:52
int G4int
Definition: G4Types.hh:78
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:158
static G4StateManager * GetStateManager()
G4GLOB_DLL std::ostream G4cout
const G4VPhysicsConstructor * GetPhysics(G4int index) const
std::vector< G4VPhysicsConstructor * > G4PhysConstVectorData
const G4String & GetPhysicsName() const
G4ApplicationState GetCurrentState() const
void SetVerboseLevel(G4int value)
const G4VPhysicsConstructor * GetPhysicsWithType(G4int physics_type) const
static G4RUN_DLL G4VMPLManager G4VMPLsubInstanceManager
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
#define G4MT_physicsVector
G4int G4Mutex
Definition: G4Threading.hh:156
void ReplacePhysics(G4VPhysicsConstructor *)
static G4RUN_DLL G4ThreadLocal T * offset
void RemovePhysics(G4VPhysicsConstructor *)
const XML_Char int const XML_Char * value
G4PhysConstVectorData * physicsVector
#define G4endl
Definition: G4ios.hh:61
G4int CreateSubInstance()
G4ApplicationState