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 /// \file g3tog4/clGeometry/clGeometry.cc << 27 /// \brief Main program of the g3tog4/clGeomet << 28 // << 29 // << 30 // 26 // >> 27 // $Id: clGeometry.cc,v 1.7 2006/06/29 17:20:00 gunter Exp $ >> 28 // GEANT4 tag $Name: geant4-09-01-patch-01 $ 31 // 29 // >> 30 // >> 31 >> 32 // controls whether drawing is to be Done or not >> 33 >> 34 #include <fstream> >> 35 #include <cmath> >> 36 #include "G4ios.hh" 32 37 33 // package includes 38 // package includes 34 #include "G3toG4ActionInitialization.hh" << 39 35 #include "G3toG4DetectorConstruction.hh" 40 #include "G3toG4DetectorConstruction.hh" >> 41 #include "G3toG4RunAction.hh" >> 42 #include "G3toG4PrimaryGeneratorAction.hh" >> 43 #include "G3toG4PhysicsList.hh" >> 44 #include "G3toG4EventAction.hh" >> 45 #include "G4LogicalVolume.hh" >> 46 #include "G3VolTable.hh" 36 47 37 // geant4 includes 48 // geant4 includes 38 #include "FTFP_BERT.hh" << 39 #include "G3VolTable.hh" << 40 49 41 #include "G4RunManagerFactory.hh" << 50 #include "G4RunManager.hh" 42 #include "G4UIExecutive.hh" << 43 #include "G4UImanager.hh" 51 #include "G4UImanager.hh" 44 #include "G4VisExecutive.hh" << 52 #include "G4UIterminal.hh" 45 #include "G4ios.hh" << 46 << 47 //....oooOO0OOooo........oooOO0OOooo........oo << 48 << 49 namespace << 50 { << 51 void PrintUsage() << 52 { << 53 G4cerr << " Usage: " << G4endl; << 54 G4cerr << "clGeometry <call_list_file> [-m m << 55 G4cerr << " note: -t option is relevant on << 56 } << 57 } // namespace << 58 53 59 //....oooOO0OOooo........oooOO0OOooo........oo << 54 // visualization >> 55 #ifdef G4VIS_USE >> 56 #include "G4VisExecutive.hh" >> 57 #endif 60 58 61 int main(int argc, char** argv) 59 int main(int argc, char** argv) 62 { 60 { 63 // Evaluate arguments << 64 // << 65 G4cout << "argc " << argc << G4endl; << 66 if (argc < 2 || argc > 8) { << 67 PrintUsage(); << 68 return 1; << 69 } << 70 << 71 G4String inFile; 61 G4String inFile; 72 G4String macro = ""; << 62 G4String macroFile = ""; 73 G4String session; << 63 74 G4int nofThreads = 0; << 64 if (argc < 2) { 75 << 65 G4cerr << "clGeometry: Correct syntax: clGeometry <call_list_file> [ <macro_file> ]" 76 // First argument is mandatory << 66 << G4endl; 77 inFile = argv[1]; << 67 G4cerr << "If only one argument is specified, interactive mode will be " 78 G4cout << "Geometry data file: " << inFile < << 68 << "entered." << G4endl << "The second argument, if specified, is " 79 std::ifstream in(inFile); << 69 << "the name of the macro file (batch mode)." << G4endl; 80 if (!in) { << 70 81 G4cerr << "Cannot open input file \"" << i << 82 return EXIT_FAILURE; 71 return EXIT_FAILURE; 83 } 72 } 84 << 73 if (argc >= 2) { 85 // Optional arguments << 74 // Process the command line 86 for (G4int i = 2; i < argc; i = i + 2) { << 75 inFile = argv[1]; 87 G4cout << "evaluating " << argv[i] << G4en << 76 std::ifstream in(inFile); 88 if (G4String(argv[i]) == "-m") << 77 if (!in) { 89 macro = argv[i + 1]; << 78 G4cerr << "Cannot open input file \"" << inFile << "\"" << G4endl; 90 else if (G4String(argv[i]) == "-u") << 79 return EXIT_FAILURE; 91 session = argv[i + 1]; << 92 else if (G4String(argv[i]) == "-t") { << 93 nofThreads = G4UIcommand::ConvertToInt(a << 94 } 80 } 95 else { << 81 } 96 PrintUsage(); << 82 if (argc >= 3) { 97 return 1; << 83 macroFile = argv[2]; >> 84 std::ifstream mac(macroFile); >> 85 if (!mac) { >> 86 G4cout << "Cannot open macro file """ << macroFile << """" << G4endl; >> 87 return 2; 98 } 88 } 99 } 89 } 100 << 90 if (argc >= 4) { 101 // Detect interactive mode (if no macro prov << 91 G4cerr << "Too many command line arguments (" << argc <<")" << G4endl; 102 // << 92 return EXIT_FAILURE; 103 G4UIExecutive* ui = nullptr; << 104 if (!macro.size()) { << 105 ui = new G4UIExecutive(argc, argv, session << 106 } 93 } 107 << 94 108 // Construct the default run manager 95 // Construct the default run manager 109 auto* runManager = G4RunManagerFactory::Crea << 96 G4RunManager* RunManager = new G4RunManager; 110 if (nofThreads > 0) runManager->SetNumberOfT << 97 111 << 98 // set mandatory initialization classes 112 // Set mandatory initialization classes << 99 RunManager->SetUserInitialization(new G3toG4DetectorConstruction(inFile)); 113 // << 100 114 // Detector construction << 101 G3toG4PhysicsList* thePhysicsList = new G3toG4PhysicsList; 115 runManager->SetUserInitialization(new G3toG4 << 102 116 << 103 // set verbosity of PhysicsList 117 // Physics list << 104 thePhysicsList->SetVerboseLevel(2); 118 runManager->SetUserInitialization(new FTFP_B << 105 RunManager->SetUserInitialization(thePhysicsList); 119 << 106 120 // User action initialization << 107 //---------------- 121 runManager->SetUserInitialization(new G3toG4 << 108 // Visualization: 122 << 109 //---------------- 123 // Initialize visualization << 110 124 // << 111 #ifdef G4VIS_USE 125 auto visManager = new G4VisExecutive; << 112 G4VisManager* VisManager = new G4VisExecutive; 126 // G4VisExecutive can take a verbosity argum << 113 VisManager -> Initialize(); 127 // G4VisManager* visManager = new G4VisExecu << 114 #endif 128 visManager->Initialize(); << 115 129 << 116 // set user action classes 130 // Get the pointer to the User Interface man << 117 131 auto UImanager = G4UImanager::GetUIpointer() << 118 RunManager->SetUserAction(new G3toG4RunAction); 132 << 119 133 // Process macro or start UI session << 120 G3toG4EventAction* theEventAction = new G3toG4EventAction; 134 // << 121 theEventAction->SetDrawFlag("all"); 135 if (macro.size()) { << 122 RunManager->SetUserAction(theEventAction); 136 // batch mode << 123 137 G4String command = "/control/execute "; << 124 RunManager->SetUserAction(new G3toG4PrimaryGeneratorAction); 138 UImanager->ApplyCommand(command + macro); << 125 >> 126 // the pointer to the User Interface manager >> 127 G4UImanager* UI = G4UImanager::GetUIpointer(); >> 128 >> 129 // set some additional defaults and initial actions >> 130 >> 131 UI->ApplyCommand("/control/verbose 1"); >> 132 UI->ApplyCommand("/run/verbose 1"); >> 133 UI->ApplyCommand("/tracking/verbose 1"); >> 134 UI->ApplyCommand("/tracking/storeTrajectory 1"); >> 135 UI->ApplyCommand("/run/initialize"); >> 136 >> 137 G4bool batch_mode = macroFile != ""; >> 138 >> 139 if(!batch_mode) { >> 140 G4UIsession * session = new G4UIterminal; >> 141 if (session != 0) { >> 142 session->SessionStart(); >> 143 delete session; >> 144 // G4cout << "deleted G4UITerminal..." << G4endl; >> 145 } 139 } 146 } 140 else { 147 else { 141 // interactive mode : define UI session << 148 // Batch mode 142 UImanager->ApplyCommand("/control/execute << 149 G4String command = "/control/execute "; 143 ui->SessionStart(); << 150 UI->ApplyCommand(command+macroFile); 144 delete ui; << 145 } 151 } >> 152 #ifdef G4VIS_USE >> 153 if (VisManager !=0) delete VisManager; >> 154 #endif >> 155 delete RunManager; >> 156 return EXIT_SUCCESS; >> 157 } >> 158 >> 159 >> 160 >> 161 >> 162 >> 163 >> 164 >> 165 >> 166 >> 167 >> 168 >> 169 >> 170 >> 171 >> 172 >> 173 >> 174 >> 175 >> 176 >> 177 >> 178 >> 179 >> 180 146 181 147 // Job termination << 148 // Free the store: user actions, physics_lis << 149 // owned and deleted by the run manager, so << 150 // in the main() program ! << 151 182 152 delete visManager; << 153 delete runManager; << 154 } << 155 183