40 #include "ActionInitialization.hh" 42 #ifdef G4MULTITHREADED 43 #include "G4MTRunManager.hh" 45 #include "G4RunManager.hh" 48 #include "G4DNAChemistryManager.hh" 49 #include "G4UImanager.hh" 50 #include "G4UIExecutive.hh" 51 #include "G4VisExecutive.hh" 53 #include "CommandLineParser.hh" 67 CommandLineParser*
parser(0);
73 void Parse(
int& argc,
char** argv);
77 int main(
int argc,
char** argv)
81 Command* commandLine(0);
86 #ifdef G4MULTITHREADED 87 G4MTRunManager* runManager=
new G4MTRunManager();
89 if((commandLine =
parser->GetCommandIfActive(
"-mt")))
92 if(commandLine->GetOption() ==
"NMAX")
94 nThreads = G4Threading::G4GetNumberOfCores();
98 nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
101 runManager->SetNumberOfThreads(nThreads);
104 G4cout <<
"**************************************************************" 105 <<
"******\n===== Chem4 is started with " 106 << runManager->GetNumberOfThreads() <<
" of " 107 << G4Threading::G4GetNumberOfCores()
108 <<
" available threads =====\n\n*************************************" 109 <<
"*******************************" 112 G4RunManager* runManager =
new G4RunManager();
116 runManager->SetUserInitialization(
new PhysicsList());
118 runManager->SetUserInitialization(
new ActionInitialization());
121 runManager->Initialize();
124 G4VisManager* visManager =
new G4VisExecutive();
127 visManager->Initialize();
130 G4UImanager* UImanager = G4UImanager::GetUIpointer();
131 G4UIExecutive* ui(0);
134 if((commandLine =
parser->GetCommandIfActive(
"-gui")))
136 ui =
new G4UIExecutive(argc, argv, commandLine->GetOption());
138 if (ui->IsGUI()) UImanager->ApplyCommand(
"/control/execute gui.mac");
140 if (
parser->GetCommandIfActive(
"-novis") == 0)
143 if ((commandLine =
parser->GetCommandIfActive(
"-vis")))
146 UImanager->ApplyCommand
147 (
G4String(
"/vis/open ") + commandLine->GetOption());
152 UImanager->ApplyCommand(
"/vis/open OGL 800x600-0+0");
154 UImanager->ApplyCommand(
"/control/execute vis.mac");
162 if((commandLine =
parser->GetCommandIfActive(
"-vis")))
164 UImanager->ApplyCommand(
G4String(
"/vis/open ")
165 + commandLine->GetOption());
166 UImanager->ApplyCommand(
"/control/execute vis.mac");
170 if((commandLine =
parser->GetCommandIfActive(
"-mac")))
172 G4String command =
"/control/execute ";
173 UImanager->ApplyCommand(command + commandLine->GetOption());
177 UImanager->ApplyCommand(
"/control/execute beam.in");
180 if((commandLine =
parser->GetCommandIfActive(
"-gui")))
192 CommandLineParser::DeleteInstance();
214 Command* commandLine(0);
216 if((commandLine =
parser->GetCommandIfActive(
"-seed")))
218 seed = atoi(commandLine->GetOption().c_str());
228 if((commandLine =
parser->GetCommandIfActive(
"-cluster")))
230 noice = labs((
long)
noise());
232 const char * env = getenv(
"PBS_JOBID");
237 G4String jobID_string = buffer.substr(0, buffer.find(
"."));
238 jobID_string.erase(std::remove_if(jobID_string.begin(),
242 jobID_int = atoi(jobID_string.c_str());
246 env = getenv(
"SGE_TASK_ID");
247 if(env) jobID_int = atoi(env);
252 seed = ((long) time(NULL)) + jobID_int + noice;
255 G4cout <<
"Seed used : " <<
seed << G4endl;
256 G4Random::setTheEngine(
new CLHEP::MixMaxRng());
257 G4Random::setTheSeed(
seed);
267 #if defined(WIN32)|| defined(_WIN32)|| defined(__WIN32)&&!defined(__CYGWIN__) 271 unsigned int random_seed, random_seed_a, random_seed_b;
272 std::ifstream
file (
"/dev/urandom", std::ios::binary);
276 int size =
sizeof(int);
277 memblock =
new char [size];
278 file.read (memblock, size);
280 random_seed_a = *
reinterpret_cast<int*
>(memblock);
287 random_seed_b = std::time(0);
288 random_seed = random_seed_a xor random_seed_b;
300 parser = CommandLineParser::GetParser();
302 parser->AddCommand(
"-gui", Command::OptionNotCompulsory,
303 "Select geant4 UI or just launch a geant4 terminal" 307 parser->AddCommand(
"-mac", Command::WithOption,
"Give a mac file to execute",
310 parser->AddCommand(
"-seed",
312 "Give a seed value in argument to be tested",
"seed");
314 #ifdef G4MULTITHREADED 315 parser->AddCommand(
"-mt",Command::WithOption,
316 "Launch in MT mode (events computed in parallel," 317 " NOT RECOMMANDED WITH CHEMISTRY)",
"2");
320 parser->AddCommand(
"-chemOFF", Command::WithoutOption,
321 "Deactivate chemistry");
323 parser->AddCommand(
"-vis", Command::WithOption,
324 "Select a visualization driver",
"OGL 600x600-0+0");
326 parser->AddCommand(
"-novis", Command::WithoutOption,
327 "Deactivate visualization when using GUI");
329 parser->AddCommand(
"-cluster", Command::WithoutOption,
330 "Launch the code on a cluster, avoid dupplicated seeds");
335 if (
parser->Parse(argc, argv) != 0)
339 CommandLineParser::DeleteInstance();
346 if(
parser->CheckIfNotHandledOptionsExists(argc, argv))
void Parse(int &argc, char **argv)
CommandLineParser * parser(0)
int main(int argc, char **argv)
TConfigurablePhysicsList< ModularPhysicsList > PhysicsList