LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
chem3.cc File Reference

Chem3 example. More...

#include "DetectorConstruction.hh"
#include "PhysicsList.hh"
#include "ActionInitialization.hh"
#include "G4RunManager.hh"
#include "G4DNAChemistryManager.hh"
#include "G4UImanager.hh"
#include "G4UIExecutive.hh"
#include "G4VisExecutive.hh"
#include "CommandLineParser.hh"

Go to the source code of this file.

Functions

CommandLineParser * parser (0)
 
void Parse (int &argc, char **argv)
 
int main (int argc, char **argv)
 

Detailed Description

Chem3 example.

Definition in file chem3.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 73 of file chem3.cc.

References Parse(), and parser().

74 {
76  // Parse options given in commandLine
77  //
78  Parse(argc, argv);
79 
81  // Construct the run manager according to whether MT is activated or not
82  //
83  Command* commandLine(0);
84 
85 #ifdef G4MULTITHREADED
86  G4RunManager* runManager(0);
87  if ((commandLine = parser->GetCommandIfActive("-mt")))
88  {
89  runManager = new G4MTRunManager;
90  int nThreads = 2;
91  const G4String& option = commandLine->GetOption();
92  if(option == "")
93  {
94  nThreads = G4UIcommand::ConvertToInt(commandLine->GetDefaultOption());
95  }
96  else if(option == "NMAX")
97  {
98  nThreads = G4Threading::G4GetNumberOfCores();
99  }
100  else
101  {
102  nThreads = G4UIcommand::ConvertToInt(option);
103  }
104 
105  G4cout << "===== Chem3 is started with "
106  << ((G4MTRunManager*) runManager)->GetNumberOfThreads()
107  << " threads =====" << G4endl;
108 
109  ((G4MTRunManager*) runManager)->SetNumberOfThreads(nThreads);
110  }
111  else
112  {
113  runManager = new G4RunManager();
114  }
115 #else
116  G4RunManager* runManager = new G4RunManager();
117 #endif
118 
120  // Set mandatory user initialization classes
121  //
123  runManager->SetUserInitialization(new PhysicsList);
124  runManager->SetUserInitialization(detector);
125  runManager->SetUserInitialization(new ActionInitialization());
126 
127  // Initialize G4 kernel
128  runManager->Initialize();
129 
130  // Initialize visualization
131  G4VisManager* visManager = new G4VisExecutive;
132  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
133  // G4VisManager* visManager = new G4VisExecutive("Quiet");
134  visManager->Initialize();
135 
136  // Get the pointer to the User Interface manager
137  G4UImanager* UImanager = G4UImanager::GetUIpointer();
138  G4UIExecutive* ui(0);
139 
140  // interactive mode : define UI session
141  if ((commandLine = parser->GetCommandIfActive("-gui")))
142  {
143  ui = new G4UIExecutive(argc, argv, commandLine->GetOption());
144 
145  if (parser->GetCommandIfActive("-novis") == 0)
146  // visualization is used by default
147  {
148  if ((commandLine = parser->GetCommandIfActive("-vis")))
149  // select a visualization driver if needed (e.g. HepFile)
150  {
151  UImanager->ApplyCommand(
152  G4String("/vis/open ") + commandLine->GetOption());
153  }
154  else
155  // by default OGL is used
156  {
157  UImanager->ApplyCommand("/vis/open OGL 800x600-0+0");
158  }
159  UImanager->ApplyCommand("/control/execute vis.mac");
160  }
161 
162  if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute gui.mac");
163  }
164  else
165  // to be use visualization file (= store the visualization into
166  // an external file:
167  // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ...
168  {
169  if ((commandLine = parser->GetCommandIfActive("-vis")))
170  {
171  UImanager->ApplyCommand(
172  G4String("/vis/open ") + commandLine->GetOption());
173  UImanager->ApplyCommand("/control/execute vis.mac");
174  }
175  }
176 
177  if ((commandLine = parser->GetCommandIfActive("-mac")))
178  {
179  G4String command = "/control/execute ";
180  UImanager->ApplyCommand(command + commandLine->GetOption());
181  }
182  else
183  {
184  UImanager->ApplyCommand("/control/execute beam.in");
185  }
186 
187  if ((commandLine = parser->GetCommandIfActive("-gui")))
188  {
189 #ifdef G4UI_USE_QT
190  G4UIQt* UIQt = static_cast<G4UIQt*> (UImanager->GetG4UIWindow());
191  if ( UIQt) {
192  UIQt->AddViewerTabFromFile("README", "README from "+ G4String(argv[0]));
193  }
194 #endif
195  ui->SessionStart();
196  delete ui;
197  }
198 
199  // Job termination
200  // Free the store: user actions, physics_list and detector_description are
201  // owned and deleted by the run manager, so they should not be deleted
202  // in the main() program !
203 
204  delete visManager;
205  delete runManager;
206 
207  CommandLineParser::DeleteInstance();
208 
209  return 0;
210 }
void Parse(int &argc, char **argv)
Definition: chem3.cc:212
CommandLineParser * parser(0)
void Parse ( int &  argc,
char **  argv 
)

Definition at line 212 of file chem3.cc.

References parser().

Referenced by main().

213 {
215  // Parse options given in commandLine
216  //
217  parser = CommandLineParser::GetParser();
218 
219  parser->AddCommand(
220  "-gui", Command::OptionNotCompulsory,
221  "Select geant4 UI or just launch a geant4 terminal session", "qt");
222 
223  parser->AddCommand("-mac", Command::WithOption, "Give a mac file to execute",
224  "macFile.mac");
225 
226 // You cann your own command, as for instance:
227 // parser->AddCommand("-seed",
228 // Command::WithOption,
229 // "Give a seed value in argument to be tested", "seed");
230 // it is then up to you to manage this option
231 
232 #ifdef G4MULTITHREADED
233  parser->AddCommand("-mt", Command::OptionNotCompulsory,
234  "Launch in MT mode (events computed in parallel,"
235  " NOT RECOMMANDED WITH CHEMISTRY)",
236  "2");
237 #endif
238 
239  parser->AddCommand("-chemOFF", Command::WithoutOption,
240  "Deactivate chemistry");
241 
242  parser->AddCommand("-vis", Command::WithOption,
243  "Select a visualization driver", "OGL 600x600-0+0");
244 
245  parser->AddCommand("-novis", Command::WithoutOption,
246  "Deactivate visualization when using GUI");
247 
249  // If -h or --help is given in option : print help and exit
250  //
251  if (parser->Parse(argc, argv) != 0) // help is being printed
252  {
253  // if you are using ROOT, create a TApplication in this condition in order
254  // to print the help from ROOT as well
255  CommandLineParser::DeleteInstance();
256  std::exit(0);
257  }
258 
260  // Kill application if wrong argument in command line
261  //
262  if (parser->CheckIfNotHandledOptionsExists(argc, argv))
263  {
264  // if you are using ROOT, you should initialise your TApplication
265  // before this condition
266  abort();
267  }
268 }
CommandLineParser * parser(0)
CommandLineParser* parser ( )

Referenced by main(), and Parse().