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