Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 /// \file g3tog4/clGeometry/clGeometry.cc << 27 /// \brief Main program of the g3tog4/clGeomet << 28 // << 29 // << 30 // 23 // >> 24 // $Id: clGeometry.cc,v 1.6 2005/06/27 15:27:39 gunter Exp $ >> 25 // GEANT4 tag $Name: geant4-07-01-patch-01 $ 31 // 26 // >> 27 // >> 28 >> 29 // controls whether drawing is to be Done or not >> 30 >> 31 #include <fstream> >> 32 #include <cmath> >> 33 #include "G4ios.hh" 32 34 33 // package includes 35 // package includes 34 #include "G3toG4ActionInitialization.hh" << 36 35 #include "G3toG4DetectorConstruction.hh" 37 #include "G3toG4DetectorConstruction.hh" >> 38 #include "G3toG4RunAction.hh" >> 39 #include "G3toG4PrimaryGeneratorAction.hh" >> 40 #include "G3toG4PhysicsList.hh" >> 41 #include "G3toG4EventAction.hh" >> 42 #include "G4LogicalVolume.hh" >> 43 #include "G3VolTable.hh" 36 44 37 // geant4 includes 45 // geant4 includes 38 #include "FTFP_BERT.hh" << 39 #include "G3VolTable.hh" << 40 46 41 #include "G4RunManagerFactory.hh" << 47 #include "G4RunManager.hh" 42 #include "G4UIExecutive.hh" << 43 #include "G4UImanager.hh" 48 #include "G4UImanager.hh" 44 #include "G4VisExecutive.hh" << 49 #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 50 59 //....oooOO0OOooo........oooOO0OOooo........oo << 51 // visualization >> 52 #ifdef G4VIS_USE >> 53 #include "G4VisExecutive.hh" >> 54 #endif 60 55 61 int main(int argc, char** argv) 56 int main(int argc, char** argv) 62 { 57 { 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; 58 G4String inFile; 72 G4String macro = ""; << 59 G4String macroFile = ""; 73 G4String session; << 60 74 G4int nofThreads = 0; << 61 if (argc < 2) { 75 << 62 G4cerr << "clGeometry: Correct syntax: clGeometry <call_list_file> [ <macro_file> ]" 76 // First argument is mandatory << 63 << G4endl; 77 inFile = argv[1]; << 64 G4cerr << "If only one argument is specified, interactive mode will be " 78 G4cout << "Geometry data file: " << inFile < << 65 << "entered." << G4endl << "The second argument, if specified, is " 79 std::ifstream in(inFile); << 66 << "the name of the macro file (batch mode)." << G4endl; 80 if (!in) { << 67 81 G4cerr << "Cannot open input file \"" << i << 82 return EXIT_FAILURE; 68 return EXIT_FAILURE; 83 } 69 } 84 << 70 if (argc >= 2) { 85 // Optional arguments << 71 // Process the command line 86 for (G4int i = 2; i < argc; i = i + 2) { << 72 inFile = argv[1]; 87 G4cout << "evaluating " << argv[i] << G4en << 73 std::ifstream in(inFile); 88 if (G4String(argv[i]) == "-m") << 74 if (!in) { 89 macro = argv[i + 1]; << 75 G4cerr << "Cannot open input file \"" << inFile << "\"" << G4endl; 90 else if (G4String(argv[i]) == "-u") << 76 return EXIT_FAILURE; 91 session = argv[i + 1]; << 92 else if (G4String(argv[i]) == "-t") { << 93 nofThreads = G4UIcommand::ConvertToInt(a << 94 } 77 } 95 else { << 78 } 96 PrintUsage(); << 79 if (argc >= 3) { 97 return 1; << 80 macroFile = argv[2]; >> 81 std::ifstream mac(macroFile); >> 82 if (!mac) { >> 83 G4cout << "Cannot open macro file """ << macroFile << """" << G4endl; >> 84 return 2; 98 } 85 } 99 } 86 } 100 << 87 if (argc >= 4) { 101 // Detect interactive mode (if no macro prov << 88 G4cerr << "Too many command line arguments (" << argc <<")" << G4endl; 102 // << 89 return EXIT_FAILURE; 103 G4UIExecutive* ui = nullptr; << 104 if (!macro.size()) { << 105 ui = new G4UIExecutive(argc, argv, session << 106 } 90 } 107 << 91 108 // Construct the default run manager 92 // Construct the default run manager 109 auto* runManager = G4RunManagerFactory::Crea << 93 G4RunManager* RunManager = new G4RunManager; 110 if (nofThreads > 0) runManager->SetNumberOfT << 94 111 << 95 // set mandatory initialization classes 112 // Set mandatory initialization classes << 96 RunManager->SetUserInitialization(new G3toG4DetectorConstruction(inFile)); 113 // << 97 114 // Detector construction << 98 G3toG4PhysicsList* thePhysicsList = new G3toG4PhysicsList; 115 runManager->SetUserInitialization(new G3toG4 << 99 116 << 100 // set verbosity of PhysicsList 117 // Physics list << 101 thePhysicsList->SetVerboseLevel(2); 118 runManager->SetUserInitialization(new FTFP_B << 102 RunManager->SetUserInitialization(thePhysicsList); 119 << 103 120 // User action initialization << 104 //---------------- 121 runManager->SetUserInitialization(new G3toG4 << 105 // Visualization: 122 << 106 //---------------- 123 // Initialize visualization << 107 124 // << 108 #ifdef G4VIS_USE 125 auto visManager = new G4VisExecutive; << 109 G4VisManager* VisManager = new G4VisExecutive; 126 // G4VisExecutive can take a verbosity argum << 110 VisManager -> Initialize(); 127 // G4VisManager* visManager = new G4VisExecu << 111 #endif 128 visManager->Initialize(); << 112 129 << 113 // set user action classes 130 // Get the pointer to the User Interface man << 114 131 auto UImanager = G4UImanager::GetUIpointer() << 115 RunManager->SetUserAction(new G3toG4RunAction); 132 << 116 133 // Process macro or start UI session << 117 G3toG4EventAction* theEventAction = new G3toG4EventAction; 134 // << 118 theEventAction->SetDrawFlag("all"); 135 if (macro.size()) { << 119 RunManager->SetUserAction(theEventAction); 136 // batch mode << 120 137 G4String command = "/control/execute "; << 121 RunManager->SetUserAction(new G3toG4PrimaryGeneratorAction); 138 UImanager->ApplyCommand(command + macro); << 122 >> 123 // the pointer to the User Interface manager >> 124 G4UImanager* UI = G4UImanager::GetUIpointer(); >> 125 >> 126 // set some additional defaults and initial actions >> 127 >> 128 UI->ApplyCommand("/control/verbose 1"); >> 129 UI->ApplyCommand("/run/verbose 1"); >> 130 UI->ApplyCommand("/tracking/verbose 1"); >> 131 UI->ApplyCommand("/tracking/storeTrajectory 1"); >> 132 UI->ApplyCommand("/run/initialize"); >> 133 >> 134 G4bool batch_mode = macroFile != ""; >> 135 >> 136 if(!batch_mode) { >> 137 G4UIsession * session = new G4UIterminal; >> 138 if (session != 0) { >> 139 session->SessionStart(); >> 140 delete session; >> 141 // G4cout << "deleted G4UITerminal..." << G4endl; >> 142 } 139 } 143 } 140 else { 144 else { 141 // interactive mode : define UI session << 145 // Batch mode 142 UImanager->ApplyCommand("/control/execute << 146 G4String command = "/control/execute "; 143 ui->SessionStart(); << 147 UI->ApplyCommand(command+macroFile); 144 delete ui; << 145 } 148 } >> 149 #ifdef G4VIS_USE >> 150 if (VisManager !=0) delete VisManager; >> 151 #endif >> 152 delete RunManager; >> 153 return EXIT_SUCCESS; >> 154 } >> 155 >> 156 >> 157 >> 158 >> 159 >> 160 >> 161 >> 162 >> 163 >> 164 >> 165 >> 166 >> 167 >> 168 >> 169 >> 170 >> 171 >> 172 >> 173 >> 174 >> 175 >> 176 >> 177 146 178 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 179 152 delete visManager; << 153 delete runManager; << 154 } << 155 180