LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
wholeNuclearDNA.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // This example is provided by the Geant4-DNA collaboration
27 // Any report or published results obtained using the Geant4-DNA software
28 // shall cite the following Geant4-DNA collaboration publication:
29 // Med. Phys. 37 (2010) 4692-4708
30 // The Geant4-DNA web site is available at http://geant4-dna.org
31 //
32 // $ID$
35 //
36 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
37 
38 #ifdef G4MULTITHREADED
39  #include "G4MTRunManager.hh"
40 #else
41  #include "G4RunManager.hh"
42 #endif
43 
44 #include "G4UImanager.hh"
45 #include "G4UIExecutive.hh"
46 #include "G4UIterminal.hh"
47 #include "G4UItcsh.hh"
48 #include "G4VisExecutive.hh"
49 #ifdef G4UI_USE_QT
50 #include "G4UIQt.hh"
51 #endif
52 
53 #include "ActionInitialization.hh"
54 #include "DetectorConstruction.hh"
55 #include "PhysicsList.hh"
56 #include "CommandLineParser.hh"
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
59 
60 using namespace G4DNAPARSER;
61 CommandLineParser* parser(0);
62 
63 void Parse(int& argc, char** argv);
64 
65 int main(int argc,char** argv)
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 }
188 
189 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
190 
191 void GetNameAndPathOfExecutable(char** argv,
192  G4String& executable,
193  G4String& path)
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 }
209 
210 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
211 
212 void Parse(int& argc, char** argv)
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 }
281 
282 
int main(int argc, char **argv)
void GetNameAndPathOfExecutable(char **argv, G4String &executable, G4String &path)
CommandLineParser * parser(0)
void Parse(int &argc, char **argv)