LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
clustering.cc File Reference

clustering 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"

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

clustering example

Definition in file clustering.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 59 of file clustering.cc.

References Parse(), and parser().

60 {
62  // Parse options given in commandLine
63  //
64  Parse(argc, argv);
65 
67  // Construct the run manager according to whether MT is activated or not
68  //
69  Command* commandLine(0);
70 
71 #ifdef G4MULTITHREADED
72  G4MTRunManager* runManager= new G4MTRunManager;
73  if ((commandLine = parser->GetCommandIfActive("-mt")))
74  {
75  int nThreads = 2;
76  if(commandLine->GetOption() == "NMAX")
77  {
78  nThreads = G4Threading::G4GetNumberOfCores();
79  }
80  else
81  {
82  nThreads = G4UIcommand::ConvertToInt(commandLine->GetOption());
83  }
84  G4cout << "===== clustering is started with "
85  << runManager->GetNumberOfThreads()
86  << " threads =====" << G4endl;
87 
88  runManager->SetNumberOfThreads(nThreads);
89  }
90 #else
91  G4RunManager* runManager = new G4RunManager();
92 #endif
93 
95  // Set mandatory user initialization classes
96  //
98  runManager->SetUserInitialization(new PhysicsList);
99  runManager->SetUserInitialization(detector);
100  runManager->SetUserInitialization(new ActionInitialization());
101 
102  // Initialize G4 kernel
103  runManager->Initialize();
104 
105  // Initialize visualization
106  G4VisManager* visManager = new G4VisExecutive;
107  visManager->Initialize();
108 
109  // Get the pointer to the User Interface manager
110  G4UImanager* UImanager = G4UImanager::GetUIpointer();
111  G4UIExecutive* ui(0);
112 
113  // interactive mode : define UI session
114  if ((commandLine = parser->GetCommandIfActive("-gui")))
115  {
116  ui = new G4UIExecutive(argc, argv, commandLine->GetOption());
117 
118  if (ui->IsGUI()) UImanager->ApplyCommand("/control/execute gui.mac");
119 
120  if (parser->GetCommandIfActive("-novis") == 0)
121  // visualization is used by default
122  {
123  if ((commandLine = parser->GetCommandIfActive("-vis")))
124  // select a visualization driver if needed (e.g. HepFile)
125  {
126  UImanager->ApplyCommand(
127  G4String("/vis/open ") + commandLine->GetOption());
128  }
129  else
130  // by default OGL is used
131  {
132  UImanager->ApplyCommand("/vis/open OGL 800x600-0+0");
133  }
134  UImanager->ApplyCommand("/control/execute vis.mac");
135  }
136  }
137  else
138  // to be use visualization file (= store the visualization into
139  // an external file:
140  // ASCIITree ; DAWNFILE ; HepRepFile ; VRML(1,2)FILE ; gMocrenFile ...
141  {
142  if ((commandLine = parser->GetCommandIfActive("-vis")))
143  {
144  UImanager->ApplyCommand(
145  G4String("/vis/open ") + commandLine->GetOption());
146  UImanager->ApplyCommand("/control/execute vis.mac");
147  }
148  }
149 
150  if ((commandLine = parser->GetCommandIfActive("-mac")))
151  {
152  G4String command = "/control/execute ";
153  UImanager->ApplyCommand(command + commandLine->GetOption());
154  }
155  else
156  {
157  UImanager->ApplyCommand("/control/execute run.in");
158  }
159 
160  if ((commandLine = parser->GetCommandIfActive("-gui")))
161  {
162  ui->SessionStart();
163  delete ui;
164  }
165 
166  // Job termination
167  // Free the store: user actions, physics_list and detector_description are
168  // owned and deleted by the run manager, so they should not be deleted
169  // in the main() program !
170 
171  delete visManager;
172  delete runManager;
173 
174  CommandLineParser::DeleteInstance();
175 
176  return 0;
177 }
CommandLineParser * parser(0)
void Parse(int &argc, char **argv)
Definition: clustering.cc:179
void Parse ( int &  argc,
char **  argv 
)

Definition at line 179 of file clustering.cc.

References parser().

Referenced by main().

180 {
182  // Parse options given in commandLine
183  //
184  parser = CommandLineParser::GetParser();
185 
186  parser->AddCommand(
187  "-gui", Command::OptionNotCompulsory,
188  "Select geant4 UI or just launch a geant4 terminal session", "qt");
189 
190  parser->AddCommand("-mac", Command::WithOption, "Give a mac file to execute",
191  "macFile.mac");
192 
193 // You cann your own command, as for instance:
194 // parser->AddCommand("-seed",
195 // Command::WithOption,
196 // "Give a seed value in argument to be tested", "seed");
197 // it is then up to you to manage this option
198 
199 #ifdef G4MULTITHREADED
200  parser->AddCommand("-mt",
201  Command::WithOption,
202  "Launch in MT mode (events computed in parallel,"
203  " NOT RECOMMENDED WITH CHEMISTRY)", "2");
204 #endif
205 
206  parser->AddCommand("-vis", Command::WithOption,
207  "Select a visualization driver", "OGL 600x600-0+0");
208 
209  parser->AddCommand("-novis", Command::WithoutOption,
210  "Deactivate visualization when using GUI");
211 
213  // If -h or --help is given in option : print help and exit
214  //
215  if (parser->Parse(argc, argv) != 0) // help is being printed
216  {
217  // if you are using ROOT, create a TApplication in this condition in order
218  // to print the help from ROOT as well
219  CommandLineParser::DeleteInstance();
220  std::exit(0);
221  }
222 
224  // Kill application if wrong argument in command line
225  //
226  if (parser->CheckIfNotHandledOptionsExists(argc, argv))
227  {
228  // if you are using ROOT, you should initialise your TApplication
229  // before this condition
230  abort();
231  }
232 }
CommandLineParser * parser(0)
CommandLineParser* parser ( )

Referenced by main(), and Parse().