Geant4  10.02.p03
chem3.cc File Reference
#include "DetectorConstruction.hh"
#include "PhysicsList.hh"
#include "ActionInitialization.hh"
#include "G4RunManager.hh"
#include "G4DNAChemistryManager.hh"
#include "G4UImanager.hh"
#include "G4UIExecutive.hh"
#include "G4VisExecutive.hh"
#include "G4UIQt.hh"
#include "CommandLineParser.hh"
Include dependency graph for chem3.cc:

Go to the source code of this file.

Functions

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

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 71 of file chem3.cc.

72 {
74  // Parse options given in commandLine
75  //
76  Parse(argc, argv);
77 
79  // Construct the run manager according to whether MT is activated or not
80  //
81  Command* commandLine(0);
82 
83 #ifdef G4MULTITHREADED
84  G4RunManager* runManager(0);
85  if ((commandLine = parser->GetCommandIfActive("-mt")))
86  {
87  runManager = new G4MTRunManager;
88  int nThreads = 2;
89  const G4String& option = commandLine->GetOption();
90  if(option == "")
91  {
92  nThreads = G4UIcommand::ConvertToInt(commandLine->GetDefaultOption());
93  }
94  else if(option == "NMAX")
95  {
97  }
98  else
99  {
100  nThreads = G4UIcommand::ConvertToInt(option);
101  }
102 
103  G4cout << "===== Chem3 is started with "
104  << ((G4MTRunManager*) runManager)->GetNumberOfThreads()
105  << " threads =====" << G4endl;
106 
107  ((G4MTRunManager*) runManager)->SetNumberOfThreads(nThreads);
108  }
109  else
110  {
111  runManager = new G4RunManager();
112  }
113 #else
114  G4RunManager* runManager = new G4RunManager();
115 #endif
116 
118  // Set mandatory user initialization classes
119  //
121  runManager->SetUserInitialization(new PhysicsList);
122  runManager->SetUserInitialization(detector);
123  runManager->SetUserInitialization(new ActionInitialization());
124 
125  // Initialize G4 kernel
126  runManager->Initialize();
127 
128  // Initialize visualization
129  G4VisManager* visManager = new G4VisExecutive;
130  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
131  // G4VisManager* visManager = new G4VisExecutive("Quiet");
132  visManager->Initialize();
133 
134  // Get the pointer to the User Interface manager
135  G4UImanager* UImanager = G4UImanager::GetUIpointer();
136  G4UIExecutive* ui(0);
137 
138  // interactive mode : define UI session
139  if ((commandLine = parser->GetCommandIfActive("-gui")))
140  {
141  ui = new G4UIExecutive(argc, argv, commandLine->GetOption());
142 
143  if (parser->GetCommandIfActive("-novis") == 0)
144  // visualization is used by default
145  {
146  if ((commandLine = parser->GetCommandIfActive("-vis")))
147  // select a visualization driver if needed (e.g. HepFile)
148  {
149  UImanager->ApplyCommand(
150  G4String("/vis/open ") + commandLine->GetOption());
151  }
152  else
153  // by default OGL is used
154  {
155  UImanager->ApplyCommand("/vis/open OGL 800x600-0+0");
156  }
157  UImanager->ApplyCommand("/control/execute vis.mac");
158  }
159 
160  if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute gui.mac");
161  }
162  else
163  // to be use visualization file (= store the visualization into
164  // an external file:
165  // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ...
166  {
167  if ((commandLine = parser->GetCommandIfActive("-vis")))
168  {
169  UImanager->ApplyCommand(
170  G4String("/vis/open ") + commandLine->GetOption());
171  UImanager->ApplyCommand("/control/execute vis.mac");
172  }
173  }
174 
175  if ((commandLine = parser->GetCommandIfActive("-mac")))
176  {
177  G4String command = "/control/execute ";
178  UImanager->ApplyCommand(command + commandLine->GetOption());
179  }
180  else
181  {
182  UImanager->ApplyCommand("/control/execute beam.in");
183  }
184 
185  if ((commandLine = parser->GetCommandIfActive("-gui")))
186  {
187 #ifdef G4UI_USE_QT
188  G4UIQt* UIQt = static_cast<G4UIQt*> (UImanager->GetG4UIWindow());
189  if ( UIQt) {
190  UIQt->AddViewerTabFromFile("README", "README from "+ G4String(argv[0]));
191  }
192 #endif
193  ui->SessionStart();
194  delete ui;
195  }
196 
197  // Job termination
198  // Free the store: user actions, physics_list and detector_description are
199  // owned and deleted by the run manager, so they should not be deleted
200  // in the main() program !
201 
202  delete visManager;
203  delete runManager;
204 
205  CommandLineParser::DeleteInstance();
206 
207  return 0;
208 }
void Parse(int &argc, char **argv)
Definition: chem3.cc:210
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
G4UIsession * GetG4UIWindow() const
Definition: G4UImanager.hh:210
Command * GetCommandIfActive(const G4String &marker)
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4GLOB_DLL std::ostream G4cout
G4int G4GetNumberOfCores()
Definition: G4Threading.cc:133
CommandLineParser * parser(0)
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:435
void Initialize()
virtual void Initialize()
Detector construction class to define materials and geometry.
#define G4endl
Definition: G4ios.hh:61
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 210 of file chem3.cc.

211 {
213  // Parse options given in commandLine
214  //
215  parser = CommandLineParser::GetParser();
216 
218  "-gui", Command::OptionNotCompulsory,
219  "Select geant4 UI or just launch a geant4 terminal session", "qt");
220 
221  parser->AddCommand("-mac", Command::WithOption, "Give a mac file to execute",
222  "macFile.mac");
223 
224 // You cann your own command, as for instance:
225 // parser->AddCommand("-seed",
226 // Command::WithOption,
227 // "Give a seed value in argument to be tested", "seed");
228 // it is then up to you to manage this option
229 
230 #ifdef G4MULTITHREADED
231  parser->AddCommand("-mt", Command::OptionNotCompulsory,
232  "Launch in MT mode (events computed in parallel,"
233  " NOT RECOMMANDED WITH CHEMISTRY)",
234  "2");
235 #endif
236 
237  parser->AddCommand("-chemOFF", Command::WithoutOption,
238  "Deactivate chemistry");
239 
240  parser->AddCommand("-vis", Command::WithOption,
241  "Select a visualization driver", "OGL 600x600-0+0");
242 
243  parser->AddCommand("-novis", Command::WithoutOption,
244  "Deactivate visualization when using GUI");
245 
247  // If -h or --help is given in option : print help and exit
248  //
249  if (parser->Parse(argc, argv) != 0) // help is being printed
250  {
251  // if you are using ROOT, create a TApplication in this condition in order
252  // to print the help from ROOT as well
253  CommandLineParser::DeleteInstance();
254  std::exit(0);
255  }
256 
258  // Kill application if wrong argument in command line
259  //
260  if (parser->CheckIfNotHandledOptionsExists(argc, argv))
261  {
262  // if you are using ROOT, you should initialise your TApplication
263  // before this condition
264  abort();
265  }
266 }
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: