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 // 33 // 34 /// \file chem2.cc 34 /// \file chem2.cc 35 /// \brief Chem2 example 35 /// \brief Chem2 example 36 36 37 #include "ActionInitialization.hh" << 38 #include "CommandLineParser.hh" << 39 #include "DetectorConstruction.hh" 37 #include "DetectorConstruction.hh" 40 #include "PhysicsList.hh" 38 #include "PhysicsList.hh" >> 39 #include "ActionInitialization.hh" 41 40 42 #include "G4DNAChemistryManager.hh" << 43 #include "G4RunManagerFactory.hh" 41 #include "G4RunManagerFactory.hh" 44 #include "G4UIExecutive.hh" << 42 >> 43 #include "G4DNAChemistryManager.hh" 45 #include "G4UImanager.hh" 44 #include "G4UImanager.hh" >> 45 #include "G4UIExecutive.hh" 46 #include "G4VisExecutive.hh" 46 #include "G4VisExecutive.hh" 47 47 >> 48 #include "CommandLineParser.hh" >> 49 48 //....oooOO0OOooo........oooOO0OOooo........oo 50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 49 51 50 /* 52 /* 51 * WARNING : Geant4 was initially not intended 53 * WARNING : Geant4 was initially not intended for this kind of application 52 * This code is delivered as a prototype 54 * This code is delivered as a prototype 53 * We will be happy to hear from you, do not h 55 * We will be happy to hear from you, do not hesitate to send your feedback and 54 * communicate on the difficulties you may enc 56 * communicate on the difficulties you may encounter 55 * The user interface may change in the next r 57 * The user interface may change in the next releases since a reiteration of the 56 * code has started 58 * code has started 57 */ 59 */ 58 60 59 using namespace G4DNAPARSER; 61 using namespace G4DNAPARSER; 60 CommandLineParser* parser(0); 62 CommandLineParser* parser(0); 61 63 62 void Parse(int& argc, char** argv); 64 void Parse(int& argc, char** argv); 63 65 64 int main(int argc, char** argv) 66 int main(int argc, char** argv) 65 { 67 { 66 ////////// 68 ////////// 67 // Parse options given in commandLine 69 // Parse options given in commandLine 68 // 70 // 69 Parse(argc, argv); 71 Parse(argc, argv); 70 72 71 ////////// 73 ////////// 72 // Construct the run manager according to wh 74 // Construct the run manager according to whether MT is activated or not 73 // 75 // 74 Command* commandLine(nullptr); 76 Command* commandLine(nullptr); 75 77 76 auto* runManager = G4RunManagerFactory::Crea 78 auto* runManager = G4RunManagerFactory::CreateRunManager(); 77 79 78 if ((commandLine = parser->GetCommandIfActiv << 80 if ((commandLine = parser->GetCommandIfActive("-mt"))) >> 81 { 79 int nThreads = 2; 82 int nThreads = 2; 80 const G4String& option = commandLine->GetO 83 const G4String& option = commandLine->GetOption(); 81 if (option == "") { << 84 if(option == "") >> 85 { 82 nThreads = G4UIcommand::ConvertToInt(com 86 nThreads = G4UIcommand::ConvertToInt(commandLine->GetDefaultOption()); 83 } 87 } 84 else if (option == "NMAX") { << 88 else if(option == "NMAX") >> 89 { 85 nThreads = G4Threading::G4GetNumberOfCor 90 nThreads = G4Threading::G4GetNumberOfCores(); 86 } 91 } 87 else { << 92 else >> 93 { 88 nThreads = G4UIcommand::ConvertToInt(opt 94 nThreads = G4UIcommand::ConvertToInt(option); 89 } 95 } 90 96 91 runManager->SetNumberOfThreads(nThreads); 97 runManager->SetNumberOfThreads(nThreads); 92 98 93 G4cout << "===== Chem2 is started with " < 99 G4cout << "===== Chem2 is started with " << runManager->GetNumberOfThreads() 94 << " threads =====" << G4endl; 100 << " threads =====" << G4endl; 95 } 101 } 96 102 97 ////////// 103 ////////// 98 // Set mandatory user initialization classes 104 // Set mandatory user initialization classes 99 // 105 // 100 DetectorConstruction* detector = new Detecto 106 DetectorConstruction* detector = new DetectorConstruction(); 101 runManager->SetUserInitialization(new Physic 107 runManager->SetUserInitialization(new PhysicsList); 102 runManager->SetUserInitialization(detector); 108 runManager->SetUserInitialization(detector); 103 runManager->SetUserInitialization(new Action 109 runManager->SetUserInitialization(new ActionInitialization()); 104 110 105 // Initialize visualization 111 // Initialize visualization 106 G4VisManager* visManager = nullptr; 112 G4VisManager* visManager = nullptr; 107 113 108 // Get the pointer to the User Interface man 114 // Get the pointer to the User Interface manager 109 G4UImanager* UImanager = G4UImanager::GetUIp 115 G4UImanager* UImanager = G4UImanager::GetUIpointer(); 110 G4UIExecutive* ui(nullptr); 116 G4UIExecutive* ui(nullptr); 111 117 112 // interactive mode : define UI session 118 // interactive mode : define UI session 113 if ((commandLine = parser->GetCommandIfActiv << 119 if ((commandLine = parser->GetCommandIfActive("-gui"))) >> 120 { 114 visManager = new G4VisExecutive; 121 visManager = new G4VisExecutive; 115 visManager->Initialize(); 122 visManager->Initialize(); 116 123 117 ui = new G4UIExecutive(argc, argv, command 124 ui = new G4UIExecutive(argc, argv, commandLine->GetOption()); 118 125 119 if (parser->GetCommandIfActive("-novis") = << 126 if(parser->GetCommandIfActive("-novis") == 0) >> 127 { 120 // visualization is used by default 128 // visualization is used by default 121 if ((commandLine = parser->GetCommandIfA << 129 if((commandLine = parser->GetCommandIfActive("-vis"))) >> 130 { 122 // select a visualization driver if ne 131 // select a visualization driver if needed (e.g. HepFile) 123 UImanager->ApplyCommand(G4String("/vis << 132 UImanager->ApplyCommand(G4String("/vis/open ")+ >> 133 commandLine->GetOption()); 124 } 134 } 125 else { << 135 else >> 136 { 126 // by default OGL is used 137 // by default OGL is used 127 UImanager->ApplyCommand("/vis/open OGL 138 UImanager->ApplyCommand("/vis/open OGL 800x600-0+0"); 128 } 139 } 129 UImanager->ApplyCommand("/control/execut 140 UImanager->ApplyCommand("/control/execute vis.mac"); 130 } 141 } 131 142 132 if (ui->IsGUI()) { << 143 if(ui->IsGUI()) >> 144 { 133 UImanager->ApplyCommand("/control/execut 145 UImanager->ApplyCommand("/control/execute gui.mac"); 134 } 146 } 135 } 147 } 136 else if ((commandLine = parser->GetCommandIf << 148 else if ((commandLine = parser->GetCommandIfActive("-vis"))) >> 149 { 137 // to be use visualization file (= store t 150 // to be use visualization file (= store the visualization into 138 // an external file: 151 // an external file: 139 // ASCIITree ; DAWNFILE ; HepRepFile ; VR 152 // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ... 140 visManager = new G4VisExecutive; 153 visManager = new G4VisExecutive; 141 visManager->Initialize(); 154 visManager->Initialize(); 142 155 143 ui = new G4UIExecutive(argc, argv, command 156 ui = new G4UIExecutive(argc, argv, commandLine->GetOption()); 144 UImanager->ApplyCommand(G4String("/vis/ope << 157 UImanager->ApplyCommand(G4String("/vis/open ")+commandLine->GetOption()); 145 UImanager->ApplyCommand("/control/execute 158 UImanager->ApplyCommand("/control/execute vis.mac"); 146 } 159 } 147 160 148 if ((commandLine = parser->GetCommandIfActiv << 161 if ((commandLine = parser->GetCommandIfActive("-mac"))) >> 162 { 149 G4String command = "/control/execute "; 163 G4String command = "/control/execute "; 150 UImanager->ApplyCommand(command + commandL 164 UImanager->ApplyCommand(command + commandLine->GetOption()); 151 } 165 } 152 else { << 166 else >> 167 { 153 UImanager->ApplyCommand("/control/execute 168 UImanager->ApplyCommand("/control/execute beam.in"); 154 } 169 } 155 170 156 if (ui) { << 171 if(ui) >> 172 { 157 ui->SessionStart(); 173 ui->SessionStart(); 158 delete ui; 174 delete ui; 159 } 175 } 160 // Job termination 176 // Job termination 161 // Free the store: user actions, physics_lis 177 // Free the store: user actions, physics_list and detector_description are 162 // owned and deleted by the run manager, so 178 // owned and deleted by the run manager, so they should not be deleted 163 // in the main() program ! 179 // in the main() program ! 164 180 165 delete visManager; 181 delete visManager; 166 delete runManager; 182 delete runManager; 167 183 168 CommandLineParser::DeleteInstance(); 184 CommandLineParser::DeleteInstance(); 169 185 170 return 0; 186 return 0; 171 } 187 } 172 188 173 void Parse(int& argc, char** argv) 189 void Parse(int& argc, char** argv) 174 { 190 { 175 ////////// 191 ////////// 176 // Parse options given in commandLine 192 // Parse options given in commandLine 177 // 193 // 178 parser = CommandLineParser::GetParser(); 194 parser = CommandLineParser::GetParser(); 179 195 180 parser->AddCommand("-gui", Command::OptionNo << 196 parser->AddCommand("-gui", 181 "Select geant4 UI or just << 197 Command::OptionNotCompulsory, 182 << 198 "Select geant4 UI or just launch a geant4 terminal session", 183 parser->AddCommand("-mac", Command::WithOpti << 199 "qt"); 184 << 200 185 // You cann your own command, as for instanc << 201 parser->AddCommand("-mac", 186 // parser->AddCommand("-seed", << 202 Command::WithOption, 187 // Command::WithOption, << 203 "Give a mac file to execute", 188 // "Give a seed value in << 204 "macFile.mac"); 189 // it is then up to you to manage this optio << 205 >> 206 // You cann your own command, as for instance: >> 207 // parser->AddCommand("-seed", >> 208 // Command::WithOption, >> 209 // "Give a seed value in argument to be tested", "seed"); >> 210 // it is then up to you to manage this option 190 211 191 parser->AddCommand("-mt", Command::OptionNot 212 parser->AddCommand("-mt", Command::OptionNotCompulsory, 192 "Launch in MT mode (event 213 "Launch in MT mode (events computed in parallel," 193 " NOT RECOMMANDED WITH CH 214 " NOT RECOMMANDED WITH CHEMISTRY)", 194 "2"); 215 "2"); 195 216 196 parser->AddCommand("-chemOFF", Command::With << 217 parser->AddCommand("-chemOFF", 197 << 218 Command::WithoutOption, 198 parser->AddCommand("-vis", Command::WithOpti << 219 "Deactivate chemistry"); >> 220 >> 221 parser->AddCommand("-vis", >> 222 Command::WithOption, >> 223 "Select a visualization driver", 199 "OGL 600x600-0+0"); 224 "OGL 600x600-0+0"); 200 225 201 parser->AddCommand("-novis", Command::Withou << 226 parser->AddCommand("-novis", >> 227 Command::WithoutOption, >> 228 "Deactivate visualization when using GUI"); 202 229 203 ////////// 230 ////////// 204 // If -h or --help is given in option : prin 231 // If -h or --help is given in option : print help and exit 205 // 232 // 206 if (parser->Parse(argc, argv) != 0) // help << 233 if (parser->Parse(argc, argv) != 0) // help is being printed 207 { 234 { 208 // if you are using ROOT, create a TApplic 235 // if you are using ROOT, create a TApplication in this condition in order 209 // to print the help from ROOT as well 236 // to print the help from ROOT as well 210 CommandLineParser::DeleteInstance(); 237 CommandLineParser::DeleteInstance(); 211 std::exit(0); 238 std::exit(0); 212 } 239 } 213 240 214 /////////// 241 /////////// 215 // Kill application if wrong argument in com 242 // Kill application if wrong argument in command line 216 // 243 // 217 if (parser->CheckIfNotHandledOptionsExists(a << 244 if (parser->CheckIfNotHandledOptionsExists(argc, argv)) >> 245 { 218 // if you are using ROOT, you should initi 246 // if you are using ROOT, you should initialise your TApplication 219 // before this condition 247 // before this condition 220 abort(); 248 abort(); 221 } 249 } 222 } 250 } 223 251