ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4ProcessTable.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4ProcessTable.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 //
28 //
29 // ------------------------------------------------------------
30 // GEANT 4 class header file
31 //
32 // History: first implementation, based on object model of
33 // 4th Aug 1998, H.Kurashige
34 // ------------------------------------------------------------
35 // History:
36 // Use STL vector instead of RW vector 1. Mar 00 H.Kurashige
37 //
38 
40 #include "G4ProcessTable.hh"
41 
42 // Static class variable: ptr to single instance of class in a thread
44 
45 // constructor //////////////////////////
47  :verboseLevel(1)
48 {
49 #ifdef G4VERBOSE
50  if (verboseLevel>1){
51  G4cout << "-- G4ProcessTable constructor --" << G4endl;
52  }
53 #endif
58 }
59 
60 // destructor //////////////////////////
62 {
63  if ( tmpTblVector != nullptr) {
64  tmpTblVector ->clear();
65  delete tmpTblVector;
66  tmpTblVector = nullptr;
67  }
68 
69  if ( fProcTblVector != nullptr) {
70  G4ProcTableVector::iterator idx;
71 
72  for (idx=fProcTblVector->begin(); idx!=fProcTblVector->end(); ++idx) {
73  delete (*idx);
74  }
75  fProcTblVector ->clear();
76  delete fProcTblVector;
77  fProcTblVector = nullptr;
78  }
79 
80  if ( fProcNameVector != nullptr) {
81  fProcNameVector ->clear();
82  delete fProcNameVector;
83  fProcNameVector = nullptr;
84  }
85  fProcessTable = nullptr;
86  delete fProcTblMessenger;
87 }
88 
91 {
92  if(!fProcessTable) {
94  fProcessTable = inst.Instance();
95  }
96  return fProcessTable;
97 }
98 
101  G4ProcessManager* aProcMgr)
102 {
103  if ( (aProcess == nullptr) || ( aProcMgr == nullptr ) ){
104 #ifdef G4VERBOSE
105  if (verboseLevel>0){
106  G4cout << "G4ProcessTable::Insert : arguments are 0 pointer "
107  <<aProcess <<","<< aProcMgr << G4endl;
108  }
109 #endif
110  return -1;
111  }
112 
113 #ifdef G4VERBOSE
114  if (verboseLevel>1){
115  G4cout << "G4ProcessTable::Insert ";
116  G4cout << " Process[" << aProcess->GetProcessName() << "]";
117  G4cout << " Particle[" << aProcMgr->GetParticleType()->GetParticleName() << "]";
118  G4cout << G4endl;
119  }
120 #endif
121 
122  G4int idxTbl=0;
123  G4ProcTblElement* anElement = nullptr;
124  G4bool isFoundInTbl = false;
125  // loop over all elements
126  for (auto itr=fProcTblVector->begin();
127  itr!=fProcTblVector->end(); ++itr, ++idxTbl) {
128  anElement = (*itr);
129  // check if this process is included
130  if (aProcess == anElement->GetProcess()) {
131  isFoundInTbl = true;
132 
133  // add the process manager into the element
134  // unless this process manager is included
135  if (!anElement->Contains(aProcMgr)) {
136  anElement->Insert(aProcMgr);
137 #ifdef G4VERBOSE
138  if (verboseLevel>2){
139  G4cout << " This Process Manager is registered !! " << G4endl;
140  }
141 #endif
142  }
143  break;
144  }
145  }
146  // add this process into the table by creating a new element
147  if (!isFoundInTbl) {
148  G4ProcTblElement* newElement = new G4ProcTblElement(aProcess);
149  newElement->Insert(aProcMgr);
150  fProcTblVector->push_back(newElement);
151  // add into name vector
152  G4bool isFound = false;
153  for (auto ip=fProcNameVector->cbegin(); ip!=fProcNameVector->cend(); ++ip) {
154  isFound |= (aProcess->GetProcessName() == (*ip));
155  }
156  if (!isFound) {
157  fProcNameVector->push_back(aProcess->GetProcessName() );
158 #ifdef G4VERBOSE
159  if (verboseLevel>2){
160  G4cout << " This Process is registered !! " << G4endl;
161  }
162 #endif
163  }
164  }
165  return idxTbl;
166 }
167 
170  G4ProcessManager* aProcMgr)
171 {
172  if ( (aProcess == nullptr) || ( aProcMgr == nullptr ) ){
173 #ifdef G4VERBOSE
174  if (verboseLevel>0){
175  G4cout << "G4ProcessTable::Remove : arguments are 0 pointer "<< G4endl;
176  }
177 #endif
178  return -1;
179  }
180 
181 #ifdef G4VERBOSE
182  if (verboseLevel>1){
183  G4cout << "G4ProcessTable::Remove ";
184  G4cout << " Process[" << aProcess->GetProcessName() << "]";
185  G4cout << " Particle[" << aProcMgr->GetParticleType()->GetParticleName() << "]" << G4endl;
186  }
187 #endif
188 
189  G4ProcTableVector::iterator itr;
190  G4int idxTbl=0;
191  G4ProcTblElement* anElement =nullptr;
192  G4bool isFound = false;
193  // loop over all elements
194  for (itr=fProcTblVector->begin(); itr!=fProcTblVector->end(); ++itr, ++idxTbl) {
195  anElement = (*itr);
196 
197  // check if this process is included
198  if (aProcess == anElement->GetProcess()) {
199  isFound = anElement->Contains(aProcMgr);
200  // remove the process manager from the element
201  anElement->Remove(aProcMgr);
202 #ifdef G4VERBOSE
203  if (verboseLevel>2){
204  G4cout << " This Process Manager is removed !! " << G4endl;
205  }
206 #endif
207  break;
208  }
209  }
210  //
211  if (!isFound) {
212 #ifdef G4VERBOSE
213  if (verboseLevel>0){
214  G4cout << " This Process Manager is not registered !! " << G4endl;
215  }
216 #endif
217  return -1;
218  }
219  // remove the element if it has no entry
220  if (anElement->Length() == 0){
221  fProcTblVector->erase(itr);
222  delete anElement;
223  // check other prcesses with same name exist or not
224  G4bool isSameName = false;
225  for (itr=fProcTblVector->begin(); itr!=fProcTblVector->end(); ++itr) {
226  anElement = (*itr);
227  if (anElement->GetProcessName() == aProcess->GetProcessName()) {
228  isSameName = true;
229  break;
230  }
231  }
232  // remove from name vector
233  if (!isSameName ) {
234  for (auto i=fProcNameVector->begin(); i!=fProcNameVector->end(); ++i) {
235  if ( *i == aProcess->GetProcessName() ) {
236  fProcNameVector->erase(i);
237  break;
238  }
239  }
240  }
241 #ifdef G4VERBOSE
242  if (verboseLevel>1){
243  G4cout << " This Process is removed !! " << G4endl;
244  }
245 #endif
246  }
247  return idxTbl;
248 }
249 
252  const G4ProcessManager* processManager)
253  const
254 {
255  G4int idxTbl = 0;
256  G4bool isFound = false;
257  G4ProcTblElement* anElement =nullptr;
258  for (auto itr=fProcTblVector->cbegin();
259  itr!=fProcTblVector->cend(); ++itr, ++idxTbl) {
260  anElement = (*itr);
261  // check name
262  if ( anElement->GetProcessName() == processName ) {
263  // check if the processManage is included
264  if ( anElement->Contains(processManager) ) {
265  isFound = true;
266  break;
267  }
268  }
269  }
270 #ifdef G4VERBOSE
271  if (!isFound && verboseLevel>1){
272  G4cout << " G4ProcessTable::FindProcess :" ;
273  G4cout << " The Process[" << processName << "] is not found ";
274  G4cout << " for " << processManager->GetParticleType()->GetParticleName() << G4endl;
275  }
276 #endif
277 
278  if (isFound) return anElement->GetProcess();
279  else return nullptr;
280 }
281 
285  const G4String& processName )
286 {
287  tmpTblVector->clear();
288 
289  G4bool isFound = false;
290  G4ProcTblElement* anElement =nullptr;
291  for (auto itr=fProcTblVector->cbegin(); itr!=fProcTblVector->cend(); ++itr) {
292  anElement = (*itr);
293  // check name
294  if ( anElement->GetProcessName() == processName ) {
295  isFound = true;
296  tmpTblVector->push_back(anElement);
297  }
298  }
299 
300  if (!isFound && verboseLevel>0){
301 #ifdef G4VERBOSE
302  G4cout << " G4ProcessTable::Find :" ;
303  G4cout << " The Process[" << processName << "] is not found " << G4endl;
304 #endif
305  }
306 
307  return tmpTblVector;
308 
309 }
313  G4ProcessType processType )
314 {
315  tmpTblVector->clear();
316 
317  G4bool isFound = false;
318  G4ProcTblElement* anElement =nullptr;
319  for (auto itr=fProcTblVector->cbegin(); itr!=fProcTblVector->cend(); ++itr) {
320  anElement = (*itr);
321  // check name
322  if ( anElement->GetProcess()->GetProcessType() == processType ) {
323  isFound = true;
324  tmpTblVector->push_back(anElement);
325  }
326  }
327 
328  if (!isFound && verboseLevel>0){
329 #ifdef G4VERBOSE
330  G4cout << " G4ProcessTable::Find :" ;
331  G4cout << " The ProcessType[" << processType << "] is not found " << G4endl;
332 #endif
333  }
334 
335  return tmpTblVector;
336 
337 }
338 
341 {
342  G4ProcessVector* procList = new G4ProcessVector();
343  // loop over all elements
344  for (auto itr=procTblVector->cbegin(); itr!=procTblVector->cend(); ++itr) {
345  G4ProcTblElement* anElement = (*itr);
346  procList->insert( anElement->GetProcess() );
347  }
348  return procList;
349 }
350 
353 {
355 }
356 
359 {
360  G4ProcessVector* procList = pManager->GetProcessList();
361  return new G4ProcessVector(*procList);
362 }
363 
366 {
367  G4ProcTableVector* pTblVector = Find(fProcTblVector, processName);
368  return ExtractProcesses(pTblVector);
369 }
370 
373 {
374  G4ProcTableVector* pTblVector = Find(fProcTblVector, processType);
375  return ExtractProcesses(pTblVector);
376 }
377 
380  G4bool fActive )
381 {
382 #ifdef G4VERBOSE
383  if (verboseLevel>1){
384  G4cout << " G4ProcessTable::SetProcessActivation:" ;
385  G4cout << " The Process[" << processName << "] "<< G4endl;
386  }
387 #endif
388 
389  G4ProcTableVector* pTblVector = Find(fProcTblVector, processName);
390  G4ProcTblElement* anElement;
391  // loop over all elements
392  for (auto itr=pTblVector->cbegin(); itr!=pTblVector->cend(); ++itr) {
393  anElement = (*itr);
394  G4VProcess* process = anElement->GetProcess();
395  for (G4int idx = 0 ; idx < anElement->Length(); idx++) {
396  G4ProcessManager* manager = anElement->GetProcessManager(idx);
397  manager->SetProcessActivation(process, fActive);
398 #ifdef G4VERBOSE
399  if (verboseLevel>1){
400  G4cout << " for " << manager->GetParticleType()->GetParticleName();
401  G4cout << " Index = " << manager->GetProcessIndex(process);
402  G4cout << G4endl;
403  }
404 #endif
405  }
406  }
407 }
408 
411  const G4String& processName,
412  G4ProcessManager* processManager,
413  G4bool fActive )
414 {
415 #ifdef G4VERBOSE
416  if (verboseLevel>1){
417  G4cout << " G4ProcessTable::SetProcessActivation:" ;
418  G4cout << " The Process[" << processName << "] "<< G4endl;
419  }
420 #endif
421 
422  G4VProcess* process = FindProcess( processName, processManager);
423  if ( process != nullptr) {
424  processManager->SetProcessActivation(process, fActive);
425 #ifdef G4VERBOSE
426  if (verboseLevel>1){
427  G4cout << " for " << processManager->GetParticleType()->GetParticleName();
428  G4cout << " Index = " << processManager->GetProcessIndex(process) << G4endl;
429  }
430 #endif
431  }
432 }
433 
434 
437  G4bool fActive )
438 {
439 #ifdef G4VERBOSE
440  if (verboseLevel>1){
441  G4cout << " G4ProcessTable::SetProcessActivation:" ;
442  G4cout << " The ProcessType[" << G4int(processType) << "] "<< G4endl;
443  }
444 #endif
445 
446  G4ProcTableVector* pTblVector = Find(fProcTblVector, processType);
447  G4ProcTblElement* anElement;
448  // loop over all elements
449  for (auto itr=pTblVector->cbegin(); itr!=pTblVector->cend(); ++itr) {
450  anElement = (*itr);
451  G4VProcess* process = anElement->GetProcess();
452 #ifdef G4VERBOSE
453  if (verboseLevel>1){
454  G4cout << " The Process[" << process->GetProcessName()<< "] "<< G4endl;
455  }
456 #endif
457  for (G4int idx = 0 ; idx < anElement->Length(); ++idx) {
458  G4ProcessManager* manager = anElement->GetProcessManager(idx);
459  manager->SetProcessActivation(process, fActive);
460 #ifdef G4VERBOSE
461  if (verboseLevel>1){
462  G4cout << " for " << manager->GetParticleType()->GetParticleName();
463  G4cout << " Index = " << manager->GetProcessIndex(process) << G4endl;
464  }
465 #endif
466  }
467  }
468 }
469 
472  G4ProcessType processType,
473  G4ProcessManager* processManager,
474  G4bool fActive )
475 {
476 #ifdef G4VERBOSE
477  if (verboseLevel>1){
478  G4cout << " G4ProcessTable::SetProcessActivation:" ;
479  G4cout << " The ProcessType[" << G4int(processType) << "] "<< G4endl;
480  }
481 #endif
482 
483  G4ProcessVector* procList = processManager->GetProcessList();
484  for (std::size_t idx = 0; idx < procList->length(); ++idx) {
485  G4VProcess* process = (*procList)(idx);
486  if ( process->GetProcessType() == processType) {
487  processManager->SetProcessActivation(process, fActive);
488 #ifdef G4VERBOSE
489  if (verboseLevel>1){
490  G4cout << " The Process[" << process->GetProcessName()<< "] "<< G4endl;
491  G4cout << " for " << processManager->GetParticleType()->GetParticleName();
492  G4cout << " Index = " << idx << G4endl;
493  }
494 #endif
495  }
496  }
497 }
498 
499 
503 {
504  G4int idxTbl=0;
505  G4ProcTblElement* anElement =nullptr;
506  G4bool isFoundInTbl = false;
507  G4ProcessManager* manager =nullptr;
508  G4int idx;
509  // loop over all elements
510  for (auto itr=fProcTblVector->cbegin();
511  itr!=fProcTblVector->cend(); ++itr, ++idxTbl) {
512  anElement = (*itr);
513  if (process == anElement->GetProcess() ){
514  if (particle != nullptr) {
515  for (idx=0; idx<anElement->Length(); idx++){
516  manager = anElement->GetProcessManager(idx);
517  if (particle == manager->GetParticleType()) {
518  isFoundInTbl = true;
519  break;
520  }
521  }
522  } else {
523  isFoundInTbl = true;
524  }
525  break;
526  }
527  }
528  if (!isFoundInTbl ) return;
529 
530  G4int tmpVerbose = process->GetVerboseLevel();
531  process->SetVerboseLevel(verboseLevel);
532  process->DumpInfo();
533  process->SetVerboseLevel(tmpVerbose);
534  if (particle == nullptr) {
535  for (idx=0; idx<anElement->Length(); idx++){
536  manager = anElement->GetProcessManager(idx);
537  G4cout << " for " << manager->GetParticleType()->GetParticleName();
538  G4cout << G4endl;
539 #ifdef G4VERBOSE
540  if (verboseLevel >2){
541  tmpVerbose = manager->GetVerboseLevel();
542  manager->SetVerboseLevel(verboseLevel);
543  manager->DumpInfo();
544  manager->SetVerboseLevel(tmpVerbose);
545  }
546 #endif
547  }
548  } else {
549  G4cout << " for " << manager->GetParticleType()->GetParticleName();
550  G4cout << G4endl;
551 #ifdef G4VERBOSE
552  if (verboseLevel >2){
553  tmpVerbose = manager->GetVerboseLevel();
554  manager->SetVerboseLevel(verboseLevel);
555  manager->DumpInfo();
556  manager->SetVerboseLevel(tmpVerbose);
557  }
558 #endif
559  }
560 }
561 
562 
563 
564 
565 
566