LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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 //
34 //
35 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
36 #include "G4Types.hh"
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 {
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 }
184 
185 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
186 
187 void GetNameAndPathOfExecutable(char** argv,
188  G4String& executable,
189  G4String& path)
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 }
205 
206 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
207 
208 void Parse(int& argc, char** argv)
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 }
277 
278 
int main(int argc, char **argv)
void GetNameAndPathOfExecutable(char **argv, G4String &executable, G4String &path)
CommandLineParser * parser(0)
void Parse(int &argc, char **argv)