Geant4  10.03
OpNovice.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 //
28 //
29 //
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 //
34 // Description: Test of Continuous Process G4Cerenkov
35 // and RestDiscrete Process G4Scintillation
36 // -- Generation Cerenkov Photons --
37 // -- Generation Scintillation Photons --
38 // -- Transport of optical Photons --
39 // Version: 5.0
40 // Created: 1996-04-30
41 // Author: Juliet Armstrong
42 // mail: gum@triumf.ca
43 //
44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
45 
46 #ifdef G4MULTITHREADED
47 #include "G4MTRunManager.hh"
48 #else
49 #include "G4RunManager.hh"
50 #endif
51 
52 #include "G4UImanager.hh"
53 
54 #include "OpNovicePhysicsList.hh"
56 
58 
59 #ifdef G4VIS_USE
60 #include "G4VisExecutive.hh"
61 #endif
62 
63 #ifdef G4UI_USE
64 #include "G4UIExecutive.hh"
65 #endif
66 
67 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
68 namespace {
69  void PrintUsage() {
70  G4cerr << " Usage: " << G4endl;
71  G4cerr << " OpNovice [-m macro ] [-u UIsession] [-t nThreads] [-r seed] "
72  << G4endl;
73  G4cerr << " note: -t option is available only for multi-threaded mode."
74  << G4endl;
75  }
76 }
77 
78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
79 
80 int main(int argc,char** argv)
81 {
82  // Evaluate arguments
83  //
84  if ( argc > 9 ) {
85  PrintUsage();
86  return 1;
87  }
88 
89  G4String macro;
91 #ifdef G4MULTITHREADED
92  G4int nThreads = 0;
93 #endif
94 
95  G4long myseed = 345354;
96  for ( G4int i=1; i<argc; i=i+2 ) {
97  if ( G4String(argv[i]) == "-m" ) macro = argv[i+1];
98  else if ( G4String(argv[i]) == "-u" ) session = argv[i+1];
99  else if ( G4String(argv[i]) == "-r" ) myseed = atoi(argv[i+1]);
100 #ifdef G4MULTITHREADED
101  else if ( G4String(argv[i]) == "-t" ) {
102  nThreads = G4UIcommand::ConvertToInt(argv[i+1]);
103  }
104 #endif
105  else {
106  PrintUsage();
107  return 1;
108  }
109  }
110 
111  // Choose the Random engine
112  //
113  G4Random::setTheEngine(new CLHEP::RanecuEngine);
114 
115  // Construct the default run manager
116  //
117 #ifdef G4MULTITHREADED
118  G4MTRunManager * runManager = new G4MTRunManager;
119  if ( nThreads > 0 ) runManager->SetNumberOfThreads(nThreads);
120 #else
121  G4RunManager * runManager = new G4RunManager;
122 #endif
123 
124  // Seed the random number generator manually
125  G4Random::setTheSeed(myseed);
126 
127  // Set mandatory initialization classes
128  //
129  // Detector construction
130  runManager-> SetUserInitialization(new OpNoviceDetectorConstruction());
131  // Physics list
132  runManager-> SetUserInitialization(new OpNovicePhysicsList());
133  // User action initialization
135 
136  // Initialize G4 kernel
137  //
138  runManager->Initialize();
139 
140 #ifdef G4VIS_USE
141  // Initialize visualization
142  //
143  G4VisManager* visManager = new G4VisExecutive;
144  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
145  // G4VisManager* visManager = new G4VisExecutive("Quiet");
146  visManager->Initialize();
147 #endif
148 
149  // Get the pointer to the User Interface manager
150  //
151  G4UImanager* UImanager = G4UImanager::GetUIpointer();
152 
153  if ( macro.size() ) {
154  // Batch mode
155  G4String command = "/control/execute ";
156  UImanager->ApplyCommand(command+macro);
157  }
158  else // Define UI session for interactive mode
159  {
160 #ifdef G4UI_USE
161  G4UIExecutive * ui = new G4UIExecutive(argc,argv,session);
162 #ifdef G4VIS_USE
163  UImanager->ApplyCommand("/control/execute vis.mac");
164 #else
165  UImanager->ApplyCommand("/control/execute OpNovice.in");
166 #endif
167  if (ui->IsGUI())
168  UImanager->ApplyCommand("/control/execute gui.mac");
169  ui->SessionStart();
170  delete ui;
171 #endif
172  }
173 
174  // Job termination
175  // Free the store: user actions, physics_list and detector_description are
176  // owned and deleted by the run manager, so they should not
177  // be deleted in the main() program !
178 
179 #ifdef G4VIS_USE
180  delete visManager;
181 #endif
182  delete runManager;
183 
184  return 0;
185 }
186 
187 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
void SetNumberOfThreads(G4int n)
long G4long
Definition: G4Types.hh:80
int G4int
Definition: G4Types.hh:78
Definition of the OpNoviceDetectorConstruction class.
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
static G4UIterminal * session
Definition of the OpNovicePhysicsList class.
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:435
void Initialize()
Definition of the OpNoviceActionInitialization class.
virtual void Initialize()
#define G4endl
Definition: G4ios.hh:61
int main(int argc, char **argv)
Definition: OpNovice.cc:80
G4bool IsGUI() const
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:446
G4GLOB_DLL std::ostream G4cerr