Geant4  10.01.p03
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 #include "G4UIQt.hh"
55 #include "CommandLineParser.hh"
56 
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 
59 using namespace G4DNAPARSER;
61 
62 void Parse(int& argc, char** argv);
63 
64 
65 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
66 
67 int main(int argc,char** argv)
68 {
70  // Parse options given in commandLine
71  //
72  Parse(argc, argv);
73 
74  // Set the Seed
75  CLHEP::RanecuEngine defaultEngine(1234567);
76  G4Random::setTheEngine(&defaultEngine);
77 
78  // Choose the Random engine
79  //
80  CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine);
81 
83  // Construct the run manager according to whether MT is activated or not
84  //
85  Command* commandLine(0);
86 
87 #ifdef G4MULTITHREADED
88  G4MTRunManager* runManager= new G4MTRunManager;
89  if ((commandLine = parser->GetCommandIfActive("-mt")))
90  {
91  int nThreads = 2;
92  if(commandLine->GetOption() == "NMAX")
93  {
95  }
96  else
97  {
98  nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
99  }
100  G4cout << "===== PDB4DNA is started with "
101  << runManager->GetNumberOfThreads()
102  << " threads =====" << G4endl;
103 
104  runManager->SetNumberOfThreads(nThreads);
105  }
106 #else
107  G4RunManager* runManager = new G4RunManager();
108 #endif
109 
110  // Set user classes
111  //
112  runManager->SetUserInitialization(new DetectorConstruction());
113  runManager->SetUserInitialization(new PhysicsList);
114  runManager->SetUserInitialization(new ActionInitialization());
115 
116  // Initialize G4 keRnel
117  //
118  // runManager->Initialize();
119 
120  // Initialize visualization
121  G4VisManager* visManager = new G4VisExecutive;
122  visManager->Initialize();
123 
124  // Get the pointer to the User Interface manager
125  G4UImanager* UImanager = G4UImanager::GetUIpointer();
126  G4UIExecutive* ui(0);
127 
128  // interactive mode : define UI session
129  if ((commandLine = parser->GetCommandIfActive("-gui")))
130  {
131  ui = new G4UIExecutive(argc, argv,
132  commandLine->GetOption());
133 
134  if(parser->GetCommandIfActive("-novis") == 0)
135  // visualization is used by default
136  {
137  if ((commandLine = parser->GetCommandIfActive("-vis")))
138  // select a visualization driver if needed (e.g. HepFile)
139  {
140  UImanager->ApplyCommand(G4String("/vis/open ")+
141  commandLine->GetOption());
142  }
143  else
144  // by default OGL is used
145  {
146  UImanager->ApplyCommand("/vis/open OGL 600x600-0+0");
147  }
148  UImanager->ApplyCommand("/control/execute vis.mac");
149  }
150  if (ui->IsGUI())
151  UImanager->ApplyCommand("/control/execute gui.mac");
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 ")+
161  commandLine->GetOption());
162  UImanager->ApplyCommand("/control/execute vis.mac");
163  }
164  }
165 
166  if ((commandLine = parser->GetCommandIfActive("-mac")))
167  {
168  G4String command = "/control/execute ";
169  UImanager->ApplyCommand(command + commandLine->GetOption());
170  }
171  else
172  {
173  UImanager->ApplyCommand("/control/execute init.mac");
174  }
175 
176  if ((commandLine = parser->GetCommandIfActive("-gui")))
177  {
178 #ifdef G4UI_USE_QT
179  G4UIQt* UIQt = static_cast<G4UIQt*> (UImanager->GetG4UIWindow());
180  if ( UIQt) {
181  UIQt->AddViewerTabFromFile("README", "README from "+ G4String(argv[0]));
182  }
183 #endif
184  ui->SessionStart();
185  delete ui;
186  }
187 
188  // Job termination
189  delete visManager;
190  delete runManager;
191 
192  return 0;
193 }
194 
195 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
196 
197 void Parse(int& argc, char** argv)
198 {
200  // Parse options given in commandLine
201  //
203 
204  parser->AddCommand("-gui",
206  "Select geant4 UI or just launch a geant4 terminal session",
207  "qt");
208 
209  parser->AddCommand("-mac",
211  "Give a mac file to execute",
212  "pdb4dna.in");
213 
214 // You cann your own command, as for instance:
215 // parser->AddCommand("-seed",
216 // Command::WithOption,
217 // "Give a seed value in argument to be tested", "seed");
218 // it is then up to you to manage this option
219 
220 #ifdef G4MULTITHREADED
222  "Launch in MT mode (events computed in parallel)",
223  "2");
224 #endif
225 
226  parser->AddCommand("-vis",
228  "Select a visualization driver",
229  "OGL 600x600-0+0");
230 
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 }
257 
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)
int main(int argc, char **argv)
Definition: pdb4dna.cc:67
bool CheckIfNotHandledOptionsExists(int &argc, char **argv)
static CommandLineParser * GetParser()
void Parse(int &argc, char **argv)
Definition: pdb4dna.cc:197
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4GLOB_DLL std::ostream G4cout
G4int G4GetNumberOfCores()
Definition: G4Threading.cc:126
G4int GetNumberOfThreads() const
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:435
Action initialization class.
void Initialize()
G4UIsession * GetG4UIWindow() const
Definition: G4UImanager.hh:210
Detector construction class to demonstrate various ways of placement.
#define G4endl
Definition: G4ios.hh:61
G4bool IsGUI() const
CommandLineParser * parser(0)
virtual const G4String & GetOption()
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:432