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