File indexing completed on 2025-02-23 09:22:04
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 #include "ActionInitialization.hh"
0044 #include "CommandLineParser.hh"
0045 #include "DetectorConstruction.hh"
0046 #include "PhysicsList.hh"
0047
0048 #include "G4DNAChemistryManager.hh"
0049 #include "G4RunManagerFactory.hh"
0050 #include "G4Timer.hh"
0051 #include "G4Types.hh"
0052 #include "G4UIExecutive.hh"
0053 #include "G4UImanager.hh"
0054 #include "G4VisExecutive.hh"
0055
0056
0057
0058 using namespace std;
0059 using namespace G4DNAPARSER;
0060
0061 CommandLineParser* parser(0);
0062
0063 void Parse(int& argc, char** argv);
0064
0065 int main(int argc, char** argv)
0066 {
0067
0068 G4Timer* timer = new G4Timer();
0069 timer->Start();
0070
0071
0072
0073
0074 Parse(argc, argv);
0075
0076
0077
0078
0079 Command* commandLine(0);
0080
0081 auto* runManager = G4RunManagerFactory::CreateRunManager();
0082
0083 if ((commandLine = parser->GetCommandIfActive("-mt"))) {
0084 G4int nThreads = 2;
0085
0086 if (commandLine->GetOption() == "NMAX") {
0087 nThreads = G4Threading::G4GetNumberOfCores();
0088 }
0089 else {
0090 nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
0091 }
0092 runManager->SetNumberOfThreads(nThreads);
0093
0094 G4cout << "===== neuron is started with " << runManager->GetNumberOfThreads()
0095 << " threads of MT MODE =====" << G4endl;
0096 }
0097
0098
0099 DetectorConstruction* detector = new DetectorConstruction;
0100 runManager->SetUserInitialization(detector);
0101 runManager->SetUserInitialization(new PhysicsList);
0102
0103
0104 runManager->SetUserInitialization(new ActionInitialization(detector));
0105
0106
0107 runManager->Initialize();
0108
0109
0110 G4VisManager* visManager = new G4VisExecutive;
0111 visManager->Initialize();
0112
0113
0114 G4UImanager* UImanager = G4UImanager::GetUIpointer();
0115 G4UIExecutive* ui(0);
0116
0117
0118 if ((commandLine = parser->GetCommandIfActive("-gui"))) {
0119 ui = new G4UIExecutive(argc, argv, commandLine->GetOption());
0120
0121 if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute gui.mac");
0122
0123 if (parser->GetCommandIfActive("-novis") == 0)
0124
0125 {
0126 if ((commandLine = parser->GetCommandIfActive("-vis")))
0127
0128 {
0129 UImanager->ApplyCommand(G4String("/vis/open ") + commandLine->GetOption());
0130 }
0131 else
0132
0133 {
0134 UImanager->ApplyCommand("/vis/open OGL 800x600-0+0");
0135 }
0136 UImanager->ApplyCommand("/control/execute vis.mac");
0137 }
0138 }
0139 else
0140
0141
0142
0143 {
0144 if ((commandLine = parser->GetCommandIfActive("-vis"))) {
0145 UImanager->ApplyCommand(G4String("/vis/open ") + commandLine->GetOption());
0146 UImanager->ApplyCommand("/control/execute vis.mac");
0147 }
0148 }
0149
0150 if ((commandLine = parser->GetCommandIfActive("-mac"))) {
0151 G4String command = "/control/execute ";
0152 UImanager->ApplyCommand(command + commandLine->GetOption());
0153 }
0154 else {
0155 UImanager->ApplyCommand("/control/execute ");
0156 }
0157
0158 if ((commandLine = parser->GetCommandIfActive("-gui"))) {
0159 ui->SessionStart();
0160 delete ui;
0161 }
0162
0163
0164 timer->Stop();
0165 G4cout << " Calculation time = " << timer->GetRealElapsed() << " s \n"
0166 << G4endl;
0167
0168 delete visManager;
0169 delete runManager;
0170
0171 return 0;
0172 }
0173
0174
0175
0176 void GetNameAndPathOfExecutable(char** argv, G4String& executable, G4String& path)
0177 {
0178
0179 std::string aux(argv[0]);
0180
0181
0182 #if defined(_WIN32) || defined(WIN32)
0183 int pos = aux.rfind('\\');
0184 #else
0185 int pos = aux.rfind('/');
0186 #endif
0187
0188
0189 path = aux.substr(0, pos + 1);
0190 executable = aux.substr(pos + 1);
0191 }
0192
0193
0194
0195 void Parse(int& argc, char** argv)
0196 {
0197
0198
0199
0200 parser = CommandLineParser::GetParser();
0201
0202 parser->AddCommand("-gui", Command::OptionNotCompulsory,
0203 "Select geant4 UI or just launch a geant4 terminal session", "qt");
0204
0205 parser->AddCommand("-mac", Command::WithOption, "Give a mac file to execute", "macFile.mac");
0206
0207
0208
0209
0210
0211
0212
0213 parser->AddCommand("-mt", Command::WithOption, "Launch in MT mode (events computed in parallel)",
0214 " NOT RECOMMANDED WITH CHEMISTRY)", "2");
0215
0216 parser->AddCommand("-sXY", Command::OptionNotCompulsory,
0217 "Initial beam position uniformly spread on a square!");
0218 parser->AddCommand("-dXY", Command::OptionNotCompulsory,
0219 "Initial beam position uniformly spread on a disk!");
0220
0221 parser->AddCommand("-dnaliv", Command::OptionNotCompulsory, "Activate Livermore + DNAPhysics");
0222 parser->AddCommand("-dnachemON", Command::OptionNotCompulsory,
0223 "Activate Livermore + DNAPhysics + DNAChemistry");
0224 parser->AddCommand("-dnahad", Command::OptionNotCompulsory,
0225 "Activate Hadronic + Livermore + DNAPhysics");
0226
0227 parser->AddCommand("-swc", Command::WithOption, "Give a SWC file to simulation", "fileName.swc");
0228
0229 parser->AddCommand("-network",
0230 Command::WithOption,
0231 "Give a DAT file to simulation", "fileName.dat");
0232
0233 parser->AddCommand("-vis", Command::WithOption, "Select a visualization driver",
0234 "OGL 600x600-0+0");
0235
0236 parser->AddCommand("-novis", Command::WithoutOption, "Deactivate visualization when using GUI");
0237
0238 G4String exec;
0239 G4String path;
0240 GetNameAndPathOfExecutable(argv, exec, path);
0241
0242 parser->AddCommand("-out", Command::OptionNotCompulsory, "Output files", exec);
0243
0244
0245
0246
0247 if (parser->Parse(argc, argv) != 0)
0248 {
0249
0250
0251 CommandLineParser::DeleteInstance();
0252 std::exit(0);
0253 }
0254
0255
0256
0257 if (parser->CheckIfNotHandledOptionsExists(argc, argv)) {
0258
0259
0260 abort();
0261 }
0262 }