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