LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
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 "CommandLineParser.hh"

Go to the source code of this file.

Functions

CommandLineParser * parser (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

int main ( int  argc,
char **  argv 
)

Definition at line 68 of file pdb4dna.cc.

References Parse(), and parser().

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  //
81  CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine);
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  {
95  nThreads = G4Threading::G4GetNumberOfCores();
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 }
void Parse(int &argc, char **argv)
Definition: pdb4dna.cc:198
CommandLineParser * parser(0)
void Parse ( int &  argc,
char **  argv 
)

Definition at line 198 of file pdb4dna.cc.

References parser().

Referenced by main().

199 {
201  // Parse options given in commandLine
202  //
203  parser = CommandLineParser::GetParser();
204 
205  parser->AddCommand("-gui",
206  Command::OptionNotCompulsory,
207  "Select geant4 UI or just launch a geant4 terminal session",
208  "qt");
209 
210  parser->AddCommand("-mac",
211  Command::WithOption,
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
222  parser->AddCommand("-mt", Command::WithOption,
223  "Launch in MT mode (events computed in parallel)",
224  "2");
225 #endif
226 
227  parser->AddCommand("-vis",
228  Command::WithOption,
229  "Select a visualization driver",
230  "OGL 600x600-0+0");
231 
232  parser->AddCommand("-novis",
233  Command::WithoutOption,
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
243  CommandLineParser::DeleteInstance();
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 }
CommandLineParser * parser(0)
CommandLineParser* parser ( )

Referenced by main(), and Parse().