Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
clustering.cc
이 파일의 문서화 페이지로 가기
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 
59 void Parse(int& argc, char** argv);
60 
61 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
62 
63 int main(int argc, char** argv)
64 {
66  // Parse options given in commandLine
67  //
68  Parse(argc, argv);
69 
71  // Construct the run manager according to whether MT is activated or not
72  //
73  Command* commandLine(0);
74 
75 #ifdef G4MULTITHREADED
76  G4MTRunManager* runManager= new G4MTRunManager;
77  if ((commandLine = parser->GetCommandIfActive("-mt")))
78  {
79  int nThreads = 2;
80  if(commandLine->GetOption() == "NMAX")
81  {
83  }
84  else
85  {
86  nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
87  }
88  G4cout << "===== clustering is started with "
89  << runManager->GetNumberOfThreads()
90  << " threads =====" << G4endl;
91 
92  runManager->SetNumberOfThreads(nThreads);
93  }
94 #else
95  G4RunManager* runManager = new G4RunManager();
96 #endif
97 
99  // Set mandatory user initialization classes
100  //
102  runManager->SetUserInitialization(new PhysicsList);
103  runManager->SetUserInitialization(detector);
104  runManager->SetUserInitialization(new ActionInitialization());
105 
106  // Initialize G4 kernel
107  runManager->Initialize();
108 
109  // Initialize visualization
110  G4VisManager* visManager = new G4VisExecutive;
111  visManager->Initialize();
112 
113  // Get the pointer to the User Interface manager
114  G4UImanager* UImanager = G4UImanager::GetUIpointer();
115  G4UIExecutive* ui(0);
116 
117  // interactive mode : define UI session
118  if ((commandLine = parser->GetCommandIfActive("-gui")))
119  {
120  ui = new G4UIExecutive(argc, argv, commandLine->GetOption());
121 
122  if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute gui.mac");
123 
124  if (parser->GetCommandIfActive("-novis") == 0)
125  // visualization is used by default
126  {
127  if ((commandLine = parser->GetCommandIfActive("-vis")))
128  // select a visualization driver if needed (e.g. HepFile)
129  {
130  UImanager->ApplyCommand(
131  G4String("/vis/open ") + commandLine->GetOption());
132  }
133  else
134  // by default OGL is used
135  {
136  UImanager->ApplyCommand("/vis/open OGL 800x600-0+0");
137  }
138  UImanager->ApplyCommand("/control/execute vis.mac");
139  }
140  }
141  else
142  // to be use visualization file (= store the visualization into
143  // an external file:
144  // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ...
145  {
146  if ((commandLine = parser->GetCommandIfActive("-vis")))
147  {
148  UImanager->ApplyCommand(
149  G4String("/vis/open ") + commandLine->GetOption());
150  UImanager->ApplyCommand("/control/execute vis.mac");
151  }
152  }
153 
154  if ((commandLine = parser->GetCommandIfActive("-mac")))
155  {
156  G4String command = "/control/execute ";
157  UImanager->ApplyCommand(command + commandLine->GetOption());
158  }
159  else
160  {
161  UImanager->ApplyCommand("/control/execute run.in");
162  }
163 
164  if ((commandLine = parser->GetCommandIfActive("-gui")))
165  {
166  ui->SessionStart();
167  delete ui;
168  }
169 
170  // Job termination
171  // Free the store: user actions, physics_list and detector_description are
172  // owned and deleted by the run manager, so they should not be deleted
173  // in the main() program !
174 
175  delete visManager;
176  delete runManager;
177 
179 
180  return 0;
181 }
182 
183 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
184 
185 void Parse(int& argc, char** argv)
186 {
188  // Parse options given in commandLine
189  //
191 
194  "Select geant4 UI or just launch a geant4 terminal session", "qt");
195 
196  parser->AddCommand("-mac", Command::WithOption, "Give a mac file to execute",
197  "macFile.mac");
198 
199 // You cann your own command, as for instance:
200 // parser->AddCommand("-seed",
201 // Command::WithOption,
202 // "Give a seed value in argument to be tested", "seed");
203 // it is then up to you to manage this option
204 
205 #ifdef G4MULTITHREADED
206  parser->AddCommand("-mt",
208  "Launch in MT mode (events computed in parallel,"
209  " NOT RECOMMENDED WITH CHEMISTRY)", "2");
210 #endif
211 
213  "Select a visualization driver", "OGL 600x600-0+0");
214 
216  "Deactivate visualization when using GUI");
217 
219  // If -h or --help is given in option : print help and exit
220  //
221  if (parser->Parse(argc, argv) != 0) // help is being printed
222  {
223  // if you are using ROOT, create a TApplication in this condition in order
224  // to print the help from ROOT as well
226  // Exit is kept
227  std::exit(0);
228  }
229 
231  // Kill application if wrong argument in command line
232  //
233  if (parser->CheckIfNotHandledOptionsExists(argc, argv))
234  {
235  // if you are using ROOT, you should initialise your TApplication
236  // before this condition
237  abort();
238  }
239 }
void Parse(int &argc, char **argv)
Definition: chem1.cc:193
virtual const G4String & GetOption()
void SetNumberOfThreads(G4int n)
static CommandLineParser * GetParser()
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:466
#define G4endl
Definition: G4ios.hh:61
G4int G4GetNumberOfCores()
Definition: G4Threading.cc:127
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:73
G4int GetNumberOfThreads() const
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:449
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
CommandLineParser * parser(0)
int main(int argc, char **argv)
Definition: genwindef.cc:359
Command * GetCommandIfActive(const G4String &marker)
G4GLOB_DLL std::ostream G4cout
void Initialize()
bool CheckIfNotHandledOptionsExists(int &argc, char **argv)
G4bool IsGUI() const
void AddCommand(const G4String &marker, Command::Type, const G4String &description="", const G4String &defaultOption="", const G4String &optionName="")
virtual void Initialize()
Simple detector construction with a box volume placed in a world.