G4RunMessenger.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 #include "G4RunMessenger.hh"
00031 #include "G4RunManager.hh"
00032 #include "G4UIdirectory.hh"
00033 #include "G4UIcmdWithoutParameter.hh"
00034 #include "G4UIcmdWithAString.hh"
00035 #include "G4UIcmdWithAnInteger.hh"
00036 #include "G4UIcmdWithABool.hh"
00037 #include "G4UIcommand.hh"
00038 #include "G4UIparameter.hh"
00039 #include "G4UImanager.hh"
00040 #include "G4ProductionCutsTable.hh"
00041 #include "G4ios.hh"
00042 #include "G4MaterialScanner.hh"
00043 #include "G4Tokenizer.hh"
00044 #include "Randomize.hh"
00045 #include <sstream>
00046 
00047 G4RunMessenger::G4RunMessenger(G4RunManager * runMgr)
00048 :runManager(runMgr)
00049 {
00050   runDirectory = new G4UIdirectory("/run/");
00051   runDirectory->SetGuidance("Run control commands.");
00052 
00053   initCmd = new G4UIcmdWithoutParameter("/run/initialize",this);
00054   initCmd->SetGuidance("Initialize G4 kernel.");
00055   initCmd->AvailableForStates(G4State_PreInit,G4State_Idle),
00056 
00057   beamOnCmd = new G4UIcommand("/run/beamOn",this);
00058   beamOnCmd->SetGuidance("Start a Run.");
00059   beamOnCmd->SetGuidance("If G4 kernel is not initialized, it will be initialized.");
00060   beamOnCmd->SetGuidance("Default number of events to be processed is 1.");
00061   beamOnCmd->SetGuidance("The second and third arguments can be used for");
00062   beamOnCmd->SetGuidance("executing a macro file at the end of each event.");
00063   beamOnCmd->SetGuidance("If the second argument, i.e. name of the macro");
00064   beamOnCmd->SetGuidance("file, is given but the third argument is not,");
00065   beamOnCmd->SetGuidance("the macro file will be executed for all of the");
00066   beamOnCmd->SetGuidance("event.");
00067   beamOnCmd->SetGuidance("If the third argument (nSelect) is given, the");
00068   beamOnCmd->SetGuidance("macro file will be executed only for the first");
00069   beamOnCmd->SetGuidance("nSelect events.");
00070   beamOnCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
00071   G4UIparameter* p1 = new G4UIparameter("numberOfEvent",'i',true);
00072   p1->SetDefaultValue(1);
00073   p1->SetParameterRange("numberOfEvent >= 0");
00074   beamOnCmd->SetParameter(p1);
00075   G4UIparameter* p2 = new G4UIparameter("macroFile",'s',true);
00076   p2->SetDefaultValue("***NULL***");
00077   beamOnCmd->SetParameter(p2);
00078   G4UIparameter* p3 = new G4UIparameter("nSelect",'i',true);
00079   p3->SetDefaultValue(-1);
00080   p3->SetParameterRange("nSelect>=-1");
00081   beamOnCmd->SetParameter(p3);
00082 
00083   verboseCmd = new G4UIcmdWithAnInteger("/run/verbose",this);
00084   verboseCmd->SetGuidance("Set the Verbose level of G4RunManager.");
00085   verboseCmd->SetGuidance(" 0 : Silent (default)");
00086   verboseCmd->SetGuidance(" 1 : Display main topics");
00087   verboseCmd->SetGuidance(" 2 : Display main topics and run summary");
00088   verboseCmd->SetParameterName("level",true);
00089   verboseCmd->SetDefaultValue(0);
00090   verboseCmd->SetRange("level >=0 && level <=2");
00091 
00092   dumpRegCmd = new G4UIcmdWithAString("/run/dumpRegion",this);
00093   dumpRegCmd->SetGuidance("Dump region information.");
00094   dumpRegCmd->SetGuidance("In case name of a region is not given, all regions will be displayed.");
00095   dumpRegCmd->SetParameterName("regionName", true);
00096   dumpRegCmd->SetDefaultValue("**ALL**");
00097   dumpRegCmd->AvailableForStates(G4State_Idle);
00098 
00099   dumpCoupleCmd = new G4UIcmdWithoutParameter("/run/dumpCouples",this);
00100   dumpCoupleCmd->SetGuidance("Dump material-cuts-couple information.");
00101   dumpCoupleCmd->SetGuidance("Note that material-cuts-couple information is updated");
00102   dumpCoupleCmd->SetGuidance("after BeamOn has started.");
00103   dumpCoupleCmd->AvailableForStates(G4State_Idle);
00104 
00105   optCmd = new G4UIcmdWithABool("/run/optimizeGeometry",this);
00106   optCmd->SetGuidance("Set the optimization flag for geometry.");
00107   optCmd->SetGuidance("If it is set to TRUE, G4GeometryManager will optimize");
00108   optCmd->SetGuidance("the geometry definitions.");
00109   optCmd->SetGuidance("GEANT4 is initialized with this flag as TRUE.");
00110   optCmd->SetParameterName("optimizeFlag",true);
00111   optCmd->SetDefaultValue(true);
00112   optCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
00113 
00114   brkBoECmd = new G4UIcmdWithABool("/run/breakAtBeginOfEvent",this);
00115   brkBoECmd->SetGuidance("Set a break point at the begining of every event.");
00116   brkBoECmd->SetParameterName("flag",true);
00117   brkBoECmd->SetDefaultValue(true);
00118   
00119   brkEoECmd = new G4UIcmdWithABool("/run/breakAtEndOfEvent",this);
00120   brkEoECmd->SetGuidance("Set a break point at the end of every event.");
00121   brkEoECmd->SetParameterName("flag",true);
00122   brkEoECmd->SetDefaultValue(true);
00123   
00124   abortCmd = new G4UIcmdWithABool("/run/abort",this);
00125   abortCmd->SetGuidance("Abort current run processing.");
00126   abortCmd->SetGuidance("If softAbort is false (default), currently processing event will be immediately aborted,");
00127   abortCmd->SetGuidance("while softAbort is true, abortion occurs after processing the current event.");
00128   abortCmd->AvailableForStates(G4State_GeomClosed,G4State_EventProc);
00129   abortCmd->SetParameterName("softAbort",true);
00130   abortCmd->SetDefaultValue(false);
00131 
00132   abortEventCmd = new G4UIcmdWithoutParameter("/run/abortCurrentEvent",this);
00133   abortEventCmd->SetGuidance("Abort currently processing event.");
00134   abortEventCmd->AvailableForStates(G4State_EventProc);
00135 
00136   geomCmd = new G4UIcmdWithoutParameter("/run/geometryModified",this);
00137   geomCmd->SetGuidance("Force geometry to be closed again.");
00138   geomCmd->SetGuidance("This command must be applied");
00139   geomCmd->SetGuidance(" if geometry has been modified after the");
00140   geomCmd->SetGuidance(" first initialization (or BeamOn).");
00141   geomCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
00142 
00143   physCmd = new G4UIcmdWithoutParameter("/run/physicsModified",this);
00144   physCmd->SetGuidance("Force all physics tables recalculated again.");
00145   physCmd->SetGuidance("This command must be applied");
00146   physCmd->SetGuidance(" if physics process has been modified after the");
00147   physCmd->SetGuidance(" first initialization (or BeamOn).");
00148   physCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
00149 
00150   cutCmd = new G4UIcmdWithoutParameter("/run/cutoffModified",this);
00151   cutCmd->SetGuidance("/run/cutoffModified becomes obsolete.");
00152   cutCmd->SetGuidance("It is safe to remove invoking this command.");
00153 
00154   constScoreCmd = new G4UIcmdWithoutParameter("/run/constructScoringWorlds",this);
00155   constScoreCmd->SetGuidance("Constrct scoring parallel world(s) if defined.");
00156   constScoreCmd->SetGuidance("This command is not mandatory, but automatically called when a run starts.");
00157   constScoreCmd->SetGuidance("But the user may use this to visualize the scoring world(s) before a run to start.");
00158   constScoreCmd->AvailableForStates(G4State_Idle);
00159 
00160   materialScanner = new G4MaterialScanner();
00161   
00162   randomDirectory = new G4UIdirectory("/random/");
00163   randomDirectory->SetGuidance("Random number status control commands.");
00164 
00165   seedCmd = new G4UIcmdWithAString("/random/setSeeds",this);
00166   seedCmd->SetGuidance("Initialize the random number generator with integer seed stream.");
00167   seedCmd->SetGuidance("Number of integers should be more than 1.");
00168   seedCmd->SetGuidance("Actual number of integers to be used depends on the individual random number engine.");
00169   seedCmd->SetParameterName("IntArray",false);
00170   seedCmd->AvailableForStates(G4State_PreInit,G4State_Idle,G4State_GeomClosed);
00171   
00172   randDirCmd = new G4UIcmdWithAString("/random/setDirectoryName",this);
00173   randDirCmd->SetGuidance("Define the directory name of the rndm status files.");
00174   randDirCmd->SetGuidance("Directory will be created if it does not exist.");
00175   randDirCmd->SetParameterName("fileName",true);
00176   randDirCmd->SetDefaultValue("./");
00177   randDirCmd->AvailableForStates(G4State_PreInit,G4State_Idle,G4State_GeomClosed);
00178   
00179   savingFlagCmd = new G4UIcmdWithABool("/random/setSavingFlag",this);
00180   savingFlagCmd->SetGuidance("The randomNumberStatus will be saved at :");
00181   savingFlagCmd->SetGuidance("begining of run (currentRun.rndm) and "
00182                              "begining of event (currentEvent.rndm) ");  
00183   savingFlagCmd->SetParameterName("flag",true);
00184   savingFlagCmd->SetDefaultValue(true);
00185   
00186   saveThisRunCmd = new G4UIcmdWithoutParameter("/random/saveThisRun",this);
00187   saveThisRunCmd->SetGuidance("copy currentRun.rndm to runXXX.rndm");
00188   saveThisRunCmd->AvailableForStates(G4State_Idle,G4State_GeomClosed,G4State_EventProc);
00189   
00190   saveThisEventCmd = new G4UIcmdWithoutParameter("/random/saveThisEvent",this);
00191   saveThisEventCmd->SetGuidance("copy currentEvent.rndm to runXXXevtYYY.rndm");
00192   saveThisEventCmd->AvailableForStates(G4State_EventProc);
00193           
00194   restoreRandCmd = new G4UIcmdWithAString("/random/resetEngineFrom",this);
00195   restoreRandCmd->SetGuidance("Reset the status of the rndm engine from a file.");
00196   restoreRandCmd->SetGuidance("See CLHEP manual for detail.");
00197   restoreRandCmd->SetGuidance("The engine status must be stored beforehand.");
00198   restoreRandCmd->SetGuidance("Directory of the status file should be set by"
00199                               " /random/setDirectoryName.");
00200   restoreRandCmd->SetParameterName("fileName",true);
00201   restoreRandCmd->SetDefaultValue("currentRun.rndm");
00202   restoreRandCmd->AvailableForStates(G4State_PreInit,G4State_Idle,G4State_GeomClosed);
00203   
00204   randEvtCmd = new G4UIcmdWithAnInteger("/run/storeRndmStatToEvent",this);
00205   randEvtCmd->SetGuidance("Flag to store rndm status to G4Event object.");
00206   randEvtCmd->SetGuidance(" flag = 0 : not store (default)");
00207   randEvtCmd->SetGuidance(" flag = 1 : status before primary particle generation is stored");
00208   randEvtCmd->SetGuidance(" flag = 2 : status before event processing (after primary particle generation) is stored");
00209   randEvtCmd->SetGuidance(" flag = 3 : both are stored");
00210   randEvtCmd->SetGuidance("Note: Some performance overhead may be seen by storing rndm status, in particular");
00211   randEvtCmd->SetGuidance("for the case of simplest geometry and small number of tracks per event.");
00212   randEvtCmd->SetParameterName("flag",true);
00213   randEvtCmd->SetDefaultValue(0);
00214   randEvtCmd->SetRange("flag>=0 && flag<3");
00215   randEvtCmd->AvailableForStates(G4State_PreInit,G4State_Idle);
00216 
00217   //old commands for the rndm engine status handling
00218   //
00219   randDirOld = new G4UIcmdWithAString("/run/randomNumberStatusDirectory",this);
00220   randDirOld->SetGuidance("Define the directory name of the rndm status files.");
00221   randDirOld->SetGuidance("Directory must be creates before storing the files.");
00222   randDirOld->SetGuidance("OBSOLETE --- Please use commands in /random/ directory");
00223   randDirOld->SetParameterName("fileName",true);
00224   randDirOld->SetDefaultValue("./");
00225   randDirOld->AvailableForStates(G4State_PreInit,G4State_Idle,G4State_GeomClosed);
00226   
00227   storeRandOld = new G4UIcmdWithAnInteger("/run/storeRandomNumberStatus",this);
00228   storeRandOld->SetGuidance("The randomNumberStatus will be saved at :");
00229   storeRandOld->SetGuidance("begining of run (currentRun.rndm) and "
00230                             "begining of event (currentEvent.rndm) ");  
00231   storeRandOld->SetGuidance("OBSOLETE --- Please use commands in /random/ directory");
00232   storeRandOld->SetParameterName("flag",true);
00233   storeRandOld->SetDefaultValue(1);
00234           
00235   restoreRandOld = new G4UIcmdWithAString("/run/restoreRandomNumberStatus",this);
00236   restoreRandOld->SetGuidance("Reset the status of the rndm engine from a file.");
00237   restoreRandOld->SetGuidance("See CLHEP manual for detail.");
00238   restoreRandOld->SetGuidance("The engine status must be stored beforehand.");
00239   restoreRandOld->SetGuidance("Directory of the status file should be set by"
00240                               " /random/setDirectoryName.");
00241   restoreRandOld->SetGuidance("OBSOLETE --- Please use commands in /random/ directory");
00242   restoreRandOld->SetParameterName("fileName",true);
00243   restoreRandOld->SetDefaultValue("currentRun.rndm");
00244   restoreRandOld->AvailableForStates(G4State_PreInit,G4State_Idle,G4State_GeomClosed);  
00245 }
00246 
00247 G4RunMessenger::~G4RunMessenger()
00248 {
00249   delete materialScanner;
00250   delete beamOnCmd;
00251   delete verboseCmd;
00252   delete optCmd;
00253   delete dumpRegCmd;
00254   delete dumpCoupleCmd;
00255   delete brkBoECmd;
00256   delete brkEoECmd;
00257   delete abortCmd;
00258   delete abortEventCmd;
00259   delete initCmd;
00260   delete geomCmd;
00261   delete physCmd;
00262   delete cutCmd;
00263   delete randEvtCmd;
00264   delete randDirOld; delete storeRandOld; delete restoreRandOld; 
00265   delete constScoreCmd;
00266   delete runDirectory;
00267   
00268   delete randDirCmd;
00269   delete seedCmd;
00270   delete savingFlagCmd;
00271   delete saveThisRunCmd;
00272   delete saveThisEventCmd;
00273   delete restoreRandCmd;
00274   delete randomDirectory;
00275 }
00276 
00277 void G4RunMessenger::SetNewValue(G4UIcommand * command,G4String newValue)
00278 {
00279   if( command==beamOnCmd )
00280   {
00281     G4int nev;
00282     G4int nst;
00283     const char* nv = (const char*)newValue;
00284     std::istringstream is(nv);
00285     is >> nev >> macroFileName >> nst;
00286     if(macroFileName=="***NULL***")
00287     { runManager->BeamOn(nev); }
00288     else
00289     { runManager->BeamOn(nev,macroFileName,nst); }
00290   }
00291   else if( command==verboseCmd )
00292   { runManager->SetVerboseLevel(verboseCmd->GetNewIntValue(newValue)); }
00293   else if( command==dumpRegCmd )
00294   { 
00295     if(newValue=="**ALL**")
00296     { runManager->DumpRegion(); }
00297     else
00298     { runManager->DumpRegion(newValue); }
00299   }
00300   else if( command==dumpCoupleCmd)
00301   {
00302     G4ProductionCutsTable::GetProductionCutsTable()->DumpCouples();
00303   }
00304   else if( command==optCmd )
00305   { runManager->SetGeometryToBeOptimized(optCmd->GetNewBoolValue(newValue)); }
00306   else if( command==brkBoECmd )
00307   { G4UImanager::GetUIpointer()->SetPauseAtBeginOfEvent(brkBoECmd->GetNewBoolValue(newValue)); }
00308   else if( command==brkEoECmd )
00309   { G4UImanager::GetUIpointer()->SetPauseAtEndOfEvent(brkEoECmd->GetNewBoolValue(newValue)); }
00310   else if( command==abortCmd )
00311   { runManager->AbortRun(abortCmd->GetNewBoolValue(newValue)); }
00312   else if( command==abortEventCmd )
00313   { runManager->AbortEvent(); }
00314   else if( command==initCmd )
00315   { runManager->Initialize(); }
00316   else if( command==geomCmd )
00317   { runManager->GeometryHasBeenModified(); }
00318   else if( command==physCmd )
00319   { runManager->PhysicsHasBeenModified(); }
00320   else if( command==cutCmd )
00321   { runManager->CutOffHasBeenModified(); }
00322  
00323   else if( command==seedCmd )
00324   {
00325     G4Tokenizer next(newValue);
00326     G4int idx=0;
00327     long seeds[100];
00328     G4String vl;
00329     while(!(vl=next()).isNull())
00330     { seeds[idx] = (long)(StoI(vl)); idx++; }
00331     if(idx<2)
00332     { G4cerr << "/random/setSeeds should have at least two integers. Command ignored." << G4endl; }
00333     else
00334     {
00335       seeds[idx] = 0;
00336       CLHEP::HepRandom::setTheSeeds(seeds);
00337     }
00338   }
00339   else if( command==randDirCmd )
00340   { runManager->SetRandomNumberStoreDir(newValue); }
00341   else if( command==savingFlagCmd )
00342   { runManager->SetRandomNumberStore(savingFlagCmd->GetNewBoolValue(newValue)); }    
00343   else if( command==saveThisRunCmd )
00344   { runManager->rndmSaveThisRun(); }
00345   else if( command==saveThisEventCmd )
00346   { runManager->rndmSaveThisEvent(); }  
00347   else if( command==restoreRandCmd )
00348   { runManager->RestoreRandomNumberStatus(newValue); }
00349   else if( command==randEvtCmd )
00350   { runManager->StoreRandomNumberStatusToG4Event(randEvtCmd->GetNewIntValue(newValue)); }
00351   
00352   else if( command==randDirOld )
00353   {G4cout << "warning: deprecated command. Use /random/setDirectoryName"
00354           << G4endl; 
00355   // runManager->SetRandomNumberStoreDir(newValue);
00356   }
00357   else if( command==storeRandOld )
00358   {G4cout << "warning: deprecated command. Use /random/setSavingFlag"
00359           << G4endl;
00360    // G4int frequency = storeRandOld->GetNewIntValue(newValue);
00361    // G4bool flag = false;
00362    // if(frequency != 0) flag = true;        
00363    // runManager->SetRandomNumberStore(flag);
00364   }    
00365   else if( command==restoreRandOld )
00366   {G4cout << "warning: deprecated command. Use /random/resetEngineFrom"
00367            << G4endl;  
00368    // runManager->RestoreRandomNumberStatus(newValue);
00369   }  
00370   else if( command==constScoreCmd )
00371   { runManager->ConstructScoringWorlds(); }
00372 
00373 }
00374 
00375 G4String G4RunMessenger::GetCurrentValue(G4UIcommand * command)
00376 {
00377   G4String cv;
00378   
00379   if( command==verboseCmd )
00380   { cv = verboseCmd->ConvertToString(runManager->GetVerboseLevel()); }
00381   else if( command==randDirCmd )
00382   { cv = runManager->GetRandomNumberStoreDir(); }
00383   else if( command==randEvtCmd )
00384   { cv = randEvtCmd->ConvertToString(runManager->GetFlagRandomNumberStatusToG4Event()); }
00385   
00386   return cv;
00387 }
00388 

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