00001
00002 #include "GeneratorMessenger.hh"
00003
00004
00005 #include "EventSourceManager.hh"
00006
00007
00008 #include "StringUtil.hh"
00009
00010
00011 #include "G4UIcommand.hh"
00012 #include "G4UIdirectory.hh"
00013 #include "G4UIcmdWithAnInteger.hh"
00014 #include "G4UIcmdWithADoubleAndUnit.hh"
00015
00016
00017 #include "CLHEP/Random/Random.h"
00018 #include "CLHEP/Random/Randomize.h"
00019
00020 namespace CLHEP {}
00021 using namespace CLHEP;
00022
00023 namespace slic
00024 {
00025
00026 GeneratorMessenger::GeneratorMessenger()
00027 {
00028 defineCommands();
00029 }
00030
00031 GeneratorMessenger::~GeneratorMessenger()
00032 {}
00033
00034 void GeneratorMessenger::SetNewValue(G4UIcommand* cmd, G4String newVals)
00035 {
00036 std::istringstream is ( ( const char* ) newVals );
00037
00038 std::string s;
00039 is >> s;
00040
00041 EventSourceManager* mgr = EventSourceManager::instance();
00042
00043
00044 if ( cmd == m_selectCmd )
00045 {
00046 mgr->setupEventSource( s );
00047 }
00048
00049 else if ( cmd == m_resetCmd )
00050 {
00051 mgr->resetCurrentEventSource();
00052 }
00053
00054 else if ( cmd == m_skipEventsCmd )
00055 {
00056 mgr->setSkipEvents( StringUtil::toInt( s ) );
00057 }
00058
00059 else if ( cmd == m_filenameCmd )
00060 {
00061 mgr->setFilename( s );
00062 }
00063
00064 else if ( cmd == m_dumpCurrentEventCmd )
00065 {
00066 mgr->dumpCurrentEvent();
00067 }
00068
00069 else if ( cmd == m_printNumEventsGeneratedCmd )
00070 {
00071 mgr->printNumEventsGenerated();
00072 }
00073
00074 else if ( cmd == m_randomSeedCmd )
00075 {
00076 G4int seed = 0;
00077
00078
00079 if ( s != std::string("") ) {
00080 seed = StringUtil::toInt( s );
00081 }
00082
00083
00084 else {
00085 seed = ((unsigned)time(NULL));
00086 }
00087
00088
00089 HepRandom::setTheSeed( seed );
00090
00091 mgr->log() << LOG::okay << "set random seed: " << seed << LOG::done;
00092 }
00093
00094 else if ( cmd == m_setLorentzTransformationAngleCmd )
00095 {
00096 EventSourceManager::instance()->setLorentzTransformationAngle(G4UIcmdWithADoubleAndUnit::GetNewDoubleValue(newVals));
00097 }
00098 else {
00099 G4Exception("Unknown cmd for this messenger.");
00100 }
00101 }
00102
00103 void GeneratorMessenger::defineCommands()
00104 {
00105 G4UIparameter *p;
00106
00107
00108 m_generatorDir = new G4UIdirectory( "/generator/" );
00109 m_generatorDir->SetGuidance( "Event generation commands. [SLIC]" );
00110
00111
00112 m_selectCmd = new G4UIcommand( "/generator/select", this );
00113 m_selectCmd->SetGuidance( "Set Generator to use: lcio, stdhep, gps or gun." );
00114 p = new G4UIparameter( "generator", 's', false );
00115 m_selectCmd->SetParameter(p);
00116
00117
00118 m_resetCmd = new G4UIcommand( "/generator/reset", this);
00119 m_resetCmd->SetGuidance( "Reset the generator using the current info." );
00120
00121
00122 m_skipEventsCmd = new G4UIcmdWithAnInteger( "/generator/skipEvents", this);
00123 m_skipEventsCmd->SetGuidance( "Skip n events of current generator." );
00124 m_skipEventsCmd->SetParameterName( "NumEvents", false);
00125
00126
00127 m_filenameCmd = new G4UIcommand( "/generator/filename", this);
00128 m_filenameCmd->SetGuidance( "Set generator input filename.");
00129 p = new G4UIparameter( "filename", 's', false);
00130 m_filenameCmd->SetParameter(p);
00131
00132
00133 m_dumpCurrentEventCmd = new G4UIcommand( "/generator/dumpEvent", this);
00134 m_dumpCurrentEventCmd->SetGuidance( "Dump information about the current generator event." );
00135
00136
00137 m_printNumEventsGeneratedCmd = new G4UIcommand( "/generator/printNumEventsGenerated", this);
00138 m_printNumEventsGeneratedCmd->SetGuidance( "Print out number of events generated with current generator.");
00139
00140
00141 m_randomSeedCmd = new G4UIcommand( "/random/seed", this );
00142 m_randomSeedCmd->SetGuidance( "Set random seed; no argument seeds with current time. [SLIC]" );
00143 p = new G4UIparameter( "seedValue", 'i', true );
00144 m_randomSeedCmd->SetParameter( p );
00145
00146
00147 m_setLorentzTransformationAngleCmd = new G4UIcmdWithADoubleAndUnit("/generator/setLorentzTransformationAngle",this);
00148 m_setLorentzTransformationAngleCmd->SetGuidance( "Set the Lorentz transformation angle to boost generated events." );
00149 }
00150 }