Geant4  10.02.p03
pdb4dna.cc File Reference

Main program of the pdb4dna example. More...

#include "DetectorConstruction.hh"
#include "PhysicsList.hh"
#include "ActionInitialization.hh"
#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "Randomize.hh"
#include "G4VisExecutive.hh"
#include "G4UIExecutive.hh"
#include "G4UIQt.hh"
#include "CommandLineParser.hh"
Include dependency graph for pdb4dna.cc:

Go to the source code of this file.

Functions

CommandLineParserparser (0)
 
void Parse (int &argc, char **argv)
 
int main (int argc, char **argv)
 

Detailed Description

Main program of the pdb4dna example.

Definition in file pdb4dna.cc.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 66 of file pdb4dna.cc.

67 {
69  // Parse options given in commandLine
70  //
71  Parse(argc, argv);
72 
73  // Set the Seed
74  CLHEP::RanecuEngine defaultEngine(1234567);
75  G4Random::setTheEngine(&defaultEngine);
76 
77  // Choose the Random engine
78  //
80 
82  // Construct the run manager according to whether MT is activated or not
83  //
84  Command* commandLine(0);
85 
86 #ifdef G4MULTITHREADED
87  G4MTRunManager* runManager= new G4MTRunManager;
88  if ((commandLine = parser->GetCommandIfActive("-mt")))
89  {
90  int nThreads = 2;
91  if(commandLine->GetOption() == "NMAX")
92  {
94  }
95  else
96  {
97  nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
98  }
99  G4cout << "===== PDB4DNA is started with "
100  << runManager->GetNumberOfThreads()
101  << " threads =====" << G4endl;
102 
103  runManager->SetNumberOfThreads(nThreads);
104  }
105 #else
106  G4RunManager* runManager = new G4RunManager();
107 #endif
108 
109  // Set user classes
110  //
111  runManager->SetUserInitialization(new DetectorConstruction());
112  runManager->SetUserInitialization(new PhysicsList);
113  runManager->SetUserInitialization(new ActionInitialization());
114 
115  // Initialize G4 keRnel
116  //
117  // runManager->Initialize();
118 
119  // Initialize visualization
120  G4VisManager* visManager = new G4VisExecutive;
121  visManager->Initialize();
122 
123  // Get the pointer to the User Interface manager
124  G4UImanager* UImanager = G4UImanager::GetUIpointer();
125  G4UIExecutive* ui(0);
126 
127  // interactive mode : define UI session
128  if ((commandLine = parser->GetCommandIfActive("-gui")))
129  {
130  ui = new G4UIExecutive(argc, argv,
131  commandLine->GetOption());
132 
133  if(parser->GetCommandIfActive("-novis") == 0)
134  // visualization is used by default
135  {
136  if ((commandLine = parser->GetCommandIfActive("-vis")))
137  // select a visualization driver if needed (e.g. HepFile)
138  {
139  UImanager->ApplyCommand(G4String("/vis/open ")+
140  commandLine->GetOption());
141  }
142  else
143  // by default OGL is used
144  {
145  UImanager->ApplyCommand("/vis/open OGL 600x600-0+0");
146  }
147  UImanager->ApplyCommand("/control/execute vis.mac");
148  }
149  if (ui->IsGUI())
150  UImanager->ApplyCommand("/control/execute gui.mac");
151  }
152  else
153  // to be use visualization file (= store the visualization into
154  // an external file:
155  // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ...
156  {
157  if ((commandLine = parser->GetCommandIfActive("-vis")))
158  {
159  UImanager->ApplyCommand(G4String("/vis/open ")+
160  commandLine->GetOption());
161  UImanager->ApplyCommand("/control/execute vis.mac");
162  }
163  }
164 
165  if ((commandLine = parser->GetCommandIfActive("-mac")))
166  {
167  G4String command = "/control/execute ";
168  UImanager->ApplyCommand(command + commandLine->GetOption());
169  }
170  else
171  {
172  UImanager->ApplyCommand("/control/execute init.mac");
173  }
174 
175  if ((commandLine = parser->GetCommandIfActive("-gui")))
176  {
177 #ifdef G4UI_USE_QT
178  G4UIQt* UIQt = static_cast<G4UIQt*> (UImanager->GetG4UIWindow());
179  if ( UIQt) {
180  UIQt->AddViewerTabFromFile("README", "README from "+ G4String(argv[0]));
181  }
182 #endif
183  ui->SessionStart();
184  delete ui;
185  }
186 
187  // Job termination
188  delete visManager;
189  delete runManager;
190 
191  return 0;
192 }
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
void SetNumberOfThreads(G4int n)
G4UIsession * GetG4UIWindow() const
Definition: G4UImanager.hh:210
Command * GetCommandIfActive(const G4String &marker)
void Parse(int &argc, char **argv)
Definition: pdb4dna.cc:196
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4GLOB_DLL std::ostream G4cout
G4int G4GetNumberOfCores()
Definition: G4Threading.cc:133
G4int GetNumberOfThreads() const
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:435
void Initialize()
Detector construction class to define materials and geometry.
#define G4endl
Definition: G4ios.hh:61
static void setTheEngine(HepRandomEngine *theNewEngine)
Definition: Random.cc:171
CommandLineParser * parser(0)
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:446
Here is the call graph for this function:

◆ Parse()

void Parse ( int &  argc,
char **  argv 
)

Definition at line 196 of file pdb4dna.cc.

197 {
199  // Parse options given in commandLine
200  //
201  parser = CommandLineParser::GetParser();
202 
203  parser->AddCommand("-gui",
204  Command::OptionNotCompulsory,
205  "Select geant4 UI or just launch a geant4 terminal session",
206  "qt");
207 
208  parser->AddCommand("-mac",
209  Command::WithOption,
210  "Give a mac file to execute",
211  "pdb4dna.in");
212 
213 // You cann your own command, as for instance:
214 // parser->AddCommand("-seed",
215 // Command::WithOption,
216 // "Give a seed value in argument to be tested", "seed");
217 // it is then up to you to manage this option
218 
219 #ifdef G4MULTITHREADED
220  parser->AddCommand("-mt", Command::WithOption,
221  "Launch in MT mode (events computed in parallel)",
222  "2");
223 #endif
224 
225  parser->AddCommand("-vis",
226  Command::WithOption,
227  "Select a visualization driver",
228  "OGL 600x600-0+0");
229 
230  parser->AddCommand("-novis",
231  Command::WithoutOption,
232  "Deactivate visualization when using GUI");
233 
235  // If -h or --help is given in option : print help and exit
236  //
237  if (parser->Parse(argc, argv) != 0) // help is being printed
238  {
239  // if you are using ROOT, create a TApplication in this condition in order
240  // to print the help from ROOT as well
241  CommandLineParser::DeleteInstance();
242  std::exit(0);
243  }
244 
246  // Kill application if wrong argument in command line
247  //
248  if (parser->CheckIfNotHandledOptionsExists(argc, argv))
249  {
250  // if you are using ROOT, you should initialise your TApplication
251  // before this condition
252  abort();
253  }
254 }
void AddCommand(const G4String &marker, Command::Type, const G4String &description="", const G4String &defaultOption="", const G4String &optionName="")
bool CheckIfNotHandledOptionsExists(int &argc, char **argv)
CommandLineParser * parser(0)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parser()

CommandLineParser* parser ( )
Here is the caller graph for this function: