ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
clGeometry.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file clGeometry.cc
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 //
32 
33 // package includes
36 
37 // geant4 includes
38 #ifdef G4MULTITHREADED
39 #include "G4MTRunManager.hh"
40 #else
41 #include "G4RunManager.hh"
42 #endif
43 
44 #include "FTFP_BERT.hh"
45 #include "G3VolTable.hh"
46 #include "G4UImanager.hh"
47 #include "G4ios.hh"
48 
49 #include "G4VisExecutive.hh"
50 #include "G4UIExecutive.hh"
51 
52 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
53 
54 namespace {
55  void PrintUsage() {
56  G4cerr << " Usage: " << G4endl;
57  G4cerr
58  << "clGeometry <call_list_file> [-m macro ] [-u UIsession] [-t nThreads]"
59  << G4endl;
60  G4cerr
61  << " note: -t option is available only for multi-threaded mode."
62  << G4endl;
63  }
64 }
65 
66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
67 
68 int main(int argc, char** argv)
69 {
70  // Evaluate arguments
71  //
72  G4cout << "argc " << argc << G4endl;
73  if ( argc < 2 || argc > 8 ) {
74  PrintUsage();
75  return 1;
76  }
77 
78  G4String inFile;
79  G4String macro = "";
81 #ifdef G4MULTITHREADED
82  G4int nofThreads = 4;
83 #endif
84 
85  // First argument is mandatory
86  inFile = argv[1];
87  G4cout << "Geometry data file: " << inFile << G4endl;
88  std::ifstream in(inFile);
89  if ( ! in ) {
90  G4cerr << "Cannot open input file \"" << inFile << "\"" << G4endl;
91  return EXIT_FAILURE;
92  }
93 
94  // Optional arguments
95  for ( G4int i=2; i<argc; i=i+2 ) {
96  G4cout << "evaluating " << argv[i] << G4endl;
97  if ( G4String(argv[i]) == "-m" ) macro = argv[i+1];
98  else if ( G4String(argv[i]) == "-u" ) session = argv[i+1];
99 #ifdef G4MULTITHREADED
100  else if ( G4String(argv[i]) == "-t" ) {
101  nofThreads = G4UIcommand::ConvertToInt(argv[i+1]);
102  }
103 #endif
104  else {
105  PrintUsage();
106  return 1;
107  }
108  }
109 
110  // Detect interactive mode (if no macro provided) and define UI session
111  //
112  G4UIExecutive* ui = nullptr;
113  if ( ! macro.size() ) {
114  ui = new G4UIExecutive(argc, argv, session);
115  }
116 
117  // Construct the default run manager
118 #ifdef G4MULTITHREADED
119  G4MTRunManager* runManager = new G4MTRunManager;
120  runManager->SetNumberOfThreads(nofThreads);
121 #else
122  G4RunManager* runManager = new G4RunManager;
123 #endif
124 
125  // Set mandatory initialization classes
126  //
127  // Detector construction
128  runManager->SetUserInitialization(new G3toG4DetectorConstruction(inFile));
129 
130  // Physics list
131  runManager->SetUserInitialization(new FTFP_BERT);
132 
133  // User action initialization
135 
136  // Initialize visualization
137  //
138  auto visManager = new G4VisExecutive;
139  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
140  // G4VisManager* visManager = new G4VisExecutive("Quiet");
141  visManager->Initialize();
142 
143  // Get the pointer to the User Interface manager
144  auto UImanager = G4UImanager::GetUIpointer();
145 
146  // Process macro or start UI session
147  //
148  if ( macro.size() ) {
149  // batch mode
150  G4String command = "/control/execute ";
151  UImanager->ApplyCommand(command+macro);
152  }
153  else {
154  // interactive mode : define UI session
155  UImanager->ApplyCommand("/control/execute init_vis.mac");
156  ui->SessionStart();
157  delete ui;
158  }
159 
160  // Job termination
161  // Free the store: user actions, physics_list and detector_description are
162  // owned and deleted by the run manager, so they should not be deleted
163  // in the main() program !
164 
165  delete visManager;
166  delete runManager;
167 }