Geant4 Cross Reference |
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 // author: Le Tuan Anh, 20/10/2023 27 /// \file main.cc 28 /// \brief Main program of the dsbandrepair 29 30 #include "G4UImanager.hh" 31 #include "G4UIterminal.hh" 32 #include "G4UItcsh.hh" 33 #include "G4UIExecutive.hh" 34 35 #include "G4RunManagerFactory.hh" 36 37 #ifdef G4VIS_USE 38 #include "G4VisExecutive.hh" 39 #endif 40 41 #include "G4Timer.hh" 42 #include "G4ExceptionSeverity.hh" 43 #include "G4DNAChemistryManager.hh" 44 #include "G4VisExecutive.hh" 45 #include "G4Filesystem.hh" 46 47 #include "ActionInitialization.hh" 48 #include "DetectorConstruction.hh" 49 #include "PhysicsList.hh" 50 51 #include "Analysis.hh" 52 53 #ifdef USE_MPI 54 #include "G4MPImanager.hh" 55 #include "G4MPIsession.hh" 56 #include "G4MPIextraWorker.hh" 57 #endif 58 #include <ctime> 59 60 //....oooOO0OOooo........oooOO0OOooo........oo 61 62 G4String ExtractChemListNameFromMacroFile(G4St 63 64 //....oooOO0OOooo........oooOO0OOooo........oo 65 66 int main(int argc,char** argv) 67 { 68 #ifdef USE_MPI 69 G4MPImanager* g4MPI = new G4MPImanager 70 g4MPI->SetVerbose(1); 71 G4MPIsession* session = g4MPI-> GetMPI 72 G4String prompt = "[40;01;33m"; 73 prompt += "G4MPI"; 74 prompt += "[40;31m(%s)[40;36m[%/][0 75 session-> SetPrompt(prompt); 76 #else 77 G4UIExecutive* ui = nullptr; 78 if ( argc == 1 ) { ui = new G4UIExecut 79 #endif // USE_MPI 80 if (argc < 2) { 81 G4cerr<<"====>> Wrong input. To run Ph 82 <<"To run Chem_geo, type : ./dsban 83 #ifdef USE_MPI 84 delete g4MPI; 85 #endif // USE_MPI 86 return EXIT_SUCCESS; 87 } 88 G4String stgstr = ""; 89 G4String macrofileName = argv[1]; 90 if (argc > 2) { 91 const G4String rmode = argv[2]; 92 if (rmode == "phys") gRunMode = Runnin 93 else if (rmode == "chem") gRunMode = R 94 else { 95 G4cout<<"Undefined Running Mode = 96 #ifdef USE_MPI 97 delete g4MPI; 98 #endif // USE_MPI 99 return EXIT_SUCCESS; 100 } 101 } 102 // Choose the Random engine 103 time_t timeStart; 104 time(&timeStart); 105 unsigned long seed = timeStart; 106 #ifdef USE_MPI 107 // Le Tuan Anh: add rankID to get differen 108 seed += g4MPI->GetRank(); 109 #endif // USE_MPI 110 G4cout<<"Initial Seed for random engine: " 111 CLHEP::HepRandom::setTheEngine(new CLHEP:: 112 CLHEP::HepRandom::setTheSeed(seed); 113 G4RunManager* runManager{nullptr}; 114 auto analysis = Analysis::GetAnalysis(); 115 if (gRunMode == RunningMode::Phys) { 116 stgstr = "physical stage"; 117 runManager = G4RunManagerFactory::Crea 118 #ifdef G4MULTITHREADED 119 G4int threadNumber= 1; 120 runManager-> SetNumberOfThreads(thread 121 #endif // G4MULTITHREADED 122 #ifdef USE_MPI 123 stgstr += " in #rank"+std::to_string(g 124 if (g4MPI->IsMaster()) analysis->Check 125 #else 126 analysis->CheckAndCreateNewFolderInPhy 127 #endif 128 } else if (gRunMode == RunningMode::Chem) 129 stgstr = "chemical stage"; 130 runManager = G4RunManagerFactory::Crea 131 G4DNAChemistryManager::Instance()->Set 132 G4Scheduler::Instance(); 133 } 134 135 DetectorConstruction* detector = new Detec 136 runManager->SetUserInitialization(detector 137 PhysicsList* physList = new PhysicsList; 138 ActionInitialization* actionIni = new Acti 139 140 if (gRunMode == RunningMode::Phys) { 141 runManager->SetUserInitialization(phys 142 runManager->SetUserInitialization(acti 143 #ifdef USE_MPI 144 session-> SessionStart(); 145 if (g4MPI->GetRank() == 0 ){ 146 analysis->WritePhysGeo(); 147 } 148 #else 149 // Get the pointer to the User Interfa 150 G4UImanager* UImanager = G4UImanager:: 151 // Process macro or start UI session 152 if ( ! ui ) { 153 // batch mode 154 G4String command = "/control/execu 155 UImanager->ApplyCommand(command+ma 156 } 157 analysis->WritePhysGeo(); 158 #endif // USE_MPI 159 } 160 161 162 if (gRunMode == RunningMode::Chem) { 163 //get the pointer to the User Interfac 164 G4UImanager* UI = G4UImanager::GetUIpo 165 #ifdef USE_MPI 166 session->SessionStart(); 167 stgstr += " in #rank"+std::to_string(g 168 if (g4MPI->IsMaster()) analysis->Check 169 #else 170 G4String command = "/control/execute " 171 UI->ApplyCommand(command+macrofileName 172 analysis->CheckAndCreateNewFolderInChe 173 #endif 174 //------------------------------------ 175 // Prepare input file 176 //------------------------------------ 177 std::string inputFileorFolder = "chem_ 178 if (argc == 4) inputFileorFolder = arg 179 G4fs::path p{inputFileorFolder}; 180 G4String outputFileName = "test"; 181 std::vector<G4String> totalNumberofFil 182 if (G4fs::is_directory(p)) { 183 for (const auto& entry : G4fs::dir 184 if (entry.path().extension() = 185 totalNumberofFilesVector.p 186 } 187 } 188 std::sort(totalNumberofFilesVector 189 #ifdef USE_MPI 190 G4int numberofRanks = g4MPI->GetAc 191 size_t filesTobeProcessedSlave = ( 192 std::floor(G4double(totalNumbe 193 // note: should not use "std::ceil 194 size_t filesTobeProcessedMaster = 195 totalNumberofFilesVector.size( 196 if (g4MPI->IsMaster()) { 197 for (size_t ii=0; ii< filesTob 198 numberOfFilesTobeProcessed 199 } 200 } else { 201 for (size_t ii=0; ii< filesTob 202 auto rankID = g4MPI->GetRa 203 size_t kk = filesTobeProce 204 numberOfFilesTobeProcessed 205 } 206 } 207 G4cout<<"-----> "<<numberOfFilesTo 208 <<" files will be processe 209 #else 210 numberOfFilesTobeProcessedVector = 211 #endif 212 if (totalNumberofFilesVector.size( 213 G4cout<<"===>> There is no fil 214 <<". You have to run Phys_geo 215 #ifdef USE_MPI 216 delete g4MPI; 217 #endif // USE_MPI 218 delete runManager; 219 return EXIT_SUCCESS; 220 } else { 221 G4cout<<"===>> Total files fou 222 <<" : "<<totalNumberofFilesVec 223 } 224 } else if (G4fs::is_regular_file(p)) { 225 numberOfFilesTobeProcessedVector.p 226 if (p.has_stem()) { 227 outputFileName = p.stem().stri 228 } else outputFileName = inputFileo 229 } 230 else G4cout<<"===>>dsbandrepair: "<<p. 231 G4String firstFileForInit=""; 232 if (numberOfFilesTobeProcessedVector.s 233 firstFileForInit=numberOfFilesTobe 234 detector->ParseGeoFileForChemMode( 235 } 236 //------------------------------------ 237 // Initialization classes 238 //------------------------------------ 239 240 runManager->SetUserInitialization(phys 241 runManager->SetUserInitialization(acti 242 runManager->Initialize(); 243 if (numberOfFilesTobeProcessedVector.s 244 size_t nprocessedfiles{0}, ncounts 245 if (numberOfFilesTobeProcessedVect 246 if (numberOfFilesTobeProcessedVect 247 if (numberOfFilesTobeProcessedVect 248 for (auto const &fileInput : numbe 249 G4fs::path aP{std::string(file 250 if (aP.has_stem()) { 251 outputFileName = aP.stem() 252 } else outputFileName = fileIn 253 analysis->SetFileName(outputFi 254 if (fileInput != firstFileForI 255 detector->InsertMoleculeInWorl 256 UI->ApplyCommand("/run/beamOn 257 nprocessedfiles++; 258 if (nprocessedfiles == 1 || 259 nprocessedfiles == numberO 260 0 == (nprocessedfiles % nc 261 G4cout<<"=====> Processed 262 <<numberOfFilesTobeP 263 #ifdef USE_MPI 264 <<" in rank #"<<g4MP 265 #endif 266 <<"!!!"<<G4endl; 267 } 268 } 269 } else { 270 UI->ApplyCommand("/run/beamOn 1"); 271 } 272 } 273 274 #ifdef USE_MPI 275 delete g4MPI; 276 #endif // USE_MPI 277 delete runManager; 278 279 G4cout <<"----------------------> Finish 280 return EXIT_SUCCESS; 281 } 282 283 //....oooOO0OOooo........oooOO0OOooo........oo 284