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