G4ProcessPlacer.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 // GEANT 4 class source file
00031 //
00032 // G4ProcessPlacer.cc
00033 //
00034 // ----------------------------------------------------------------------
00035 
00036 #include "G4ProcessPlacer.hh"
00037 #include "G4ProcessManager.hh"
00038 #include "G4VProcess.hh"
00039 #include "G4ParticleTable.hh"
00040 
00041 G4ProcessPlacer::G4ProcessPlacer(const G4String &particlename)
00042   : fParticleName(particlename)
00043 {
00044 }
00045 
00046 G4ProcessPlacer::~G4ProcessPlacer()
00047 {
00048 }
00049 
00050 void G4ProcessPlacer::RemoveProcess(G4VProcess *process)
00051 {
00052   G4cout << "=== G4ProcessPlacer::RemoveProcess: for: " <<  fParticleName 
00053          << G4endl;
00054   G4cout << "  ProcessName: " << process->GetProcessName() 
00055          << ", will be removed!" << G4endl;
00056 
00057   G4cout << "  The initial AlongStep Vectors: " << G4endl;
00058   PrintAlongStepGPILVec();
00059   PrintAlongStepDoItVec();
00060 
00061   G4cout << "  The initial PostStep Vectors: " << G4endl;
00062   PrintPostStepGPILVec();
00063   PrintPostStepDoItVec();
00064 
00065   GetProcessManager()->RemoveProcess(process);
00066 
00067   G4cout << "  The final AlongStep Vectors: " << G4endl;
00068   PrintAlongStepGPILVec();
00069   PrintAlongStepDoItVec();
00070 
00071   G4cout << "  The final PostStep Vectors: " << G4endl;
00072   PrintPostStepGPILVec();
00073   PrintPostStepDoItVec();
00074 
00075   G4cout << "================================================" << G4endl;
00076   
00077 }
00078 
00079 void G4ProcessPlacer::AddProcessAs(G4VProcess *process, SecondOrLast sol)
00080 {
00081   G4cout << "  Modifying Process Order for ProcessName: " << process->GetProcessName() << G4endl;
00082 
00083   G4cout << "  The initial AlongStep Vectors: " << G4endl;
00084   PrintAlongStepGPILVec();
00085   PrintAlongStepDoItVec();
00086 
00087   G4cout << "The initial PostStep Vectors: " << G4endl;
00088   PrintPostStepGPILVec();
00089   PrintPostStepDoItVec();
00090 
00091   if (sol == eLast)
00092   {  
00093     GetProcessManager()->AddProcess(process, ordInActive, ordInActive, ordLast);
00094   } 
00095   else if (sol == eSecond)
00096   {
00097     // get transportation process
00098     G4VProcess *transportation = 
00099      (* (GetProcessManager()->GetProcessList()))[0];
00100 
00101     if (!transportation)
00102     {
00103       G4Exception("G4ProcessPlacer::AddProcessAs","Bias0001",RunMustBeAborted," could not get process id=0");
00104     }
00105     if (transportation->GetProcessName() != "Transportation" && transportation->GetProcessName() != "Transportation8" && transportation->GetProcessName() != "CoupledTransportation")
00106     {
00107       //      G4cout << " GOT HERE CoupledTransportation" << G4endl;
00108       G4cout << transportation->GetProcessName() << G4endl;
00109       G4Exception("G4ProcessPlacer::AddProcessAs","Bias0002",RunMustBeAborted," process id=0 is not Transportation");
00110     }
00111 
00112     // place the given proces as first for the moment
00113     // 31/5/11 previously set to first, then transportation set ahead of it, 
00114     // which is more conveniently correctly set with placing it second!
00115     GetProcessManager()->AddProcess(process);
00116     GetProcessManager()->SetProcessOrderingToSecond(process, 
00117                                                   idxAlongStep);
00118     GetProcessManager()->SetProcessOrderingToSecond(process, 
00119                                                   idxPostStep);
00120     // xx test
00121     //     if(process->GetProcessName() == "ImportanceProcess") 
00122     //bug31/10/07    GetProcessManager()->SetProcessOrdering(process, 
00123     //bug31/10/07                                           idxAlongStep, 1);
00124     // place transportation first again
00125 //     GetProcessManager()->SetProcessOrderingToFirst(transportation, 
00126 //                                                   idxAlongStep);
00127 //     GetProcessManager()->SetProcessOrderingToFirst(transportation, 
00128 //                                                   idxPostStep);
00129   }
00130   
00131   // for verification inly
00132   G4cout << "  The final AlongStep Vectors: " << G4endl;
00133   PrintAlongStepGPILVec();
00134   PrintAlongStepDoItVec();
00135 
00136   G4cout << "The final PostStep Vectors: " << G4endl;
00137   PrintPostStepGPILVec();
00138   PrintPostStepDoItVec();
00139   
00140   G4cout << "================================================" << G4endl;
00141 }
00142 
00143 void G4ProcessPlacer::AddProcessAsSecondDoIt(G4VProcess *process)
00144 {
00145   G4cout << "=== G4ProcessPlacer::AddProcessAsSecondDoIt: for: " 
00146          << fParticleName << G4endl;
00147   AddProcessAs(process, eSecond);
00148 }
00149 
00150 void G4ProcessPlacer::AddProcessAsLastDoIt(G4VProcess *process)
00151 {
00152   G4cout << "=== G4ProcessPlacer::AddProcessAsLastDoIt: for: " 
00153          << fParticleName << G4endl;
00154   AddProcessAs(process, eLast);
00155 }
00156 
00157 G4ProcessManager *G4ProcessPlacer::GetProcessManager()
00158 { 
00159   // get particle iterator to add processes ---------------------
00160   G4ParticleTable* theParticleTable = 0;
00161   G4ParticleTable::G4PTblDicIterator* theParticleIterator = 0;
00162   theParticleTable = G4ParticleTable::GetParticleTable();
00163   theParticleIterator = theParticleTable->GetIterator();
00164   // -------------------------------------------------------
00165   G4ProcessManager *processmanager = 0;
00166   // find process manager ---------------------------
00167   theParticleIterator->reset();
00168   while( (*theParticleIterator)() )
00169   {
00170     G4ParticleDefinition* particle = theParticleIterator->value();
00171     if (particle->GetParticleName() == fParticleName)
00172     {
00173       processmanager =  particle->GetProcessManager();
00174       break;
00175     }
00176   }
00177   // ---------------------------------------------------------
00178   if (!processmanager)
00179   {
00180     G4Exception("G4ProcessPlacer::GetProcessManager()", "InvalidSetup",
00181                 FatalException, "NULL pointer to Process Manager ! Sampler.Configure() must be after PhysicsList instantiation");
00182   }
00183   return processmanager;
00184 }
00185 
00186 void G4ProcessPlacer::PrintAlongStepGPILVec()
00187 {
00188   G4cout << "GPIL Vector: " << G4endl;
00189   G4ProcessVector* processGPILVec = 
00190     GetProcessManager()->GetAlongStepProcessVector(typeGPIL);
00191   PrintProcVec(processGPILVec);
00192 } 
00193 
00194 void G4ProcessPlacer::PrintAlongStepDoItVec()
00195 {
00196   G4cout << "DoIt Vector: " << G4endl;
00197   G4ProcessVector* processDoItVec = 
00198     GetProcessManager()->GetAlongStepProcessVector(typeDoIt); 
00199   PrintProcVec(processDoItVec);
00200 }
00201 
00202 
00203 void G4ProcessPlacer::PrintPostStepGPILVec()
00204 {
00205   G4cout << "GPIL Vector: " << G4endl;
00206   G4ProcessVector* processGPILVec = 
00207     GetProcessManager()->GetPostStepProcessVector(typeGPIL);
00208   PrintProcVec(processGPILVec);
00209 } 
00210 
00211 void G4ProcessPlacer::PrintPostStepDoItVec()
00212 {
00213   G4cout << "DoIt Vector: " << G4endl;
00214   G4ProcessVector* processDoItVec = 
00215     GetProcessManager()->GetPostStepProcessVector(typeDoIt); 
00216   PrintProcVec(processDoItVec);
00217 }
00218 
00219 
00220 void G4ProcessPlacer::PrintProcVec(G4ProcessVector* processVec)
00221 {
00222   if (!processVec)
00223   {
00224     G4Exception("G4ProcessPlacer::G4ProcessPlacer()", "InvalidArgument",
00225                 FatalException, "NULL pointer to process-vector !");
00226   }
00227   size_t len = processVec->length();
00228   if (len==0)
00229   {
00230     G4Exception("G4ProcessPlacer::G4ProcessPlacer()", "InvalidSetup",
00231                 FatalException, "Length of process-vector is zero !");
00232   }
00233   for (size_t i=0; i<len; i++)
00234   {
00235     G4VProcess *p = (*processVec)[i];
00236     if (p)
00237     {
00238       G4cout << "   " << p->GetProcessName() << G4endl;
00239     } 
00240     else
00241     {
00242       G4cout << "   " << "no process found for position: " << i 
00243              << ", in vector of length: " << len << G4endl;
00244     }
00245   }
00246 }

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