File indexing completed on 2026-06-02 08:06:54
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 #include "G4RunManagerFactory.hh"
0038 #include "G4Types.hh"
0039 #include "G4UIExecutive.hh"
0040 #include "G4UImanager.hh"
0041 #include "G4UItcsh.hh"
0042 #include "G4UIterminal.hh"
0043 #include "G4VisExecutive.hh"
0044 #ifdef G4UI_USE_QT
0045 # include "G4UIQt.hh"
0046 #endif
0047
0048 #include "ActionInitialization.hh"
0049 #include "CommandLineParser.hh"
0050 #include "DetectorConstruction.hh"
0051 #include "PhysicsList.hh"
0052
0053
0054
0055 using namespace G4DNAPARSER;
0056 CommandLineParser* parser(0);
0057
0058 void Parse(int& argc, char** argv);
0059
0060 int main(int argc, char** argv)
0061 {
0062
0063
0064
0065 Parse(argc, argv);
0066
0067
0068
0069
0070 Command* commandLine(0);
0071
0072 auto* runManager = G4RunManagerFactory::CreateRunManager();
0073 if ((commandLine = parser->GetCommandIfActive("-mt"))) {
0074 int nThreads = 2;
0075 if (commandLine->GetOption() == "NMAX") {
0076 nThreads = G4Threading::G4GetNumberOfCores();
0077 }
0078 else {
0079 nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
0080 }
0081
0082 runManager->SetNumberOfThreads(nThreads);
0083
0084 G4cout << "===== WholeNuclearDNA is started with " << runManager->GetNumberOfThreads()
0085 << " threads =====" << G4endl;
0086 }
0087
0088
0089 DetectorConstruction* detector = new DetectorConstruction;
0090 runManager->SetUserInitialization(detector);
0091 runManager->SetUserInitialization(new PhysicsList);
0092 runManager->SetUserInitialization(new ActionInitialization());
0093
0094
0095 runManager->Initialize();
0096
0097
0098 G4VisManager* visManager = new G4VisExecutive;
0099
0100
0101 visManager->Initialize();
0102
0103
0104 G4UImanager* UImanager = G4UImanager::GetUIpointer();
0105 G4UIExecutive* ui(0);
0106
0107
0108 if ((commandLine = parser->GetCommandIfActive("-gui"))) {
0109 ui = new G4UIExecutive(argc, argv, commandLine->GetOption());
0110
0111 if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute gui.mac");
0112
0113 if (parser->GetCommandIfActive("-novis") == 0)
0114
0115 {
0116 if ((commandLine = parser->GetCommandIfActive("-vis")))
0117
0118 {
0119 UImanager->ApplyCommand(G4String("/vis/open ") + commandLine->GetOption());
0120 }
0121 else
0122
0123 {
0124 UImanager->ApplyCommand("/vis/open OGL 800x600-0+0");
0125 }
0126 UImanager->ApplyCommand("/control/execute vis.mac");
0127 }
0128 }
0129 else
0130
0131
0132
0133 {
0134 if ((commandLine = parser->GetCommandIfActive("-vis"))) {
0135 UImanager->ApplyCommand(G4String("/vis/open ") + commandLine->GetOption());
0136 UImanager->ApplyCommand("/control/execute vis.mac");
0137 }
0138 }
0139
0140 if ((commandLine = parser->GetCommandIfActive("-mac"))) {
0141 G4String command = "/control/execute ";
0142 UImanager->ApplyCommand(command + commandLine->GetOption());
0143 }
0144 else {
0145 UImanager->ApplyCommand("/control/execute wholeNuclearDNA.in");
0146 }
0147
0148 if ((commandLine = parser->GetCommandIfActive("-gui"))) {
0149 #ifdef G4UI_USE_QT
0150 G4UIQt* UIQt = static_cast<G4UIQt*>(UImanager->GetG4UIWindow());
0151 if (UIQt) {
0152 UIQt->AddViewerTabFromFile("README", "README from " + G4String(argv[0]));
0153 }
0154 #endif
0155 ui->SessionStart();
0156 delete ui;
0157 }
0158
0159 delete visManager;
0160 delete runManager;
0161
0162 return 0;
0163 }
0164
0165
0166
0167 void GetNameAndPathOfExecutable(char** argv, G4String& executable, G4String& path)
0168 {
0169
0170 std::string aux(argv[0]);
0171
0172
0173 #if defined(_WIN32) || defined(WIN32)
0174 int pos = aux.rfind('\\');
0175 #else
0176 int pos = aux.rfind('/');
0177 #endif
0178
0179
0180 path = aux.substr(0, pos + 1);
0181 executable = aux.substr(pos + 1);
0182 }
0183
0184
0185
0186 void Parse(int& argc, char** argv)
0187 {
0188
0189
0190
0191 parser = CommandLineParser::GetParser();
0192
0193 parser->AddCommand("-gui", Command::OptionNotCompulsory,
0194 "Select geant4 UI or just launch a geant4 terminal session", "qt");
0195
0196 parser->AddCommand("-mac", Command::WithOption, "Give a mac file to execute", "macFile.mac");
0197
0198
0199
0200
0201
0202
0203
0204 parser->AddCommand("-mt", Command::WithOption, "Launch in MT mode (events computed in parallel)",
0205 "2");
0206
0207 parser->AddCommand("-vis", Command::WithOption, "Select a visualization driver",
0208 "OGL 600x600-0+0");
0209
0210 parser->AddCommand("-novis", Command::WithoutOption, "Deactivate visualization when using GUI");
0211
0212 G4String exec;
0213 G4String path;
0214 GetNameAndPathOfExecutable(argv, exec, path);
0215
0216 parser->AddCommand("-out", Command::OptionNotCompulsory, "Output files (ROOT is used by default)",
0217 exec);
0218
0219
0220
0221
0222 if (parser->Parse(argc, argv) != 0)
0223 {
0224
0225
0226 CommandLineParser::DeleteInstance();
0227 std::exit(0);
0228 }
0229
0230
0231
0232
0233 if (parser->CheckIfNotHandledOptionsExists(argc, argv)) {
0234
0235
0236 abort();
0237 }
0238 }