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 // The Geant4-DNA web site is available at http://geant4-dna.org 31 // 32 // 33 /// \file clustering.cc 34 /// \brief clustering example 35 36 #include "ActionInitialization.hh" 37 #include "CommandLineParser.hh" 38 #include "DetectorConstruction.hh" 39 #include "PhysicsList.hh" 40 41 #include "G4DNAChemistryManager.hh" 42 #include "G4RunManagerFactory.hh" 43 #include "G4UIExecutive.hh" 44 #include "G4UImanager.hh" 45 #include "G4VisExecutive.hh" 46 47 using namespace G4DNAPARSER; 48 CommandLineParser* parser(0); 49 50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 51 52 void Parse(int& argc, char** argv); 53 54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 55 56 int main(int argc, char** argv) 57 { 58 ////////// 59 // Parse options given in commandLine 60 // 61 Parse(argc, argv); 62 63 ////////// 64 // Construct the run manager according to whether MT is activated or not 65 // 66 Command* commandLine(0); 67 68 auto* runManager = G4RunManagerFactory::CreateRunManager(); 69 if ((commandLine = parser->GetCommandIfActive("-mt"))) { 70 int nThreads = 2; 71 if (commandLine->GetOption() == "NMAX") { 72 nThreads = G4Threading::G4GetNumberOfCores(); 73 } 74 else { 75 nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption()); 76 } 77 runManager->SetNumberOfThreads(nThreads); 78 79 G4cout << "===== clustering is started with " << runManager->GetNumberOfThreads() 80 << " threads =====" << G4endl; 81 } 82 83 ////////// 84 // Set mandatory user initialization classes 85 // 86 DetectorConstruction* detector = new DetectorConstruction; 87 runManager->SetUserInitialization(new PhysicsList); 88 runManager->SetUserInitialization(detector); 89 runManager->SetUserInitialization(new ActionInitialization()); 90 91 // Initialize G4 kernel 92 runManager->Initialize(); 93 94 // Initialize visualization 95 G4VisManager* visManager = new G4VisExecutive; 96 visManager->Initialize(); 97 98 // Get the pointer to the User Interface manager 99 G4UImanager* UImanager = G4UImanager::GetUIpointer(); 100 G4UIExecutive* ui(0); 101 102 // interactive mode : define UI session 103 if ((commandLine = parser->GetCommandIfActive("-gui"))) { 104 ui = new G4UIExecutive(argc, argv, commandLine->GetOption()); 105 106 if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute gui.mac"); 107 108 if (parser->GetCommandIfActive("-novis") == 0) 109 // visualization is used by default 110 { 111 if ((commandLine = parser->GetCommandIfActive("-vis"))) 112 // select a visualization driver if needed (e.g. HepFile) 113 { 114 UImanager->ApplyCommand(G4String("/vis/open ") + commandLine->GetOption()); 115 } 116 else 117 // by default OGL is used 118 { 119 UImanager->ApplyCommand("/vis/open OGL 800x600-0+0"); 120 } 121 UImanager->ApplyCommand("/control/execute vis.mac"); 122 } 123 } 124 else 125 // to be use visualization file (= store the visualization into 126 // an external file: 127 // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ... 128 { 129 if ((commandLine = parser->GetCommandIfActive("-vis"))) { 130 UImanager->ApplyCommand(G4String("/vis/open ") + commandLine->GetOption()); 131 UImanager->ApplyCommand("/control/execute vis.mac"); 132 } 133 } 134 135 if ((commandLine = parser->GetCommandIfActive("-mac"))) { 136 G4String command = "/control/execute "; 137 UImanager->ApplyCommand(command + commandLine->GetOption()); 138 } 139 else { 140 UImanager->ApplyCommand("/control/execute run.in"); 141 } 142 143 if ((commandLine = parser->GetCommandIfActive("-gui"))) { 144 ui->SessionStart(); 145 delete ui; 146 } 147 148 // Job termination 149 // Free the store: user actions, physics_list and detector_description are 150 // owned and deleted by the run manager, so they should not be deleted 151 // in the main() program ! 152 153 delete visManager; 154 delete runManager; 155 156 CommandLineParser::DeleteInstance(); 157 158 return 0; 159 } 160 161 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 162 163 void Parse(int& argc, char** argv) 164 { 165 ////////// 166 // Parse options given in commandLine 167 // 168 parser = CommandLineParser::GetParser(); 169 170 parser->AddCommand("-gui", Command::OptionNotCompulsory, 171 "Select geant4 UI or just launch a geant4 terminal session", "qt"); 172 173 parser->AddCommand("-mac", Command::WithOption, "Give a mac file to execute", "macFile.mac"); 174 175 // You cann your own command, as for instance: 176 // parser->AddCommand("-seed", 177 // Command::WithOption, 178 // "Give a seed value in argument to be tested", "seed"); 179 // it is then up to you to manage this option 180 181 parser->AddCommand("-mt", Command::WithOption, 182 "Launch in MT mode (events computed in parallel," 183 " NOT RECOMMENDED WITH CHEMISTRY)", 184 "2"); 185 186 parser->AddCommand("-vis", Command::WithOption, "Select a visualization driver", 187 "OGL 600x600-0+0"); 188 189 parser->AddCommand("-novis", Command::WithoutOption, "Deactivate visualization when using GUI"); 190 191 ////////// 192 // If -h or --help is given in option : print help and exit 193 // 194 if (parser->Parse(argc, argv) != 0) // help is being printed 195 { 196 // if you are using ROOT, create a TApplication in this condition in order 197 // to print the help from ROOT as well 198 CommandLineParser::DeleteInstance(); 199 // Exit is kept 200 std::exit(0); 201 } 202 203 /////////// 204 // Kill application if wrong argument in command line 205 // 206 if (parser->CheckIfNotHandledOptionsExists(argc, argv)) { 207 // if you are using ROOT, you should initialise your TApplication 208 // before this condition 209 abort(); 210 } 211 } 212