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

Chem4 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 chem4.cc:

Go to the source code of this file.

Functions

CommandLineParserparser (0)
 
unsigned int noise ()
 
void SetSeed ()
 
void Parse (int &argc, char **argv)
 
int main (int argc, char **argv)
 
bool IsBracket (char c)
 

Variables

long seed = 0
 

Detailed Description

Chem4 example.

Definition in file chem4.cc.

Function Documentation

bool IsBracket ( char  c)

Definition at line 198 of file chem4.cc.

199 {
200  switch(c)
201  {
202  case '[':
203  case ']':
204  return true;
205  default:
206  return false;
207  }
208 }
tuple c
Definition: test.py:13

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 77 of file chem4.cc.

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

unsigned int noise ( )

Definition at line 265 of file chem4.cc.

266 {
267 #if defined(WIN32)|| defined(_WIN32)|| defined(__WIN32)&&!defined(__CYGWIN__)
268  // TODO: MS Win
269  return std::time(0);
270 #else
271  unsigned int random_seed, random_seed_a, random_seed_b;
272  std::ifstream file ("/dev/urandom", std::ios::binary);
273  if (file.is_open())
274  {
275  char * memblock;
276  int size = sizeof(int);
277  memblock = new char [size];
278  file.read (memblock, size);
279  file.close();
280  random_seed_a = *reinterpret_cast<int*>(memblock);
281  delete[] memblock;
282  }// end if
283  else
284  {
285  random_seed_a = 0;
286  }
287  random_seed_b = std::time(0);
288  random_seed = random_seed_a xor random_seed_b;
289  return random_seed;
290 #endif
291 }
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)

Here is the call graph for this function:

Here is the caller graph for this function:

void Parse ( int argc,
char **  argv 
)
CommandLineParser* parser ( )
void SetSeed ( )

Definition at line 212 of file chem4.cc.

213 {
214  Command* commandLine(0);
215 
216  if((commandLine = parser->GetCommandIfActive("-seed")))
217  {
218  seed = atoi(commandLine->GetOption().c_str());
219  }
220 
221  if(seed == 0) // If no seed given in argument, setup the seed
222  {
223  long jobID_int = 0;
224  long noice = 0;
225 
226  //____________________________________
227  // In case on cluster
228  if((commandLine = parser->GetCommandIfActive("-cluster")))
229  {
230  noice = labs((long) noise());
231 
232  const char * env = getenv("PBS_JOBID");
233 
234  if(env)
235  {
236  G4String buffer(env);
237  G4String jobID_string = buffer.substr(0, buffer.find("."));
238  jobID_string.erase(std::remove_if(jobID_string.begin(),
239  jobID_string.end(),
240  &IsBracket),
241  jobID_string.end());
242  jobID_int = atoi(jobID_string.c_str());
243  }
244  else
245  {
246  env = getenv("SGE_TASK_ID");
247  if(env) jobID_int = atoi(env);
248  }
249  } // end cluster
250 
251  //____________________________________
252  seed = ((long) time(NULL)) + jobID_int + noice;
253  }
254 
255  G4cout << "Seed used : " << seed << G4endl;
256  G4Random::setTheEngine(new CLHEP::MixMaxRng());
257  G4Random::setTheSeed(seed);
258 
259  // Choose the Random engine
260  // CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine);
261 }
bool IsBracket(char c)
Definition: chem4.cc:198
Command * GetCommandIfActive(const G4String &marker)
#define buffer
Definition: xmlparse.cc:628
unsigned int noise()
Definition: chem4.cc:265
G4GLOB_DLL std::ostream G4cout
long seed
Definition: chem4.cc:68
CommandLineParser * parser(0)
#define G4endl
Definition: G4ios.hh:61

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

long seed = 0

Definition at line 68 of file chem4.cc.