Geant4  10.03
G4ProcessTable.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: G4ProcessTable.cc 91916 2015-08-11 07:03:22Z gcosmo $
28 //
29 //
30 // ------------------------------------------------------------
31 // GEANT 4 class header file
32 //
33 // History: first implementation, based on object model of
34 // 4th Aug 1998, H.Kurashige
35 // ------------------------------------------------------------
36 // History:
37 // Use STL vector instead of RW vector 1. Mar 00 H.Kurashige
38 //
39 
41 #include "G4ProcessTable.hh"
42 
43 // constructor //////////////////////////
45 {
46 #ifdef G4VERBOSE
47  if (verboseLevel>1){
48  G4cout << "-- G4ProcessTable constructor --" << G4endl;
49  }
50 #endif
55 }
56 
57 // copy constructor //////////////////////////
59  :verboseLevel(1)
60 {
61  fProcTblVector = 0;
62  fProcNameVector = 0;
63  tmpTblVector = 0;
65 #ifdef G4VERBOSE
66  if (verboseLevel>0){
67  G4cout << "-- G4ProcessTable copy constructor --" << G4endl;
68  }
69 #endif
70 }
71 
72 // destructor //////////////////////////
74 {
75 #ifdef G4VERBOSE
76  if (verboseLevel>1){
77  G4cout << "-- G4ProcessTable destructor --" << G4endl;
78  }
79 #endif
80 
81  if ( tmpTblVector != 0) {
82  tmpTblVector ->clear();
83  delete tmpTblVector;
84  }
85 
86  if ( fProcTblVector != 0) {
87  G4ProcTableVector::iterator idx;
88 
89  // destruction of processes has moved to G4VUserPhysicsList
90  for (idx=fProcTblVector->begin(); idx!=fProcTblVector->end(); ++idx) {
91  // delete all processes
92  // delete (*idx)->GetProcess();
93  delete (*idx);
94  }
95  fProcTblVector ->clear();
96  delete fProcTblVector;
97  }
98 
99  if ( fProcNameVector != 0) {
100  fProcNameVector ->clear();
101  delete fProcNameVector;
102  }
103  fProcessTable =0;
104 }
105 
108 {
109  if (fProcTblMessenger == 0) {
111  }
112  return fProcTblMessenger;
113 }
114 
117 {
118  if (fProcTblMessenger != 0) {
119  delete fProcTblMessenger;
120  }
121 }
122 
123 
126 {
127 #ifdef G4VERBOSE
128  if (verboseLevel>0){
129  G4cout << "-- G4ProcessTable assignment operator --" << G4endl;
130  }
131 #endif
132  return *this;
133 }
134 
137 {
138  return (this == &right);
139 }
140 
143 {
144  return (this != &right);
145 }
146 
147 // Static class variable: ptr to single instance of class
149 
150 
153 {
154  static G4ThreadLocal G4ProcessTable *theProcessTable_G4MT_TLS_ = 0 ; if (!theProcessTable_G4MT_TLS_) theProcessTable_G4MT_TLS_ = new G4ProcessTable ; G4ProcessTable &theProcessTable = *theProcessTable_G4MT_TLS_;
155  if (!fProcessTable){
156  fProcessTable = &theProcessTable;
157  }
158  return fProcessTable;
159 }
160 
163  G4ProcessManager* aProcMgr)
164 {
165  if ( (aProcess == 0) || ( aProcMgr == 0 ) ){
166 #ifdef G4VERBOSE
167  if (verboseLevel>0){
168  G4cout << "G4ProcessTable::Insert : arguments are 0 pointer "
169  <<aProcess <<","<< aProcMgr << G4endl;
170  }
171 #endif
172  return -1;
173  }
174 
175 #ifdef G4VERBOSE
176  if (verboseLevel>1){
177  G4cout << "G4ProcessTable::Insert ";
178  G4cout << " Process[" << aProcess->GetProcessName() << "]";
179  G4cout << " Particle[" << aProcMgr->GetParticleType()->GetParticleName() << "]";
180  G4cout << G4endl;
181  }
182 #endif
183 
184  G4ProcTableVector::iterator itr;
185  G4int idxTbl=0;
186  G4ProcTblElement* anElement;
187  G4bool isFoundInTbl = false;
188  // loop over all elements
189  for (itr=fProcTblVector->begin(); itr!=fProcTblVector->end(); ++itr, ++idxTbl) {
190  anElement = (*itr);
191  // check if this process is included
192  if (aProcess == anElement->GetProcess()) {
193  isFoundInTbl = true;
194 
195  // add the process manager into the element
196  // unless this process manager is included
197  if (!anElement->Contains(aProcMgr)) {
198  anElement->Insert(aProcMgr);
199 #ifdef G4VERBOSE
200  if (verboseLevel>2){
201  G4cout << " This Process Manager is registered !! " << G4endl;
202  }
203 #endif
204  }
205  break;
206  }
207  }
208  // add this process into the table by creating a new element
209  if (!isFoundInTbl) {
210  G4ProcTblElement* newElement = new G4ProcTblElement(aProcess);
211  newElement->Insert(aProcMgr);
212  fProcTblVector->push_back(newElement);
213  // add into name vector
214  G4ProcNameVector::iterator ip;
215  G4bool isFound = false;
216  for (ip=fProcNameVector->begin(); ip!=fProcNameVector->end(); ++ip) {
217  isFound |= (aProcess->GetProcessName() == (*ip));
218  }
219  if (!isFound) {
220  fProcNameVector->push_back(aProcess->GetProcessName() );
221 #ifdef G4VERBOSE
222  if (verboseLevel>2){
223  G4cout << " This Process is registered !! " << G4endl;
224  }
225 #endif
226  }
227  }
228  return idxTbl;
229 }
230 
233  G4ProcessManager* aProcMgr)
234 {
235  if ( (aProcess == 0) || ( aProcMgr == 0 ) ){
236 #ifdef G4VERBOSE
237  if (verboseLevel>0){
238  G4cout << "G4ProcessTable::Remove : arguments are 0 pointer "<< G4endl;
239  }
240 #endif
241  return -1;
242  }
243 
244 #ifdef G4VERBOSE
245  if (verboseLevel>1){
246  G4cout << "G4ProcessTable::Remove ";
247  G4cout << " Process[" << aProcess->GetProcessName() << "]";
248  G4cout << " Particle[" << aProcMgr->GetParticleType()->GetParticleName() << "]" << G4endl;
249  }
250 #endif
251 
252  G4ProcTableVector::iterator itr;
253  G4int idxTbl=0;
254  G4ProcTblElement* anElement=0;
255  G4bool isFound = false;
256  // loop over all elements
257  for (itr=fProcTblVector->begin(); itr!=fProcTblVector->end(); ++itr, ++idxTbl) {
258  anElement = (*itr);
259 
260  // check if this process is included
261  if (aProcess == anElement->GetProcess()) {
262  isFound = anElement->Contains(aProcMgr);
263  // remove the process manager from the element
264  anElement->Remove(aProcMgr);
265 #ifdef G4VERBOSE
266  if (verboseLevel>2){
267  G4cout << " This Process Manager is removed !! " << G4endl;
268  }
269 #endif
270  break;
271  }
272  }
273  //
274  if (!isFound) {
275 #ifdef G4VERBOSE
276  if (verboseLevel>0){
277  G4cout << " This Process Manager is not registered !! " << G4endl;
278  }
279 #endif
280  return -1;
281  }
282  // remove the element if it has no entry
283  if (anElement->Length() == 0){
284  fProcTblVector->erase(itr);
285  delete anElement;
286  // check other prcesses with same name exist or not
287  G4bool isSameName = false;
288  for (itr=fProcTblVector->begin(); itr!=fProcTblVector->end(); ++itr) {
289  anElement = (*itr);
290  if (anElement->GetProcessName() == aProcess->GetProcessName()) {
291  isSameName = true;
292  break;
293  }
294  }
295  // remove from name vector
296  if (!isSameName ) {
297  G4ProcNameVector::iterator i;
298  for (i=fProcNameVector->begin(); i!=fProcNameVector->end(); ++i) {
299  if ( *i == aProcess->GetProcessName() ) {
300  fProcNameVector->erase(i);
301  break;
302  }
303  }
304  }
305 #ifdef G4VERBOSE
306  if (verboseLevel>1){
307  G4cout << " This Process is removed !! " << G4endl;
308  }
309 #endif
310  }
311  return idxTbl;
312 }
313 
316  const G4ProcessManager* processManager)
317  const
318 {
319  G4ProcTableVector::iterator itr;
320  G4int idxTbl = 0;
321  G4bool isFound = false;
322  G4ProcTblElement* anElement=0;
323  for (itr=fProcTblVector->begin(); itr!=fProcTblVector->end(); ++itr, ++idxTbl) {
324  anElement = (*itr);
325  // check name
326  if ( anElement->GetProcessName() == processName ) {
327  // check if the processManage is included
328  if ( anElement->Contains(processManager) ) {
329  isFound = true;
330  break;
331  }
332  }
333  }
334 #ifdef G4VERBOSE
335  if (!isFound && verboseLevel>1){
336  G4cout << " G4ProcessTable::FindProcess :" ;
337  G4cout << " The Process[" << processName << "] is not found ";
338  G4cout << " for " << processManager->GetParticleType()->GetParticleName() << G4endl;
339  }
340 #endif
341 
342  if (isFound) return anElement->GetProcess();
343  else return 0;
344 }
345 
349  const G4String& processName )
350 {
351  tmpTblVector->clear();
352 
353  G4ProcTableVector::iterator itr;
354  G4bool isFound = false;
355  G4ProcTblElement* anElement=0;
356  for (itr=fProcTblVector->begin(); itr!=fProcTblVector->end(); ++itr) {
357  anElement = (*itr);
358  // check name
359  if ( anElement->GetProcessName() == processName ) {
360  isFound = true;
361  tmpTblVector->push_back(anElement);
362  }
363  }
364 
365  if (!isFound && verboseLevel>0){
366 #ifdef G4VERBOSE
367  G4cout << " G4ProcessTable::Find :" ;
368  G4cout << " The Process[" << processName << "] is not found " << G4endl;
369 #endif
370  }
371 
372  return tmpTblVector;
373 
374 }
378  G4ProcessType processType )
379 {
380  tmpTblVector->clear();
381 
382  G4ProcTableVector::iterator itr;
383  G4bool isFound = false;
384  G4ProcTblElement* anElement=0;
385  for (itr=fProcTblVector->begin(); itr!=fProcTblVector->end(); ++itr) {
386  anElement = (*itr);
387  // check name
388  if ( anElement->GetProcess()->GetProcessType() == processType ) {
389  isFound = true;
390  tmpTblVector->push_back(anElement);
391  }
392  }
393 
394  if (!isFound && verboseLevel>0){
395 #ifdef G4VERBOSE
396  G4cout << " G4ProcessTable::Find :" ;
397  G4cout << " The ProcessType[" << processType << "] is not found " << G4endl;
398 #endif
399  }
400 
401  return tmpTblVector;
402 
403 }
404 
407 {
408  G4ProcessVector* procList = new G4ProcessVector();
409  G4ProcTableVector::iterator itr;
410  // loop over all elements
411  for (itr=procTblVector->begin(); itr!=procTblVector->end(); ++itr) {
412  G4ProcTblElement* anElement = (*itr);
413  procList->insert( anElement->GetProcess() );
414  }
415  return procList;
416 }
417 
420 {
422 }
423 
426 {
427  G4ProcessVector* procList = pManager->GetProcessList();
428  return new G4ProcessVector(*procList);
429 }
430 
433 {
434  G4ProcTableVector* pTblVector = Find(fProcTblVector, processName);
435  return ExtractProcesses(pTblVector);
436 }
437 
440 {
441  G4ProcTableVector* pTblVector = Find(fProcTblVector, processType);
442  return ExtractProcesses(pTblVector);
443 }
444 
447  G4bool fActive )
448 {
449 #ifdef G4VERBOSE
450  if (verboseLevel>1){
451  G4cout << " G4ProcessTable::SetProcessActivation:" ;
452  G4cout << " The Process[" << processName << "] "<< G4endl;
453  }
454 #endif
455 
456  G4ProcTableVector* pTblVector = Find(fProcTblVector, processName);
457  G4ProcTableVector::iterator itr;
458  G4ProcTblElement* anElement;
459  // loop over all elements
460  for (itr=pTblVector->begin(); itr!=pTblVector->end(); ++itr) {
461  anElement = (*itr);
462  G4VProcess* process = anElement->GetProcess();
463  for (G4int idx = 0 ; idx < anElement->Length(); idx++) {
464  G4ProcessManager* manager = anElement->GetProcessManager(idx);
465  manager->SetProcessActivation(process, fActive);
466 #ifdef G4VERBOSE
467  if (verboseLevel>1){
468  G4cout << " for " << manager->GetParticleType()->GetParticleName();
469  G4cout << " Index = " << manager->GetProcessIndex(process);
470  G4cout << G4endl;
471  }
472 #endif
473  }
474  }
475 }
476 
479  const G4String& processName,
480  G4ProcessManager* processManager,
481  G4bool fActive )
482 {
483 #ifdef G4VERBOSE
484  if (verboseLevel>1){
485  G4cout << " G4ProcessTable::SetProcessActivation:" ;
486  G4cout << " The Process[" << processName << "] "<< G4endl;
487  }
488 #endif
489 
490  G4VProcess* process = FindProcess( processName, processManager);
491  if ( process != 0) {
492  processManager->SetProcessActivation(process, fActive);
493 #ifdef G4VERBOSE
494  if (verboseLevel>1){
495  G4cout << " for " << processManager->GetParticleType()->GetParticleName();
496  G4cout << " Index = " << processManager->GetProcessIndex(process) << G4endl;
497  }
498 #endif
499  }
500 }
501 
502 
505  G4bool fActive )
506 {
507 #ifdef G4VERBOSE
508  if (verboseLevel>1){
509  G4cout << " G4ProcessTable::SetProcessActivation:" ;
510  G4cout << " The ProcessType[" << G4int(processType) << "] "<< G4endl;
511  }
512 #endif
513 
514  G4ProcTableVector* pTblVector = Find(fProcTblVector, processType);
515  G4ProcTableVector::iterator itr;
516  G4ProcTblElement* anElement;
517  // loop over all elements
518  for (itr=pTblVector->begin(); itr!=pTblVector->end(); ++itr) {
519  anElement = (*itr);
520  G4VProcess* process = anElement->GetProcess();
521 #ifdef G4VERBOSE
522  if (verboseLevel>1){
523  G4cout << " The Process[" << process->GetProcessName()<< "] "<< G4endl;
524  }
525 #endif
526  for (G4int idx = 0 ; idx < anElement->Length(); idx++) {
527  G4ProcessManager* manager = anElement->GetProcessManager(idx);
528  manager->SetProcessActivation(process, fActive);
529 #ifdef G4VERBOSE
530  if (verboseLevel>1){
531  G4cout << " for " << manager->GetParticleType()->GetParticleName();
532  G4cout << " Index = " << manager->GetProcessIndex(process) << G4endl;
533  }
534 #endif
535  }
536  }
537 }
538 
541  G4ProcessType processType,
542  G4ProcessManager* processManager,
543  G4bool fActive )
544 {
545 #ifdef G4VERBOSE
546  if (verboseLevel>1){
547  G4cout << " G4ProcessTable::SetProcessActivation:" ;
548  G4cout << " The ProcessType[" << G4int(processType) << "] "<< G4endl;
549  }
550 #endif
551 
552  G4ProcessVector* procList = processManager->GetProcessList();
553  for (G4int idx = 0; idx < procList->length(); idx++) {
554  G4VProcess* process = (*procList)(idx);
555  if ( process->GetProcessType() == processType) {
556  processManager->SetProcessActivation(process, fActive);
557 #ifdef G4VERBOSE
558  if (verboseLevel>1){
559  G4cout << " The Process[" << process->GetProcessName()<< "] "<< G4endl;
560  G4cout << " for " << processManager->GetParticleType()->GetParticleName();
561  G4cout << " Index = " << idx << G4endl;
562  }
563 #endif
564  }
565  }
566 }
567 
568 
571  G4ParticleDefinition* particle)
572 {
573  G4ProcTableVector::iterator itr;
574  G4int idxTbl=0;
575  G4ProcTblElement* anElement=0;
576  G4bool isFoundInTbl = false;
577  G4ProcessManager* manager=0;
578  G4int idx;
579  // loop over all elements
580  for (itr=fProcTblVector->begin(); itr!=fProcTblVector->end(); ++itr, ++idxTbl) {
581  anElement = (*itr);
582  if (process == anElement->GetProcess() ){
583  if (particle!=0) {
584  for (idx=0; idx<anElement->Length(); idx++){
585  manager = anElement->GetProcessManager(idx);
586  if (particle == manager->GetParticleType()) {
587  isFoundInTbl = true;
588  break;
589  }
590  }
591  } else {
592  isFoundInTbl = true;
593  }
594  break;
595  }
596  }
597  if (!isFoundInTbl ) return;
598 
599  G4int tmpVerbose = process->GetVerboseLevel();
600  process->SetVerboseLevel(verboseLevel);
601  process->DumpInfo();
602  process->SetVerboseLevel(tmpVerbose);
603  if (particle==0) {
604  for (idx=0; idx<anElement->Length(); idx++){
605  manager = anElement->GetProcessManager(idx);
606  G4cout << " for " << manager->GetParticleType()->GetParticleName();
607  G4cout << G4endl;
608 #ifdef G4VERBOSE
609  if (verboseLevel >2){
610  tmpVerbose = manager->GetVerboseLevel();
611  manager->SetVerboseLevel(verboseLevel);
612  manager->DumpInfo();
613  manager->SetVerboseLevel(tmpVerbose);
614  }
615 #endif
616  }
617  } else {
618  G4cout << " for " << manager->GetParticleType()->GetParticleName();
619  G4cout << G4endl;
620 #ifdef G4VERBOSE
621  if (verboseLevel >2){
622  tmpVerbose = manager->GetVerboseLevel();
623  manager->SetVerboseLevel(verboseLevel);
624  manager->DumpInfo();
625  manager->SetVerboseLevel(tmpVerbose);
626  }
627 #endif
628  }
629 }
630 
631 
632 
633 
634 
635 
G4ProcessTableMessenger * fProcTblMessenger
static G4ThreadLocal G4ProcessTable * fProcessTable
G4int Insert(G4VProcess *aProcess, G4ProcessManager *aProcMgr)
G4ProcTableVector * tmpTblVector
void DumpInfo(G4VProcess *process, G4ParticleDefinition *particle=0)
G4UImessenger * CreateMessenger()
G4int Remove(G4VProcess *aProcess, G4ProcessManager *aProcMgr)
void SetVerboseLevel(G4int value)
G4ProcessManager * GetProcessManager(G4int index) const
G4ProcessType GetProcessType() const
Definition: G4VProcess.hh:414
#define G4ThreadLocal
Definition: tls.hh:89
G4int GetVerboseLevel() const
int G4int
Definition: G4Types.hh:78
void SetProcessActivation(const G4String &processName, G4bool fActive)
const G4String & GetParticleName() const
G4int Length() const
G4VProcess * SetProcessActivation(G4VProcess *aProcess, G4bool fActive)
G4ProcessTable & operator=(const G4ProcessTable &right)
G4int GetVerboseLevel() const
Definition: G4VProcess.hh:442
G4ProcTableVector * Find(G4ProcTableVector *procTableVector, const G4String &processName)
G4ProcTableVector * fProcTblVector
G4GLOB_DLL std::ostream G4cout
G4int operator==(const G4ProcessTable &right) const
G4bool Contains(const G4ProcessManager *pManager) const
bool G4bool
Definition: G4Types.hh:79
void Insert(G4ProcessManager *aProcMgr)
G4int length() const
const G4String & GetProcessName() const
G4ParticleDefinition * GetParticleType() const
const G4String & GetProcessName() const
Definition: G4VProcess.hh:408
G4bool insert(G4VProcess *aProcess)
void Remove(G4ProcessManager *aProcMgr)
G4VProcess * GetProcess() const
std::vector< G4String > G4ProcNameVector
std::vector< G4ProcTblElement * > G4ProcTableVector
G4ProcNameVector * fProcNameVector
G4int GetProcessIndex(G4VProcess *) const
#define G4endl
Definition: G4ios.hh:61
virtual void DumpInfo() const
Definition: G4VProcess.cc:178
G4ProcessVector * ExtractProcesses(G4ProcTableVector *procTableVector)
G4ProcessVector * FindProcesses()
G4int operator!=(const G4ProcessTable &right) const
static G4ProcessTable * GetProcessTable()
G4VProcess * FindProcess(const G4String &processName, const G4String &particleName) const
void SetVerboseLevel(G4int value)
Definition: G4VProcess.hh:437
G4ProcessVector * GetProcessList() const
G4ProcessType