Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4PhysListRegistry << 27 // 26 // 28 // Author: R. Hatcher, 2014-10-15 << 27 // 29 // ------------------------------------------- << 28 // ------------------------------------------------------------------- >> 29 // >> 30 // GEANT4 Class file >> 31 // >> 32 // File name: G4PhysListRegistry >> 33 // >> 34 // Author R. Hatcher 2014-10-15 >> 35 // >> 36 // Modifications: based on G4PhysicsConstructorRegistry >> 37 // >> 38 //#define G4VERBOSE 1 30 39 >> 40 #include "G4ios.hh" 31 #include <iomanip> 41 #include <iomanip> 32 #include <algorithm> 42 #include <algorithm> 33 43 34 #include "G4ios.hh" << 35 #include "G4PhysListRegistry.hh" 44 #include "G4PhysListRegistry.hh" 36 #include "G4VModularPhysicsList.hh" 45 #include "G4VModularPhysicsList.hh" 37 #include "G4PhysListStamper.hh" 46 #include "G4PhysListStamper.hh" 38 47 39 #include "G4PhysicsConstructorRegistry.hh" 48 #include "G4PhysicsConstructorRegistry.hh" 40 // include G4_REFERENCE_PHYSCONSTR_FACTORY() m 49 // include G4_REFERENCE_PHYSCONSTR_FACTORY() macros here to pull them in 41 // for static builds. Would do this in G4Ph 50 // for static builds. Would do this in G4PhysicsConstructorRegistry 42 // but that causes a circular dependency when 51 // but that causes a circular dependency when the phys_ctor libs 43 // are broken in a "granular" build. 52 // are broken in a "granular" build. 44 #define REGREF PhysListReg // REGREF is used t 53 #define REGREF PhysListReg // REGREF is used to make instances unique 45 #include "G4RegisterPhysicsConstructors.icc" 54 #include "G4RegisterPhysicsConstructors.icc" 46 55 47 // include this with this compilation unit so 56 // include this with this compilation unit so static builds pull them in 48 #include "G4RegisterPhysLists.icc" 57 #include "G4RegisterPhysLists.icc" 49 58 50 G4ThreadLocal G4PhysListRegistry* G4PhysListRe << 59 G4ThreadLocal G4PhysListRegistry* G4PhysListRegistry::theInstance = 0; 51 60 52 const G4int doReplace = 0x01; // _ (ReplaceP << 61 const int doReplace = 0x01; // _ (ReplacePhysics) vs. + (RegisterPhysics) 53 const G4int isCtorName = 0x02; // true if act << 62 const int isCtorName = 0x02; // true if actual physCtor name vs. ext name 54 63 55 G4PhysListRegistry* G4PhysListRegistry::Instan 64 G4PhysListRegistry* G4PhysListRegistry::Instance() 56 { 65 { 57 if ( nullptr == theInstance) { << 66 if ( 0 == theInstance) { 58 theInstance = new G4PhysListRegistry; << 67 static G4ThreadLocal G4PhysListRegistry *manager_G4MT_TLS_ = 0; 59 << 68 if (!manager_G4MT_TLS_) manager_G4MT_TLS_ = new G4PhysListRegistry; 60 // common EM overrides << 69 G4PhysListRegistry &manager = *manager_G4MT_TLS_; 61 theInstance->AddPhysicsExtension("EM0","G4 << 70 theInstance = &manager; 62 theInstance->AddPhysicsExtension("EMV","G4 << 71 } 63 theInstance->AddPhysicsExtension("EMX","G4 << 72 64 theInstance->AddPhysicsExtension("EMY","G4 << 73 // common EM overrides 65 theInstance->AddPhysicsExtension("EMZ","G4 << 74 theInstance->AddPhysicsExtension("EM0","G4EmStandardPhysics"); 66 theInstance->AddPhysicsExtension("LIV","G4 << 75 theInstance->AddPhysicsExtension("EMV","G4EmStandardPhysics_option1"); 67 theInstance->AddPhysicsExtension("PEN","G4 << 76 theInstance->AddPhysicsExtension("EMX","G4EmStandardPhysics_option2"); 68 // the GS EM extension originally required << 77 theInstance->AddPhysicsExtension("EMY","G4EmStandardPhysics_option3"); 69 // support either one or two as __GS is co << 78 theInstance->AddPhysicsExtension("EMZ","G4EmStandardPhysics_option4"); 70 // same for __SS << 79 theInstance->AddPhysicsExtension("LIV","G4EmLivermorePhysics"); 71 theInstance->AddPhysicsExtension("GS" ,"G4 << 80 theInstance->AddPhysicsExtension("PEN","G4EmPenelopePhysics"); 72 theInstance->AddPhysicsExtension("_GS","G4 << 81 // the GS EM extension originally required double underscores 73 theInstance->AddPhysicsExtension("SS" ,"G4 << 82 // support either one or two as __GS is confusing to users 74 theInstance->AddPhysicsExtension("_SS","G4 << 83 // same for __SS 75 << 84 theInstance->AddPhysicsExtension("GS" ,"G4EmStandardPhysicsGS"); 76 theInstance->AddPhysicsExtension("EM0","G4 << 85 theInstance->AddPhysicsExtension("_GS","G4EmStandardPhysicsGS"); 77 theInstance->AddPhysicsExtension("WVI","G4 << 86 theInstance->AddPhysicsExtension("SS" ,"G4EmStandardPhysicsSS"); 78 theInstance->AddPhysicsExtension("LE" ,"G4 << 87 theInstance->AddPhysicsExtension("_SS","G4EmStandardPhysicsSS"); 79 theInstance->AddPhysicsExtension("_LE","G4 << 88 80 << 89 theInstance->AddPhysicsExtension("EM0","G4EmStandardPhysics"); 81 theInstance->AddPhysicsExtension("HPT","G4 << 90 theInstance->AddPhysicsExtension("WVI","G4EmStandardPhysicsWVI"); 82 } << 91 theInstance->AddPhysicsExtension("LE" ,"G4EmLowEPPhysics"); >> 92 theInstance->AddPhysicsExtension("_LE","G4EmLowEPPhysics"); 83 93 84 return theInstance; 94 return theInstance; 85 } 95 } 86 96 87 G4PhysListRegistry::G4PhysListRegistry() 97 G4PhysListRegistry::G4PhysListRegistry() 88 : verbose(1) 98 : verbose(1) 89 , unknownFatal(0) 99 , unknownFatal(0) 90 , systemDefault("FTFP_BERT") 100 , systemDefault("FTFP_BERT") 91 { 101 { 92 SetUserDefaultPhysList(); 102 SetUserDefaultPhysList(); 93 } 103 } 94 104 95 G4PhysListRegistry::~G4PhysListRegistry() 105 G4PhysListRegistry::~G4PhysListRegistry() 96 { 106 { 97 } 107 } 98 108 99 void G4PhysListRegistry::SetUserDefaultPhysLis 109 void G4PhysListRegistry::SetUserDefaultPhysList(const G4String& name) 100 { 110 { 101 if ( name == "" ) userDefault = systemDefaul 111 if ( name == "" ) userDefault = systemDefault; 102 else userDefault = name; 112 else userDefault = name; 103 } 113 } 104 114 105 void G4PhysListRegistry::AddFactory(G4String n 115 void G4PhysListRegistry::AddFactory(G4String name, G4VBasePhysListStamper* factory) 106 { 116 { 107 factories[name] = factory; 117 factories[name] = factory; 108 } 118 } 109 119 110 void G4PhysListRegistry::AddPhysicsExtension(G 120 void G4PhysListRegistry::AddPhysicsExtension(G4String name, G4String procname) 111 { 121 { 112 // a mapping from short extension names to a 122 // a mapping from short extension names to actual physics process constructors 113 physicsExtensions[name] = procname; 123 physicsExtensions[name] = procname; 114 } 124 } 115 125 116 G4VModularPhysicsList* 126 G4VModularPhysicsList* 117 G4PhysListRegistry::GetModularPhysicsList(cons 127 G4PhysListRegistry::GetModularPhysicsList(const G4String& name) 118 { 128 { 119 // 129 // 120 // 130 // 121 G4String plBase = ""; 131 G4String plBase = ""; 122 std::vector<G4String> physExt; 132 std::vector<G4String> physExt; 123 std::vector<G4int> physReplace; 133 std::vector<G4int> physReplace; 124 G4bool allKnown = 134 G4bool allKnown = 125 DeconstructPhysListName(name,plBase,physEx 135 DeconstructPhysListName(name,plBase,physExt,physReplace,verbose); 126 136 127 std::size_t npc = physExt.size(); << 137 size_t npc = physExt.size(); 128 if ( verbose > 0 ) { 138 if ( verbose > 0 ) { 129 G4cout << "G4PhysListRegistry::GetModularP 139 G4cout << "G4PhysListRegistry::GetModularPhysicsList <" 130 << name << ">" 140 << name << ">" 131 << ", as \"" << plBase << "\" with 141 << ", as \"" << plBase << "\" with extensions \""; 132 for ( std::size_t ipc = 0; ipc < npc; ++ip << 142 for ( size_t ipc = 0; ipc < npc; ++ipc ) 133 G4cout << ((physReplace[ipc]&doReplace)? 143 G4cout << ((physReplace[ipc]&doReplace)?"_":"+") << physExt[ipc]; 134 G4cout << "\"" << G4endl; 144 G4cout << "\"" << G4endl; 135 } 145 } 136 146 137 if ( ! allKnown ) { 147 if ( ! allKnown ) { 138 // couldn't match what the user wanted ... 148 // couldn't match what the user wanted ... 139 G4cout << "### G4PhysListRegistry WARNING: 149 G4cout << "### G4PhysListRegistry WARNING: " << name 140 << " is not known" << G4endl << G4e 150 << " is not known" << G4endl << G4endl; 141 if ( ! unknownFatal ) return nullptr; << 151 if ( ! unknownFatal ) return 0; 142 152 143 G4ExceptionDescription ED; 153 G4ExceptionDescription ED; 144 ED << "The factory for the physicslist ["< 154 ED << "The factory for the physicslist ["<< name << "] does not exist!" 145 << G4endl; 155 << G4endl; 146 if ( plBase == "" ) { 156 if ( plBase == "" ) { 147 ED << "Could determine no sensible base 157 ED << "Could determine no sensible base physics list" << G4endl; 148 } else { 158 } else { 149 ED << "One or more of the extensions doe 159 ED << "One or more of the extensions does not exist [ "; 150 for ( std::size_t ipc = 0; ipc < physExt << 160 for ( size_t ipc = 0; ipc < physExt.size(); ++ipc ) { 151 ED << physExt[ipc] << " "; 161 ED << physExt[ipc] << " "; 152 } 162 } 153 ED << "]" << G4endl; 163 ED << "]" << G4endl; 154 } 164 } 155 G4Exception("G4PhysListRegistry::GetModula 165 G4Exception("G4PhysListRegistry::GetModularPhysicsList", 156 "PhysicsList002", FatalExcepti 166 "PhysicsList002", FatalException, ED); 157 return nullptr; << 167 return 0; 158 } 168 } 159 169 160 // if we want this method "const" then the n 170 // if we want this method "const" then the next line becomes more complex 161 // because there is no const version of [] ( 171 // because there is no const version of [] (which adds an entry if the 162 // key doesn't exist) 172 // key doesn't exist) 163 G4VModularPhysicsList* pl = factories[plBase 173 G4VModularPhysicsList* pl = factories[plBase]->Instantiate(verbose); 164 G4PhysicsConstructorRegistry* pcRegistry = 174 G4PhysicsConstructorRegistry* pcRegistry = 165 G4PhysicsConstructorRegistry::Instance(); 175 G4PhysicsConstructorRegistry::Instance(); 166 G4int ver = pl->GetVerboseLevel(); 176 G4int ver = pl->GetVerboseLevel(); 167 pl->SetVerboseLevel(0); 177 pl->SetVerboseLevel(0); 168 for ( std::size_t ipc = 0; ipc < npc; ++ipc << 178 for ( size_t ipc = 0; ipc < npc; ++ipc ) { 169 // got back a list of short names, need to 179 // got back a list of short names, need to use the map to get the 170 // full physics constructor name 180 // full physics constructor name 171 G4String extName = physExt[ipc]; 181 G4String extName = physExt[ipc]; 172 G4String pcname = 182 G4String pcname = 173 ((physReplace[ipc]&isCtorName)) ? extNam 183 ((physReplace[ipc]&isCtorName)) ? extName : physicsExtensions[extName]; 174 // this doesn't have a verbose option ... 184 // this doesn't have a verbose option ... it should 175 // but G4PhysicsConstructorFactory doesn't 185 // but G4PhysicsConstructorFactory doesn't support it 176 G4VPhysicsConstructor* pctor = pcRegistry- 186 G4VPhysicsConstructor* pctor = pcRegistry->GetPhysicsConstructor(pcname); 177 G4String reporreg = ""; 187 G4String reporreg = ""; 178 if (( physReplace[ipc] & doReplace)) { 188 if (( physReplace[ipc] & doReplace)) { 179 pl->ReplacePhysics(pctor); 189 pl->ReplacePhysics(pctor); 180 reporreg = "ReplacePhysics "; 190 reporreg = "ReplacePhysics "; 181 } else { 191 } else { 182 pl->RegisterPhysics(pctor); 192 pl->RegisterPhysics(pctor); 183 reporreg = "RegisterPhysics"; 193 reporreg = "RegisterPhysics"; 184 } 194 } 185 if ( verbose > 0 ) G4cout << "<<< " << rep 195 if ( verbose > 0 ) G4cout << "<<< " << reporreg << " with " << pcname 186 << " \"" << extN 196 << " \"" << extName << "\"" << G4endl; 187 } 197 } 188 pl->SetVerboseLevel(ver); 198 pl->SetVerboseLevel(ver); 189 G4cout << "<<< Reference Physics List " << n 199 G4cout << "<<< Reference Physics List " << name << " is built" << G4endl; 190 G4cout << G4endl; // old factory has this 200 G4cout << G4endl; // old factory has this 191 201 192 return pl; 202 return pl; 193 } 203 } 194 204 195 G4VModularPhysicsList* 205 G4VModularPhysicsList* 196 G4PhysListRegistry::GetModularPhysicsListFromE 206 G4PhysListRegistry::GetModularPhysicsListFromEnv() 197 { 207 { 198 // 208 // 199 // instantiate PhysList by environment varia 209 // instantiate PhysList by environment variable "PHYSLIST" 200 // if not set use default 210 // if not set use default 201 G4String name = ""; 211 G4String name = ""; 202 char* path = std::getenv("PHYSLIST"); 212 char* path = std::getenv("PHYSLIST"); 203 if (path) { 213 if (path) { 204 name = G4String(path); 214 name = G4String(path); 205 } else { 215 } else { 206 name = userDefault; 216 name = userDefault; 207 G4cout << "### G4PhysListRegistry WARNING: 217 G4cout << "### G4PhysListRegistry WARNING: " 208 << " environment variable PHYSLIST 218 << " environment variable PHYSLIST is not defined" 209 << G4endl 219 << G4endl 210 << " Default Physics Lists " << 220 << " Default Physics Lists " << name 211 << " is instantiated" 221 << " is instantiated" 212 << G4endl; 222 << G4endl; 213 } 223 } 214 return GetModularPhysicsList(name); 224 return GetModularPhysicsList(name); 215 } 225 } 216 226 217 G4bool G4PhysListRegistry::IsReferencePhysList 227 G4bool G4PhysListRegistry::IsReferencePhysList(G4String name) const 218 { 228 { 219 G4String plBase = ""; 229 G4String plBase = ""; 220 std::vector<G4String> physExt; 230 std::vector<G4String> physExt; 221 std::vector<G4int> physReplace; 231 std::vector<G4int> physReplace; 222 G4bool allKnown = DeconstructPhysListName(na 232 G4bool allKnown = DeconstructPhysListName(name,plBase,physExt,physReplace,1); 223 return allKnown; 233 return allKnown; 224 } 234 } 225 235 226 G4bool G4PhysListRegistry::DeconstructPhysList 236 G4bool G4PhysListRegistry::DeconstructPhysListName(const G4String& name, 227 237 G4String& plBase, 228 238 std::vector<G4String>& physExt, 229 239 std::vector<G4int>& replace, 230 240 G4int verb) const 231 { 241 { 232 // Take apart a name given to us by the user 242 // Take apart a name given to us by the user 233 // this name might be a base PhysList + unkn 243 // this name might be a base PhysList + unknown number of extensions 234 // Extensions preceeded with a "_" should us 244 // Extensions preceeded with a "_" should use 235 // ReplacePhysics() 245 // ReplacePhysics() 236 // those proceeded with a "+" should use 246 // those proceeded with a "+" should use 237 // RegisterPhysics() 247 // RegisterPhysics() 238 // the former is in line with previous behav 248 // the former is in line with previous behaviour, while the second allows 239 // additional flexibility 249 // additional flexibility 240 plBase = ""; 250 plBase = ""; 241 physExt.clear(); 251 physExt.clear(); 242 replace.clear(); 252 replace.clear(); 243 G4bool allKnown = false; << 253 bool allKnown = false; 244 254 245 G4String workingName = name; 255 G4String workingName = name; 246 256 247 const std::vector<G4String>& availBases = A 257 const std::vector<G4String>& availBases = AvailablePhysLists(); 248 const std::vector<G4String>& availExtras = A 258 const std::vector<G4String>& availExtras = AvailablePhysicsExtensions(); 249 259 250 G4PhysicsConstructorRegistry* physConstRegis 260 G4PhysicsConstructorRegistry* physConstRegistry = 251 G4PhysicsConstructorRegistry::Instance(); 261 G4PhysicsConstructorRegistry::Instance(); 252 262 253 const std::vector<G4String>& availPhysCtors 263 const std::vector<G4String>& availPhysCtors = 254 physConstRegistry->AvailablePhysicsConstru 264 physConstRegistry->AvailablePhysicsConstructors(); 255 265 256 // find the longest base list that is contai 266 // find the longest base list that is contained in the user supplied name 257 // and starts at the beginning 267 // and starts at the beginning 258 G4String bestBase = ""; 268 G4String bestBase = ""; 259 allKnown = FindLongestMatch(workingName,"bas 269 allKnown = FindLongestMatch(workingName,"base",availBases,plBase); 260 if ( verb > 2 ) { 270 if ( verb > 2 ) { 261 G4cout << " " << name << ", base known=" 271 G4cout << " " << name << ", base known=" << ((allKnown)?"true":"false") 262 << " chosen plBase \"" << plBase << 272 << " chosen plBase \"" << plBase << "\"" << G4endl; 263 } 273 } 264 if ( ! allKnown ) { 274 if ( ! allKnown ) { 265 // didn't find any matching base physics l 275 // didn't find any matching base physics list 266 // no point of going on to the extensions 276 // no point of going on to the extensions 267 return allKnown; 277 return allKnown; 268 } 278 } 269 // remove base name for working name 279 // remove base name for working name 270 workingName.erase(0,plBase.size()); 280 workingName.erase(0,plBase.size()); 271 281 272 // now start trying to match up extensions a 282 // now start trying to match up extensions and/or physCtors 273 // each should be preceeded by at "_" (repla 283 // each should be preceeded by at "_" (replace) or "+" (register) 274 // but don't freak if it isn't, just assume 284 // but don't freak if it isn't, just assume "_" 275 while ( ! workingName.empty() ) { 285 while ( ! workingName.empty() ) { 276 char c = workingName.data()[0]; // leadin 286 char c = workingName.data()[0]; // leading character 277 if ( '_' == c || '+' == c ) workingName.er 287 if ( '_' == c || '+' == c ) workingName.erase(0,1); // and remove it 278 G4int replaceExtra = (( c != '+' ) ? do 288 G4int replaceExtra = (( c != '+' ) ? doReplace : 0 ); 279 G4String extraName = ""; 289 G4String extraName = ""; 280 G4bool extraKnown = false; 290 G4bool extraKnown = false; 281 291 282 extraKnown = FindLongestMatch(workingName, 292 extraKnown = FindLongestMatch(workingName,"extNames",availExtras,extraName); 283 if ( extraKnown ) { 293 if ( extraKnown ) { 284 // physics mapping name is known, but is 294 // physics mapping name is known, but is it actually linked to physics? 285 //const issue// G4String pcname = physic 295 //const issue// G4String pcname = physicsExtensions[extraName]; 286 std::map<G4String,G4String>::const_itera 296 std::map<G4String,G4String>::const_iterator itr = 287 physicsExtensions.find(extraName); 297 physicsExtensions.find(extraName); 288 G4String pcname = ""; 298 G4String pcname = ""; 289 if ( itr != physicsExtensions.end() ) pc 299 if ( itr != physicsExtensions.end() ) pcname = itr->second; 290 G4bool realknown = physConstRegistry->Is << 300 bool realknown = physConstRegistry->IsKnownPhysicsConstructor(pcname); 291 if ( ! realknown ) allKnown = false; 301 if ( ! realknown ) allKnown = false; 292 #ifdef G4VERBOSE 302 #ifdef G4VERBOSE 293 if ( verb > 2 ) { 303 if ( verb > 2 ) { 294 G4cout << " extraName \"" << extraNam 304 G4cout << " extraName \"" << extraName << "\" maps to physics ctor \"" 295 << pcname << "\" which is itsel 305 << pcname << "\" which is itself realknown " << realknown 296 << G4endl; 306 << G4endl; 297 } 307 } 298 #endif 308 #endif 299 } else { 309 } else { 300 // perhaps it's an explicit physCtor nam 310 // perhaps it's an explicit physCtor name 301 extraKnown = 311 extraKnown = 302 FindLongestMatch(workingName,"physCtor 312 FindLongestMatch(workingName,"physCtors",availPhysCtors,extraName); 303 if ( extraKnown ) replaceExtra |= isCtor 313 if ( extraKnown ) replaceExtra |= isCtorName; // flag it 304 } 314 } 305 #ifdef G4VERBOSE 315 #ifdef G4VERBOSE 306 if ( verb > 2 ) { 316 if ( verb > 2 ) { 307 G4cout << " physextra " << name << " [" 317 G4cout << " physextra " << name << " [" << workingName << "]" 308 <<", extra known " << extraKnown 318 <<", extra known " << extraKnown 309 << " chosen extra \"" << extraNam 319 << " chosen extra \"" << extraName << "\"" 310 << " replace " << replaceExtra << 320 << " replace " << replaceExtra << G4endl; 311 } 321 } 312 #endif 322 #endif 313 if ( extraKnown ) { 323 if ( extraKnown ) { 314 physExt.push_back(extraName); 324 physExt.push_back(extraName); 315 replace.push_back(replaceExtra); 325 replace.push_back(replaceExtra); 316 // and remove it so we can look for the 326 // and remove it so we can look for the next bit 317 workingName.erase(0,extraName.size()); 327 workingName.erase(0,extraName.size()); 318 328 319 } else { 329 } else { 320 #ifdef G4VERBOSE 330 #ifdef G4VERBOSE 321 if ( verb > 2 ) { 331 if ( verb > 2 ) { 322 G4cout << " workingName \"" << workin 332 G4cout << " workingName \"" << workingName << "\"" 323 << " couldn't be found in the e 333 << " couldn't be found in the extensions list" 324 << G4endl; 334 << G4endl; 325 } 335 } 326 #endif 336 #endif 327 allKnown = false; 337 allKnown = false; 328 // found a pattern that we can't map 338 // found a pattern that we can't map 329 return allKnown; 339 return allKnown; 330 } 340 } 331 } // workingName not empty 341 } // workingName not empty 332 342 333 return allKnown; 343 return allKnown; 334 } 344 } 335 345 336 G4bool G4PhysListRegistry::FindLongestMatch(co 346 G4bool G4PhysListRegistry::FindLongestMatch(const G4String& workingName, 337 co 347 const G4String& searchName, 338 co 348 const std::vector<G4String>& validNames, 339 G4 349 G4String& bestMatch, 340 G4 350 G4int verb) const 341 { 351 { 342 bestMatch = ""; 352 bestMatch = ""; 343 G4bool found = false; << 353 bool found = false; 344 354 345 std::size_t n = validNames.size(); << 355 size_t n = validNames.size(); 346 for (std::size_t i=0; i<n; ++i) { << 356 for (size_t i=0; i<n; ++i) { 347 const G4String& testName = validNames[i]; 357 const G4String& testName = validNames[i]; 348 std::size_t ipos = workingName.find(testNa << 358 size_t ipos = workingName.find(testName); 349 if ( ipos == 0 ) { 359 if ( ipos == 0 ) { 350 std::size_t testNameSize = testName.size << 360 if ( testName.size() > bestMatch.size() ) { 351 std::size_t workNameSize = workingName.s << 361 bestMatch = testName; 352 G4bool match = true; << 362 found = true; 353 if ( searchName == "base" ) { << 363 if ( verb > 3 ) { 354 // if searching for a valid base impos << 364 G4cout << " " << searchName << " current best guess: " 355 // either must exactly match or the ne << 365 << testName << G4endl; 356 // one of the standard delimiters of " << 357 if (workNameSize > testNameSize) { << 358 char nextChar = workingName[(G4int)t << 359 if ( nextChar != '_' && nextChar != << 360 if ( verb > 3 ) { << 361 G4cout << " " << searchName << " << 362 << testName << " nextChar " << 363 } << 364 } << 365 } << 366 if ( verb > 3 ) { << 367 G4cout << " " << searchName << " matc << 368 << " " << testName << G4endl; << 369 } << 370 if ( match ) { << 371 if ( testName.size() > bestMatch.size( << 372 bestMatch = testName; << 373 found = true; << 374 if ( verb > 3 ) { << 375 G4cout << " " << searchName << " << 376 << testName << G4endl; << 377 } << 378 } else { << 379 if ( verb > 3 ) { << 380 G4cout << " " << searchName << " << 381 << testName << G4endl; << 382 } << 383 } 366 } 384 } else { 367 } else { 385 if ( verb > 3 ) { << 368 if ( verb > 3 ) { 386 G4cout << " " << searchName << " << 369 G4cout << " " << searchName << " match but shorter: " 387 << testName << G4endl; << 370 << testName << G4endl; 388 } << 371 } 389 } 372 } 390 } else { 373 } else { 391 if ( verb > 3 ) { 374 if ( verb > 3 ) { 392 G4cout << " " << searchName << " reje 375 G4cout << " " << searchName << " reject: " << testName << G4endl; 393 } 376 } 394 } 377 } 395 } 378 } 396 return found; 379 return found; 397 } 380 } 398 381 399 382 400 const std::vector<G4String>& G4PhysListRegistr 383 const std::vector<G4String>& G4PhysListRegistry::AvailablePhysLists() const 401 { 384 { 402 availBasePhysLists.clear(); 385 availBasePhysLists.clear(); 403 std::map<G4String,G4VBasePhysListStamper*>:: 386 std::map<G4String,G4VBasePhysListStamper*>::const_iterator itr; 404 for ( itr = factories.begin(); itr != factor 387 for ( itr = factories.begin(); itr != factories.end(); ++itr ) { 405 availBasePhysLists.push_back(itr->first); 388 availBasePhysLists.push_back(itr->first); 406 } 389 } 407 390 408 return availBasePhysLists; 391 return availBasePhysLists; 409 } 392 } 410 393 411 const std::vector<G4String>& G4PhysListRegistr 394 const std::vector<G4String>& G4PhysListRegistry::AvailablePhysicsExtensions() const 412 { 395 { 413 availExtensions.clear(); 396 availExtensions.clear(); 414 std::map<G4String,G4String>::const_iterator 397 std::map<G4String,G4String>::const_iterator itr; 415 for ( itr = physicsExtensions.begin(); itr ! 398 for ( itr = physicsExtensions.begin(); itr != physicsExtensions.end(); ++itr ) { 416 availExtensions.push_back(itr->first); 399 availExtensions.push_back(itr->first); 417 } 400 } 418 401 419 return availExtensions; 402 return availExtensions; 420 } 403 } 421 404 422 const std::vector<G4String>& G4PhysListRegistr 405 const std::vector<G4String>& G4PhysListRegistry::AvailablePhysListsEM() const 423 { 406 { 424 // in principle this method could weed out a 407 // in principle this method could weed out all the extensions that aren't 425 // EM replacements ... but for now just use 408 // EM replacements ... but for now just use it as a synonym for 426 // AvailablePhysicsExtensions() 409 // AvailablePhysicsExtensions() 427 return AvailablePhysicsExtensions(); 410 return AvailablePhysicsExtensions(); 428 } 411 } 429 412 430 void G4PhysListRegistry::PrintAvailablePhysLis 413 void G4PhysListRegistry::PrintAvailablePhysLists() const 431 { 414 { 432 std::vector<G4String> avail = AvailablePhysL 415 std::vector<G4String> avail = AvailablePhysLists(); 433 G4cout << "Base G4VModularPhysicsLists in G4 416 G4cout << "Base G4VModularPhysicsLists in G4PhysListRegistry are:" 434 << G4endl; 417 << G4endl; 435 if ( avail.empty() ) G4cout << "... no regis 418 if ( avail.empty() ) G4cout << "... no registered lists" << G4endl; 436 else { 419 else { 437 std::size_t n = avail.size(); << 420 size_t n = avail.size(); 438 for (std::size_t i=0; i<n; ++i ) { << 421 for (size_t i=0; i<n; ++i ) { 439 G4cout << " [" << std::setw(3) << i << " 422 G4cout << " [" << std::setw(3) << i << "] " 440 << " \"" << avail[i] << "\"" << G 423 << " \"" << avail[i] << "\"" << G4endl; 441 } 424 } 442 } 425 } 443 426 444 G4PhysicsConstructorRegistry* physConstRegis 427 G4PhysicsConstructorRegistry* physConstRegistry = G4PhysicsConstructorRegistry::Instance(); 445 428 446 std::map<G4String,G4String>::const_iterator 429 std::map<G4String,G4String>::const_iterator itr; 447 G4cout << "Replacement mappings in G4PhysLis 430 G4cout << "Replacement mappings in G4PhysListRegistry are:" 448 << G4endl; 431 << G4endl; 449 for ( itr = physicsExtensions.begin(); itr ! 432 for ( itr = physicsExtensions.begin(); itr != physicsExtensions.end(); ++itr ) { 450 G4bool known = physConstRegistry->IsKnownP << 433 bool known = physConstRegistry->IsKnownPhysicsConstructor(itr->second); 451 434 452 G4cout << " " << std::setw(10) << itr-> 435 G4cout << " " << std::setw(10) << itr->first << " => " 453 << std::setw(30) << itr->second << 436 << std::setw(30) << itr->second << " " 454 << ( (known)?"":"[unregistered phys 437 << ( (known)?"":"[unregistered physics]") 455 << G4endl; 438 << G4endl; 456 } 439 } 457 G4cout << "Use these mapping to extend physi 440 G4cout << "Use these mapping to extend physics list; append with _EXT or +EXT" << G4endl 458 << " to use ReplacePhysics() (\"_\" 441 << " to use ReplacePhysics() (\"_\") or RegisterPhysics() (\"+\")." 459 << G4endl; 442 << G4endl; 460 } 443 } 461 444