Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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 = (G4int)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 = (G4int)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 std::size_t nn = fListProcesses.size();
273 for(std::size_t 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 != nullptr && 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 != nullptr && 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 if ( anElement != nullptr) 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 if ( anElement == nullptr ) continue;
510 G4VProcess* process = anElement->GetProcess();
511 for (G4int idx = 0 ; idx < anElement->Length(); ++idx)
512 {
513 G4ProcessManager* manager = anElement->GetProcessManager(idx);
514 manager->SetProcessActivation(process, fActive);
515#ifdef G4VERBOSE
516 if (verboseLevel>1)
517 {
518 G4cout << " for " << manager->GetParticleType()->GetParticleName();
519 G4cout << " Index = " << manager->GetProcessIndex(process);
520 G4cout << G4endl;
521 }
522#endif
523 }
524 }
525}
526
527// --------------------------------------------------------------------
528//
530 G4ProcessManager* processManager,
531 G4bool fActive )
532{
533#ifdef G4VERBOSE
534 if (verboseLevel>1)
535 {
536 G4cout << " G4ProcessTable::SetProcessActivation() -" ;
537 G4cout << " The Process[" << processName << "] "<< G4endl;
538 }
539#endif
540
541 G4VProcess* process = FindProcess( processName, processManager);
542 if ( process != nullptr)
543 {
544 processManager->SetProcessActivation(process, fActive);
545#ifdef G4VERBOSE
546 if (verboseLevel>1)
547 {
548 G4cout << " for "
549 << processManager->GetParticleType()->GetParticleName();
550 G4cout << " Index = "
551 << processManager->GetProcessIndex(process) << G4endl;
552 }
553#endif
554 }
555}
556
557// --------------------------------------------------------------------
558//
560 G4bool fActive )
561{
562#ifdef G4VERBOSE
563 if (verboseLevel>1)
564 {
565 G4cout << " G4ProcessTable::SetProcessActivation() -" ;
566 G4cout << " The ProcessType[" << G4int(processType) << "] "<< G4endl;
567 }
568#endif
569
570 G4ProcTableVector* pTblVector = Find(processType);
571 G4ProcTblElement* anElement;
572 // loop over all elements
573 for (auto itr=pTblVector->cbegin(); itr!=pTblVector->cend(); ++itr)
574 {
575 anElement = (*itr);
576 if ( anElement == nullptr ) continue;
577 G4VProcess* process = anElement->GetProcess();
578#ifdef G4VERBOSE
579 if (verboseLevel>1)
580 {
581 G4cout << " The Process[" << process->GetProcessName()<< "] "<< G4endl;
582 }
583#endif
584 for (G4int idx = 0 ; idx < anElement->Length(); ++idx)
585 {
586 G4ProcessManager* manager = anElement->GetProcessManager(idx);
587 manager->SetProcessActivation(process, fActive);
588#ifdef G4VERBOSE
589 if (verboseLevel>1)
590 {
591 G4cout << " for " << manager->GetParticleType()->GetParticleName();
592 G4cout << " Index = " << manager->GetProcessIndex(process) << G4endl;
593 }
594#endif
595 }
596 }
597}
598
599// --------------------------------------------------------------------
600//
602 G4ProcessManager* processManager,
603 G4bool fActive )
604{
605#ifdef G4VERBOSE
606 if (verboseLevel>1)
607 {
608 G4cout << " G4ProcessTable::SetProcessActivation() -" ;
609 G4cout << " The ProcessType[" << G4int(processType) << "] "<< G4endl;
610 }
611#endif
612
613 G4ProcessVector* procList = processManager->GetProcessList();
614 for (G4int idx = 0; idx < (G4int)procList->length(); ++idx)
615 {
616 G4VProcess* process = (*procList)(idx);
617 if ( process->GetProcessType() == processType)
618 {
619 processManager->SetProcessActivation(process, fActive);
620#ifdef G4VERBOSE
621 if (verboseLevel>1)
622 {
623 G4cout << " The Process[" << process->GetProcessName()<< "] "<< G4endl;
624 G4cout << " for "
625 << processManager->GetParticleType()->GetParticleName();
626 G4cout << " Index = " << idx << G4endl;
627 }
628#endif
629 }
630 }
631}
632
633// --------------------------------------------------------------------
634//
636 const G4ParticleDefinition* particle)
637{
638 G4int idxTbl=0;
639 G4ProcTblElement* anElement = nullptr;
640 G4bool isFoundInTbl = false;
641 G4ProcessManager* manager = nullptr;
642 G4int idx;
643 // loop over all elements
644 for (auto itr=fProcTblVector->cbegin();
645 itr!=fProcTblVector->cend(); ++itr, ++idxTbl)
646 {
647 anElement = (*itr);
648 if ( anElement == nullptr ) continue;
649 if (process == anElement->GetProcess() )
650 {
651 if (particle != nullptr)
652 {
653 for (idx=0; idx<anElement->Length(); ++idx)
654 {
655 manager = anElement->GetProcessManager(idx);
656 if (particle == manager->GetParticleType())
657 {
658 isFoundInTbl = true;
659 break;
660 }
661 }
662 }
663 else
664 {
665 isFoundInTbl = true;
666 }
667 break;
668 }
669 }
670 if (!isFoundInTbl ) return;
671
672 G4int tmpVerbose = process->GetVerboseLevel();
673 process->SetVerboseLevel(verboseLevel);
674 process->DumpInfo();
675 process->SetVerboseLevel(tmpVerbose);
676 if (particle == nullptr)
677 {
678 for (idx=0; idx<anElement->Length(); ++idx)
679 {
680 manager = anElement->GetProcessManager(idx);
681 G4cout << " for " << manager->GetParticleType()->GetParticleName();
682 G4cout << G4endl;
683#ifdef G4VERBOSE
684 if (verboseLevel >2)
685 {
686 tmpVerbose = manager->GetVerboseLevel();
687 manager->SetVerboseLevel(verboseLevel);
688 manager->DumpInfo();
689 manager->SetVerboseLevel(tmpVerbose);
690 }
691#endif
692 }
693 }
694 else
695 {
696 G4cout << " for " << manager->GetParticleType()->GetParticleName();
697 G4cout << G4endl;
698#ifdef G4VERBOSE
699 if (verboseLevel >2)
700 {
701 tmpVerbose = manager->GetVerboseLevel();
702 manager->SetVerboseLevel(verboseLevel);
703 manager->DumpInfo();
704 manager->SetVerboseLevel(tmpVerbose);
705 }
706#endif
707 }
708}
#define elem(i, j)
G4ProcessType
@ fParameterisation
@ fParallel
@ fTransportation
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
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 * 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)
G4int GetVerboseLevel() const
G4ProcessType GetProcessType() const
virtual void DumpInfo() const
const G4String & GetProcessName() const
#define G4ThreadLocal
Definition tls.hh:77