Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 100421 2016-10-21 12:49:57Z 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 
44 
46 {
48 }
49 
50 //G4ThreadLocal G4VModularPhysicsList::G4PhysConstVector* G4VModularPhysicsList::physicsVector = 0;
51 
54  verboseLevel(0)
55 {
57 }
58 
60 {
61  G4PhysConstVector::iterator itr;
62  for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
63  delete (*itr);
64  }
65  G4MT_physicsVector->clear();
66  delete G4MT_physicsVector;
67 }
68 
70  verboseLevel(0)
71 {
73 }
74 
76 {
77  if (this != &right) {
85  //fDisplayThreshold = static_cast<const G4VUserPhysicsList&>(right).GetSubInstanceManager().offset[right.GetInstanceID()]._fDisplayThreshold;
86  (this->subInstanceManager.offset[this->g4vuplInstanceID])._fDisplayThreshold=
87  static_cast<const G4VUserPhysicsList&>(right).GetSubInstanceManager().offset[right.GetInstanceID()]._fDisplayThreshold;
88  //fIsPhysicsTableBuilt = static_cast<const G4VUserPhysicsList&>(right).GetSubInstanceManager().offset[right.GetInstanceID()]._fIsPhysicsTableBuilt;
89  (this->subInstanceManager.offset[this->g4vuplInstanceID])._fDisplayThreshold=
90  static_cast<const G4VUserPhysicsList&>(right).GetSubInstanceManager().offset[right.GetInstanceID()]._fIsPhysicsTableBuilt;
91  //fDisplayThreshold = right.fDisplayThreshold;
93  verboseLevel = right.verboseLevel;
94 
95  if(G4MT_physicsVector !=0) {
96  G4PhysConstVector::iterator itr;
97  for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
98  delete (*itr);
99  }
100  G4MT_physicsVector->clear();
101  delete G4MT_physicsVector;
102  }
104  }
105  return *this;
106 }
107 
109 {
110  // create particles
111  G4PhysConstVector::iterator itr;
112  for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
113  (*itr)->ConstructParticle();;
114  }
115 }
116 
117 
118 //Andrea Dotti: May 6 2013
119 //Current limitation being debugged: Construction of physics processes
120 //needs to be sequential (there is at least one HAD processes creating problems)
121 //This is not yet understood and needs to be debugged since we do not want
122 //this part to be sequential (imagine when one has 100 threads)
123 //TODO: Remove this lock
124 #include "G4AutoLock.hh"
125 namespace {
126  G4Mutex constructProcessMutex = G4MUTEX_INITIALIZER;
127 }
128 
130 {
131  G4AutoLock l(&constructProcessMutex); //Protection to be removed (A.Dotti)
133 
134  G4PhysConstVector::iterator itr;
135  for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
136  (*itr)->ConstructProcess();
137  }
138 }
139 
140 
141 
143 {
145  G4ApplicationState currentState = stateManager->GetCurrentState();
146  if(!(currentState==G4State_PreInit)){
147  G4Exception("G4VModularPhysicsList::RegisterPhysics",
148  "Run0201", JustWarning,
149  "Geant4 kernel is not PreInit state : Method ignored.");
150  return;
151  }
152 
153  G4String pName = fPhysics->GetPhysicsName();
154  G4int pType = fPhysics->GetPhysicsType();
155  // If physics_type is equal to 0,
156  // following duplication check is omitted
157  // This is TEMPORAL treatment.
158  if (pType == 0) {
159  G4MT_physicsVector->push_back(fPhysics);
160 #ifdef G4VERBOSE
161  if (verboseLevel >1){
162  G4cout << "G4VModularPhysicsList::RegisterPhysics: "
163  << pName << "with type : " << pType
164  << " is added"
165  << G4endl;
166  }
167 #endif
168  return;
169  }
170 
171  // Check if physics with the physics_type same as one of given physics
172  G4PhysConstVector::iterator itr;
173  for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
174  if ( pType == (*itr)->GetPhysicsType()) break;
175  }
176  if (itr!= G4MT_physicsVector->end()) {
177 #ifdef G4VERBOSE
178  if (verboseLevel >0){
179  G4cout << "G4VModularPhysicsList::RegisterPhysics: "
180  << "a physics with given type already exists "
181  << G4endl;
182  G4cout << " Type = " << pType << " : "
183  << " existing physics is " << (*itr)->GetPhysicsName()
184  << G4endl;
185  G4cout << pName << " can not be registered "<<G4endl;
186  }
187 #endif
188  G4String comment ="Duplicate type for ";
189  comment += pName;
190  G4Exception("G4VModularPhysicsList::RegisterPhysics",
191  "Run0202", JustWarning, comment);
192  return;
193  }
194 
195  // register
196  G4MT_physicsVector->push_back(fPhysics);
197 
198 }
199 
201 {
203  G4ApplicationState currentState = stateManager->GetCurrentState();
204  if(!(currentState==G4State_PreInit)){
205  G4Exception("G4VModularPhysicsList::ReplacePhysics",
206  "Run0203", JustWarning,
207  "Geant4 kernel is not PreInit state : Method ignored.");
208  return;
209  }
210 
211  G4String pName = fPhysics->GetPhysicsName();
212  G4int pType = fPhysics->GetPhysicsType();
213  // If physics_type is equal to 0,
214  // duplication check is omitted and just added.
215  // This is TEMPORAL treatment.
216  if (pType == 0) {
217  // register
218  G4MT_physicsVector->push_back(fPhysics);
219 #ifdef G4VERBOSE
220  if (verboseLevel >0){
221  G4cout << "G4VModularPhysicsList::ReplacePhysics: "
222  << pName << "with type : " << pType
223  << " is added"
224  << G4endl;
225  }
226 #endif
227  return;
228  }
229 
230  // Check if physics with the physics_type same as one of given physics
231  G4PhysConstVector::iterator itr= G4MT_physicsVector->begin();
232  for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
233  if ( pType == (*itr)->GetPhysicsType()) break;
234  }
235  if (itr == G4MT_physicsVector->end()) {
236  // register
237  G4MT_physicsVector->push_back(fPhysics);
238  } else {
239 #ifdef G4VERBOSE
240  if (verboseLevel >0){
241  G4cout << "G4VModularPhysicsList::ReplacePhysics: "
242  << (*itr)->GetPhysicsName() << "with type : " << pType
243  << " is replaces with " << pName
244  << G4endl;
245  }
246 #endif
247 
248  // delete exsiting one
249  delete (*itr);
250  // replace with given one
251  (*itr) = fPhysics;
252 
253  }
254 
255  return;
256 }
257 
259 {
261  G4ApplicationState currentState = stateManager->GetCurrentState();
262  if(!(currentState==G4State_PreInit)){
263  G4Exception("G4VModularPhysicsList::RemovePhysics",
264  "Run0204", JustWarning,
265  "Geant4 kernel is not PreInit state : Method ignored.");
266  return;
267  }
268 
269  for (G4PhysConstVector::iterator itr = G4MT_physicsVector->begin();
270  itr!= G4MT_physicsVector->end();) {
271  if ( pType == (*itr)->GetPhysicsType()) {
272  G4String pName = (*itr)->GetPhysicsName();
273 #ifdef G4VERBOSE
274  if (verboseLevel > 0){
275  G4cout << "G4VModularPhysicsList::RemovePhysics: "
276  << pName << " is removed"
277  << G4endl;
278  }
279 #endif
280  G4MT_physicsVector->erase(itr);
281  break;
282  } else {
283  itr++;
284  }
285  }
286 }
287 
289 {
291  G4ApplicationState currentState = stateManager->GetCurrentState();
292  if(!(currentState==G4State_PreInit)){
293  G4Exception("G4VModularPhysicsList::RemovePhysics",
294  "Run0205", JustWarning,
295  "Geant4 kernel is not PreInit state : Method ignored.");
296  return;
297  }
298 
299  for (G4PhysConstVector::iterator itr = G4MT_physicsVector->begin();
300  itr!= G4MT_physicsVector->end();) {
301  if ( fPhysics == (*itr)) {
302  G4String pName = (*itr)->GetPhysicsName();
303 #ifdef G4VERBOSE
304  if (verboseLevel > 0 ){
305  G4cout << "G4VModularPhysicsList::RemovePhysics: "
306  << pName << " is removed"
307  << G4endl;
308  }
309 #endif
310  G4MT_physicsVector->erase(itr);
311  break;
312  } else {
313  itr++;
314  }
315  }
316 }
318 {
320  G4ApplicationState currentState = stateManager->GetCurrentState();
321  if(!(currentState==G4State_PreInit)){
322  G4Exception("G4VModularPhysicsList::RemovePhysics",
323  "Run0206", JustWarning,
324  "Geant4 kernel is not PreInit state : Method ignored.");
325  return;
326  }
327 
328  for (G4PhysConstVector::iterator itr = G4MT_physicsVector->begin();
329  itr!= G4MT_physicsVector->end();) {
330  G4String pName = (*itr)->GetPhysicsName();
331  if ( name == pName) {
332 #ifdef G4VERBOSE
333  if (verboseLevel > 0){
334  G4cout << "G4VModularPhysicsList::RemovePhysics: "
335  << pName << " is removed"
336  << G4endl;
337  }
338 #endif
339  G4MT_physicsVector->erase(itr);
340  break;
341  } else {
342  itr++;
343  }
344  }
345 }
346 
348 {
349  G4int i;
350  G4PhysConstVector::iterator itr= G4MT_physicsVector->begin();
351  for (i=0; i<idx && itr!= G4MT_physicsVector->end() ; ++i) ++itr;
352  if (itr!= G4MT_physicsVector->end()) return (*itr);
353  else return 0;
354 }
355 
357 {
358  G4PhysConstVector::iterator itr;
359  for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
360  if ( name == (*itr)->GetPhysicsName()) break;
361  }
362  if (itr!= G4MT_physicsVector->end()) return (*itr);
363  else return 0;
364 }
365 
367 {
368  G4PhysConstVector::iterator itr;
369  for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
370  if ( pType == (*itr)->GetPhysicsType()) break;
371  }
372  if (itr!= G4MT_physicsVector->end()) return (*itr);
373  else return 0;
374 }
375 
376 
378 {
380 
381  // Loop over constructors
382  G4PhysConstVector::iterator itr;
383  for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
384  (*itr)->SetVerboseLevel(verboseLevel);
385  }
386 
387 }
const XML_Char * name
Definition: expat.h:151
void RegisterPhysics(G4VPhysicsConstructor *)
G4VModularPhysicsList & operator=(const G4VModularPhysicsList &)
G4bool fIsCheckedForRetrievePhysicsTable
int G4int
Definition: G4Types.hh:78
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:175
G4RUN_DLL G4ThreadLocalStatic T * offset
static G4StateManager * GetStateManager()
G4GLOB_DLL std::ostream G4cout
const G4VPhysicsConstructor * GetPhysics(G4int index) const
const XML_Char int const XML_Char * value
Definition: expat.h:331
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:173
void ReplacePhysics(G4VPhysicsConstructor *)
void RemovePhysics(G4VPhysicsConstructor *)
static G4RUN_DLL G4VUPLManager subInstanceManager
G4PhysConstVectorData * physicsVector
#define G4endl
Definition: G4ios.hh:61
G4int CreateSubInstance()
G4ApplicationState