Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
field06.cc
Go to the documentation of this file.
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 // $Id: field06.cc 75572 2013-11-04 11:46:08Z gcosmo $
27 //
28 /// \file field/field06/field06.cc
29 /// \brief Main program of the field/field06 example
30 //
31 //
32 //
33 //
34 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
35 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
36 
37 #ifndef WIN32
38 #include <unistd.h>
39 #endif
40 
41 #include "F06PhysicsList.hh"
44 
45 #ifdef G4MULTITHREADED
46 #include "G4MTRunManager.hh"
47 #else
48 #include "G4RunManager.hh"
49 #endif
50 
51 #include "G4UImanager.hh"
52 #include "G4UIcommand.hh"
53 
54 #include "Randomize.hh"
55 
56 #ifdef G4VIS_USE
57 #include "G4VisExecutive.hh"
58 #endif
59 
60 #ifdef G4UI_USE
61 #include "G4UIExecutive.hh"
62 #endif
63 
64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
65 namespace {
66  void PrintUsage() {
67  G4cerr << " Usage: " << G4endl;
68  G4cerr << " field06 [-m macro ] [-u UIsession] [-t nThreads] [-r seed] "
69  << G4endl;
70  G4cerr << " note: -t option is available only for multi-threaded mode."
71  << G4endl;
72  }
73 }
74 
75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
76 
77 int main(int argc,char** argv)
78 {
79  // Evaluate arguments
80  //
81  if ( argc > 9 ) {
82  PrintUsage();
83  return 1;
84  }
85 
86  G4String macro;
87  G4String session;
88 #ifdef G4MULTITHREADED
89  G4int nThreads = 0;
90 #endif
91 
92  G4long myseed = 1234;
93  for ( G4int i=1; i<argc; i=i+2 ) {
94  if ( G4String(argv[i]) == "-m" ) macro = argv[i+1];
95  else if ( G4String(argv[i]) == "-u" ) session = argv[i+1];
96  else if ( G4String(argv[i]) == "-r" ) myseed = atoi(argv[i+1]);
97 #ifdef G4MULTITHREADED
98  else if ( G4String(argv[i]) == "-t" ) {
99  nThreads = G4UIcommand::ConvertToInt(argv[i+1]);
100  }
101 #endif
102  else {
103  PrintUsage();
104  return 1;
105  }
106  }
107 
108  // Choose the Random engine
109  //
110  G4Random::setTheEngine(new CLHEP::RanecuEngine);
111 
112  // Construct the default run manager
113  //
114 #ifdef G4MULTITHREADED
115  G4MTRunManager * runManager = new G4MTRunManager;
116  if ( nThreads > 0 ) runManager->SetNumberOfThreads(nThreads);
117 #else
118  G4RunManager * runManager = new G4RunManager;
119 #endif
120 
121  // Seed the random number generator manually
122  G4Random::setTheSeed(myseed);
123 
124  // Set mandatory initialization classes
125  //
126  // Detector construction
128  // Physics list
129  runManager->SetUserInitialization(new F06PhysicsList());
130  // User action initialization
132 
133  // Initialize G4 kernel
134  //
135  runManager->Initialize();
136 
137 #ifdef G4VIS_USE
138  // Initialize visualization
139  //
140  G4VisManager* visManager = new G4VisExecutive;
141  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
142  // G4VisManager* visManager = new G4VisExecutive("Quiet");
143  visManager->Initialize();
144 #endif
145 
146  // Get the pointer to the User Interface manager
147  //
148  G4UImanager* UImanager = G4UImanager::GetUIpointer();
149 
150  if ( macro.size() ) {
151  // batch mode
152  G4String command = "/control/execute ";
153  UImanager->ApplyCommand(command+macro);
154  }
155  else
156  { // interactive mode : define UI session
157 #ifdef G4UI_USE
158  G4UIExecutive* ui = new G4UIExecutive(argc, argv, session);
159 #ifdef G4VIS_USE
160  UImanager->ApplyCommand("/control/execute vis.mac");
161 #else
162  UImanager->ApplyCommand("/control/execute field06.in");
163 #endif
164  if (ui->IsGUI())
165  UImanager->ApplyCommand("/control/execute gui.mac");
166  ui->SessionStart();
167  delete ui;
168 #endif
169  }
170 
171  // Job termination
172  // Free the store: user actions, physics_list and detector_description are
173  // owned and deleted by the run manager, so they should not
174  // be deleted in the main() program !
175 
176 #ifdef G4VIS_USE
177  delete visManager;
178 #endif
179  delete runManager;
180 
181  return 0;
182 }
183 
184 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
Action initialization class.
void SetNumberOfThreads(G4int n)
int main(int argc, char **argv)
Definition: field06.cc:77
long G4long
Definition: G4Types.hh:80
int G4int
Definition: G4Types.hh:78
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
Definition of the F06DetectorConstruction class.
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:421
void Initialize()
Definition of the F06PhysicsList class.
Definition of the F06ActionInitialization class.
virtual void Initialize()
#define G4endl
Definition: G4ios.hh:61
G4bool IsGUI() const
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:419
G4GLOB_DLL std::ostream G4cerr