Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pdb4dna.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 // Delage et al. PDB4DNA: implementation of DNA geometry from the Protein Data
31 // Bank (PDB) description for Geant4-DNA Monte-Carlo
32 // simulations (submitted to Comput. Phys. Commun.)
33 // The Geant4-DNA web site is available at http://geant4-dna.org
34 //
35 // $Id$
36 //
39 
40 #include "DetectorConstruction.hh"
41 #include "PhysicsList.hh"
42 #include "ActionInitialization.hh"
43 
44 #ifdef G4MULTITHREADED
45 #include "G4MTRunManager.hh"
46 #else
47 #include "G4RunManager.hh"
48 #endif
49 
50 #include "G4UImanager.hh"
51 #include "Randomize.hh"
52 #include "G4VisExecutive.hh"
53 #include "G4UIExecutive.hh"
54 #ifdef G4UI_USE_QT
55 #include "G4UIQt.hh"
56 #endif
57 #include "CommandLineParser.hh"
58 
59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
60 
61 using namespace G4DNAPARSER;
63 
64 void Parse(int& argc, char** argv);
65 
66 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
67 
68 int main(int argc,char** argv)
69 {
71  // Parse options given in commandLine
72  //
73  Parse(argc, argv);
74 
75  // Set the Seed
76  CLHEP::RanecuEngine defaultEngine(1234567);
77  G4Random::setTheEngine(&defaultEngine);
78 
79  // Choose the Random engine
80  //
82 
84  // Construct the run manager according to whether MT is activated or not
85  //
86  Command* commandLine(0);
87 
88 #ifdef G4MULTITHREADED
89  G4MTRunManager* runManager= new G4MTRunManager;
90  if ((commandLine = parser->GetCommandIfActive("-mt")))
91  {
92  int nThreads = 2;
93  if(commandLine->GetOption() == "NMAX")
94  {
96  }
97  else
98  {
99  nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
100  }
101  G4cout << "===== PDB4DNA is started with "
102  << runManager->GetNumberOfThreads()
103  << " threads =====" << G4endl;
104 
105  runManager->SetNumberOfThreads(nThreads);
106  }
107 #else
108  G4RunManager* runManager = new G4RunManager();
109 #endif
110 
111  // Set user classes
112  //
113  runManager->SetUserInitialization(new DetectorConstruction());
114  runManager->SetUserInitialization(new PhysicsList);
115  runManager->SetUserInitialization(new ActionInitialization());
116 
117  // Initialize G4 keRnel
118  //
119  // runManager->Initialize();
120 
121  // Initialize visualization
122  G4VisManager* visManager = new G4VisExecutive;
123  visManager->Initialize();
124 
125  // Get the pointer to the User Interface manager
126  G4UImanager* UImanager = G4UImanager::GetUIpointer();
127  G4UIExecutive* ui(0);
128 
129  // interactive mode : define UI session
130  if ((commandLine = parser->GetCommandIfActive("-gui")))
131  {
132  ui = new G4UIExecutive(argc, argv,
133  commandLine->GetOption());
134 
135  if(parser->GetCommandIfActive("-novis") == 0)
136  // visualization is used by default
137  {
138  if ((commandLine = parser->GetCommandIfActive("-vis")))
139  // select a visualization driver if needed (e.g. HepFile)
140  {
141  UImanager->ApplyCommand(G4String("/vis/open ")+
142  commandLine->GetOption());
143  }
144  else
145  // by default OGL is used
146  {
147  UImanager->ApplyCommand("/vis/open OGL 600x600-0+0");
148  }
149  UImanager->ApplyCommand("/control/execute vis.mac");
150  }
151  if (ui->IsGUI())
152  UImanager->ApplyCommand("/control/execute gui.mac");
153  }
154  else
155  // to be use visualization file (= store the visualization into
156  // an external file:
157  // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ...
158  {
159  if ((commandLine = parser->GetCommandIfActive("-vis")))
160  {
161  UImanager->ApplyCommand(G4String("/vis/open ")+
162  commandLine->GetOption());
163  UImanager->ApplyCommand("/control/execute vis.mac");
164  }
165  }
166 
167  if ((commandLine = parser->GetCommandIfActive("-mac")))
168  {
169  G4String command = "/control/execute ";
170  UImanager->ApplyCommand(command + commandLine->GetOption());
171  }
172  else
173  {
174  UImanager->ApplyCommand("/control/execute init.mac");
175  }
176 
177  if ((commandLine = parser->GetCommandIfActive("-gui")))
178  {
179 #ifdef G4UI_USE_QT
180  G4UIQt* UIQt = static_cast<G4UIQt*> (UImanager->GetG4UIWindow());
181  if ( UIQt) {
182  UIQt->AddViewerTabFromFile("README", "README from "+ G4String(argv[0]));
183  }
184 #endif
185  ui->SessionStart();
186  delete ui;
187  }
188 
189  // Job termination
190  delete visManager;
191  delete runManager;
192 
193  return 0;
194 }
195 
196 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
197 
198 void Parse(int& argc, char** argv)
199 {
201  // Parse options given in commandLine
202  //
204 
205  parser->AddCommand("-gui",
207  "Select geant4 UI or just launch a geant4 terminal session",
208  "qt");
209 
210  parser->AddCommand("-mac",
212  "Give a mac file to execute",
213  "pdb4dna.in");
214 
215 // You cann your own command, as for instance:
216 // parser->AddCommand("-seed",
217 // Command::WithOption,
218 // "Give a seed value in argument to be tested", "seed");
219 // it is then up to you to manage this option
220 
221 #ifdef G4MULTITHREADED
223  "Launch in MT mode (events computed in parallel)",
224  "2");
225 #endif
226 
227  parser->AddCommand("-vis",
229  "Select a visualization driver",
230  "OGL 600x600-0+0");
231 
232  parser->AddCommand("-novis",
234  "Deactivate visualization when using GUI");
235 
237  // If -h or --help is given in option : print help and exit
238  //
239  if (parser->Parse(argc, argv) != 0) // help is being printed
240  {
241  // if you are using ROOT, create a TApplication in this condition in order
242  // to print the help from ROOT as well
244  std::exit(0);
245  }
246 
248  // Kill application if wrong argument in command line
249  //
250  if (parser->CheckIfNotHandledOptionsExists(argc, argv))
251  {
252  // if you are using ROOT, you should initialise your TApplication
253  // before this condition
254  abort();
255  }
256 }
void Parse(int &argc, char **argv)
Definition: chem1.cc:193
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)
int main(int argc, char **argv)
Definition: genwindef.cpp:30
static CommandLineParser * GetParser()
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:59
G4GLOB_DLL std::ostream G4cout
G4int G4GetNumberOfCores()
Definition: G4Threading.cc:143
G4int GetNumberOfThreads() const
CommandLineParser * parser(0)
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:447
void Initialize()
G4UIsession * GetG4UIWindow() const
Definition: G4UImanager.hh:210
Detector construction class to define materials and geometry.
#define G4endl
Definition: G4ios.hh:61
static void setTheEngine(HepRandomEngine *theNewEngine)
Definition: Random.cc:270
G4bool IsGUI() const
virtual const G4String & GetOption()
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:447
Physics list class.
Definition: PhysicsList.hh:47