LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
clGeometry.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 // $Id: clGeometry.cc 82227 2014-06-12 09:43:33Z gcosmo $
31 //
32 //
33 
34 // package includes
35 #include "G3toG4DetectorConstruction.hh"
36 #include "G3toG4ActionInitialization.hh"
37 
38 // geant4 includes
39 #ifdef G4MULTITHREADED
40 #include "G4MTRunManager.hh"
41 #else
42 #include "G4RunManager.hh"
43 #endif
44 
45 #include "FTFP_BERT.hh"
46 #include "G3VolTable.hh"
47 #include "G4RunManager.hh"
48 #include "G4UImanager.hh"
49 #include "G4ios.hh"
50 
51 // visualization
52 #ifdef G4VIS_USE
53 #include "G4VisExecutive.hh"
54 #endif
55 
56 // (G)UI
57 #ifdef G4UI_USE
58 #include "G4UIExecutive.hh"
59 #endif
60 
61 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
62 
63 namespace {
64  void PrintUsage() {
65  G4cerr << " Usage: " << G4endl;
66  G4cerr
67  << "clGeometry <call_list_file> [-m macro ] [-u UIsession] [-t nThreads]"
68  << G4endl;
69  G4cerr
70  << " 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  G4cout << "argc " << argc << G4endl;
82  if ( argc < 2 || argc > 8 ) {
83  PrintUsage();
84  return 1;
85  }
86 
87  G4String inFile;
88  G4String macro = "";
90 #ifdef G4MULTITHREADED
91  G4int nofThreads = 4;
92 #endif
93 
94  // First argument is mandatory
95  inFile = argv[1];
96  G4cout << "Geometry data file: " << inFile << G4endl;
97  std::ifstream in(inFile);
98  if ( ! in ) {
99  G4cerr << "Cannot open input file \"" << inFile << "\"" << G4endl;
100  return EXIT_FAILURE;
101  }
102 
103  // Optional arguments
104  for ( G4int i=2; i<argc; i=i+2 ) {
105  G4cout << "evaluating " << argv[i] << G4endl;
106  if ( G4String(argv[i]) == "-m" ) macro = argv[i+1];
107  else if ( G4String(argv[i]) == "-u" ) session = argv[i+1];
108 #ifdef G4MULTITHREADED
109  else if ( G4String(argv[i]) == "-t" ) {
110  nofThreads = G4UIcommand::ConvertToInt(argv[i+1]);
111  }
112 #endif
113  else {
114  PrintUsage();
115  return 1;
116  }
117  }
118 
119  // Construct the default run manager
120 #ifdef G4MULTITHREADED
121  G4MTRunManager* runManager = new G4MTRunManager;
122  runManager->SetNumberOfThreads(nofThreads);
123 #else
124  G4RunManager* runManager = new G4RunManager;
125 #endif
126 
127  // Set mandatory initialization classes
128  //
129  // Detector construction
130  runManager->SetUserInitialization(new G3toG4DetectorConstruction(inFile));
131 
132  // Physics list
133  runManager->SetUserInitialization(new FTFP_BERT);
134 
135  // User action initialization
136  runManager->SetUserInitialization(new G3toG4ActionInitialization());
137 
138  // Initialize G4 kernel
139  //
140  runManager->Initialize();
141 
142  //--------------------
143  // Visualization & UI
144  //--------------------
145 
146 #ifdef G4VIS_USE
147  // Initialize visualization
148  G4VisManager* visManager = new G4VisExecutive;
149  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
150  // G4VisManager* visManager = new G4VisExecutive("Quiet");
151  visManager->Initialize();
152 #endif
153 
154  // Get the pointer to the User Interface manager
155  G4UImanager* uiManager = G4UImanager::GetUIpointer();
156 
157  if ( macro.size() ) {
158  // batch mode
159  G4String command = "/control/execute ";
160  uiManager->ApplyCommand(command+macro);
161  }
162  else {
163  // interactive mode : define UI session
164 #ifdef G4UI_USE
165  G4UIExecutive* ui = new G4UIExecutive(argc, argv, session);
166 #ifdef G4VIS_USE
167  uiManager->ApplyCommand("/control/execute init_vis.mac");
168 #else
169  uiManager->ApplyCommand("/control/execute init.mac");
170 #endif
171  ui->SessionStart();
172  delete ui;
173 #endif
174  }
175 
176  // Job termination
177  // Free the store: user actions, physics_list and detector_description are
178  // owned and deleted by the run manager, so they should not be deleted
179  // in the main() program !
180 
181 #ifdef G4VIS_USE
182  delete visManager;
183 #endif
184  delete runManager;
185 
186  return 0;
187 }
static G4UIterminal * session
void PrintUsage()
ifstream in
Definition: comparison.C:7
int main(int argc, char **argv)
Definition: clGeometry.cc:77