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