Geant4  10.01.p01
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 78775 2014-01-23 11:23:25Z 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  verboseLevel = right.verboseLevel;
128 #ifdef G4VERBOSE
129  if (verboseLevel>0){
130  G4cout << "-- G4ProcessTable assignment operator --" << G4endl;
131  }
132 #endif
133  if (&right == this) return *this;
134  else return *this;
135 }
136 
139 {
140  return (this == &right);
141 }
142 
145 {
146  return (this != &right);
147 }
148 
149 // Static class variable: ptr to single instance of class
151 
152 
155 {
156  static G4ThreadLocal G4ProcessTable *theProcessTable_G4MT_TLS_ = 0 ; if (!theProcessTable_G4MT_TLS_) theProcessTable_G4MT_TLS_ = new G4ProcessTable ; G4ProcessTable &theProcessTable = *theProcessTable_G4MT_TLS_;
157  if (!fProcessTable){
158  fProcessTable = &theProcessTable;
159  }
160  return fProcessTable;
161 }
162 
165  G4ProcessManager* aProcMgr)
166 {
167  if ( (aProcess == 0) || ( aProcMgr == 0 ) ){
168 #ifdef G4VERBOSE
169  if (verboseLevel>0){
170  G4cout << "G4ProcessTable::Insert : arguments are 0 pointer "
171  <<aProcess <<","<< aProcMgr << G4endl;
172  }
173 #endif
174  return -1;
175  }
176 
177 #ifdef G4VERBOSE
178  if (verboseLevel>1){
179  G4cout << "G4ProcessTable::Insert ";
180  G4cout << " Process[" << aProcess->GetProcessName() << "]";
181  G4cout << " Particle[" << aProcMgr->GetParticleType()->GetParticleName() << "]";
182  G4cout << G4endl;
183  }
184 #endif
185 
186  G4ProcTableVector::iterator itr;
187  G4int idxTbl=0;
188  G4ProcTblElement* anElement;
189  G4bool isFoundInTbl = false;
190  // loop over all elements
191  for (itr=fProcTblVector->begin(); itr!=fProcTblVector->end(); ++itr, ++idxTbl) {
192  anElement = (*itr);
193  // check if this process is included
194  if (aProcess == anElement->GetProcess()) {
195  isFoundInTbl = true;
196 
197  // add the process manager into the element
198  // unless this process manager is included
199  if (!anElement->Contains(aProcMgr)) {
200  anElement->Insert(aProcMgr);
201 #ifdef G4VERBOSE
202  if (verboseLevel>2){
203  G4cout << " This Process Manager is registered !! " << G4endl;
204  }
205 #endif
206  }
207  break;
208  }
209  }
210  // add this process into the table by creating a new element
211  if (!isFoundInTbl) {
212  G4ProcTblElement* newElement = new G4ProcTblElement(aProcess);
213  newElement->Insert(aProcMgr);
214  fProcTblVector->push_back(newElement);
215  // add into name vector
216  G4ProcNameVector::iterator ip;
217  G4bool isFound = false;
218  for (ip=fProcNameVector->begin(); ip!=fProcNameVector->end(); ++ip) {
219  isFound |= (aProcess->GetProcessName() == (*ip));
220  }
221  if (!isFound) {
222  fProcNameVector->push_back(aProcess->GetProcessName() );
223 #ifdef G4VERBOSE
224  if (verboseLevel>2){
225  G4cout << " This Process is registered !! " << G4endl;
226  }
227 #endif
228  }
229  }
230  return idxTbl;
231 }
232 
235  G4ProcessManager* aProcMgr)
236 {
237  if ( (aProcess == 0) || ( aProcMgr == 0 ) ){
238 #ifdef G4VERBOSE
239  if (verboseLevel>0){
240  G4cout << "G4ProcessTable::Remove : arguments are 0 pointer "<< G4endl;
241  }
242 #endif
243  return -1;
244  }
245 
246 #ifdef G4VERBOSE
247  if (verboseLevel>1){
248  G4cout << "G4ProcessTable::Remove ";
249  G4cout << " Process[" << aProcess->GetProcessName() << "]";
250  G4cout << " Particle[" << aProcMgr->GetParticleType()->GetParticleName() << "]" << G4endl;
251  }
252 #endif
253 
254  G4ProcTableVector::iterator itr;
255  G4int idxTbl=0;
256  G4ProcTblElement* anElement=0;
257  G4bool isFound = false;
258  // loop over all elements
259  for (itr=fProcTblVector->begin(); itr!=fProcTblVector->end(); ++itr, ++idxTbl) {
260  anElement = (*itr);
261 
262  // check if this process is included
263  if (aProcess == anElement->GetProcess()) {
264  isFound = anElement->Contains(aProcMgr);
265  // remove the process manager from the element
266  anElement->Remove(aProcMgr);
267 #ifdef G4VERBOSE
268  if (verboseLevel>2){
269  G4cout << " This Process Manager is removed !! " << G4endl;
270  }
271 #endif
272  break;
273  }
274  }
275  //
276  if (!isFound) {
277 #ifdef G4VERBOSE
278  if (verboseLevel>0){
279  G4cout << " This Process Manager is not registered !! " << G4endl;
280  }
281 #endif
282  return -1;
283  }
284  // remove the element if it has no entry
285  if (anElement->Length() == 0){
286  fProcTblVector->erase(itr);
287  delete anElement;
288  // check other prcesses with same name exist or not
289  G4bool isSameName = false;
290  for (itr=fProcTblVector->begin(); itr!=fProcTblVector->end(); ++itr) {
291  anElement = (*itr);
292  if (anElement->GetProcessName() == aProcess->GetProcessName()) {
293  isSameName = true;
294  break;
295  }
296  }
297  // remove from name vector
298  if (!isSameName ) {
299  G4ProcNameVector::iterator i;
300  for (i=fProcNameVector->begin(); i!=fProcNameVector->end(); ++i) {
301  if ( *i == aProcess->GetProcessName() ) {
302  fProcNameVector->erase(i);
303  break;
304  }
305  }
306  }
307 #ifdef G4VERBOSE
308  if (verboseLevel>1){
309  G4cout << " This Process is removed !! " << G4endl;
310  }
311 #endif
312  }
313  return idxTbl;
314 }
315 
318  const G4ProcessManager* processManager)
319  const
320 {
321  G4ProcTableVector::iterator itr;
322  G4int idxTbl = 0;
323  G4bool isFound = false;
324  G4ProcTblElement* anElement=0;
325  for (itr=fProcTblVector->begin(); itr!=fProcTblVector->end(); ++itr, ++idxTbl) {
326  anElement = (*itr);
327  // check name
328  if ( anElement->GetProcessName() == processName ) {
329  // check if the processManage is included
330  if ( anElement->Contains(processManager) ) {
331  isFound = true;
332  break;
333  }
334  }
335  }
336 #ifdef G4VERBOSE
337  if (!isFound && verboseLevel>1){
338  G4cout << " G4ProcessTable::FindProcess :" ;
339  G4cout << " The Process[" << processName << "] is not found ";
340  G4cout << " for " << processManager->GetParticleType()->GetParticleName() << G4endl;
341  }
342 #endif
343 
344  if (isFound) return anElement->GetProcess();
345  else return 0;
346 }
347 
351  const G4String& processName )
352 {
353  tmpTblVector->clear();
354 
355  G4ProcTableVector::iterator itr;
356  G4bool isFound = false;
357  G4ProcTblElement* anElement=0;
358  for (itr=fProcTblVector->begin(); itr!=fProcTblVector->end(); ++itr) {
359  anElement = (*itr);
360  // check name
361  if ( anElement->GetProcessName() == processName ) {
362  isFound = true;
363  tmpTblVector->push_back(anElement);
364  }
365  }
366 
367  if (!isFound && verboseLevel>0){
368 #ifdef G4VERBOSE
369  G4cout << " G4ProcessTable::Find :" ;
370  G4cout << " The Process[" << processName << "] is not found " << G4endl;
371 #endif
372  }
373 
374  return tmpTblVector;
375 
376 }
380  G4ProcessType processType )
381 {
382  tmpTblVector->clear();
383 
384  G4ProcTableVector::iterator itr;
385  G4bool isFound = false;
386  G4ProcTblElement* anElement=0;
387  for (itr=fProcTblVector->begin(); itr!=fProcTblVector->end(); ++itr) {
388  anElement = (*itr);
389  // check name
390  if ( anElement->GetProcess()->GetProcessType() == processType ) {
391  isFound = true;
392  tmpTblVector->push_back(anElement);
393  }
394  }
395 
396  if (!isFound && verboseLevel>0){
397 #ifdef G4VERBOSE
398  G4cout << " G4ProcessTable::Find :" ;
399  G4cout << " The ProcessType[" << processType << "] is not found " << G4endl;
400 #endif
401  }
402 
403  return tmpTblVector;
404 
405 }
406 
409 {
410  G4ProcessVector* procList = new G4ProcessVector();
411  G4ProcTableVector::iterator itr;
412  // loop over all elements
413  for (itr=procTblVector->begin(); itr!=procTblVector->end(); ++itr) {
414  G4ProcTblElement* anElement = (*itr);
415  procList->insert( anElement->GetProcess() );
416  }
417  return procList;
418 }
419 
422 {
424 }
425 
428 {
429  G4ProcessVector* procList = pManager->GetProcessList();
430  return new G4ProcessVector(*procList);
431 }
432 
435 {
436  G4ProcTableVector* pTblVector = Find(fProcTblVector, processName);
437  return ExtractProcesses(pTblVector);
438 }
439 
442 {
443  G4ProcTableVector* pTblVector = Find(fProcTblVector, processType);
444  return ExtractProcesses(pTblVector);
445 }
446 
449  G4bool fActive )
450 {
451 #ifdef G4VERBOSE
452  if (verboseLevel>1){
453  G4cout << " G4ProcessTable::SetProcessActivation:" ;
454  G4cout << " The Process[" << processName << "] "<< G4endl;
455  }
456 #endif
457 
458  G4ProcTableVector* pTblVector = Find(fProcTblVector, processName);
459  G4ProcTableVector::iterator itr;
460  G4ProcTblElement* anElement;
461  // loop over all elements
462  for (itr=pTblVector->begin(); itr!=pTblVector->end(); ++itr) {
463  anElement = (*itr);
464  G4VProcess* process = anElement->GetProcess();
465  for (G4int idx = 0 ; idx < anElement->Length(); idx++) {
466  G4ProcessManager* manager = anElement->GetProcessManager(idx);
467  manager->SetProcessActivation(process, fActive);
468 #ifdef G4VERBOSE
469  if (verboseLevel>1){
470  G4cout << " for " << manager->GetParticleType()->GetParticleName();
471  G4cout << " Index = " << manager->GetProcessIndex(process);
472  G4cout << G4endl;
473  }
474 #endif
475  }
476  }
477 }
478 
481  const G4String& processName,
482  G4ProcessManager* processManager,
483  G4bool fActive )
484 {
485 #ifdef G4VERBOSE
486  if (verboseLevel>1){
487  G4cout << " G4ProcessTable::SetProcessActivation:" ;
488  G4cout << " The Process[" << processName << "] "<< G4endl;
489  }
490 #endif
491 
492  G4VProcess* process = FindProcess( processName, processManager);
493  if ( process != 0) {
494  processManager->SetProcessActivation(process, fActive);
495 #ifdef G4VERBOSE
496  if (verboseLevel>1){
497  G4cout << " for " << processManager->GetParticleType()->GetParticleName();
498  G4cout << " Index = " << processManager->GetProcessIndex(process) << G4endl;
499  }
500 #endif
501  }
502 }
503 
504 
507  G4bool fActive )
508 {
509 #ifdef G4VERBOSE
510  if (verboseLevel>1){
511  G4cout << " G4ProcessTable::SetProcessActivation:" ;
512  G4cout << " The ProcessType[" << G4int(processType) << "] "<< G4endl;
513  }
514 #endif
515 
516  G4ProcTableVector* pTblVector = Find(fProcTblVector, processType);
517  G4ProcTableVector::iterator itr;
518  G4ProcTblElement* anElement;
519  // loop over all elements
520  for (itr=pTblVector->begin(); itr!=pTblVector->end(); ++itr) {
521  anElement = (*itr);
522  G4VProcess* process = anElement->GetProcess();
523 #ifdef G4VERBOSE
524  if (verboseLevel>1){
525  G4cout << " The Process[" << process->GetProcessName()<< "] "<< G4endl;
526  }
527 #endif
528  for (G4int idx = 0 ; idx < anElement->Length(); idx++) {
529  G4ProcessManager* manager = anElement->GetProcessManager(idx);
530  manager->SetProcessActivation(process, fActive);
531 #ifdef G4VERBOSE
532  if (verboseLevel>1){
533  G4cout << " for " << manager->GetParticleType()->GetParticleName();
534  G4cout << " Index = " << manager->GetProcessIndex(process) << G4endl;
535  }
536 #endif
537  }
538  }
539 }
540 
543  G4ProcessType processType,
544  G4ProcessManager* processManager,
545  G4bool fActive )
546 {
547 #ifdef G4VERBOSE
548  if (verboseLevel>1){
549  G4cout << " G4ProcessTable::SetProcessActivation:" ;
550  G4cout << " The ProcessType[" << G4int(processType) << "] "<< G4endl;
551  }
552 #endif
553 
554  G4ProcessVector* procList = processManager->GetProcessList();
555  for (G4int idx = 0; idx < procList->length(); idx++) {
556  G4VProcess* process = (*procList)(idx);
557  if ( process->GetProcessType() == processType) {
558  processManager->SetProcessActivation(process, fActive);
559 #ifdef G4VERBOSE
560  if (verboseLevel>1){
561  G4cout << " The Process[" << process->GetProcessName()<< "] "<< G4endl;
562  G4cout << " for " << processManager->GetParticleType()->GetParticleName();
563  G4cout << " Index = " << idx << G4endl;
564  }
565 #endif
566  }
567  }
568 }
569 
570 
573  G4ParticleDefinition* particle)
574 {
575  G4ProcTableVector::iterator itr;
576  G4int idxTbl=0;
577  G4ProcTblElement* anElement=0;
578  G4bool isFoundInTbl = false;
579  G4ProcessManager* manager=0;
580  G4int idx;
581  // loop over all elements
582  for (itr=fProcTblVector->begin(); itr!=fProcTblVector->end(); ++itr, ++idxTbl) {
583  anElement = (*itr);
584  if (process == anElement->GetProcess() ){
585  if (particle!=0) {
586  for (idx=0; idx<anElement->Length(); idx++){
587  manager = anElement->GetProcessManager(idx);
588  if (particle == manager->GetParticleType()) {
589  isFoundInTbl = true;
590  break;
591  }
592  }
593  } else {
594  isFoundInTbl = true;
595  }
596  break;
597  }
598  }
599  if (!isFoundInTbl ) return;
600 
601  G4int tmpVerbose = process->GetVerboseLevel();
602  process->SetVerboseLevel(verboseLevel);
603  process->DumpInfo();
604  process->SetVerboseLevel(tmpVerbose);
605  if (particle==0) {
606  for (idx=0; idx<anElement->Length(); idx++){
607  manager = anElement->GetProcessManager(idx);
608  G4cout << " for " << manager->GetParticleType()->GetParticleName();
609  G4cout << G4endl;
610 #ifdef G4VERBOSE
611  if (verboseLevel >2){
612  tmpVerbose = manager->GetVerboseLevel();
613  manager->SetVerboseLevel(verboseLevel);
614  manager->DumpInfo();
615  manager->SetVerboseLevel(tmpVerbose);
616  }
617 #endif
618  }
619  } else {
620  G4cout << " for " << manager->GetParticleType()->GetParticleName();
621  G4cout << G4endl;
622 #ifdef G4VERBOSE
623  if (verboseLevel >2){
624  tmpVerbose = manager->GetVerboseLevel();
625  manager->SetVerboseLevel(verboseLevel);
626  manager->DumpInfo();
627  manager->SetVerboseLevel(tmpVerbose);
628  }
629 #endif
630  }
631 }
632 
633 
634 
635 
636 
637 
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