G4ProcessManagerMessenger.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 //
00032 //  G4ProcessManagerMessenger.cc
00033 //
00034 //  Description:
00035 //    This is a messenger class to interface to exchange information
00036 //    between ProcessManagerand UI.
00037 //
00038 //  History:
00039 //    13 June 1997, H. Kurashige   : The 1st version created.
00040 //    10 Nov. 1997  H. Kurashige   : fixed bugs 
00041 //    08 jan. 1998  H. Kurashige   : new UIcommnds 
00042 //    02 June 2006  M. Maire       : add physicsModified in activate/inactivate
00043 //
00044 //---------------------------------------------------------------
00045 
00046 
00047 #include "G4UImanager.hh"
00048 #include "G4UIdirectory.hh"
00049 #include "G4UIcmdWithoutParameter.hh"
00050 #include "G4UIcmdWithAnInteger.hh"
00051 
00052 #include "G4VProcess.hh"
00053 #include "G4ProcessManager.hh"
00054 #include "G4ParticleTable.hh"
00055 
00056 #include "G4ProcessManagerMessenger.hh"
00057 #include "G4ios.hh"                 // Include from 'system'
00058 #include <iomanip>                  // Include from 'system'
00059 
00060 #include <sstream>
00061 
00062 G4ProcessManagerMessenger::G4ProcessManagerMessenger(G4ParticleTable* pTable)
00063                         :theParticleTable(pTable),
00064                          currentParticle(0),
00065                          currentProcess(0),
00066                          theManager(0),
00067                          theProcessList(0)
00068 {
00069   if ( theParticleTable == 0) theParticleTable = G4ParticleTable::GetParticleTable();
00070 
00071   //Commnad   /particle/process
00072   thisDirectory = new G4UIdirectory("/particle/process/");
00073   thisDirectory->SetGuidance("Process Manager control commands.");
00074 
00075   //Commnad   /particle/process/dump
00076   dumpCmd = new G4UIcmdWithAnInteger("/particle/process/dump",this);
00077   dumpCmd->SetGuidance("dump process manager or process information");
00078   dumpCmd->SetGuidance("  dump [process index]");
00079   dumpCmd->SetGuidance("   process index: -1 for process manager");
00080   dumpCmd->SetParameterName("index", true);
00081   dumpCmd->SetDefaultValue(-1);
00082 
00083   //Commnad   /particle/process/Verbose
00084   verboseCmd = new G4UIcommand("/particle/process/verbose",this);
00085   verboseCmd->SetGuidance("Set Verbose Level for Process or Process Manager");
00086   verboseCmd->SetGuidance("  Verbose [Verbose] [process index]");
00087   verboseCmd->SetGuidance("   process index: -1 for process manager");
00088   G4UIparameter* param = new G4UIparameter("Verbose",'i',true);
00089   param->SetDefaultValue(1);
00090   verboseCmd->SetParameter(param);
00091   param = new G4UIparameter("index",'i',true);
00092   param->SetDefaultValue(-1);
00093   verboseCmd->SetParameter(param);
00094   verboseCmd->AvailableForStates(G4State_PreInit,G4State_Init,G4State_Idle,G4State_GeomClosed,G4State_EventProc);
00095 
00096   //Commnad   /particle/process/Activate
00097   activateCmd = new G4UIcmdWithAnInteger("/particle/process/activate",this);
00098   activateCmd->SetGuidance("Activate process  ");
00099   activateCmd->SetGuidance(" Activate [process index]");
00100   activateCmd->SetParameterName("index", false);
00101   activateCmd->SetDefaultValue(0);
00102   activateCmd->SetRange("index >=0");
00103   activateCmd->AvailableForStates(G4State_Idle,G4State_GeomClosed,G4State_EventProc);
00104 
00105   //Commnad   /particle/process/inactivate
00106   inactivateCmd = new G4UIcmdWithAnInteger("/particle/process/inactivate",this);
00107   inactivateCmd->SetGuidance("Inactivate process  ");
00108   inactivateCmd->SetGuidance(" inactivate [process index]");
00109   inactivateCmd->SetParameterName("index", false);
00110   inactivateCmd->SetDefaultValue(0);
00111   inactivateCmd->SetRange("index >=0");
00112   inactivateCmd->AvailableForStates(G4State_Idle,G4State_GeomClosed,G4State_EventProc);
00113 
00114 }
00115 
00116 G4ProcessManagerMessenger::~G4ProcessManagerMessenger()
00117 {
00118   delete activateCmd; 
00119   delete inactivateCmd; 
00120   delete verboseCmd;
00121   delete dumpCmd;
00122   delete thisDirectory;
00123 }
00124 
00125 G4ParticleDefinition* G4ProcessManagerMessenger::SetCurrentParticle()
00126 {
00127   // set currentParticle pointer
00128   // get particle name by asking G4ParticleMessenger
00129   G4String particleName = G4UImanager::GetUIpointer()->GetCurrentStringValue("/particle/select");
00130 
00131   currentParticle = theParticleTable->FindParticle(particleName);
00132   if (currentParticle == 0) {
00133     theManager = 0;
00134     G4cout << "G4ProcessManagerMessenger::SetCurrentParticle() ";
00135     G4cout << particleName << " not found " << G4endl;
00136   } else {
00137     theManager = currentParticle->GetProcessManager();
00138     theProcessList = theManager->GetProcessList();
00139   }
00140   return currentParticle;
00141 }
00142 
00143 void G4ProcessManagerMessenger::SetNewValue(G4UIcommand * command,G4String newValue)
00144 {
00145   if (SetCurrentParticle()==0) {
00146       G4cout << "Particle is not selected yet !! Command ignored." << G4endl;
00147       return;
00148   }
00149   if( command == dumpCmd ){
00150     //Commnad   /particle/process/dump
00151     G4int index = dumpCmd->GetNewIntValue(newValue);
00152     if (index <0) {
00153        theManager->DumpInfo();
00154     } else if ( index < theManager->GetProcessListLength()){
00155       currentProcess =  (*theProcessList)(index);
00156       if (currentProcess == 0) {
00157         G4cout << " no process at index of " << index;
00158         G4cout << "in the Process Vector" << G4endl;
00159       } else {
00160         currentProcess->DumpInfo();
00161       }
00162     } else {
00163       G4cout << " illegal index !!! " << G4endl;
00164       currentProcess = 0;
00165     } 
00166  
00167   } else if( command==activateCmd ) {
00168     //Commnad   /particle/process/activate
00169     theManager->SetProcessActivation(activateCmd->GetNewIntValue(newValue), true);
00170     G4UImanager::GetUIpointer()->ApplyCommand("/run/physicsModified");
00171     
00172   } else if( command==inactivateCmd ) {
00173     //Commnad   /particle/process/inactivate
00174     theManager->SetProcessActivation(inactivateCmd->GetNewIntValue(newValue), false);
00175     G4UImanager::GetUIpointer()->ApplyCommand("/run/physicsModified");
00176     
00177   } else if( command==verboseCmd ) {
00178     //Commnad   /particle/process/Verbose
00179     //  inputstream for newValues 
00180     const char* temp = (const char*)(newValue);
00181     std::istringstream is((char*)temp);
00182     G4int Verbose, index;
00183     is  >>Verbose >>index;
00184     if (index <0) {
00185       theManager->SetVerboseLevel(Verbose);
00186       
00187     } else if ( index < theManager->GetProcessListLength()){
00188       currentProcess =  (*theProcessList)(index);
00189       if (currentProcess == 0) {
00190         G4cout << " no process at index of " << index;
00191         G4cout << "in the Process Vector" << G4endl;
00192       } else {
00193         currentProcess->SetVerboseLevel(Verbose);
00194       }
00195     } else {
00196       G4cout << " illegal index !!! " << G4endl;
00197       currentProcess = 0;
00198     } 
00199   }
00200 }
00201 
00202 
00203 G4String G4ProcessManagerMessenger::GetCurrentValue(G4UIcommand * command)
00204 {
00205   G4String returnValue('\0');
00206   if(SetCurrentParticle() == 0) {
00207     // no particle is selected. return null strings
00208     return returnValue;
00209   }
00210 
00211   std::ostringstream os;
00212   
00213   if( command==verboseCmd ){
00214     //Commnad   /particle/process/Verbose
00215     os << theManager->GetVerboseLevel();
00216     returnValue = os.str();
00217   } 
00218   return returnValue;
00219 }
00220 
00221 
00222 
00223 
00224 

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