Geant4  10.02.p03
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"
#include "G4UIQt.hh"
Include dependency graph for wholeNuclearDNA.cc:

Go to the source code of this file.

Functions

CommandLineParserparser (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

◆ GetNameAndPathOfExecutable()

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

Definition at line 189 of file wholeNuclearDNA.cc.

192 {
193  // Get the last position of '/'
194  std::string aux(argv[0]);
195 
196  // get '/' or '\\' depending on unix/mac or windows.
197 #if defined(_WIN32) || defined(WIN32)
198  int pos = aux.rfind('\\');
199 #else
200  int pos = aux.rfind('/');
201 #endif
202 
203  // Get the path and the name
204  path = aux.substr(0, pos + 1);
205  executable = aux.substr(pos + 1);
206 }
static const G4double pos
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 63 of file wholeNuclearDNA.cc.

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

◆ Parse()

void Parse ( int &  argc,
char **  argv 
)

Definition at line 210 of file wholeNuclearDNA.cc.

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

◆ parser()

CommandLineParser* parser ( )
Here is the caller graph for this function: