G4ProcessTable.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // 
00030 // ------------------------------------------------------------
00031 //      GEANT 4 class header file 
00032 //
00033 //      History: first implementation, based on object model of
00034 //      4th Aug 1998, H.Kurashige
00035 // ------------------------------------------------------------
00036 //  History:
00037 //   Use STL vector instead of RW vector    1. Mar 00 H.Kurashige
00038 //
00039 
00040 #include "G4ProcessTableMessenger.hh"
00041 #include "G4ProcessTable.hh"
00042 
00043 //  constructor //////////////////////////
00044 G4ProcessTable::G4ProcessTable():verboseLevel(1)
00045 {
00046 #ifdef G4VERBOSE
00047   if (verboseLevel>1){
00048     G4cout << "--  G4ProcessTable constructor  --" << G4endl;
00049   }
00050 #endif
00051   fProcTblVector  = new  G4ProcTableVector();
00052   fProcNameVector = new  G4ProcNameVector();
00053   tmpTblVector    = new  G4ProcTableVector();
00054   fProcTblMessenger = 0;
00055 }
00056 
00057 // copy constructor //////////////////////////
00058 G4ProcessTable::G4ProcessTable(const G4ProcessTable &)
00059   :verboseLevel(1)
00060 {
00061   fProcTblVector  = 0;
00062   fProcNameVector = 0;
00063   tmpTblVector    = 0;
00064   fProcTblMessenger = 0;
00065 #ifdef G4VERBOSE
00066   if (verboseLevel>0){
00067     G4cout << "--  G4ProcessTable copy constructor  --" << G4endl;
00068   }
00069 #endif
00070 }
00071 
00072 // destructor //////////////////////////
00073 G4ProcessTable::~G4ProcessTable()
00074 {
00075 #ifdef G4VERBOSE
00076   if (verboseLevel>1){
00077     G4cout << "--  G4ProcessTable destructor  --" << G4endl;
00078   }
00079 #endif
00080 
00081   if ( tmpTblVector != 0) {
00082     tmpTblVector ->clear();
00083     delete tmpTblVector;
00084   }
00085 
00086   if ( fProcTblVector != 0) {
00087     G4ProcTableVector::iterator idx;
00088     
00089     // destruction of processes has moved to G4VUserPhysicsList
00090     for (idx=fProcTblVector->begin(); idx!=fProcTblVector->end(); ++idx) {
00091       // delete all processes
00092       // delete (*idx)->GetProcess();
00093       delete (*idx);
00094     }  
00095     fProcTblVector ->clear();
00096     delete fProcTblVector;
00097   }
00098 
00099   if ( fProcNameVector != 0) {
00100     fProcNameVector ->clear();
00101     delete fProcNameVector;
00102   }
00103   fProcessTable =0;
00104 }
00105 
00107 G4UImessenger* G4ProcessTable::CreateMessenger()
00108 {
00109   if (fProcTblMessenger == 0) {
00110     fProcTblMessenger = new G4ProcessTableMessenger(this);
00111   }
00112   return     fProcTblMessenger;
00113 }
00114 
00116 void  G4ProcessTable::DeleteMessenger()
00117 {
00118   if (fProcTblMessenger != 0) {
00119     delete fProcTblMessenger;
00120   }
00121 }
00122 
00123 
00125 G4ProcessTable & G4ProcessTable::operator=(const G4ProcessTable &right)
00126 {
00127   verboseLevel = right.verboseLevel;
00128 #ifdef G4VERBOSE
00129   if (verboseLevel>0){
00130     G4cout << "--  G4ProcessTable assignment operator  --" << G4endl;
00131   }
00132 #endif
00133   if (&right == this) return *this;
00134   else return *this;
00135 }
00136 
00138 G4int G4ProcessTable::operator==(const G4ProcessTable &right) const
00139 {
00140   return (this == &right);
00141 }
00142 
00144 G4int G4ProcessTable::operator!=(const G4ProcessTable &right) const
00145 {
00146   return (this != &right);
00147 }
00148 
00149 // Static class variable: ptr to single instance of class
00150 G4ProcessTable* G4ProcessTable::fProcessTable =0;
00151 
00152 
00154 G4ProcessTable* G4ProcessTable::GetProcessTable()
00155 {
00156     static G4ProcessTable theProcessTable;
00157     if (!fProcessTable){
00158       fProcessTable =  &theProcessTable;
00159     }
00160     return fProcessTable;
00161 }
00162 
00164 G4int   G4ProcessTable::Insert(G4VProcess* aProcess, 
00165                                G4ProcessManager* aProcMgr)
00166 {
00167   if ( (aProcess == 0) || ( aProcMgr == 0 ) ){
00168 #ifdef G4VERBOSE
00169     if (verboseLevel>0){
00170       G4cout << "G4ProcessTable::Insert : arguments are 0 pointer "
00171              <<aProcess <<","<<  aProcMgr << G4endl;
00172     }
00173 #endif
00174     return -1;
00175   }
00176     
00177 #ifdef G4VERBOSE
00178   if (verboseLevel>1){
00179     G4cout << "G4ProcessTable::Insert ";
00180     G4cout << " Process["  << aProcess->GetProcessName() << "]";
00181     G4cout << " Particle["  << aProcMgr->GetParticleType()->GetParticleName() << "]";
00182     G4cout << G4endl;
00183   }
00184 #endif
00185 
00186   G4ProcTableVector::iterator itr; 
00187   G4int idxTbl=0;
00188   G4ProcTblElement* anElement;
00189   G4bool isFoundInTbl = false;
00190   // loop over all elements
00191   for (itr=fProcTblVector->begin(); itr!=fProcTblVector->end(); ++itr, ++idxTbl) {
00192     anElement = (*itr);
00193     // check if this process is included
00194     if (aProcess == anElement->GetProcess()) {
00195       isFoundInTbl = true;
00196 
00197       // add the process manager into the element 
00198       //  unless  this process manager is included
00199       if (!anElement->Contains(aProcMgr)) {
00200         anElement->Insert(aProcMgr);
00201 #ifdef G4VERBOSE
00202         if (verboseLevel>2){
00203           G4cout << " This Process Manager is registered !! " << G4endl;
00204         }
00205 #endif
00206       }
00207       break;
00208     }
00209   }
00210   // add this process into the table by creating a new element
00211   if (!isFoundInTbl) {
00212     G4ProcTblElement* newElement = new G4ProcTblElement(aProcess);
00213     newElement->Insert(aProcMgr);
00214     fProcTblVector->push_back(newElement);
00215     // add into name vector     
00216     G4ProcNameVector::iterator ip;
00217     G4bool isFound = false;
00218     for (ip=fProcNameVector->begin(); ip!=fProcNameVector->end(); ++ip) {
00219       isFound |= (aProcess->GetProcessName() == (*ip));
00220     }
00221     if (!isFound) {
00222       fProcNameVector->push_back(aProcess->GetProcessName() );
00223 #ifdef G4VERBOSE
00224       if (verboseLevel>2){
00225         G4cout << " This Process is registered !! " << G4endl;
00226       }
00227 #endif
00228     }
00229   }
00230   return idxTbl;
00231 }
00232 
00234 G4int  G4ProcessTable::Remove( G4VProcess* aProcess, 
00235                                G4ProcessManager* aProcMgr)
00236 {
00237   if ( (aProcess == 0) || ( aProcMgr == 0 ) ){
00238 #ifdef G4VERBOSE
00239     if (verboseLevel>0){
00240       G4cout << "G4ProcessTable::Remove : arguments are 0 pointer "<< G4endl;
00241     }
00242 #endif
00243     return -1;
00244   }
00245     
00246 #ifdef G4VERBOSE
00247   if (verboseLevel>1){
00248     G4cout << "G4ProcessTable::Remove ";
00249     G4cout << " Process["  << aProcess->GetProcessName() << "]";
00250     G4cout << " Particle[" << aProcMgr->GetParticleType()->GetParticleName() << "]" << G4endl;
00251   }
00252 #endif
00253 
00254   G4ProcTableVector::iterator itr; 
00255   G4int idxTbl=0;
00256   G4ProcTblElement* anElement=0;
00257   G4bool isFound = false;
00258   // loop over all elements
00259   for (itr=fProcTblVector->begin(); itr!=fProcTblVector->end(); ++itr, ++idxTbl) {
00260     anElement = (*itr);
00261 
00262     // check if this process is included
00263     if (aProcess == anElement->GetProcess()) {
00264       isFound = anElement->Contains(aProcMgr);
00265       // remove the process manager from the element
00266       anElement->Remove(aProcMgr);
00267 #ifdef G4VERBOSE
00268       if (verboseLevel>2){
00269         G4cout << " This Process Manager is removed !! " << G4endl;
00270       }
00271 #endif
00272       break;
00273     }
00274   }
00275   // 
00276   if (!isFound) {
00277 #ifdef G4VERBOSE
00278     if (verboseLevel>0){
00279       G4cout << " This Process Manager is not registered !! " << G4endl;
00280     }
00281 #endif
00282     return -1;
00283   }
00284   // remove the element if it has no entry
00285   if (anElement->Length() == 0){
00286     fProcTblVector->erase(itr);
00287     delete anElement;
00288     // check other prcesses with same name exist or not
00289     G4bool isSameName = false;
00290     for (itr=fProcTblVector->begin(); itr!=fProcTblVector->end(); ++itr) {
00291       anElement = (*itr);
00292       if (anElement->GetProcessName() == aProcess->GetProcessName()) {
00293         isSameName = true;
00294         break;
00295       }
00296     }
00297     // remove from name vector
00298     if (!isSameName ) {
00299       G4ProcNameVector::iterator i; 
00300       for (i=fProcNameVector->begin(); i!=fProcNameVector->end(); ++i) {
00301         if ( *i == aProcess->GetProcessName() ) {
00302           fProcNameVector->erase(i);
00303           break;
00304         }
00305       }
00306     }
00307 #ifdef G4VERBOSE
00308     if (verboseLevel>1){
00309       G4cout << " This Process is removed !! " << G4endl;
00310     }
00311 #endif
00312   }
00313   return idxTbl;
00314 }
00315 
00317 G4VProcess* G4ProcessTable::FindProcess(const G4String& processName, 
00318                                         const G4ProcessManager* processManager)
00319                                         const
00320 {
00321   G4ProcTableVector::iterator itr;   
00322   G4int idxTbl = 0;
00323   G4bool isFound = false;
00324   G4ProcTblElement* anElement=0;
00325   for (itr=fProcTblVector->begin(); itr!=fProcTblVector->end(); ++itr, ++idxTbl) {
00326     anElement = (*itr);
00327     // check name
00328     if ( anElement->GetProcessName() == processName ) {
00329       // check if the processManage is included
00330       if ( anElement->Contains(processManager) ) {
00331         isFound = true;
00332         break;
00333       }
00334     }
00335   }
00336 #ifdef G4VERBOSE
00337   if (!isFound && verboseLevel>1){
00338     G4cout << " G4ProcessTable::FindProcess :" ;
00339     G4cout << " The Process[" << processName << "] is not found  ";
00340     G4cout << " for " << processManager->GetParticleType()->GetParticleName() << G4endl;
00341   }
00342 #endif
00343   
00344   if (isFound) return anElement->GetProcess();
00345   else         return 0;
00346 }
00347 
00349 G4ProcessTable::G4ProcTableVector* G4ProcessTable::Find( 
00350                                          G4ProcTableVector*,
00351                                          const G4String& processName )
00352 {
00353   tmpTblVector->clear();
00354 
00355   G4ProcTableVector::iterator itr; 
00356   G4bool isFound = false;
00357   G4ProcTblElement* anElement=0;
00358   for (itr=fProcTblVector->begin(); itr!=fProcTblVector->end(); ++itr) {
00359     anElement = (*itr);
00360     // check name
00361     if ( anElement->GetProcessName() == processName ) {
00362       isFound = true;
00363       tmpTblVector->push_back(anElement);
00364     }
00365   }
00366 
00367 #ifdef G4VERBOSE
00368   if (!isFound && verboseLevel>0){
00369     G4cout << " G4ProcessTable::Find :" ;
00370     G4cout << " The Process[" << processName << "] is not found  " << G4endl;
00371   }
00372 #endif
00373   
00374   return tmpTblVector;
00375 
00376 }     
00378 G4ProcessTable::G4ProcTableVector* G4ProcessTable::Find( 
00379                                          G4ProcTableVector*,
00380                                          G4ProcessType   processType )
00381 {
00382   tmpTblVector->clear();
00383 
00384   G4ProcTableVector::iterator itr; 
00385   G4bool isFound = false;
00386   G4ProcTblElement* anElement=0;
00387   for (itr=fProcTblVector->begin(); itr!=fProcTblVector->end(); ++itr) {
00388     anElement = (*itr);
00389     // check name
00390     if ( anElement->GetProcess()->GetProcessType() == processType ) {
00391       isFound = true;
00392       tmpTblVector->push_back(anElement);
00393     }
00394   }
00395 
00396 #ifdef G4VERBOSE
00397   if (!isFound && verboseLevel>0){
00398     G4cout << " G4ProcessTable::Find :" ;
00399     G4cout << " The ProcessType[" << processType << "] is not found  " << G4endl;
00400   }
00401 #endif
00402   
00403   return tmpTblVector;
00404 
00405 }     
00406 
00408 G4ProcessVector* G4ProcessTable::ExtractProcesses( G4ProcTableVector* procTblVector)
00409 {
00410   G4ProcessVector* procList = new G4ProcessVector();
00411   G4ProcTableVector::iterator itr; 
00412   // loop over all elements
00413   for (itr=procTblVector->begin(); itr!=procTblVector->end(); ++itr) {
00414     G4ProcTblElement* anElement = (*itr);
00415     procList->insert( anElement->GetProcess() );
00416   }
00417   return procList;
00418 }
00419 
00421 G4ProcessVector* G4ProcessTable::FindProcesses()
00422 {
00423   return ExtractProcesses(fProcTblVector);
00424 }
00425 
00427 G4ProcessVector* G4ProcessTable::FindProcesses( const G4ProcessManager* pManager )
00428 {
00429   G4ProcessVector* procList = pManager->GetProcessList();
00430   return new G4ProcessVector(*procList);
00431 }
00432 
00434 G4ProcessVector* G4ProcessTable::FindProcesses( const G4String& processName )
00435 {
00436   G4ProcTableVector* pTblVector =  Find(fProcTblVector, processName);
00437   return ExtractProcesses(pTblVector);
00438 }
00439 
00441 G4ProcessVector* G4ProcessTable::FindProcesses( G4ProcessType processType)
00442 {
00443   G4ProcTableVector* pTblVector =  Find(fProcTblVector, processType);
00444   return ExtractProcesses(pTblVector);
00445 }
00446 
00448 void G4ProcessTable::SetProcessActivation( const G4String& processName, 
00449                                            G4bool          fActive  )
00450 {
00451 #ifdef G4VERBOSE
00452   if (verboseLevel>1){
00453     G4cout << " G4ProcessTable::SetProcessActivation:" ;
00454     G4cout << " The Process[" << processName << "] "<< G4endl;
00455   }
00456 #endif
00457 
00458   G4ProcTableVector* pTblVector =  Find(fProcTblVector, processName);
00459   G4ProcTableVector::iterator itr; 
00460   G4ProcTblElement* anElement;  
00461    // loop over all elements
00462   for (itr=pTblVector->begin(); itr!=pTblVector->end(); ++itr) {
00463     anElement = (*itr);
00464     G4VProcess* process = anElement->GetProcess();
00465     for (G4int idx = 0 ; idx < anElement->Length(); idx++) {
00466       G4ProcessManager* manager = anElement->GetProcessManager(idx);
00467       manager->SetProcessActivation(process, fActive);
00468 #ifdef G4VERBOSE
00469       if (verboseLevel>1){
00470         G4cout << "  for " << manager->GetParticleType()->GetParticleName();
00471         G4cout << "  Index = " << manager->GetProcessIndex(process); 
00472         G4cout << G4endl;
00473       }
00474 #endif
00475     }
00476   }
00477 }
00478 
00480 void G4ProcessTable::SetProcessActivation( 
00481                            const G4String& processName, 
00482                            G4ProcessManager* processManager, 
00483                            G4bool          fActive  )
00484 {
00485 #ifdef G4VERBOSE
00486   if (verboseLevel>1){
00487     G4cout << " G4ProcessTable::SetProcessActivation:" ;
00488     G4cout << " The Process[" << processName << "] "<< G4endl;
00489   }
00490 #endif
00491   
00492   G4VProcess* process = FindProcess( processName,  processManager);
00493   if ( process != 0) {
00494     processManager->SetProcessActivation(process, fActive);
00495 #ifdef G4VERBOSE
00496     if (verboseLevel>1){
00497       G4cout << "  for " << processManager->GetParticleType()->GetParticleName();
00498       G4cout << "  Index = " << processManager->GetProcessIndex(process) << G4endl;
00499     }
00500 #endif
00501   } 
00502 }
00503 
00504 
00506 void G4ProcessTable::SetProcessActivation( G4ProcessType   processType, 
00507                                            G4bool          fActive  )
00508 {
00509 #ifdef G4VERBOSE
00510   if (verboseLevel>1){
00511     G4cout << " G4ProcessTable::SetProcessActivation:" ;
00512     G4cout << " The ProcessType[" << G4int(processType) << "] "<< G4endl;
00513   }
00514 #endif
00515 
00516   G4ProcTableVector* pTblVector =  Find(fProcTblVector, processType);
00517   G4ProcTableVector::iterator itr; 
00518   G4ProcTblElement* anElement;  
00519   // loop over all elements
00520   for (itr=pTblVector->begin(); itr!=pTblVector->end(); ++itr) {
00521     anElement = (*itr);
00522     G4VProcess* process = anElement->GetProcess();
00523 #ifdef G4VERBOSE
00524     if (verboseLevel>1){
00525       G4cout << " The Process[" << process->GetProcessName()<< "] "<< G4endl;
00526     }
00527 #endif
00528     for (G4int idx = 0 ; idx < anElement->Length(); idx++) {
00529       G4ProcessManager* manager = anElement->GetProcessManager(idx);
00530       manager->SetProcessActivation(process, fActive);
00531 #ifdef G4VERBOSE
00532       if (verboseLevel>1){
00533         G4cout << "  for " << manager->GetParticleType()->GetParticleName();
00534         G4cout << "  Index = " << manager->GetProcessIndex(process) << G4endl;
00535       }
00536 #endif
00537     }
00538   }
00539 }
00540 
00542 void G4ProcessTable::SetProcessActivation( 
00543                            G4ProcessType   processType, 
00544                            G4ProcessManager* processManager, 
00545                            G4bool          fActive  )
00546 {
00547 #ifdef G4VERBOSE
00548   if (verboseLevel>1){
00549     G4cout << " G4ProcessTable::SetProcessActivation:" ;
00550     G4cout << " The ProcessType[" << G4int(processType) << "] "<< G4endl;
00551   }
00552 #endif
00553   
00554   G4ProcessVector* procList =  processManager->GetProcessList();
00555   for (G4int idx = 0; idx < procList->length(); idx++) {
00556     G4VProcess* process = (*procList)(idx);
00557     if ( process->GetProcessType() == processType) {
00558       processManager->SetProcessActivation(process, fActive);
00559 #ifdef G4VERBOSE
00560       if (verboseLevel>1){
00561         G4cout << " The Process[" << process->GetProcessName()<< "] "<< G4endl;
00562         G4cout << "  for " << processManager->GetParticleType()->GetParticleName();
00563         G4cout << "  Index = " << idx << G4endl;
00564       }
00565 #endif
00566     }
00567   }
00568 }
00569 
00570 
00572 void G4ProcessTable::DumpInfo(G4VProcess* process, 
00573                               G4ParticleDefinition* particle)
00574 {
00575   G4ProcTableVector::iterator itr; 
00576   G4int idxTbl=0;
00577   G4ProcTblElement* anElement=0;
00578   G4bool isFoundInTbl = false;
00579   G4ProcessManager* manager=0;
00580   G4int idx;
00581   // loop over all elements
00582   for (itr=fProcTblVector->begin(); itr!=fProcTblVector->end(); ++itr, ++idxTbl) {
00583     anElement = (*itr);
00584     if (process == anElement->GetProcess() ){
00585       if (particle!=0) {
00586         for (idx=0; idx<anElement->Length(); idx++){
00587           manager = anElement->GetProcessManager(idx);
00588           if (particle == manager->GetParticleType()) {
00589             isFoundInTbl = true;
00590             break;
00591           }
00592         }
00593       } else {
00594         isFoundInTbl = true;
00595       }
00596       break;
00597     }
00598   }
00599   if  (!isFoundInTbl ) return;
00600   
00601   G4int tmpVerbose = process->GetVerboseLevel();
00602   process->SetVerboseLevel(verboseLevel);
00603   process->DumpInfo();
00604   process->SetVerboseLevel(tmpVerbose);
00605   if (particle==0) {
00606     for (idx=0; idx<anElement->Length(); idx++){
00607       manager = anElement->GetProcessManager(idx);
00608       G4cout << " for " << manager->GetParticleType()->GetParticleName();
00609       G4cout << G4endl;
00610 #ifdef G4VERBOSE
00611       if (verboseLevel >2){
00612         tmpVerbose = manager->GetVerboseLevel();
00613         manager->SetVerboseLevel(verboseLevel);
00614         manager->DumpInfo();
00615         manager->SetVerboseLevel(tmpVerbose);
00616       }
00617 #endif
00618     }
00619   } else {
00620     G4cout << " for " << manager->GetParticleType()->GetParticleName();
00621     G4cout << G4endl;
00622 #ifdef G4VERBOSE
00623     if (verboseLevel >2){
00624       tmpVerbose = manager->GetVerboseLevel();
00625       manager->SetVerboseLevel(verboseLevel);
00626       manager->DumpInfo();
00627       manager->SetVerboseLevel(tmpVerbose);
00628     }
00629 #endif
00630   }
00631 }
00632 
00633 
00634 
00635 
00636 
00637 

Generated on Mon May 27 17:49:26 2013 for Geant4 by  doxygen 1.4.7