Geant4  10.01.p03
chem2.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 // J. Comput. Phys. 274 (2014) 841-882
31 // The Geant4-DNA web site is available at http://geant4-dna.org
32 //
33 // $Id$
34 //
37 
38 #include "DetectorConstruction.hh"
39 #include "PhysicsList.hh"
40 #include "ActionInitialization.hh"
41 
42 #ifdef G4MULTITHREADED
43 #include "G4MTRunManager.hh"
44 #else
45 #include "G4RunManager.hh"
46 #endif
47 
48 #include "G4DNAChemistryManager.hh"
49 #include "G4UImanager.hh"
50 #include "G4UIExecutive.hh"
51 #include "G4VisExecutive.hh"
52 
53 #include "CommandLineParser.hh"
54 
55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
56 
57 /*
58  * WARNING : Geant4 was initially not intended for this kind of application
59  * This code is delivered as a prototype
60  * We will be happy to hear from you, do not hesitate to send your feedback and
61  * communicate on the difficulties you may encounter
62  * The user interface may change in the next releases since a reiteration of the
63  * code has started
64  */
65 
66 using namespace G4DNAPARSER;
68 
69 void Parse(int& argc, char** argv);
70 
71 int main(int argc, char** argv)
72 {
74  // Parse options given in commandLine
75  //
76  Parse(argc, argv);
77 
79  // Construct the run manager according to whether MT is activated or not
80  //
81  Command* commandLine(0);
82 
83 #ifdef G4MULTITHREADED
84  G4MTRunManager* runManager= new G4MTRunManager;
85  if ((commandLine = parser->GetCommandIfActive("-mt")))
86  {
87  int nThreads = 2;
88  if(commandLine->GetOption() == "NMAX")
89  {
91  }
92  else
93  {
94  nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
95  }
96  G4cout << "===== Chem2 is started with "
97  << runManager->GetNumberOfThreads()
98  << " threads =====" << G4endl;
99 
100  runManager->SetNumberOfThreads(nThreads);
101  }
102 #else
103  G4RunManager* runManager = new G4RunManager();
104 #endif
105 
107  // Set mandatory user initialization classes
108  //
110  runManager->SetUserInitialization(new PhysicsList);
111  runManager->SetUserInitialization(detector);
112  runManager->SetUserInitialization(new ActionInitialization());
113 
114  // Initialize G4 kernel
115  runManager->Initialize();
116 
117  // Initialize visualization
118  G4VisManager* visManager = new G4VisExecutive;
119  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
120  // G4VisManager* visManager = new G4VisExecutive("Quiet");
121  visManager->Initialize();
122 
123  // Get the pointer to the User Interface manager
124  G4UImanager* UImanager = G4UImanager::GetUIpointer();
125  G4UIExecutive* ui(0);
126 
127  // interactive mode : define UI session
128  if ((commandLine = parser->GetCommandIfActive("-gui")))
129  {
130  ui = new G4UIExecutive(argc, argv,
131  commandLine->GetOption());
132 
133  if(ui->IsGUI())
134  UImanager->ApplyCommand("/control/execute gui.mac");
135 
136  if(parser->GetCommandIfActive("-novis") == 0)
137  // visualization is used by default
138  {
139  if((commandLine = parser->GetCommandIfActive("-vis")))
140  // select a visualization driver if needed (e.g. HepFile)
141  {
142  UImanager->ApplyCommand(G4String("/vis/open ")+
143  commandLine->GetOption());
144  }
145  else
146  // by default OGL is used
147  {
148  UImanager->ApplyCommand("/vis/open OGL 800x600-0+0");
149  }
150  UImanager->ApplyCommand("/control/execute vis.mac");
151  }
152  }
153  else
154  // to be use visualization file (= store the visualization into
155  // an external file:
156  // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ...
157  {
158  if ((commandLine = parser->GetCommandIfActive("-vis")))
159  {
160  UImanager->ApplyCommand(G4String("/vis/open ")+commandLine->GetOption());
161  UImanager->ApplyCommand("/control/execute vis.mac");
162  }
163  }
164 
165  if ((commandLine = parser->GetCommandIfActive("-mac")))
166  {
167  G4String command = "/control/execute ";
168  UImanager->ApplyCommand(command + commandLine->GetOption());
169  }
170  else
171  {
172  UImanager->ApplyCommand("/control/execute beam.in");
173  }
174 
175  if ((commandLine = parser->GetCommandIfActive("-gui")))
176  {
177  ui->SessionStart();
178  delete ui;
179  }
180 
181  // Job termination
182  // Free the store: user actions, physics_list and detector_description are
183  // owned and deleted by the run manager, so they should not be deleted
184  // in the main() program !
185 
186  delete visManager;
187  delete runManager;
188 
190 
191  return 0;
192 }
193 
194 void Parse(int& argc, char** argv)
195 {
197  // Parse options given in commandLine
198  //
200 
201  parser->AddCommand("-gui",
203  "Select geant4 UI or just launch a geant4 terminal session",
204  "qt");
205 
206  parser->AddCommand("-mac",
208  "Give a mac file to execute",
209  "macFile.mac");
210 
211 // You cann your own command, as for instance:
212 // parser->AddCommand("-seed",
213 // Command::WithOption,
214 // "Give a seed value in argument to be tested", "seed");
215 // it is then up to you to manage this option
216 
217 #ifdef G4MULTITHREADED
218  parser->AddCommand("-mt",
220  "Launch in MT mode (events computed in parallel,"
221  " NOT RECOMMANDED WITH CHEMISTRY)", "2");
222 #endif
223 
224  parser->AddCommand("-chemOFF",
226  "Deactivate chemistry");
227 
228  parser->AddCommand("-vis",
230  "Select a visualization driver",
231  "OGL 600x600-0+0");
232 
233  parser->AddCommand("-novis",
235  "Deactivate visualization when using GUI");
236 
238  // If -h or --help is given in option : print help and exit
239  //
240  if (parser->Parse(argc, argv) != 0) // help is being printed
241  {
242  // if you are using ROOT, create a TApplication in this condition in order
243  // to print the help from ROOT as well
245  std::exit(0);
246  }
247 
249  // Kill application if wrong argument in command line
250  //
251  if (parser->CheckIfNotHandledOptionsExists(argc, argv))
252  {
253  // if you are using ROOT, you should initialise your TApplication
254  // before this condition
255  abort();
256  }
257 }
void Parse(int &argc, char **argv)
Definition: chem2.cc:194
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
int Parse(int &argc, char **argv)
void SetNumberOfThreads(G4int n)
void AddCommand(const G4String &marker, Command::Type, const G4String &description="", const G4String &defaultOption="", const G4String &optionName="")
Command * GetCommandIfActive(const G4String &marker)
bool CheckIfNotHandledOptionsExists(int &argc, char **argv)
static CommandLineParser * GetParser()
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4GLOB_DLL std::ostream G4cout
G4int G4GetNumberOfCores()
Definition: G4Threading.cc:126
G4int GetNumberOfThreads() const
CommandLineParser * parser(0)
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:435
Action initialization class.
void Initialize()
int main(int argc, char **argv)
Definition: chem2.cc:71
virtual void Initialize()
Detector construction class to demonstrate various ways of placement.
#define G4endl
Definition: G4ios.hh:61
G4bool IsGUI() const
virtual const G4String & GetOption()
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:432