LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
chem2.cc File Reference

Chem2 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

Chem2 example.

Definition in file chem2.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 71 of file chem2.cc.

References Parse(), and parser().

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

Definition at line 205 of file chem2.cc.

References parser().

Referenced by main().

206 {
208  // Parse options given in commandLine
209  //
210  parser = CommandLineParser::GetParser();
211 
212  parser->AddCommand("-gui",
213  Command::OptionNotCompulsory,
214  "Select geant4 UI or just launch a geant4 terminal session",
215  "qt");
216 
217  parser->AddCommand("-mac",
218  Command::WithOption,
219  "Give a mac file to execute",
220  "macFile.mac");
221 
222 // You cann your own command, as for instance:
223 // parser->AddCommand("-seed",
224 // Command::WithOption,
225 // "Give a seed value in argument to be tested", "seed");
226 // it is then up to you to manage this option
227 
228 #ifdef G4MULTITHREADED
229  parser->AddCommand("-mt", Command::OptionNotCompulsory,
230  "Launch in MT mode (events computed in parallel,"
231  " NOT RECOMMANDED WITH CHEMISTRY)",
232  "2");
233 #endif
234 
235  parser->AddCommand("-chemOFF",
236  Command::WithoutOption,
237  "Deactivate chemistry");
238 
239  parser->AddCommand("-vis",
240  Command::WithOption,
241  "Select a visualization driver",
242  "OGL 600x600-0+0");
243 
244  parser->AddCommand("-novis",
245  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().