LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
wholeNuclearDNA.cc File Reference

Implementation of the microdosimetry example. More...

#include "G4Types.hh"
#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 187 of file wholeNuclearDNA.cc.

Referenced by Parse().

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

Definition at line 65 of file wholeNuclearDNA.cc.

References Parse(), and parser().

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

Definition at line 208 of file wholeNuclearDNA.cc.

References GetNameAndPathOfExecutable(), and parser().

Referenced by main().

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

Referenced by main(), and Parse().