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] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/extended/medical/dna/chem5/chem5.cc (Version 11.3.0) and /examples/extended/medical/dna/chem5/chem5.cc (Version 10.2.p3)


  1 //                                                  1 
  2 // *******************************************    
  3 // * License and Disclaimer                       
  4 // *                                              
  5 // * The  Geant4 software  is  copyright of th    
  6 // * the Geant4 Collaboration.  It is provided    
  7 // * conditions of the Geant4 Software License    
  8 // * LICENSE and available at  http://cern.ch/    
  9 // * include a list of copyright holders.         
 10 // *                                              
 11 // * Neither the authors of this software syst    
 12 // * institutes,nor the agencies providing fin    
 13 // * work  make  any representation or  warran    
 14 // * regarding  this  software system or assum    
 15 // * use.  Please see the license in the file     
 16 // * for the full disclaimer and the limitatio    
 17 // *                                              
 18 // * This  code  implementation is the result     
 19 // * technical work of the GEANT4 collaboratio    
 20 // * By using,  copying,  modifying or  distri    
 21 // * any work based  on the software)  you  ag    
 22 // * use  in  resulting  scientific  publicati    
 23 // * acceptance of all terms of the Geant4 Sof    
 24 // *******************************************    
 25 //                                                
 26 // This example is provided by the Geant4-DNA     
 27 // Any report or published results obtained us    
 28 // shall cite the following Geant4-DNA collabo    
 29 // Med. Phys. 37 (2010) 4692-4708                 
 30 // J. Comput. Phys. 274 (2014) 841-882            
 31 // Phys. Med. Biol. 63(10) (2018) 105014-12pp     
 32 // The Geant4-DNA web site is available at htt    
 33 //                                                
 34 //                                                
 35 /// \file chem5.cc                                
 36 /// \brief Chem5 example                          
 37                                                   
 38 #include "ActionInitialization.hh"                
 39 #include "CommandLineParser.hh"                   
 40 #include "DetectorConstruction.hh"                
 41 #include "PhysicsList.hh"                         
 42                                                   
 43 #include "G4DNAChemistryManager.hh"               
 44 #include "G4RunManagerFactory.hh"                 
 45 #include "G4UIExecutive.hh"                       
 46 #include "G4UImanager.hh"                         
 47 #include "G4VisExecutive.hh"                      
 48                                                   
 49 /*                                                
 50  * WARNING : Geant4 was initially not intended    
 51  * This code is delivered as a prototype          
 52  * We will be happy to hear from you, do not h    
 53  * communicate on the difficulties you may enc    
 54  * The user interface may change in the next r    
 55  * code has started                               
 56  */                                               
 57                                                   
 58 //....oooOO0OOooo........oooOO0OOooo........oo    
 59                                                   
 60 using namespace G4DNAPARSER;                      
 61 CommandLineParser* parser(0);                     
 62 long seed = 0;                                    
 63                                                   
 64 unsigned int noise();                             
 65 void SetSeed();                                   
 66                                                   
 67 void Parse(int& argc, char** argv);               
 68                                                   
 69 //....oooOO0OOooo........oooOO0OOooo........oo    
 70                                                   
 71 int main(int argc, char** argv)                   
 72 {                                                 
 73   // Parse options given in commandLine           
 74   Parse(argc, argv);                              
 75   Command* commandLine(0);                        
 76   SetSeed();                                      
 77                                                   
 78   // Construct the run manager according to wh    
 79   //                                              
 80   auto* runManager = G4RunManagerFactory::Crea    
 81                                                   
 82   if ((commandLine = parser->GetCommandIfActiv    
 83     int nThreads = 2;                             
 84     if (commandLine->GetOption() == "NMAX") {     
 85       nThreads = G4Threading::G4GetNumberOfCor    
 86     }                                             
 87     else {                                        
 88       nThreads = G4UIcommand::ConvertToInt(com    
 89     }                                             
 90                                                   
 91     runManager->SetNumberOfThreads(nThreads);     
 92   }                                               
 93                                                   
 94   G4cout << "*********************************    
 95          << "******\n===== Chem5 is started wi    
 96          << G4Threading::G4GetNumberOfCores()     
 97          << " available threads =====\n\n*****    
 98          << "*******************************"     
 99                                                   
100   // Set mandatory initialization classes         
101   runManager->SetUserInitialization(new Physic    
102   runManager->SetUserInitialization(new Detect    
103   runManager->SetUserInitialization(new Action    
104                                                   
105   // Initialize G4 kernel                         
106   runManager->Initialize();                       
107                                                   
108   // Initialize visualization                     
109   G4VisManager* visManager = new G4VisExecutiv    
110   // G4VisExecutive can take a verbosity argum    
111   // G4VisManager* visManager = new G4VisExecu    
112   visManager->Initialize();                       
113                                                   
114   // Get the pointer to the User Interface man    
115   G4UImanager* UImanager = G4UImanager::GetUIp    
116   G4UIExecutive* ui(0);                           
117                                                   
118   // interactive mode : define UI session         
119   if ((commandLine = parser->GetCommandIfActiv    
120     ui = new G4UIExecutive(argc, argv, command    
121                                                   
122     if (ui->IsGUI()) UImanager->ApplyCommand("    
123                                                   
124     if (parser->GetCommandIfActive("-novis") =    
125       // visualization is used by default         
126       if ((commandLine = parser->GetCommandIfA    
127         // select a visualization driver if ne    
128         UImanager->ApplyCommand(G4String("/vis    
129       }                                           
130       else {                                      
131         // by default OGL is used                 
132         UImanager->ApplyCommand("/vis/open OGL    
133       }                                           
134       UImanager->ApplyCommand("/control/execut    
135     }                                             
136   }                                               
137   else {                                          
138     // to be use visualization file (= store t    
139     // an external file:                          
140     // ASCIITree ;  DAWNFILE ; HepRepFile ; VR    
141     if ((commandLine = parser->GetCommandIfAct    
142       UImanager->ApplyCommand(G4String("/vis/o    
143       UImanager->ApplyCommand("/control/execut    
144     }                                             
145   }                                               
146                                                   
147   if ((commandLine = parser->GetCommandIfActiv    
148     G4String command = "/control/execute ";       
149     UImanager->ApplyCommand(command + commandL    
150   }                                               
151   else {                                          
152     UImanager->ApplyCommand("/control/execute     
153   }                                               
154                                                   
155   if ((commandLine = parser->GetCommandIfActiv    
156     ui->SessionStart();                           
157     delete ui;                                    
158   }                                               
159                                                   
160   // Job termination                              
161   // Free the store: user actions, physics_lis    
162   // owned and deleted by the run manager, so     
163   // in the main() program !                      
164   delete visManager;                              
165   delete runManager;                              
166   CommandLineParser::DeleteInstance();            
167   return 0;                                       
168 }                                                 
169                                                   
170 //....oooOO0OOooo........oooOO0OOooo........oo    
171                                                   
172 bool IsBracket(char c)                            
173 {                                                 
174   switch (c) {                                    
175     case '[':                                     
176     case ']':                                     
177       return true;                                
178     default:                                      
179       return false;                               
180   }                                               
181 }                                                 
182                                                   
183 //....oooOO0OOooo........oooOO0OOooo........oo    
184                                                   
185 void SetSeed()                                    
186 {                                                 
187   Command* commandLine(0);                        
188                                                   
189   if ((commandLine = parser->GetCommandIfActiv    
190     seed = atoi(commandLine->GetOption().c_str    
191   }                                               
192                                                   
193   if (seed == 0)  // If no seed given in argum    
194   {                                               
195     long jobID_int = 0;                           
196     long noice = 0;                               
197                                                   
198     //____________________________________        
199     // In case on cluster                         
200     if ((commandLine = parser->GetCommandIfAct    
201       noice = labs((long)noise());                
202                                                   
203       const char* env = std::getenv("PBS_JOBID    
204                                                   
205       if (env) {                                  
206         G4String buffer(env);                     
207         G4String jobID_string = buffer.substr(    
208         jobID_string.erase(std::remove_if(jobI    
209                            jobID_string.end())    
210         jobID_int = atoi(jobID_string.c_str())    
211       }                                           
212       else {                                      
213         env = std::getenv("SGE_TASK_ID");         
214         if (env) jobID_int = atoi(env);           
215       }                                           
216     }  // end cluster                             
217                                                   
218     //____________________________________        
219     seed = ((long)time(NULL)) + jobID_int + no    
220   }                                               
221                                                   
222   G4cout << "Seed used : " << seed << G4endl;     
223   G4Random::setTheEngine(new CLHEP::MixMaxRng(    
224   G4Random::setTheSeed(seed);                     
225                                                   
226   // Choose the Random engine                     
227   // CLHEP::HepRandom::setTheEngine(new CLHEP:    
228 }                                                 
229                                                   
230 //....oooOO0OOooo........oooOO0OOooo........oo    
231                                                   
232 unsigned int noise()                              
233 {                                                 
234 #if defined(WIN32) || defined(_WIN32) || defin    
235   // TODO: MS Win                                 
236   return std::time(0);                            
237 #else                                             
238   unsigned int random_seed, random_seed_a, ran    
239   std::ifstream file("/dev/urandom", std::ios:    
240   if (file.is_open()) {                           
241     char* memblock;                               
242     int size = sizeof(int);                       
243     memblock = new char[size];                    
244     file.read(memblock, size);                    
245     file.close();                                 
246     random_seed_a = *reinterpret_cast<int*>(me    
247     delete[] memblock;                            
248   }  // end if                                    
249   else {                                          
250     random_seed_a = 0;                            
251   }                                               
252   random_seed_b = std::time(0);                   
253   random_seed = random_seed_a xor random_seed_    
254   return random_seed;                             
255 #endif                                            
256 }                                                 
257                                                   
258 //....oooOO0OOooo........oooOO0OOooo........oo    
259                                                   
260 void Parse(int& argc, char** argv)                
261 {                                                 
262   //////////                                      
263   // Parse options given in commandLine           
264   //                                              
265   parser = CommandLineParser::GetParser();        
266                                                   
267   parser->AddCommand("-gui", Command::OptionNo    
268                      "Select geant4 UI or just    
269                      "session",                   
270                      "qt");                       
271                                                   
272   parser->AddCommand("-mac", Command::WithOpti    
273                                                   
274   parser->AddCommand("-seed", Command::WithOpt    
275                      "seed");                     
276                                                   
277   parser->AddCommand("-mt", Command::WithOptio    
278                      "Launch in MT mode (event    
279                      " NOT RECOMMANDED WITH CH    
280                      "2");                        
281                                                   
282   parser->AddCommand("-chemOFF", Command::With    
283                                                   
284   parser->AddCommand("-vis", Command::WithOpti    
285                      "OGL 600x600-0+0");          
286                                                   
287   parser->AddCommand("-novis", Command::Withou    
288                                                   
289   parser->AddCommand("-cluster", Command::With    
290                      "Launch the code on a clu    
291                                                   
292   //////////                                      
293   // If -h or --help is given in option : prin    
294   //                                              
295   if (parser->Parse(argc, argv) != 0)  // help    
296   {                                               
297     // if you are using ROOT, create a TApplic    
298     // to print the help from ROOT as well        
299     CommandLineParser::DeleteInstance();          
300     std::exit(0);                                 
301   }                                               
302                                                   
303   ///////////                                     
304   // Kill application if wrong argument in com    
305   //                                              
306   if (parser->CheckIfNotHandledOptionsExists(a    
307     // if you are using ROOT, you should initi    
308     // before this condition                      
309     std::exit(0);                                 
310   }                                               
311 }                                                 
312