Geant4  10.02.p02
clustering.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$
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 using namespace G4DNAPARSER;
56 
57 void Parse(int& argc, char** argv);
58 
59 int main(int argc, char** argv)
60 {
62  // Parse options given in commandLine
63  //
64  Parse(argc, argv);
65 
67  // Construct the run manager according to whether MT is activated or not
68  //
69  Command* commandLine(0);
70 
71 #ifdef G4MULTITHREADED
72  G4MTRunManager* runManager= new G4MTRunManager;
73  if ((commandLine = parser->GetCommandIfActive("-mt")))
74  {
75  int nThreads = 2;
76  if(commandLine->GetOption() == "NMAX")
77  {
79  }
80  else
81  {
82  nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
83  }
84  G4cout << "===== clustering is started with "
85  << runManager->GetNumberOfThreads()
86  << " threads =====" << G4endl;
87 
88  runManager->SetNumberOfThreads(nThreads);
89  }
90 #else
91  G4RunManager* runManager = new G4RunManager();
92 #endif
93 
95  // Set mandatory user initialization classes
96  //
98  runManager->SetUserInitialization(new PhysicsList);
99  runManager->SetUserInitialization(detector);
100  runManager->SetUserInitialization(new ActionInitialization());
101 
102  // Initialize G4 kernel
103  runManager->Initialize();
104 
105  // Initialize visualization
106  G4VisManager* visManager = new G4VisExecutive;
107  visManager->Initialize();
108 
109  // Get the pointer to the User Interface manager
110  G4UImanager* UImanager = G4UImanager::GetUIpointer();
111  G4UIExecutive* ui(0);
112 
113  // interactive mode : define UI session
114  if ((commandLine = parser->GetCommandIfActive("-gui")))
115  {
116  ui = new G4UIExecutive(argc, argv, commandLine->GetOption());
117 
118  if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute gui.mac");
119 
120  if (parser->GetCommandIfActive("-novis") == 0)
121  // visualization is used by default
122  {
123  if ((commandLine = parser->GetCommandIfActive("-vis")))
124  // select a visualization driver if needed (e.g. HepFile)
125  {
126  UImanager->ApplyCommand(
127  G4String("/vis/open ") + commandLine->GetOption());
128  }
129  else
130  // by default OGL is used
131  {
132  UImanager->ApplyCommand("/vis/open OGL 800x600-0+0");
133  }
134  UImanager->ApplyCommand("/control/execute vis.mac");
135  }
136  }
137  else
138  // to be use visualization file (= store the visualization into
139  // an external file:
140  // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ...
141  {
142  if ((commandLine = parser->GetCommandIfActive("-vis")))
143  {
144  UImanager->ApplyCommand(
145  G4String("/vis/open ") + commandLine->GetOption());
146  UImanager->ApplyCommand("/control/execute vis.mac");
147  }
148  }
149 
150  if ((commandLine = parser->GetCommandIfActive("-mac")))
151  {
152  G4String command = "/control/execute ";
153  UImanager->ApplyCommand(command + commandLine->GetOption());
154  }
155  else
156  {
157  UImanager->ApplyCommand("/control/execute run.in");
158  }
159 
160  if ((commandLine = parser->GetCommandIfActive("-gui")))
161  {
162  ui->SessionStart();
163  delete ui;
164  }
165 
166  // Job termination
167  // Free the store: user actions, physics_list and detector_description are
168  // owned and deleted by the run manager, so they should not be deleted
169  // in the main() program !
170 
171  delete visManager;
172  delete runManager;
173 
175 
176  return 0;
177 }
178 
179 void Parse(int& argc, char** argv)
180 {
182  // Parse options given in commandLine
183  //
185 
188  "Select geant4 UI or just launch a geant4 terminal session", "qt");
189 
190  parser->AddCommand("-mac", Command::WithOption, "Give a mac file to execute",
191  "macFile.mac");
192 
193 // You cann your own command, as for instance:
194 // parser->AddCommand("-seed",
195 // Command::WithOption,
196 // "Give a seed value in argument to be tested", "seed");
197 // it is then up to you to manage this option
198 
199 #ifdef G4MULTITHREADED
200  parser->AddCommand("-mt",
202  "Launch in MT mode (events computed in parallel,"
203  " NOT RECOMMENDED WITH CHEMISTRY)", "2");
204 #endif
205 
207  "Select a visualization driver", "OGL 600x600-0+0");
208 
210  "Deactivate visualization when using GUI");
211 
213  // If -h or --help is given in option : print help and exit
214  //
215  if (parser->Parse(argc, argv) != 0) // help is being printed
216  {
217  // if you are using ROOT, create a TApplication in this condition in order
218  // to print the help from ROOT as well
220  std::exit(0);
221  }
222 
224  // Kill application if wrong argument in command line
225  //
226  if (parser->CheckIfNotHandledOptionsExists(argc, argv))
227  {
228  // if you are using ROOT, you should initialise your TApplication
229  // before this condition
230  abort();
231  }
232 }
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:127
G4int GetNumberOfThreads() const
CommandLineParser * parser(0)
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:435
Action initialization class.
void Initialize()
void Parse(int &argc, char **argv)
Definition: clustering.cc:179
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:446
Physics list class.
Definition: PhysicsList.hh:47
int main(int argc, char **argv)
Definition: clustering.cc:59