Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
chem1.cc File Reference

Chem1 example. More...

#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 "CommandLineParser.hh"
Include dependency graph for chem1.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

Chem1 example.

Definition in file chem1.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 71 of file chem1.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  G4MTRunManager* runManager= new G4MTRunManager;
85  if ((commandLine = parser->GetCommandIfActive("-mt")))
86  {
87  int nThreads = 2;
88  if(commandLine->GetOption() == "NMAX")
89  {
91  }
92  else
93  {
94  nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
95  }
96  G4cout << "===== Chem1 is started with "
97  << runManager->GetNumberOfThreads()
98  << " threads =====" << G4endl;
99 
100  runManager->SetNumberOfThreads(nThreads);
101  }
102 #else
103  G4RunManager* runManager = new G4RunManager();
104 #endif
105 
107  // Set mandatory user initialization classes
108  //
110  runManager->SetUserInitialization(new PhysicsList);
111  runManager->SetUserInitialization(detector);
112  runManager->SetUserInitialization(new ActionInitialization());
113 
114  // Initialize G4 kernel
115  runManager->Initialize();
116 
117  // Initialize visualization
118  G4VisManager* visManager = new G4VisExecutive;
119  // G4VisExecutive can take a verbosity argument - see /vis/verbose guidance.
120  // G4VisManager* visManager = new G4VisExecutive("Quiet");
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, commandLine->GetOption());
131 
132  if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute gui.mac");
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(
141  G4String("/vis/open ") + commandLine->GetOption());
142  }
143  else
144  // by default OGL is used
145  {
146  UImanager->ApplyCommand("/vis/open OGL 800x600-0+0");
147  }
148  UImanager->ApplyCommand("/control/execute vis.mac");
149  }
150  }
151  else
152  // to be use visualization file (= store the visualization into
153  // an external file:
154  // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ...
155  {
156  if ((commandLine = parser->GetCommandIfActive("-vis")))
157  {
158  UImanager->ApplyCommand(
159  G4String("/vis/open ") + commandLine->GetOption());
160  UImanager->ApplyCommand("/control/execute vis.mac");
161  }
162  }
163 
164  if ((commandLine = parser->GetCommandIfActive("-mac")))
165  {
166  G4String command = "/control/execute ";
167  UImanager->ApplyCommand(command + commandLine->GetOption());
168  }
169  else
170  {
171  UImanager->ApplyCommand("/control/execute beam.in");
172  }
173 
174  if ((commandLine = parser->GetCommandIfActive("-gui")))
175  {
176  ui->SessionStart();
177  delete ui;
178  }
179 
180  // Job termination
181  // Free the store: user actions, physics_list and detector_description are
182  // owned and deleted by the run manager, so they should not be deleted
183  // in the main() program !
184 
185  delete visManager;
186  delete runManager;
187 
188  CommandLineParser::DeleteInstance();
189 
190  return 0;
191 }
void Parse(int &argc, char **argv)
Definition: chem1.cc:193
virtual void SetUserInitialization(G4VUserDetectorConstruction *userInit)
void SetNumberOfThreads(G4int n)
Command * GetCommandIfActive(const G4String &marker)
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()
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:447
Physics list class.
Definition: PhysicsList.hh:47

Here is the call graph for this function:

void Parse ( int argc,
char **  argv 
)

Definition at line 193 of file chem1.cc.

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

CommandLineParser* parser ( )

Here is the caller graph for this function: