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

Implementation of the microdosimetry example. More...

#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "G4UIExecutive.hh"
#include "G4UIterminal.hh"
#include "G4UItcsh.hh"
#include "G4VisExecutive.hh"
#include "ActionInitialization.hh"
#include "DetectorConstruction.hh"
#include "PhysicsList.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)
 
void GetNameAndPathOfExecutable (char **argv, G4String &executable, G4String &path)
 

Detailed Description

Implementation of the microdosimetry example.

Definition in file wholeNuclearDNA.cc.

Function Documentation

void GetNameAndPathOfExecutable ( char **  argv,
G4String executable,
G4String path 
)

Definition at line 191 of file wholeNuclearDNA.cc.

Referenced by Parse().

194 {
195  // Get the last position of '/'
196  std::string aux(argv[0]);
197 
198  // get '/' or '\\' depending on unix/mac or windows.
199 #if defined(_WIN32) || defined(WIN32)
200  int pos = aux.rfind('\\');
201 #else
202  int pos = aux.rfind('/');
203 #endif
204 
205  // Get the path and the name
206  path = aux.substr(0, pos + 1);
207  executable = aux.substr(pos + 1);
208 }
int main ( int  argc,
char **  argv 
)

Definition at line 65 of file wholeNuclearDNA.cc.

References Parse(), and parser().

66 {
67  // Choose the Random engine
68 
69  G4Random::setTheEngine(new CLHEP::RanecuEngine);
70 
72  // Parse options given in commandLine
73  //
74  Parse(argc, argv);
75 
77  // Construct the run manager according to whether MT is activated or not
78  //
79  Command* commandLine(0);
80 
81 #ifdef G4MULTITHREADED
82  G4MTRunManager* runManager= new G4MTRunManager;
83  if ((commandLine = parser->GetCommandIfActive("-mt")))
84  {
85  int nThreads = 2;
86  if(commandLine->GetOption() == "NMAX")
87  {
88  nThreads = G4Threading::G4GetNumberOfCores();
89  }
90  else
91  {
92  nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
93  }
94  G4cout << "===== WholeNuclearDNA is started with "
95  << runManager->GetNumberOfThreads()
96  << " threads =====" << G4endl;
97 
98  runManager->SetNumberOfThreads(nThreads);
99  }
100 #else
101  G4RunManager* runManager = new G4RunManager();
102 #endif
103 
104  // Set mandatory user initialization classes
106  runManager->SetUserInitialization(detector);
107  runManager->SetUserInitialization(new PhysicsList);
108  runManager->SetUserInitialization(new ActionInitialization());
109 
110  // Initialize G4 kernel
111  runManager->Initialize();
112 
113  // Initialize visualization
114  G4VisManager* visManager = new G4VisExecutive;
115  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
116  // G4VisManager* visManager = new G4VisExecutive("Quiet");
117  visManager->Initialize();
118 
119  // Get the pointer to the User Interface manager
120  G4UImanager* UImanager = G4UImanager::GetUIpointer();
121  G4UIExecutive* ui(0);
122 
123  // interactive mode : define UI session
124  if ((commandLine = parser->GetCommandIfActive("-gui")))
125  {
126  ui = new G4UIExecutive(argc, argv,
127  commandLine->GetOption());
128 
129  if(ui->IsGUI())
130  UImanager->ApplyCommand("/control/execute gui.mac");
131 
132  if(parser->GetCommandIfActive("-novis") == 0)
133  // visualization is used by default
134  {
135  if((commandLine = parser->GetCommandIfActive("-vis")))
136  // select a visualization driver if needed (e.g. HepFile)
137  {
138  UImanager->ApplyCommand(G4String("/vis/open ")+
139  commandLine->GetOption());
140  }
141  else
142  // by default OGL is used
143  {
144  UImanager->ApplyCommand("/vis/open OGL 800x600-0+0");
145  }
146  UImanager->ApplyCommand("/control/execute vis.mac");
147  }
148  }
149  else
150  // to be use visualization file (= store the visualization into
151  // an external file:
152  // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ...
153  {
154  if ((commandLine = parser->GetCommandIfActive("-vis")))
155  {
156  UImanager->ApplyCommand(G4String("/vis/open ")+commandLine->GetOption());
157  UImanager->ApplyCommand("/control/execute vis.mac");
158  }
159  }
160 
161  if ((commandLine = parser->GetCommandIfActive("-mac")))
162  {
163  G4String command = "/control/execute ";
164  UImanager->ApplyCommand(command + commandLine->GetOption());
165  }
166  else
167  {
168  UImanager->ApplyCommand("/control/execute wholeNuclearDNA.in");
169  }
170 
171  if ((commandLine = parser->GetCommandIfActive("-gui")))
172  {
173 #ifdef G4UI_USE_QT
174  G4UIQt* UIQt = static_cast<G4UIQt*> (UImanager->GetG4UIWindow());
175  if ( UIQt) {
176  UIQt->AddViewerTabFromFile("README", "README from "+ G4String(argv[0]));
177  }
178 #endif
179  ui->SessionStart();
180  delete ui;
181  }
182 
183  delete visManager;
184  delete runManager;
185 
186  return 0;
187 }
CommandLineParser * parser(0)
void Parse(int &argc, char **argv)
void Parse ( int &  argc,
char **  argv 
)

Definition at line 212 of file wholeNuclearDNA.cc.

References GetNameAndPathOfExecutable(), and parser().

Referenced by main().

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

Referenced by main(), and Parse().