Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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// G4ProcessTable class implementation
27//
28// Author: H.Kurashige, 4 August 1998
29// --------------------------------------------------------------------
30
32#include "G4ProcessTable.hh"
33#include "G4ParticleTable.hh"
34#include "G4ios.hh"
35
36// --------------------------------------------------------------------
37// Static class variable: ptr to single instance of class in a thread
38G4ThreadLocal G4ProcessTable* G4ProcessTable::fProcessTable = nullptr;
39
40// --------------------------------------------------------------------
41// Default constructor
42//
44{
45#ifdef G4VERBOSE
46 if (verboseLevel>1)
47 {
48 G4cout << "-- G4ProcessTable constructor --" << G4endl;
49 }
50#endif
51 fProcTblVector = new G4ProcTableVector();
52 fProcNameVector = new G4ProcNameVector();
53 tmpTblVector = new G4ProcTableVector();
54 fProcTblMessenger = new G4ProcessTableMessenger(this);
55}
56
57// --------------------------------------------------------------------
58// Destructor
59//
61{
62 if ( tmpTblVector != nullptr )
63 {
64 tmpTblVector ->clear();
65 delete tmpTblVector;
66 tmpTblVector = nullptr;
67 }
68
69 if ( fProcTblVector != nullptr )
70 {
71 for (auto elem : *fProcTblVector)
72 {
73 delete elem;
74 }
75 fProcTblVector ->clear();
76 delete fProcTblVector;
77 fProcTblVector = nullptr;
78 }
79
80 // delete all process except transportation
81 for(auto proc : fListProcesses)
82 {
83 if ( proc != nullptr )
84 {
85 G4ProcessType type = proc->GetProcessType();
86 if (type != fTransportation && type != fParallel
87 && type != fParameterisation)
88 {
89 delete proc;
90 }
91 }
92 }
93
94 fListProcesses.clear();
95
96 if ( fProcNameVector != nullptr )
97 {
98 fProcNameVector ->clear();
99 delete fProcNameVector;
100 fProcNameVector = nullptr;
101 }
102 fProcessTable = nullptr;
103 delete fProcTblMessenger;
104}
105
106// --------------------------------------------------------------------
107//
109{
110 if(fProcessTable == nullptr)
111 {
113 fProcessTable = inst.Instance();
114 }
115 return fProcessTable;
116}
117
118// --------------------------------------------------------------------
119//
121 G4ProcessManager* aProcMgr)
122{
123 if ( (aProcess == nullptr) || ( aProcMgr == nullptr ) || !fProcTblVector )
124 {
125#ifdef G4VERBOSE
126 if (verboseLevel>0)
127 {
128 G4cout << "G4ProcessTable::Insert() - arguments are null pointer "
129 << aProcess << "," << aProcMgr << G4endl;
130 }
131#endif
132 return -1;
133 }
134
135#ifdef G4VERBOSE
136 if (verboseLevel>1)
137 {
138 G4cout << "G4ProcessTable::Insert() -";
139 G4cout << " Process[" << aProcess->GetProcessName() << "]";
140 G4cout << " Particle[" << aProcMgr->GetParticleType()->GetParticleName()
141 << "]" << G4endl;
142 }
143#endif
144
145 G4int idxTbl = 0;
146 G4int nidx = fProcTblVector->size();
147 G4ProcTblElement* anElement = nullptr;
148 // loop over all elements
149 for (; idxTbl < nidx; ++idxTbl)
150 {
151 anElement = (*fProcTblVector)[idxTbl];
152 if(!anElement) { continue; }
153 // check if this process is included
154 if (aProcess == anElement->GetProcess())
155 {
156 // add the process manager into the element
157 // unless this process manager is included
158 if (!anElement->Contains(aProcMgr))
159 {
160 anElement->Insert(aProcMgr);
161#ifdef G4VERBOSE
162 if (verboseLevel>2)
163 {
164 G4cout << " This Process Manager is registered !! " << G4endl;
165 }
166#endif
167 }
168 return idxTbl;
169 }
170 }
171 // add this process into the table by creating a new element
172 if (verboseLevel>2)
173 {
174 G4cout << " New element is created !! " << G4endl;
175 }
176 anElement = new G4ProcTblElement(aProcess);
177 anElement->Insert(aProcMgr);
178 fProcTblVector->push_back(anElement);
179 fProcNameVector->push_back(aProcess->GetProcessName() );
180 return nidx;
181}
182
183// --------------------------------------------------------------------
184//
186 G4ProcessManager* aProcMgr )
187{
188 if ( (aProcess == nullptr) || ( aProcMgr == nullptr ) || !fProcTblVector )
189 {
190#ifdef G4VERBOSE
191 if (verboseLevel>0)
192 {
193 G4cout << "G4ProcessTable::Remove() - arguments are null pointer "
194 << G4endl;
195 }
196#endif
197 return -1;
198 }
199
200#ifdef G4VERBOSE
201 if (verboseLevel>1)
202 {
203 G4cout << "G4ProcessTable::Remove() -";
204 G4cout << " Process[" << aProcess->GetProcessName() << "]";
205 G4cout << " Particle[" << aProcMgr->GetParticleType()->GetParticleName()
206 << "]" << G4endl;
207 }
208#endif
209
210 G4int idxTbl = 0;
211 G4int nidx = fProcTblVector->size();
212 G4ProcTblElement* anElement =nullptr;
213 // loop over all elements
214 for (; idxTbl < nidx; ++idxTbl)
215 {
216 anElement = (*fProcTblVector)[idxTbl];
217 if(!anElement) { continue; }
218
219 // check if this process is included
220 if (aProcess == anElement->GetProcess())
221 {
222 if(anElement->Contains(aProcMgr))
223 {
224 // remove the process manager from the element
225 anElement->Remove(aProcMgr);
226#ifdef G4VERBOSE
227 if (verboseLevel>2)
228 {
229 G4cout << " This Process Manager is removed !! " << G4endl;
230 }
231#endif
232 if(anElement->Length() == 0)
233 {
234 delete anElement;
235 (*fProcTblVector)[idxTbl] = nullptr;
236#ifdef G4VERBOSE
237 if (verboseLevel>1)
238 {
239 G4cout << " This Process is removed !! " << G4endl;
240 }
241#endif
242 }
243 return idxTbl;
244 }
245 }
246 }
247#ifdef G4VERBOSE
248 if (verboseLevel>1)
249 {
250 G4cout << " This Process Manager is not registered to the process!! "
251 << G4endl;
252 }
253#endif
254 return -1;
255}
256
257// --------------------------------------------------------------------
258//
260{
261 for(auto proc : fListProcesses)
262 {
263 if(ptr == proc) { return; }
264 }
265 fListProcesses.push_back(ptr);
266}
267
268// --------------------------------------------------------------------
269//
271{
272 G4int nn = fListProcesses.size();
273 for(G4int i=0; i<nn; ++i)
274 {
275 if(ptr == fListProcesses[i])
276 {
277 fListProcesses[i] = nullptr;
278 return;
279 }
280 }
281}
282
283// --------------------------------------------------------------------
284//
286 const G4String& particleName) const
287{
288 return FindProcess(processName,
289 G4ParticleTable::GetParticleTable()->FindParticle(particleName));
290}
291
292// --------------------------------------------------------------------
293//
295 const G4ProcessManager* processManager)
296 const
297{
298 for (auto anElement : *fProcTblVector)
299 {
300 // check name and if the processManage is included
301 if (anElement && anElement->GetProcessName() == processName
302 && anElement->Contains(processManager))
303 {
304 return anElement->GetProcess();
305 }
306 }
307#ifdef G4VERBOSE
308 if (verboseLevel > 1)
309 {
310 G4cout << " G4ProcessTable::FindProcess() -" ;
311 G4cout << " The Process[" << processName << "] is not found ";
312 G4cout << " for [" << processManager->GetParticleType()->GetParticleName()
313 << "]" << G4endl;
314 }
315#endif
316 return nullptr;
317}
318
319// --------------------------------------------------------------------
320//
323 const G4ParticleDefinition* particle) const
324{
325 // find the first process of given type for this particle
326
327 const G4ProcessManager* processManager = particle->GetProcessManager();
328 for (auto anElement : *fProcTblVector)
329 {
330 if (anElement && anElement->GetProcess()->GetProcessType() == processType
331 && anElement->Contains(processManager))
332 {
333 return anElement->GetProcess();
334 }
335 }
336#ifdef G4VERBOSE
337 if (verboseLevel > 1)
338 {
339 G4cout << " G4ProcessTable::FindProcess() -";
340 G4cout << " The Process Type " << processType << " is not found ";
341 G4cout << " for [" << particle->GetParticleName() << "]" << G4endl;
342 }
343#endif
344 return nullptr;
345}
346
347// --------------------------------------------------------------------
348//
351 const G4ParticleDefinition* particle) const
352{
353 // find the first process of given type for this particle
354
355 const G4ProcessManager* processManager = particle->GetProcessManager();
356 for (auto anElement : *fProcTblVector)
357 {
358 if ( anElement != nullptr
359 && anElement->GetProcess()->GetProcessSubType() == procSubType
360 && anElement->Contains(processManager) )
361 {
362 return anElement->GetProcess();
363 }
364 }
365#ifdef G4VERBOSE
366 if (verboseLevel > 1)
367 {
368 G4cout << " G4ProcessTable::FindProcess() -";
369 G4cout << " The Process SubType " << procSubType << " is not found ";
370 G4cout << " for [" << particle->GetParticleName() << "]" << G4endl;
371 }
372#endif
373 return nullptr;
374}
375
376// --------------------------------------------------------------------
377//
379G4ProcessTable::Find(const G4String& processName)
380{
381 tmpTblVector->clear();
382
383 G4bool isFound = false;
384 G4ProcTblElement* anElement = nullptr;
385 for (auto itr=fProcTblVector->cbegin(); itr!=fProcTblVector->cend(); ++itr)
386 {
387 anElement = (*itr);
388 // check name
389 if ( anElement->GetProcessName() == processName )
390 {
391 isFound = true;
392 tmpTblVector->push_back(anElement);
393 }
394 }
395
396 if (!isFound && verboseLevel>0)
397 {
398#ifdef G4VERBOSE
399 G4cout << " G4ProcessTable::Find() -" ;
400 G4cout << " The Process[" << processName << "] is not found " << G4endl;
401#endif
402 }
403
404 return tmpTblVector;
405}
406
407// --------------------------------------------------------------------
408//
410G4ProcessTable::Find(G4ProcessType processType)
411{
412 tmpTblVector->clear();
413
414 G4bool isFound = false;
415 G4ProcTblElement* anElement = nullptr;
416 for (auto itr=fProcTblVector->cbegin(); itr!=fProcTblVector->cend(); ++itr)
417 {
418 anElement = (*itr);
419 // check name
420 if ( anElement->GetProcess()->GetProcessType() == processType )
421 {
422 isFound = true;
423 tmpTblVector->push_back(anElement);
424 }
425 }
426
427 if (!isFound && verboseLevel>0)
428 {
429#ifdef G4VERBOSE
430 G4cout << " G4ProcessTable::Find() -" ;
431 G4cout << " The ProcessType[" << processType << "] is not found "
432 << G4endl;
433#endif
434 }
435
436 return tmpTblVector;
437}
438
439// --------------------------------------------------------------------
440//
442G4ProcessTable::ExtractProcesses(G4ProcTableVector* procTblVector) const
443{
444 G4ProcessVector* procList = new G4ProcessVector();
445 // loop over all elements
446 for (auto itr=procTblVector->cbegin(); itr!=procTblVector->cend(); ++itr)
447 {
448 G4ProcTblElement* anElement = (*itr);
449 procList->insert( anElement->GetProcess() );
450 }
451 return procList;
452}
453
454// --------------------------------------------------------------------
455//
457 const G4String& particleName,
458 G4bool fActive )
459{
460 if (particleName == "ALL" )
461 {
462 SetProcessActivation( processName, fActive);
463 }
464 else
465 {
466 SetProcessActivation(processName,
467 G4ParticleTable::GetParticleTable()->FindParticle(particleName),
468 fActive );
469 }
470}
471
472// --------------------------------------------------------------------
473//
475 const G4String& particleName ,
476 G4bool fActive)
477{
478 if ((particleName == "ALL" ) || (particleName == "all" ))
479 {
480 SetProcessActivation( processType, fActive );
481 }
482 else
483 {
484 SetProcessActivation(processType,
485 G4ParticleTable::GetParticleTable()->FindParticle(particleName),
486 fActive );
487 }
488}
489
490// --------------------------------------------------------------------
491//
493 G4bool fActive )
494{
495#ifdef G4VERBOSE
496 if (verboseLevel>1)
497 {
498 G4cout << " G4ProcessTable::SetProcessActivation() -" ;
499 G4cout << " The Process[" << processName << "] "<< G4endl;
500 }
501#endif
502
503 G4ProcTableVector* pTblVector = Find(processName);
504 G4ProcTblElement* anElement;
505 // loop over all elements
506 for (auto itr=pTblVector->cbegin(); itr!=pTblVector->cend(); ++itr)
507 {
508 anElement = (*itr);
509 G4VProcess* process = anElement->GetProcess();
510 for (G4int idx = 0 ; idx < anElement->Length(); ++idx)
511 {
512 G4ProcessManager* manager = anElement->GetProcessManager(idx);
513 manager->SetProcessActivation(process, fActive);
514#ifdef G4VERBOSE
515 if (verboseLevel>1)
516 {
517 G4cout << " for " << manager->GetParticleType()->GetParticleName();
518 G4cout << " Index = " << manager->GetProcessIndex(process);
519 G4cout << G4endl;
520 }
521#endif
522 }
523 }
524}
525
526// --------------------------------------------------------------------
527//
529 G4ProcessManager* processManager,
530 G4bool fActive )
531{
532#ifdef G4VERBOSE
533 if (verboseLevel>1)
534 {
535 G4cout << " G4ProcessTable::SetProcessActivation() -" ;
536 G4cout << " The Process[" << processName << "] "<< G4endl;
537 }
538#endif
539
540 G4VProcess* process = FindProcess( processName, processManager);
541 if ( process != nullptr)
542 {
543 processManager->SetProcessActivation(process, fActive);
544#ifdef G4VERBOSE
545 if (verboseLevel>1)
546 {
547 G4cout << " for "
548 << processManager->GetParticleType()->GetParticleName();
549 G4cout << " Index = "
550 << processManager->GetProcessIndex(process) << G4endl;
551 }
552#endif
553 }
554}
555
556// --------------------------------------------------------------------
557//
559 G4bool fActive )
560{
561#ifdef G4VERBOSE
562 if (verboseLevel>1)
563 {
564 G4cout << " G4ProcessTable::SetProcessActivation() -" ;
565 G4cout << " The ProcessType[" << G4int(processType) << "] "<< G4endl;
566 }
567#endif
568
569 G4ProcTableVector* pTblVector = Find(processType);
570 G4ProcTblElement* anElement;
571 // loop over all elements
572 for (auto itr=pTblVector->cbegin(); itr!=pTblVector->cend(); ++itr)
573 {
574 anElement = (*itr);
575 G4VProcess* process = anElement->GetProcess();
576#ifdef G4VERBOSE
577 if (verboseLevel>1)
578 {
579 G4cout << " The Process[" << process->GetProcessName()<< "] "<< G4endl;
580 }
581#endif
582 for (G4int idx = 0 ; idx < anElement->Length(); ++idx)
583 {
584 G4ProcessManager* manager = anElement->GetProcessManager(idx);
585 manager->SetProcessActivation(process, fActive);
586#ifdef G4VERBOSE
587 if (verboseLevel>1)
588 {
589 G4cout << " for " << manager->GetParticleType()->GetParticleName();
590 G4cout << " Index = " << manager->GetProcessIndex(process) << G4endl;
591 }
592#endif
593 }
594 }
595}
596
597// --------------------------------------------------------------------
598//
600 G4ProcessManager* processManager,
601 G4bool fActive )
602{
603#ifdef G4VERBOSE
604 if (verboseLevel>1)
605 {
606 G4cout << " G4ProcessTable::SetProcessActivation() -" ;
607 G4cout << " The ProcessType[" << G4int(processType) << "] "<< G4endl;
608 }
609#endif
610
611 G4ProcessVector* procList = processManager->GetProcessList();
612 for (std::size_t idx = 0; idx < procList->length(); ++idx)
613 {
614 G4VProcess* process = (*procList)(idx);
615 if ( process->GetProcessType() == processType)
616 {
617 processManager->SetProcessActivation(process, fActive);
618#ifdef G4VERBOSE
619 if (verboseLevel>1)
620 {
621 G4cout << " The Process[" << process->GetProcessName()<< "] "<< G4endl;
622 G4cout << " for "
623 << processManager->GetParticleType()->GetParticleName();
624 G4cout << " Index = " << idx << G4endl;
625 }
626#endif
627 }
628 }
629}
630
631// --------------------------------------------------------------------
632//
634 const G4ParticleDefinition* particle)
635{
636 G4int idxTbl=0;
637 G4ProcTblElement* anElement = nullptr;
638 G4bool isFoundInTbl = false;
639 G4ProcessManager* manager = nullptr;
640 G4int idx;
641 // loop over all elements
642 for (auto itr=fProcTblVector->cbegin();
643 itr!=fProcTblVector->cend(); ++itr, ++idxTbl)
644 {
645 anElement = (*itr);
646 if (process == anElement->GetProcess() )
647 {
648 if (particle != nullptr)
649 {
650 for (idx=0; idx<anElement->Length(); ++idx)
651 {
652 manager = anElement->GetProcessManager(idx);
653 if (particle == manager->GetParticleType())
654 {
655 isFoundInTbl = true;
656 break;
657 }
658 }
659 }
660 else
661 {
662 isFoundInTbl = true;
663 }
664 break;
665 }
666 }
667 if (!isFoundInTbl ) return;
668
669 G4int tmpVerbose = process->GetVerboseLevel();
670 process->SetVerboseLevel(verboseLevel);
671 process->DumpInfo();
672 process->SetVerboseLevel(tmpVerbose);
673 if (particle == nullptr)
674 {
675 for (idx=0; idx<anElement->Length(); ++idx)
676 {
677 manager = anElement->GetProcessManager(idx);
678 G4cout << " for " << manager->GetParticleType()->GetParticleName();
679 G4cout << G4endl;
680#ifdef G4VERBOSE
681 if (verboseLevel >2)
682 {
683 tmpVerbose = manager->GetVerboseLevel();
684 manager->SetVerboseLevel(verboseLevel);
685 manager->DumpInfo();
686 manager->SetVerboseLevel(tmpVerbose);
687 }
688#endif
689 }
690 }
691 else
692 {
693 G4cout << " for " << manager->GetParticleType()->GetParticleName();
694 G4cout << G4endl;
695#ifdef G4VERBOSE
696 if (verboseLevel >2)
697 {
698 tmpVerbose = manager->GetVerboseLevel();
699 manager->SetVerboseLevel(verboseLevel);
700 manager->DumpInfo();
701 manager->SetVerboseLevel(tmpVerbose);
702 }
703#endif
704 }
705}
G4ProcessType
@ fParameterisation
@ fParallel
@ fTransportation
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4ProcessManager * GetProcessManager() const
const G4String & GetParticleName() const
static G4ParticleTable * GetParticleTable()
const G4String & GetProcessName() const
G4VProcess * GetProcess() const
G4bool Contains(const G4ProcessManager *pManager) const
void Remove(G4ProcessManager *aProcMgr)
G4int Length() const
G4ProcessManager * GetProcessManager(G4int index) const
void Insert(G4ProcessManager *aProcMgr)
G4VProcess * GetProcess(const G4String &) const
G4VProcess * SetProcessActivation(G4VProcess *aProcess, G4bool fActive)
G4ParticleDefinition * GetParticleType() const
void SetVerboseLevel(G4int value)
G4ProcessVector * GetProcessList() const
G4int GetProcessIndex(G4VProcess *) const
G4int GetVerboseLevel() const
G4ProcessTable(const G4ProcessTable &)=delete
void DumpInfo(G4VProcess *process, const G4ParticleDefinition *particle=nullptr)
static G4ProcessTable * GetProcessTable()
G4VProcess * FindProcess(const G4String &processName, const G4String &particleName) const
G4int Insert(G4VProcess *aProcess, G4ProcessManager *aProcMgr)
void RegisterProcess(G4VProcess *)
void DeRegisterProcess(G4VProcess *)
G4int Remove(G4VProcess *aProcess, G4ProcessManager *aProcMgr)
void SetProcessActivation(const G4String &processName, G4bool fActive)
std::vector< G4ProcTblElement * > G4ProcTableVector
std::vector< G4String > G4ProcNameVector
G4bool insert(G4VProcess *aProcess)
std::size_t length() const
void SetVerboseLevel(G4int value)
Definition: G4VProcess.hh:412
G4int GetVerboseLevel() const
Definition: G4VProcess.hh:418
G4ProcessType GetProcessType() const
Definition: G4VProcess.hh:388
virtual void DumpInfo() const
Definition: G4VProcess.cc:167
const G4String & GetProcessName() const
Definition: G4VProcess.hh:382
#define G4ThreadLocal
Definition: tls.hh:77