Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // This example is provided by the Geant4-DNA 26 // This example is provided by the Geant4-DNA collaboration 27 // Any report or published results obtained us 27 // Any report or published results obtained using the Geant4-DNA software 28 // shall cite the following Geant4-DNA collabo 28 // shall cite the following Geant4-DNA collaboration publication: 29 // Med. Phys. 37 (2010) 4692-4708 29 // Med. Phys. 37 (2010) 4692-4708 30 // J. Comput. Phys. 274 (2014) 841-882 30 // J. Comput. Phys. 274 (2014) 841-882 31 // The Geant4-DNA web site is available at htt 31 // The Geant4-DNA web site is available at http://geant4-dna.org 32 // 32 // >> 33 // $Id$ 33 // 34 // 34 /// \file chem2.cc << 35 /// \file main.cc 35 /// \brief Chem2 example 36 /// \brief Chem2 example 36 37 37 #include "ActionInitialization.hh" << 38 #include "CommandLineParser.hh" << 39 #include "DetectorConstruction.hh" 38 #include "DetectorConstruction.hh" 40 #include "PhysicsList.hh" 39 #include "PhysicsList.hh" >> 40 #include "ActionInitialization.hh" >> 41 >> 42 #ifdef G4MULTITHREADED >> 43 #include "G4MTRunManager.hh" >> 44 #else >> 45 #include "G4RunManager.hh" >> 46 #endif 41 47 42 #include "G4DNAChemistryManager.hh" 48 #include "G4DNAChemistryManager.hh" 43 #include "G4RunManagerFactory.hh" << 44 #include "G4UIExecutive.hh" << 45 #include "G4UImanager.hh" 49 #include "G4UImanager.hh" >> 50 #include "G4UIExecutive.hh" 46 #include "G4VisExecutive.hh" 51 #include "G4VisExecutive.hh" 47 52 >> 53 #include "CommandLineParser.hh" >> 54 48 //....oooOO0OOooo........oooOO0OOooo........oo 55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 49 56 50 /* 57 /* 51 * WARNING : Geant4 was initially not intended 58 * WARNING : Geant4 was initially not intended for this kind of application 52 * This code is delivered as a prototype 59 * This code is delivered as a prototype 53 * We will be happy to hear from you, do not h 60 * We will be happy to hear from you, do not hesitate to send your feedback and 54 * communicate on the difficulties you may enc 61 * communicate on the difficulties you may encounter 55 * The user interface may change in the next r 62 * The user interface may change in the next releases since a reiteration of the 56 * code has started 63 * code has started 57 */ 64 */ 58 65 59 using namespace G4DNAPARSER; 66 using namespace G4DNAPARSER; 60 CommandLineParser* parser(0); 67 CommandLineParser* parser(0); 61 68 62 void Parse(int& argc, char** argv); 69 void Parse(int& argc, char** argv); 63 70 64 int main(int argc, char** argv) 71 int main(int argc, char** argv) 65 { 72 { 66 ////////// 73 ////////// 67 // Parse options given in commandLine 74 // Parse options given in commandLine 68 // 75 // 69 Parse(argc, argv); 76 Parse(argc, argv); 70 77 71 ////////// 78 ////////// 72 // Construct the run manager according to wh 79 // Construct the run manager according to whether MT is activated or not 73 // 80 // 74 Command* commandLine(nullptr); << 81 Command* commandLine(0); 75 82 76 auto* runManager = G4RunManagerFactory::Crea << 83 #ifdef G4MULTITHREADED 77 << 84 G4RunManager* runManager(0); 78 if ((commandLine = parser->GetCommandIfActiv << 85 if ((commandLine = parser->GetCommandIfActive("-mt"))) >> 86 { >> 87 runManager = new G4MTRunManager; 79 int nThreads = 2; 88 int nThreads = 2; 80 const G4String& option = commandLine->GetO 89 const G4String& option = commandLine->GetOption(); 81 if (option == "") { << 90 if(option == "") >> 91 { 82 nThreads = G4UIcommand::ConvertToInt(com 92 nThreads = G4UIcommand::ConvertToInt(commandLine->GetDefaultOption()); 83 } 93 } 84 else if (option == "NMAX") { << 94 else if(option == "NMAX") 85 nThreads = G4Threading::G4GetNumberOfCor << 95 { >> 96 nThreads = G4Threading::G4GetNumberOfCores(); 86 } 97 } 87 else { << 98 else >> 99 { 88 nThreads = G4UIcommand::ConvertToInt(opt 100 nThreads = G4UIcommand::ConvertToInt(option); 89 } 101 } 90 102 91 runManager->SetNumberOfThreads(nThreads); << 103 G4cout << "===== Chem2 is started with " >> 104 << ((G4MTRunManager*) runManager)->GetNumberOfThreads() >> 105 << " threads =====" << G4endl; 92 106 93 G4cout << "===== Chem2 is started with " < << 107 ((G4MTRunManager*) runManager)->SetNumberOfThreads(nThreads); 94 << " threads =====" << G4endl; << 108 } >> 109 else >> 110 { >> 111 runManager = new G4RunManager(); 95 } 112 } >> 113 #else >> 114 G4RunManager* runManager = new G4RunManager(); >> 115 #endif 96 116 97 ////////// 117 ////////// 98 // Set mandatory user initialization classes 118 // Set mandatory user initialization classes 99 // 119 // 100 DetectorConstruction* detector = new Detecto << 120 DetectorConstruction* detector = new DetectorConstruction; 101 runManager->SetUserInitialization(new Physic 121 runManager->SetUserInitialization(new PhysicsList); 102 runManager->SetUserInitialization(detector); 122 runManager->SetUserInitialization(detector); 103 runManager->SetUserInitialization(new Action 123 runManager->SetUserInitialization(new ActionInitialization()); 104 124 >> 125 // Initialize G4 kernel >> 126 runManager->Initialize(); >> 127 105 // Initialize visualization 128 // Initialize visualization 106 G4VisManager* visManager = nullptr; << 129 G4VisManager* visManager = new G4VisExecutive; >> 130 // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance. >> 131 // G4VisManager* visManager = new G4VisExecutive("Quiet"); >> 132 visManager->Initialize(); 107 133 108 // Get the pointer to the User Interface man 134 // Get the pointer to the User Interface manager 109 G4UImanager* UImanager = G4UImanager::GetUIp 135 G4UImanager* UImanager = G4UImanager::GetUIpointer(); 110 G4UIExecutive* ui(nullptr); << 136 G4UIExecutive* ui(0); 111 137 112 // interactive mode : define UI session 138 // interactive mode : define UI session 113 if ((commandLine = parser->GetCommandIfActiv << 139 if ((commandLine = parser->GetCommandIfActive("-gui"))) 114 visManager = new G4VisExecutive; << 140 { 115 visManager->Initialize(); << 141 ui = new G4UIExecutive(argc, argv, 116 << 142 commandLine->GetOption()); 117 ui = new G4UIExecutive(argc, argv, command << 143 118 << 144 if(parser->GetCommandIfActive("-novis") == 0) 119 if (parser->GetCommandIfActive("-novis") = << 145 // visualization is used by default 120 // visualization is used by default << 146 { 121 if ((commandLine = parser->GetCommandIfA << 147 if((commandLine = parser->GetCommandIfActive("-vis"))) 122 // select a visualization driver if ne << 148 // select a visualization driver if needed (e.g. HepFile) 123 UImanager->ApplyCommand(G4String("/vis << 149 { >> 150 UImanager->ApplyCommand(G4String("/vis/open ")+ >> 151 commandLine->GetOption()); 124 } 152 } 125 else { << 153 else 126 // by default OGL is used << 154 // by default OGL is used >> 155 { 127 UImanager->ApplyCommand("/vis/open OGL 156 UImanager->ApplyCommand("/vis/open OGL 800x600-0+0"); 128 } 157 } 129 UImanager->ApplyCommand("/control/execut 158 UImanager->ApplyCommand("/control/execute vis.mac"); 130 } 159 } 131 160 132 if (ui->IsGUI()) { << 161 if(ui->IsGUI()) 133 UImanager->ApplyCommand("/control/execut << 162 UImanager->ApplyCommand("/control/execute gui.mac"); 134 } << 135 } 163 } 136 else if ((commandLine = parser->GetCommandIf << 164 else 137 // to be use visualization file (= store t << 165 // to be use visualization file (= store the visualization into 138 // an external file: << 166 // an external file: 139 // ASCIITree ; DAWNFILE ; HepRepFile ; VR << 167 // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ... 140 visManager = new G4VisExecutive; << 168 { 141 visManager->Initialize(); << 169 if ((commandLine = parser->GetCommandIfActive("-vis"))) 142 << 170 { 143 ui = new G4UIExecutive(argc, argv, command << 171 UImanager->ApplyCommand(G4String("/vis/open ")+commandLine->GetOption()); 144 UImanager->ApplyCommand(G4String("/vis/ope << 172 UImanager->ApplyCommand("/control/execute vis.mac"); 145 UImanager->ApplyCommand("/control/execute << 173 } 146 } 174 } 147 << 175 148 if ((commandLine = parser->GetCommandIfActiv << 176 if ((commandLine = parser->GetCommandIfActive("-mac"))) >> 177 { 149 G4String command = "/control/execute "; 178 G4String command = "/control/execute "; 150 UImanager->ApplyCommand(command + commandL 179 UImanager->ApplyCommand(command + commandLine->GetOption()); 151 } 180 } 152 else { << 181 else >> 182 { 153 UImanager->ApplyCommand("/control/execute 183 UImanager->ApplyCommand("/control/execute beam.in"); 154 } 184 } 155 185 156 if (ui) { << 186 if ((commandLine = parser->GetCommandIfActive("-gui"))) >> 187 { 157 ui->SessionStart(); 188 ui->SessionStart(); 158 delete ui; 189 delete ui; 159 } 190 } >> 191 160 // Job termination 192 // Job termination 161 // Free the store: user actions, physics_lis 193 // Free the store: user actions, physics_list and detector_description are 162 // owned and deleted by the run manager, so 194 // owned and deleted by the run manager, so they should not be deleted 163 // in the main() program ! 195 // in the main() program ! 164 196 165 delete visManager; 197 delete visManager; 166 delete runManager; 198 delete runManager; 167 199 168 CommandLineParser::DeleteInstance(); 200 CommandLineParser::DeleteInstance(); 169 201 170 return 0; 202 return 0; 171 } 203 } 172 204 173 void Parse(int& argc, char** argv) 205 void Parse(int& argc, char** argv) 174 { 206 { 175 ////////// 207 ////////// 176 // Parse options given in commandLine 208 // Parse options given in commandLine 177 // 209 // 178 parser = CommandLineParser::GetParser(); 210 parser = CommandLineParser::GetParser(); >> 211 >> 212 parser->AddCommand("-gui", >> 213 Command::OptionNotCompulsory, >> 214 "Select geant4 UI or just launch a geant4 terminal session", >> 215 "qt"); >> 216 >> 217 parser->AddCommand("-mac", >> 218 Command::WithOption, >> 219 "Give a mac file to execute", >> 220 "macFile.mac"); >> 221 >> 222 // You cann your own command, as for instance: >> 223 // parser->AddCommand("-seed", >> 224 // Command::WithOption, >> 225 // "Give a seed value in argument to be tested", "seed"); >> 226 // it is then up to you to manage this option 179 227 180 parser->AddCommand("-gui", Command::OptionNo << 228 #ifdef G4MULTITHREADED 181 "Select geant4 UI or just << 182 << 183 parser->AddCommand("-mac", Command::WithOpti << 184 << 185 // You cann your own command, as for instanc << 186 // parser->AddCommand("-seed", << 187 // Command::WithOption, << 188 // "Give a seed value in << 189 // it is then up to you to manage this optio << 190 << 191 parser->AddCommand("-mt", Command::OptionNot 229 parser->AddCommand("-mt", Command::OptionNotCompulsory, 192 "Launch in MT mode (event 230 "Launch in MT mode (events computed in parallel," 193 " NOT RECOMMANDED WITH CH 231 " NOT RECOMMANDED WITH CHEMISTRY)", 194 "2"); 232 "2"); >> 233 #endif 195 234 196 parser->AddCommand("-chemOFF", Command::With << 235 parser->AddCommand("-chemOFF", 197 << 236 Command::WithoutOption, 198 parser->AddCommand("-vis", Command::WithOpti << 237 "Deactivate chemistry"); >> 238 >> 239 parser->AddCommand("-vis", >> 240 Command::WithOption, >> 241 "Select a visualization driver", 199 "OGL 600x600-0+0"); 242 "OGL 600x600-0+0"); 200 243 201 parser->AddCommand("-novis", Command::Withou << 244 parser->AddCommand("-novis", >> 245 Command::WithoutOption, >> 246 "Deactivate visualization when using GUI"); 202 247 203 ////////// 248 ////////// 204 // If -h or --help is given in option : prin 249 // If -h or --help is given in option : print help and exit 205 // 250 // 206 if (parser->Parse(argc, argv) != 0) // help << 251 if (parser->Parse(argc, argv) != 0) // help is being printed 207 { 252 { 208 // if you are using ROOT, create a TApplic 253 // if you are using ROOT, create a TApplication in this condition in order 209 // to print the help from ROOT as well 254 // to print the help from ROOT as well 210 CommandLineParser::DeleteInstance(); 255 CommandLineParser::DeleteInstance(); 211 std::exit(0); 256 std::exit(0); 212 } 257 } 213 258 214 /////////// 259 /////////// 215 // Kill application if wrong argument in com 260 // Kill application if wrong argument in command line 216 // 261 // 217 if (parser->CheckIfNotHandledOptionsExists(a << 262 if (parser->CheckIfNotHandledOptionsExists(argc, argv)) >> 263 { 218 // if you are using ROOT, you should initi 264 // if you are using ROOT, you should initialise your TApplication 219 // before this condition 265 // before this condition 220 abort(); 266 abort(); 221 } 267 } 222 } 268 } 223 269