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