39 #include "ActionInitialization.hh" 41 #ifdef G4MULTITHREADED 42 #include "G4MTRunManager.hh" 44 #include "G4RunManager.hh" 47 #include "G4DNAChemistryManager.hh" 48 #include "G4UImanager.hh" 49 #include "G4UIExecutive.hh" 50 #include "G4VisExecutive.hh" 52 #include "CommandLineParser.hh" 66 CommandLineParser*
parser(0);
72 void Parse(
int& argc,
char** argv);
76 int main(
int argc,
char** argv)
80 Command* commandLine(0);
85 #ifdef G4MULTITHREADED 86 G4MTRunManager* runManager=
new G4MTRunManager();
88 if((commandLine =
parser->GetCommandIfActive(
"-mt")))
91 if(commandLine->GetOption() ==
"NMAX")
93 nThreads = G4Threading::G4GetNumberOfCores();
97 nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
100 runManager->SetNumberOfThreads(nThreads);
103 G4cout <<
"**************************************************************" 104 <<
"******\n===== Chem4 is started with " 105 << runManager->GetNumberOfThreads() <<
" of " 106 << G4Threading::G4GetNumberOfCores()
107 <<
" available threads =====\n\n*************************************" 108 <<
"*******************************" 111 G4RunManager* runManager =
new G4RunManager();
115 runManager->SetUserInitialization(
new PhysicsList());
117 runManager->SetUserInitialization(
new ActionInitialization());
120 G4VisManager* visManager =
new G4VisExecutive();
123 visManager->Initialize();
126 G4UImanager* UImanager = G4UImanager::GetUIpointer();
127 G4UIExecutive* ui(0);
130 if((commandLine =
parser->GetCommandIfActive(
"-gui")))
132 ui =
new G4UIExecutive(argc, argv, commandLine->GetOption());
134 if (ui->IsGUI()) UImanager->ApplyCommand(
"/control/execute gui.mac");
136 if (
parser->GetCommandIfActive(
"-novis") == 0)
139 if ((commandLine =
parser->GetCommandIfActive(
"-vis")))
142 UImanager->ApplyCommand
143 (
G4String(
"/vis/open ") + commandLine->GetOption());
148 UImanager->ApplyCommand(
"/vis/open OGL 800x600-0+0");
150 UImanager->ApplyCommand(
"/control/execute vis.mac");
158 if((commandLine =
parser->GetCommandIfActive(
"-vis")))
160 UImanager->ApplyCommand(
G4String(
"/vis/open ")
161 + commandLine->GetOption());
162 UImanager->ApplyCommand(
"/control/execute vis.mac");
166 if((commandLine =
parser->GetCommandIfActive(
"-mac")))
168 G4String command =
"/control/execute ";
169 UImanager->ApplyCommand(command + commandLine->GetOption());
173 UImanager->ApplyCommand(
"/control/execute beam.in");
176 if((commandLine =
parser->GetCommandIfActive(
"-gui")))
188 CommandLineParser::DeleteInstance();
210 Command* commandLine(0);
212 if((commandLine =
parser->GetCommandIfActive(
"-seed")))
214 seed = atoi(commandLine->GetOption().c_str());
224 if((commandLine =
parser->GetCommandIfActive(
"-cluster")))
226 noice = labs((
long)
noise());
228 const char * env = std::getenv(
"PBS_JOBID");
233 G4String jobID_string = buffer.substr(0, buffer.find(
"."));
234 jobID_string.erase(std::remove_if(jobID_string.begin(),
238 jobID_int = atoi(jobID_string.c_str());
242 env = std::getenv(
"SGE_TASK_ID");
243 if(env) jobID_int = atoi(env);
248 seed = ((long) time(NULL)) + jobID_int + noice;
251 G4cout <<
"Seed used : " <<
seed << G4endl;
252 G4Random::setTheEngine(
new CLHEP::MixMaxRng());
253 G4Random::setTheSeed(
seed);
263 #if defined(WIN32)|| defined(_WIN32)|| defined(__WIN32)&&!defined(__CYGWIN__) 267 unsigned int random_seed, random_seed_a, random_seed_b;
268 std::ifstream
file (
"/dev/urandom", std::ios::binary);
272 int size =
sizeof(int);
273 memblock =
new char [
size];
274 file.read (memblock, size);
276 random_seed_a = *
reinterpret_cast<int*
>(memblock);
283 random_seed_b = std::time(0);
284 random_seed = random_seed_a xor random_seed_b;
296 parser = CommandLineParser::GetParser();
298 parser->AddCommand(
"-gui", Command::OptionNotCompulsory,
299 "Select geant4 UI or just launch a geant4 terminal" 303 parser->AddCommand(
"-mac", Command::WithOption,
"Give a mac file to execute",
306 parser->AddCommand(
"-seed",
308 "Give a seed value in argument to be tested",
"seed");
310 #ifdef G4MULTITHREADED 311 parser->AddCommand(
"-mt",Command::WithOption,
312 "Launch in MT mode (events computed in parallel," 313 " NOT RECOMMANDED WITH CHEMISTRY)",
"2");
316 parser->AddCommand(
"-chemOFF", Command::WithoutOption,
317 "Deactivate chemistry");
319 parser->AddCommand(
"-vis", Command::WithOption,
320 "Select a visualization driver",
"OGL 600x600-0+0");
322 parser->AddCommand(
"-novis", Command::WithoutOption,
323 "Deactivate visualization when using GUI");
325 parser->AddCommand(
"-cluster", Command::WithoutOption,
326 "Launch the code on a cluster, avoid dupplicated seeds");
331 if (
parser->Parse(argc, argv) != 0)
335 CommandLineParser::DeleteInstance();
342 if(
parser->CheckIfNotHandledOptionsExists(argc, argv))
void Parse(int &argc, char **argv)
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
TConfigurablePhysicsList< ModularPhysicsList > PhysicsList
CommandLineParser * parser(0)
int main(int argc, char **argv)