Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4VModularPhysicsList.cc
이 파일의 문서화 페이지로 가기
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 103803 2017-04-27 14:03:05Z 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 #include <algorithm>
39 
40 // This macros change the references to fields that are now encapsulated
41 // in the class G4VMPLData.
42 #define G4MT_physicsVector ((G4VMPLsubInstanceManager.offset[g4vmplInstanceID]).physicsVector)
43 
45 
47 {
49 }
50 
51 //G4ThreadLocal G4VModularPhysicsList::G4PhysConstVector* G4VModularPhysicsList::physicsVector = 0;
52 
55  verboseLevel(0)
56 {
58 }
59 
61 {
62  for (auto 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  for (auto itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
97  delete (*itr);
98  }
99  G4MT_physicsVector->clear();
100  delete G4MT_physicsVector;
101  }
103  }
104  return *this;
105 }
106 
108 {
109  // create particles
110  for (auto itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
111  (*itr)->ConstructParticle();;
112  }
113 }
114 
115 
116 //Andrea Dotti: May 6 2013
117 //Current limitation being debugged: Construction of physics processes
118 //needs to be sequential (there is at least one HAD processes creating problems)
119 //This is not yet understood and needs to be debugged since we do not want
120 //this part to be sequential (imagine when one has 100 threads)
121 //TODO: Remove this lock
122 #include "G4AutoLock.hh"
123 namespace {
124  G4Mutex constructProcessMutex = G4MUTEX_INITIALIZER;
125 }
126 
128 {
129  G4AutoLock l(&constructProcessMutex); //Protection to be removed (A.Dotti)
131 
132  for (auto itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
133  (*itr)->ConstructProcess();
134  }
135 }
136 
137 
138 
140 {
142  G4ApplicationState currentState = stateManager->GetCurrentState();
143  if(!(currentState==G4State_PreInit)){
144  G4Exception("G4VModularPhysicsList::RegisterPhysics",
145  "Run0201", JustWarning,
146  "Geant4 kernel is not PreInit state : Method ignored.");
147  return;
148  }
149 
150  G4String pName = fPhysics->GetPhysicsName();
151  G4int pType = fPhysics->GetPhysicsType();
152  // If physics_type is equal to 0,
153  // following duplication check is omitted
154  // This is TEMPORAL treatment.
155  if (pType == 0) {
156  G4MT_physicsVector->push_back(fPhysics);
157 #ifdef G4VERBOSE
158  if (verboseLevel >1){
159  G4cout << "G4VModularPhysicsList::RegisterPhysics: "
160  << pName << "with type : " << pType
161  << " is added"
162  << G4endl;
163  }
164 #endif
165  return;
166  }
167 
168  // Check if physics with the physics_type same as one of given physics
169  auto itr = G4MT_physicsVector->begin();
170  for (; itr!= G4MT_physicsVector->end(); ++itr) {
171  if ( pType == (*itr)->GetPhysicsType()) break;
172  }
173  if (itr!= G4MT_physicsVector->end()) {
174 #ifdef G4VERBOSE
175  if (verboseLevel >0){
176  G4cout << "G4VModularPhysicsList::RegisterPhysics: "
177  << "a physics with given type already exists "
178  << G4endl;
179  G4cout << " Type = " << pType << " : "
180  << " existing physics is " << (*itr)->GetPhysicsName()
181  << G4endl;
182  G4cout << pName << " can not be registered "<<G4endl;
183  }
184 #endif
185  G4String comment ="Duplicate type for ";
186  comment += pName;
187  G4Exception("G4VModularPhysicsList::RegisterPhysics",
188  "Run0202", JustWarning, comment);
189  return;
190  }
191 
192  // register
193  G4MT_physicsVector->push_back(fPhysics);
194 
195 }
196 
198 {
200  G4ApplicationState currentState = stateManager->GetCurrentState();
201  if(!(currentState==G4State_PreInit)){
202  G4Exception("G4VModularPhysicsList::ReplacePhysics",
203  "Run0203", JustWarning,
204  "Geant4 kernel is not PreInit state : Method ignored.");
205  return;
206  }
207 
208  G4String pName = fPhysics->GetPhysicsName();
209  G4int pType = fPhysics->GetPhysicsType();
210  // If physics_type is equal to 0,
211  // duplication check is omitted and just added.
212  // This is TEMPORAL treatment.
213  if (pType == 0) {
214  // register
215  G4MT_physicsVector->push_back(fPhysics);
216 #ifdef G4VERBOSE
217  if (verboseLevel >0){
218  G4cout << "G4VModularPhysicsList::ReplacePhysics: "
219  << pName << "with type : " << pType
220  << " is added"
221  << G4endl;
222  }
223 #endif
224  return;
225  }
226 
227  // Check if physics with the physics_type same as one of given physics
228  auto itr= G4MT_physicsVector->begin();
229  for (itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
230  if ( pType == (*itr)->GetPhysicsType()) break;
231  }
232  if (itr == G4MT_physicsVector->end()) {
233  // register
234  G4MT_physicsVector->push_back(fPhysics);
235  } else {
236 #ifdef G4VERBOSE
237  if (verboseLevel >0){
238  G4cout << "G4VModularPhysicsList::ReplacePhysics: "
239  << (*itr)->GetPhysicsName() << "with type : " << pType
240  << " is replaces with " << pName
241  << G4endl;
242  }
243 #endif
244 
245  // delete exsiting one
246  delete (*itr);
247  // replace with given one
248  (*itr) = fPhysics;
249 
250  }
251 
252  return;
253 }
254 
256 {
258  G4ApplicationState currentState = stateManager->GetCurrentState();
259  if(!(currentState==G4State_PreInit)){
260  G4Exception("G4VModularPhysicsList::RemovePhysics",
261  "Run0204", JustWarning,
262  "Geant4 kernel is not PreInit state : Method ignored.");
263  return;
264  }
265 
266  for (auto itr = G4MT_physicsVector->begin();
267  itr!= G4MT_physicsVector->end();) {
268  if ( pType == (*itr)->GetPhysicsType()) {
269  G4String pName = (*itr)->GetPhysicsName();
270 #ifdef G4VERBOSE
271  if (verboseLevel > 0){
272  G4cout << "G4VModularPhysicsList::RemovePhysics: "
273  << pName << " is removed"
274  << G4endl;
275  }
276 #endif
277  G4MT_physicsVector->erase(itr);
278  break;
279  } else {
280  itr++;
281  }
282  }
283 }
284 
286 {
288  G4ApplicationState currentState = stateManager->GetCurrentState();
289  if(!(currentState==G4State_PreInit)){
290  G4Exception("G4VModularPhysicsList::RemovePhysics",
291  "Run0205", JustWarning,
292  "Geant4 kernel is not PreInit state : Method ignored.");
293  return;
294  }
295 
296  for (auto itr = G4MT_physicsVector->begin();
297  itr!= G4MT_physicsVector->end();) {
298  if ( fPhysics == (*itr)) {
299  G4String pName = (*itr)->GetPhysicsName();
300 #ifdef G4VERBOSE
301  if (verboseLevel > 0 ){
302  G4cout << "G4VModularPhysicsList::RemovePhysics: "
303  << pName << " is removed"
304  << G4endl;
305  }
306 #endif
307  G4MT_physicsVector->erase(itr);
308  break;
309  } else {
310  itr++;
311  }
312  }
313 }
315 {
317  G4ApplicationState currentState = stateManager->GetCurrentState();
318  if(!(currentState==G4State_PreInit)){
319  G4Exception("G4VModularPhysicsList::RemovePhysics",
320  "Run0206", JustWarning,
321  "Geant4 kernel is not PreInit state : Method ignored.");
322  return;
323  }
324 
325  for (auto itr = G4MT_physicsVector->begin();
326  itr!= G4MT_physicsVector->end();) {
327  G4String pName = (*itr)->GetPhysicsName();
328  if ( name == pName) {
329 #ifdef G4VERBOSE
330  if (verboseLevel > 0){
331  G4cout << "G4VModularPhysicsList::RemovePhysics: "
332  << pName << " is removed"
333  << G4endl;
334  }
335 #endif
336  G4MT_physicsVector->erase(itr);
337  break;
338  } else {
339  itr++;
340  }
341  }
342 }
343 
345 {
346  G4int i;
347  auto itr= G4MT_physicsVector->begin();
348  for (i=0; i<idx && itr!= G4MT_physicsVector->end() ; ++i) ++itr;
349  if (itr!= G4MT_physicsVector->end()) return (*itr);
350  else return 0;
351 }
352 
354 {
355  auto itr = G4MT_physicsVector->begin();
356  for (; itr!= G4MT_physicsVector->end(); ++itr) {
357  if ( name == (*itr)->GetPhysicsName()) break;
358  }
359  if (itr!= G4MT_physicsVector->end()) return (*itr);
360  else return 0;
361 }
362 
364 {
365  auto itr = G4MT_physicsVector->begin();
366  for (; itr!= G4MT_physicsVector->end(); ++itr) {
367  if ( pType == (*itr)->GetPhysicsType()) break;
368  }
369  if (itr!= G4MT_physicsVector->end()) return (*itr);
370  else return 0;
371 }
372 
373 
375 {
377  // Loop over constructors
378  for (auto itr = G4MT_physicsVector->begin(); itr!= G4MT_physicsVector->end(); ++itr) {
379  (*itr)->SetVerboseLevel(verboseLevel);
380  }
381 
382 }
383 
385 {
386  //See https://jira-geant4.kek.jp/browse/DEV-284
387  std::for_each( G4MT_physicsVector->begin() , G4MT_physicsVector->end() ,
388  [](G4PhysConstVector::value_type el) { el->TerminateWorker();});
390 }
const XML_Char * name
Definition: expat.h:151
virtual void ConstructParticle() override
G4RUN_DLL G4ThreadLocalStatic T * offset
#define G4endl
Definition: G4ios.hh:61
#define G4MT_physicsVector
static G4RUN_DLL G4VUPLManager subInstanceManager
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:88
void RemovePhysics(G4VPhysicsConstructor *)
const G4VPhysicsConstructor * GetPhysics(G4int index) const
const XML_Char int const XML_Char * value
Definition: expat.h:331
const G4String & GetPhysicsName() const
void RegisterPhysics(G4VPhysicsConstructor *)
G4int CreateSubInstance()
G4bool fIsCheckedForRetrievePhysicsTable
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
void ReplacePhysics(G4VPhysicsConstructor *)
int G4int
Definition: G4Types.hh:78
G4ApplicationState GetCurrentState() const
G4PhysConstVectorData * physicsVector
G4GLOB_DLL std::ostream G4cout
virtual void TerminateWorker()
std::vector< G4VPhysicsConstructor * > G4PhysConstVectorData
G4ApplicationState
virtual void TerminateWorker() override
static G4RUN_DLL G4VMPLManager G4VMPLsubInstanceManager
const G4VPhysicsConstructor * GetPhysicsWithType(G4int physics_type) const
G4VModularPhysicsList & operator=(const G4VModularPhysicsList &)
static G4StateManager * GetStateManager()
virtual void ConstructProcess() override
std::mutex G4Mutex
Definition: G4Threading.hh:84
void SetVerboseLevel(G4int value)