LArSoft  v09_90_00
Liquid Argon Software toolkit - https://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 62 of file clustering.cc.

References Parse(), and parser().

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

Definition at line 184 of file clustering.cc.

References parser().

Referenced by main().

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

Referenced by main(), and Parse().