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 // 26 // 27 // Author: Mathieu Karamitros (kara (AT) cenbg 27 // Author: Mathieu Karamitros (kara (AT) cenbg . in2p3 . fr) 28 // 28 // 29 // History: 29 // History: 30 // ----------- 30 // ----------- 31 // 10 Oct 2011 M.Karamitros created 31 // 10 Oct 2011 M.Karamitros created 32 // 32 // 33 // ------------------------------------------- 33 // ------------------------------------------------------------------- 34 34 35 #include "G4MolecularConfiguration.hh" 35 #include "G4MolecularConfiguration.hh" 36 #include "G4MoleculeDefinition.hh" 36 #include "G4MoleculeDefinition.hh" 37 #include "G4UIcommand.hh" 37 #include "G4UIcommand.hh" 38 #include "G4AllocatorList.hh" 38 #include "G4AllocatorList.hh" 39 #include "G4AutoLock.hh" 39 #include "G4AutoLock.hh" 40 #include "G4MoleculeTable.hh" 40 #include "G4MoleculeTable.hh" 41 #include "G4Serialize.hh" 41 #include "G4Serialize.hh" 42 #include <fstream> 42 #include <fstream> 43 43 44 using CLHEP::m2; 44 using CLHEP::m2; 45 using CLHEP::s; 45 using CLHEP::s; 46 using CLHEP::kelvin; 46 using CLHEP::kelvin; 47 47 48 using namespace std; 48 using namespace std; 49 49 50 #if defined ( WIN32 ) 50 #if defined ( WIN32 ) 51 #define __func__ __FUNCTION__ 51 #define __func__ __FUNCTION__ 52 #endif 52 #endif 53 53 54 /*G4ThreadLocal*/G4double G4MolecularConfigura 54 /*G4ThreadLocal*/G4double G4MolecularConfiguration::fgTemperature = 298; // 310*kelvin; 55 // 25°C, used to shoot an energy 55 // 25°C, used to shoot an energy 56 56 57 //____________________________________________ 57 //______________________________________________________________________________ 58 // G4MolecularConfigurationManager 58 // G4MolecularConfigurationManager 59 using MolecularConfigurationManager = G4Molecu << 59 typedef G4MolecularConfiguration::G4MolecularConfigurationManager >> 60 MolecularConfigurationManager; 60 61 61 MolecularConfigurationManager* G4MolecularConf << 62 MolecularConfigurationManager* G4MolecularConfiguration::fgManager = 0; 62 63 63 G4Mutex MolecularConfigurationManager::fManage 64 G4Mutex MolecularConfigurationManager::fManagerCreationMutex; 64 65 65 int G4MolecularConfiguration::GetNumberOfSpeci 66 int G4MolecularConfiguration::GetNumberOfSpecies() 66 { 67 { 67 return GetManager()->GetNumberOfCreatedSpeci 68 return GetManager()->GetNumberOfCreatedSpecies(); 68 } 69 } 69 70 70 double G4MolecularConfiguration::ReturnDefault 71 double G4MolecularConfiguration::ReturnDefaultDiffCoeff(const G4Material*, 71 double, 72 double, 72 const G4M 73 const G4MolecularConfiguration* 73 molConf) 74 molConf) 74 { 75 { 75 return molConf->fDynDiffusionCoefficient; 76 return molConf->fDynDiffusionCoefficient; 76 } 77 } 77 78 78 G4MolecularConfiguration::G4MolecularConfigura 79 G4MolecularConfiguration::G4MolecularConfiguration(const G4MoleculeDefinition* moleculeDef, 79 80 const G4String& label, 80 81 int charge) 81 { 82 { 82 fMoleculeDefinition = moleculeDef; 83 fMoleculeDefinition = moleculeDef; 83 84 84 fLabel = new G4String(label); 85 fLabel = new G4String(label); 85 86 86 fMoleculeID = GetManager()->Insert(moleculeD 87 fMoleculeID = GetManager()->Insert(moleculeDef, 87 label, 88 label, 88 this); 89 this); 89 fElectronOccupancy = nullptr; << 90 fElectronOccupancy = 0; 90 91 91 fDynCharge = charge; 92 fDynCharge = charge; 92 93 93 fDynMass = fMoleculeDefinition->GetMass(); 94 fDynMass = fMoleculeDefinition->GetMass(); 94 95 95 fDynDiffusionCoefficient = fMoleculeDefiniti 96 fDynDiffusionCoefficient = fMoleculeDefinition->GetDiffusionCoefficient(); 96 fDynVanDerVaalsRadius = fMoleculeDefinition- 97 fDynVanDerVaalsRadius = fMoleculeDefinition->GetVanDerVaalsRadius(); 97 fDynDecayTime = fMoleculeDefinition->GetDeca 98 fDynDecayTime = fMoleculeDefinition->GetDecayTime(); 98 99 99 fName = fMoleculeDefinition->GetName(); 100 fName = fMoleculeDefinition->GetName(); 100 fName += "^"; 101 fName += "^"; 101 fName += G4UIcommand::ConvertToString(fDynCh 102 fName += G4UIcommand::ConvertToString(fDynCharge); 102 103 103 fFormatedName = fMoleculeDefinition->GetForm 104 fFormatedName = fMoleculeDefinition->GetFormatedName(); 104 fFormatedName += "^"; 105 fFormatedName += "^"; 105 fFormatedName += "{"; 106 fFormatedName += "{"; 106 fFormatedName += G4UIcommand::ConvertToStrin 107 fFormatedName += G4UIcommand::ConvertToString(fDynCharge); 107 fFormatedName += "}"; 108 fFormatedName += "}"; 108 109 109 fDiffParam = &G4MolecularConfiguration::Retu 110 fDiffParam = &G4MolecularConfiguration::ReturnDefaultDiffCoeff; 110 fIsFinalized = false; 111 fIsFinalized = false; 111 } 112 } 112 113 113 void G4MolecularConfiguration::MakeExceptionIf 114 void G4MolecularConfiguration::MakeExceptionIfFinalized() 114 { 115 { 115 if(fIsFinalized) 116 if(fIsFinalized) 116 { 117 { 117 G4ExceptionDescription errMsg; 118 G4ExceptionDescription errMsg; 118 errMsg << "This molecular configuration " 119 errMsg << "This molecular configuration " << GetName() 119 << " is already finalized. Therefor 120 << " is already finalized. Therefore its " 120 " properties cannot be changed."; 121 " properties cannot be changed."; 121 G4Exception("G4MolecularConfiguration::Mak 122 G4Exception("G4MolecularConfiguration::MakeExceptionIfFinalized", 122 "CONF_FINALIZED",FatalExceptio 123 "CONF_FINALIZED",FatalException,errMsg); 123 } 124 } 124 } 125 } 125 126 126 //____________________________________________ 127 //______________________________________________________________________________ 127 128 128 G4MolecularConfiguration::G4MolecularConfigura 129 G4MolecularConfiguration::G4MolecularConfigurationManager* 129 G4MolecularConfiguration::GetManager() 130 G4MolecularConfiguration::GetManager() 130 { 131 { 131 if (fgManager == nullptr) << 132 if (!fgManager) 132 { 133 { 133 G4AutoLock lock(&MolecularConfigurationMan 134 G4AutoLock lock(&MolecularConfigurationManager::fManagerCreationMutex); 134 if (fgManager == nullptr) // double check << 135 if (!fgManager) // double check for MT 135 { 136 { 136 fgManager = new G4MolecularConfiguration 137 fgManager = new G4MolecularConfiguration:: 137 G4MolecularConfigurationManager(); 138 G4MolecularConfigurationManager(); 138 } 139 } 139 lock.unlock(); 140 lock.unlock(); 140 } 141 } 141 142 142 return fgManager; 143 return fgManager; 143 } 144 } 144 145 145 //____________________________________________ 146 //______________________________________________________________________________ 146 147 147 G4MolecularConfiguration:: 148 G4MolecularConfiguration:: 148 G4MolecularConfigurationManager::~G4MolecularC 149 G4MolecularConfigurationManager::~G4MolecularConfigurationManager() 149 { 150 { 150 // G4cout << "Does G4AllocatorList exists= "; 151 // G4cout << "Does G4AllocatorList exists= "; 151 // G4cout << (G4AllocatorList::GetAllocatorLi 152 // G4cout << (G4AllocatorList::GetAllocatorListIfExist() ? "true":"false") 152 // << G4endl; 153 // << G4endl; 153 154 154 G4MolecularConfigurationManager::MolElectron 155 G4MolecularConfigurationManager::MolElectronConfTable::iterator it1; 155 G4MolecularConfigurationManager::ElectronOcc 156 G4MolecularConfigurationManager::ElectronOccupancyTable:: 156 iterator it2; 157 iterator it2; 157 158 158 for (it1 = fElecOccTable.begin(); it1 != fEl 159 for (it1 = fElecOccTable.begin(); it1 != fElecOccTable.end(); it1++) 159 { 160 { 160 for (it2 = it1->second.begin(); it2 != it1 161 for (it2 = it1->second.begin(); it2 != it1->second.end(); it2++) 161 { 162 { 162 << 163 if (it2->second) 163 << 164 { 164 delete it2->second; 165 delete it2->second; 165 << 166 } 166 } 167 } 167 } 168 } 168 fElecOccTable.clear(); 169 fElecOccTable.clear(); 169 fgManager = nullptr; << 170 fgManager = 0; 170 } 171 } 171 172 172 //____________________________________________ 173 //______________________________________________________________________________ 173 // G4MolecularConfigurationManager 174 // G4MolecularConfigurationManager 174 G4int G4MolecularConfiguration:: 175 G4int G4MolecularConfiguration:: 175 G4MolecularConfigurationManager:: 176 G4MolecularConfigurationManager:: 176 Insert(const G4MoleculeDefinition* molDef, 177 Insert(const G4MoleculeDefinition* molDef, 177 const G4ElectronO 178 const G4ElectronOccupancy& eOcc, 178 G4MolecularConfig 179 G4MolecularConfiguration* molConf) 179 { 180 { 180 //G4AutoLock lock(&fMoleculeCreationMutex); 181 //G4AutoLock lock(&fMoleculeCreationMutex); 181 182 182 ElectronOccupancyTable& table2 = fElecOccTab 183 ElectronOccupancyTable& table2 = fElecOccTable[molDef]; 183 auto it = table2.find(eOcc); << 184 ElectronOccupancyTable::iterator it = table2.find(eOcc); 184 185 185 if(it == table2.end()) 186 if(it == table2.end()) 186 { 187 { 187 table2[eOcc] = molConf; 188 table2[eOcc] = molConf; 188 } 189 } 189 else 190 else 190 { 191 { 191 G4ExceptionDescription errMsg; 192 G4ExceptionDescription errMsg; 192 errMsg << "The same molecular configuratio 193 errMsg << "The same molecular configuration seemed to be recorded twice"; 193 G4Exception("G4MolecularConfigurationManag 194 G4Exception("G4MolecularConfigurationManager::" 194 "SetMolecularConfiguration(con 195 "SetMolecularConfiguration(const G4MoleculeDefinition* molDef," 195 "const G4ElectronOccupancy& eO 196 "const G4ElectronOccupancy& eOcc," 196 "G4MolecularConfiguration* mol 197 "G4MolecularConfiguration* molConf)", 197 "", 198 "", 198 FatalException, 199 FatalException, 199 errMsg 200 errMsg 200 ); 201 ); 201 } 202 } 202 203 203 fLastMoleculeID++; 204 fLastMoleculeID++; 204 205 205 fMolConfPerID.push_back(molConf); 206 fMolConfPerID.push_back(molConf); 206 207 207 //lock.unlock(); 208 //lock.unlock(); 208 return fLastMoleculeID; 209 return fLastMoleculeID; 209 } 210 } 210 211 211 //____________________________________________ 212 //______________________________________________________________________________ 212 213 213 const G4ElectronOccupancy* 214 const G4ElectronOccupancy* 214 G4MolecularConfiguration::G4MolecularConfigura 215 G4MolecularConfiguration::G4MolecularConfigurationManager:: 215 FindCommonElectronOccupancy(const G4MoleculeDe 216 FindCommonElectronOccupancy(const G4MoleculeDefinition* molDef, 216 const G4ElectronOc 217 const G4ElectronOccupancy& eOcc) 217 { 218 { 218 //G4AutoLock lock(&fMoleculeCreationMutex); 219 //G4AutoLock lock(&fMoleculeCreationMutex); 219 220 220 auto it1 = fElecOccTable.find(molDef); << 221 MolElectronConfTable::iterator it1 = fElecOccTable.find(molDef); 221 222 222 if(it1 == fElecOccTable.end()) 223 if(it1 == fElecOccTable.end()) 223 { 224 { 224 // TODO = handle exception ? 225 // TODO = handle exception ? 225 return nullptr; << 226 return 0; 226 } 227 } 227 228 228 ElectronOccupancyTable& table2 = it1->second 229 ElectronOccupancyTable& table2 = it1->second; 229 auto it2 = table2.find(eOcc); << 230 ElectronOccupancyTable::iterator it2 = table2.find(eOcc); 230 231 231 //lock.unlock(); 232 //lock.unlock(); 232 233 233 if (it2 == table2.end()) 234 if (it2 == table2.end()) 234 { 235 { 235 // TODO = handle exception ? 236 // TODO = handle exception ? 236 return nullptr; << 237 return 0; 237 } 238 } 238 239 239 return &(it2->first); 240 return &(it2->first); 240 } 241 } 241 242 242 //____________________________________________ 243 //______________________________________________________________________________ 243 244 244 G4MolecularConfiguration* 245 G4MolecularConfiguration* 245 G4MolecularConfiguration::G4MolecularConfigura 246 G4MolecularConfiguration::G4MolecularConfigurationManager:: 246 GetMolecularConfiguration(const G4MoleculeDefi 247 GetMolecularConfiguration(const G4MoleculeDefinition* molDef, 247 const G4ElectronOccu 248 const G4ElectronOccupancy& eOcc) 248 { 249 { 249 auto it1 = fElecOccTable.find(molDef); << 250 MolElectronConfTable::iterator it1 = fElecOccTable.find(molDef); 250 251 251 if(it1 == fElecOccTable.end()) return nullpt << 252 if(it1 == fElecOccTable.end()) return 0; 252 253 253 ElectronOccupancyTable& table2 = it1->second 254 ElectronOccupancyTable& table2 = it1->second; 254 auto it = table2.find(eOcc); << 255 ElectronOccupancyTable::iterator it = table2.find(eOcc); 255 256 256 if(it == table2.end()) 257 if(it == table2.end()) 257 { 258 { 258 return nullptr; << 259 return 0; 259 } 260 } 260 << 261 else 261 return it->second; << 262 { >> 263 return it->second; >> 264 } >> 265 >> 266 return 0; 262 } 267 } 263 268 264 //____________________________________________ 269 //______________________________________________________________________________ 265 270 266 G4int G4MolecularConfiguration::G4MolecularCon 271 G4int G4MolecularConfiguration::G4MolecularConfigurationManager:: 267 Insert(const G4MoleculeDefinition* molDef, 272 Insert(const G4MoleculeDefinition* molDef, 268 int charge, 273 int charge, 269 G4MolecularConfiguration* molConf) 274 G4MolecularConfiguration* molConf) 270 { 275 { 271 276 272 //G4AutoLock lock(&fMoleculeCreationMutex); 277 //G4AutoLock lock(&fMoleculeCreationMutex); 273 ChargeTable& table2 = fChargeTable[molDef]; 278 ChargeTable& table2 = fChargeTable[molDef]; 274 auto it = table2.find(charge); << 279 ChargeTable::iterator it = table2.find(charge); 275 280 276 if(it == table2.end()) 281 if(it == table2.end()) 277 { 282 { 278 table2[charge] = molConf; 283 table2[charge] = molConf; 279 } 284 } 280 else 285 else 281 { 286 { 282 //lock.unlock(); 287 //lock.unlock(); 283 G4ExceptionDescription errMsg; 288 G4ExceptionDescription errMsg; 284 errMsg << "The same molecular configuratio 289 errMsg << "The same molecular configuration seemed to be recorded twice"; 285 G4Exception("G4MolecularConfigurationManag 290 G4Exception("G4MolecularConfigurationManager::" 286 "SetMolecularConfiguration(con 291 "SetMolecularConfiguration(const G4MoleculeDefinition* molDef," 287 "int charge," 292 "int charge," 288 "G4MolecularConfiguration* mol 293 "G4MolecularConfiguration* molConf)", 289 "", FatalException, errMsg); 294 "", FatalException, errMsg); 290 } 295 } 291 296 292 fLastMoleculeID++; 297 fLastMoleculeID++; 293 fMolConfPerID.push_back(molConf); 298 fMolConfPerID.push_back(molConf); 294 //lock.unlock(); 299 //lock.unlock(); 295 return fLastMoleculeID; 300 return fLastMoleculeID; 296 } 301 } 297 302 298 //____________________________________________ 303 //______________________________________________________________________________ 299 304 300 G4MolecularConfiguration* 305 G4MolecularConfiguration* 301 G4MolecularConfiguration::G4MolecularConfigura 306 G4MolecularConfiguration::G4MolecularConfigurationManager:: 302 GetMolecularConfiguration(const G4MoleculeDefi 307 GetMolecularConfiguration(const G4MoleculeDefinition* molDef, 303 int charge) 308 int charge) 304 { 309 { 305 //G4AutoLock lock(&fMoleculeCreationMutex); 310 //G4AutoLock lock(&fMoleculeCreationMutex); 306 311 307 auto it1 = fChargeTable.find(molDef); << 312 MolChargeConfTable::iterator it1 = fChargeTable.find(molDef); 308 313 309 if(it1 == fChargeTable.end()) return nullptr << 314 if(it1 == fChargeTable.end()) return 0; 310 315 311 ChargeTable& table2 = it1->second; 316 ChargeTable& table2 = it1->second; 312 auto it = table2.find(charge); << 317 ChargeTable::iterator it = table2.find(charge); 313 318 314 if(it == table2.end()) 319 if(it == table2.end()) 315 { 320 { 316 return nullptr; << 321 return 0; 317 } 322 } 318 << 323 else 319 return it->second; << 324 { 320 << 325 return it->second; >> 326 } >> 327 >> 328 return 0; >> 329 >> 330 //lock.unlock(); >> 331 return 0; 321 } 332 } 322 333 323 //____________________________________________ 334 //______________________________________________________________________________ 324 // Static method in G4MolecularConfiguration 335 // Static method in G4MolecularConfiguration 325 G4MolecularConfiguration* 336 G4MolecularConfiguration* 326 G4MolecularConfiguration:: 337 G4MolecularConfiguration:: 327 GetOrCreateMolecularConfiguration(const G4Mole 338 GetOrCreateMolecularConfiguration(const G4MoleculeDefinition* molDef) 328 { 339 { 329 if (molDef->GetGroundStateElectronOccupancy( << 340 if (molDef->GetGroundStateElectronOccupancy()) 330 { 341 { 331 const G4ElectronOccupancy& elecOcc = 342 const G4ElectronOccupancy& elecOcc = 332 *molDef->GetGroundStateElectronOccupan 343 *molDef->GetGroundStateElectronOccupancy(); 333 G4MolecularConfiguration* molConf = 344 G4MolecularConfiguration* molConf = 334 GetManager()->GetMolecularConfiguratio 345 GetManager()->GetMolecularConfiguration(molDef, elecOcc); 335 346 336 if (molConf != nullptr) << 347 if (molConf) 337 { 348 { 338 return molConf; 349 return molConf; 339 } 350 } 340 << 351 else 341 auto newConf = << 352 { 342 new G4MolecularConfiguration(molDef, << 353 G4MolecularConfiguration* newConf = 343 elecOcc); << 354 new G4MolecularConfiguration(molDef, 344 newConf->SetUserID(molDef->GetName()); << 355 elecOcc); 345 return newConf; << 356 newConf->SetUserID(molDef->GetName()); >> 357 return newConf; >> 358 } 346 } 359 } 347 << 360 else 348 G4MolecularConfiguration* molConf = << 349 GetManager()->GetMolecularConfiguration( << 350 if(molConf != nullptr) << 351 { 361 { 352 return molConf; << 362 G4MolecularConfiguration* molConf = >> 363 GetManager()->GetMolecularConfiguration(molDef, molDef->GetCharge()); >> 364 if(molConf) >> 365 { >> 366 return molConf; >> 367 } >> 368 else >> 369 { >> 370 G4MolecularConfiguration* newConf = >> 371 new G4MolecularConfiguration(molDef, molDef->GetCharge()); >> 372 newConf->SetUserID(molDef->GetName()); >> 373 return newConf; >> 374 } 353 } 375 } 354 << 355 auto newConf = << 356 new G4MolecularConfiguration(molDef, mol << 357 newConf->SetUserID(molDef->GetName()); << 358 return newConf; << 359 } 376 } 360 377 361 //____________________________________________ 378 //______________________________________________________________________________ 362 379 363 G4MolecularConfiguration* 380 G4MolecularConfiguration* 364 G4MolecularConfiguration:: 381 G4MolecularConfiguration:: 365 GetOrCreateMolecularConfiguration(const G4Mole 382 GetOrCreateMolecularConfiguration(const G4MoleculeDefinition* molDef, 366 const G4Elec 383 const G4ElectronOccupancy& elecOcc) 367 { 384 { 368 return GetManager()->GetOrCreateMolecularCon 385 return GetManager()->GetOrCreateMolecularConfiguration(molDef, elecOcc); 369 386 370 // G4MolecularConfiguration* molConf = 387 // G4MolecularConfiguration* molConf = 371 // GetManager()->GetMolecularConfiguratio 388 // GetManager()->GetMolecularConfiguration(molDef, elecOcc); 372 // 389 // 373 // if (molConf) 390 // if (molConf) 374 // { 391 // { 375 // return molConf; 392 // return molConf; 376 // } 393 // } 377 // else 394 // else 378 // { 395 // { 379 // G4MolecularConfiguration* newConf = 396 // G4MolecularConfiguration* newConf = 380 // new G4MolecularConfiguration(molDef, 397 // new G4MolecularConfiguration(molDef, elecOcc); 381 // return newConf; 398 // return newConf; 382 // } 399 // } 383 } 400 } 384 401 385 //____________________________________________ 402 //______________________________________________________________________________ 386 403 387 G4MolecularConfiguration* 404 G4MolecularConfiguration* 388 G4MolecularConfiguration:: 405 G4MolecularConfiguration:: 389 GetOrCreateMolecularConfiguration(const G4Mole 406 GetOrCreateMolecularConfiguration(const G4MoleculeDefinition* molDef, 390 int charge) 407 int charge) 391 { 408 { 392 G4MolecularConfiguration* molConf = 409 G4MolecularConfiguration* molConf = 393 GetManager()->GetMolecularConfiguration( 410 GetManager()->GetMolecularConfiguration(molDef, charge); 394 411 395 if(molConf != nullptr) << 412 if(molConf) 396 { 413 { 397 return molConf; 414 return molConf; 398 } 415 } 399 << 416 else 400 auto newConf = << 417 { 401 new G4MolecularConfiguration(molDef, cha << 418 G4MolecularConfiguration* newConf = 402 return newConf; << 419 new G4MolecularConfiguration(molDef, charge); >> 420 return newConf; >> 421 } 403 } 422 } 404 423 405 //____________________________________________ 424 //______________________________________________________________________________ 406 425 407 void G4MolecularConfiguration::DeleteManager() 426 void G4MolecularConfiguration::DeleteManager() 408 { 427 { 409 G4AutoLock lock(&MolecularConfigurationManag 428 G4AutoLock lock(&MolecularConfigurationManager::fManagerCreationMutex); 410 delete fgManager; << 429 if (fgManager) delete fgManager; 411 fgManager = nullptr; << 430 fgManager = 0; 412 lock.unlock(); 431 lock.unlock(); 413 } 432 } 414 433 415 //____________________________________________ 434 //______________________________________________________________________________ 416 // G4MolecularConfiguration 435 // G4MolecularConfiguration 417 G4MolecularConfiguration:: 436 G4MolecularConfiguration:: 418 G4MolecularConfiguration(const G4MoleculeDefin 437 G4MolecularConfiguration(const G4MoleculeDefinition* moleculeDef, 419 const G4ElectronOccup 438 const G4ElectronOccupancy& elecOcc, 420 const G4String& label 439 const G4String& label) 421 { 440 { 422 fMoleculeDefinition = moleculeDef; 441 fMoleculeDefinition = moleculeDef; 423 442 424 fMoleculeID = GetManager()->Insert(moleculeD 443 fMoleculeID = GetManager()->Insert(moleculeDef, 425 elecOcc, 444 elecOcc, 426 this); 445 this); 427 fElectronOccupancy = GetManager()->FindCommo 446 fElectronOccupancy = GetManager()->FindCommonElectronOccupancy(moleculeDef, 428 447 elecOcc); 429 448 430 /* 449 /* 431 fgManager->fTable[fMoleculeDefinition][elec 450 fgManager->fTable[fMoleculeDefinition][elecOcc] = this; 432 std::map<G4ElectronOccupancy, G4MolecularCo 451 std::map<G4ElectronOccupancy, G4MolecularConfiguration*, comparator>::iterator it ; 433 it = fgManager->fTable[moleculeDef].find(el 452 it = fgManager->fTable[moleculeDef].find(elecOcc); 434 fElectronOccupancy = &(it->first); 453 fElectronOccupancy = &(it->first); 435 */ 454 */ 436 455 437 fDynCharge = fMoleculeDefinition->GetNbElect 456 fDynCharge = fMoleculeDefinition->GetNbElectrons() 438 - fElectronOccupancy->GetTotalOccupancy( 457 - fElectronOccupancy->GetTotalOccupancy() 439 + moleculeDef->GetCharge(); 458 + moleculeDef->GetCharge(); 440 fDynMass = fMoleculeDefinition->GetMass(); 459 fDynMass = fMoleculeDefinition->GetMass(); 441 460 442 fDynDiffusionCoefficient = fMoleculeDefiniti 461 fDynDiffusionCoefficient = fMoleculeDefinition->GetDiffusionCoefficient(); 443 fDynVanDerVaalsRadius = fMoleculeDefinition- 462 fDynVanDerVaalsRadius = fMoleculeDefinition->GetVanDerVaalsRadius(); 444 fDynDecayTime = fMoleculeDefinition->GetDeca 463 fDynDecayTime = fMoleculeDefinition->GetDecayTime(); 445 464 446 fName = fMoleculeDefinition->GetName(); 465 fName = fMoleculeDefinition->GetName(); 447 fName += "^"; 466 fName += "^"; 448 fName += G4UIcommand::ConvertToString(fDynCh 467 fName += G4UIcommand::ConvertToString(fDynCharge); 449 468 450 fFormatedName = fMoleculeDefinition->GetForm 469 fFormatedName = fMoleculeDefinition->GetFormatedName(); 451 fFormatedName += "^"; 470 fFormatedName += "^"; 452 fFormatedName += "{"; 471 fFormatedName += "{"; 453 fFormatedName += G4UIcommand::ConvertToStrin 472 fFormatedName += G4UIcommand::ConvertToString(fDynCharge); 454 fFormatedName += "}"; 473 fFormatedName += "}"; 455 474 456 fLabel = nullptr; // let it here << 475 fLabel = 0; // let it here 457 476 458 if(!label.empty()) << 477 if(label != "") 459 { 478 { 460 SetLabel(label); 479 SetLabel(label); 461 } 480 } 462 481 463 fDiffParam = &G4MolecularConfiguration::Retu 482 fDiffParam = &G4MolecularConfiguration::ReturnDefaultDiffCoeff; 464 483 465 fIsFinalized = false; 484 fIsFinalized = false; 466 } 485 } 467 486 468 //____________________________________________ 487 //______________________________________________________________________________ 469 488 470 G4MolecularConfiguration:: 489 G4MolecularConfiguration:: 471 G4MolecularConfiguration(const G4MoleculeDefin 490 G4MolecularConfiguration(const G4MoleculeDefinition* moleculeDef, 472 int charge) 491 int charge) 473 { 492 { 474 fMoleculeDefinition = moleculeDef; 493 fMoleculeDefinition = moleculeDef; 475 494 476 fMoleculeID = GetManager()->Insert(moleculeD 495 fMoleculeID = GetManager()->Insert(moleculeDef, 477 charge, 496 charge, 478 this); 497 this); 479 fElectronOccupancy = nullptr; << 498 fElectronOccupancy = 0; 480 499 481 fDynCharge = charge; 500 fDynCharge = charge; 482 fDynMass = fMoleculeDefinition->GetMass(); 501 fDynMass = fMoleculeDefinition->GetMass(); 483 502 484 fDynDiffusionCoefficient = fMoleculeDefiniti 503 fDynDiffusionCoefficient = fMoleculeDefinition->GetDiffusionCoefficient(); 485 fDynVanDerVaalsRadius = fMoleculeDefinition- 504 fDynVanDerVaalsRadius = fMoleculeDefinition->GetVanDerVaalsRadius(); 486 fDynDecayTime = fMoleculeDefinition->GetDeca 505 fDynDecayTime = fMoleculeDefinition->GetDecayTime(); 487 506 488 fName = fMoleculeDefinition->GetName(); 507 fName = fMoleculeDefinition->GetName(); 489 fName += "^"; 508 fName += "^"; 490 fName += G4UIcommand::ConvertToString(fDynCh 509 fName += G4UIcommand::ConvertToString(fDynCharge); 491 510 492 fFormatedName = fMoleculeDefinition->GetForm 511 fFormatedName = fMoleculeDefinition->GetFormatedName(); 493 fFormatedName += "^"; 512 fFormatedName += "^"; 494 fFormatedName += "{"; 513 fFormatedName += "{"; 495 fFormatedName += G4UIcommand::ConvertToStrin 514 fFormatedName += G4UIcommand::ConvertToString(fDynCharge); 496 fFormatedName += "}"; 515 fFormatedName += "}"; 497 516 498 fLabel = nullptr; << 517 fLabel = 0; 499 518 500 fDiffParam = &G4MolecularConfiguration::Retu 519 fDiffParam = &G4MolecularConfiguration::ReturnDefaultDiffCoeff; 501 520 502 fIsFinalized = false; 521 fIsFinalized = false; 503 } 522 } 504 523 505 //____________________________________________ 524 //______________________________________________________________________________ 506 525 507 G4MolecularConfiguration::~G4MolecularConfigur 526 G4MolecularConfiguration::~G4MolecularConfiguration() 508 { 527 { 509 if (fgManager != nullptr) fgManager->RemoveM << 528 if (fgManager) fgManager->RemoveMolecularConfigurationFromTable(this); 510 529 511 // if (G4AllocatorList::GetAllocatorListIfExi 530 // if (G4AllocatorList::GetAllocatorListIfExist()) 512 // { 531 // { 513 // if (fElectronOccupancy) 532 // if (fElectronOccupancy) 514 // { 533 // { 515 // delete fElectronOccupancy; 534 // delete fElectronOccupancy; 516 // fElectronOccupancy = 0; 535 // fElectronOccupancy = 0; 517 // } 536 // } 518 // } 537 // } 519 } 538 } 520 539 521 //____________________________________________ 540 //______________________________________________________________________________ 522 541 523 G4MolecularConfiguration* 542 G4MolecularConfiguration* 524 G4MolecularConfiguration:: 543 G4MolecularConfiguration:: 525 ChangeConfiguration(const G4ElectronOccupancy& 544 ChangeConfiguration(const G4ElectronOccupancy& newElectronOccupancy) const 526 { 545 { 527 G4MolecularConfiguration* output = 546 G4MolecularConfiguration* output = 528 GetManager()->GetMolecularConfiguration( 547 GetManager()->GetMolecularConfiguration(fMoleculeDefinition, 529 548 newElectronOccupancy); 530 549 531 if (output == nullptr) << 550 if (!output) 532 { 551 { 533 output = new G4MolecularConfiguration(fMol 552 output = new G4MolecularConfiguration(fMoleculeDefinition, 534 newE 553 newElectronOccupancy); 535 } 554 } 536 return output; 555 return output; 537 } 556 } 538 557 539 //____________________________________________ 558 //______________________________________________________________________________ 540 559 541 G4MolecularConfiguration* 560 G4MolecularConfiguration* 542 G4MolecularConfiguration::ChangeConfiguration( 561 G4MolecularConfiguration::ChangeConfiguration(int charge) const 543 { 562 { 544 G4MolecularConfiguration* output = 563 G4MolecularConfiguration* output = 545 GetManager()->GetMolecularConfiguration( 564 GetManager()->GetMolecularConfiguration(fMoleculeDefinition, charge); 546 565 547 if (output == nullptr) << 566 if (!output) 548 { 567 { 549 output = new G4MolecularConfiguration(fMol 568 output = new G4MolecularConfiguration(fMoleculeDefinition, charge); 550 } 569 } 551 return output; 570 return output; 552 } 571 } 553 572 554 //____________________________________________ 573 //______________________________________________________________________________ 555 574 556 G4MolecularConfiguration& 575 G4MolecularConfiguration& 557 G4MolecularConfiguration::operator=(G4Molecula 576 G4MolecularConfiguration::operator=(G4MolecularConfiguration& /*right*/) 558 { 577 { 559 // if (&right == this) return *this; 578 // if (&right == this) return *this; 560 return *this; 579 return *this; 561 } 580 } 562 581 563 //____________________________________________ 582 //______________________________________________________________________________ 564 583 565 /** Method used in Geant4-DNA to excite water 584 /** Method used in Geant4-DNA to excite water molecules 566 */ 585 */ 567 G4MolecularConfiguration* 586 G4MolecularConfiguration* 568 G4MolecularConfiguration::ExciteMolecule(G4int 587 G4MolecularConfiguration::ExciteMolecule(G4int ExcitedLevel) const 569 { 588 { 570 // MakeExceptionIfFinalized(); 589 // MakeExceptionIfFinalized(); 571 CheckElectronOccupancy(__func__); 590 CheckElectronOccupancy(__func__); 572 G4ElectronOccupancy newElectronOccupancy(*fE 591 G4ElectronOccupancy newElectronOccupancy(*fElectronOccupancy); 573 592 574 newElectronOccupancy.RemoveElectron(ExcitedL 593 newElectronOccupancy.RemoveElectron(ExcitedLevel, 1); 575 newElectronOccupancy.AddElectron(5, 1); 594 newElectronOccupancy.AddElectron(5, 1); 576 595 577 return ChangeConfiguration(newElectronOccupa 596 return ChangeConfiguration(newElectronOccupancy); 578 } 597 } 579 598 580 //____________________________________________ 599 //______________________________________________________________________________ 581 600 582 /** Method used in Geant4-DNA to ionize water 601 /** Method used in Geant4-DNA to ionize water molecules 583 */ 602 */ 584 G4MolecularConfiguration* 603 G4MolecularConfiguration* 585 G4MolecularConfiguration::IonizeMolecule(G4int 604 G4MolecularConfiguration::IonizeMolecule(G4int IonizedLevel) const 586 { 605 { 587 // MakeExceptionIfFinalized(); 606 // MakeExceptionIfFinalized(); 588 CheckElectronOccupancy(__func__); 607 CheckElectronOccupancy(__func__); 589 G4ElectronOccupancy newElectronOccupancy(*fE 608 G4ElectronOccupancy newElectronOccupancy(*fElectronOccupancy); 590 609 591 if (newElectronOccupancy.GetOccupancy(Ionize 610 if (newElectronOccupancy.GetOccupancy(IonizedLevel) != 0) 592 { 611 { 593 newElectronOccupancy.RemoveElectron(Ionize 612 newElectronOccupancy.RemoveElectron(IonizedLevel, 1); 594 } 613 } 595 else 614 else 596 { 615 { 597 G4String errMsg = "There is no electron on 616 G4String errMsg = "There is no electron on the orbit " 598 + G4UIcommand::ConvertToString(Ionized 617 + G4UIcommand::ConvertToString(IonizedLevel) 599 + " you want to free. The molecule's n 618 + " you want to free. The molecule's name you want to ionized is " 600 + GetName(); 619 + GetName(); 601 G4Exception("G4MolecularConfiguration::Ion 620 G4Exception("G4MolecularConfiguration::IonizeMolecule", 602 "", 621 "", 603 FatalErrorInArgument, 622 FatalErrorInArgument, 604 errMsg); 623 errMsg); 605 PrintState(); 624 PrintState(); 606 } 625 } 607 626 608 // DEBUG 627 // DEBUG 609 // PrintState(); 628 // PrintState(); 610 629 611 return ChangeConfiguration(newElectronOccupa 630 return ChangeConfiguration(newElectronOccupancy); 612 } 631 } 613 632 614 //____________________________________________ 633 //______________________________________________________________________________ 615 634 616 G4MolecularConfiguration* G4MolecularConfigura 635 G4MolecularConfiguration* G4MolecularConfiguration::AddElectron(G4int orbit, 617 636 G4int number) const 618 { 637 { 619 // MakeExceptionIfFinalized(); 638 // MakeExceptionIfFinalized(); 620 CheckElectronOccupancy(__func__); 639 CheckElectronOccupancy(__func__); 621 G4ElectronOccupancy newElectronOccupancy(*fE 640 G4ElectronOccupancy newElectronOccupancy(*fElectronOccupancy); 622 newElectronOccupancy.AddElectron(orbit, numb 641 newElectronOccupancy.AddElectron(orbit, number); 623 return ChangeConfiguration(newElectronOccupa 642 return ChangeConfiguration(newElectronOccupancy); 624 } 643 } 625 644 626 //____________________________________________ 645 //______________________________________________________________________________ 627 646 628 G4MolecularConfiguration* 647 G4MolecularConfiguration* 629 G4MolecularConfiguration::RemoveElectron(G4int 648 G4MolecularConfiguration::RemoveElectron(G4int orbit, 630 G4int 649 G4int number) const 631 { 650 { 632 // MakeExceptionIfFinalized(); 651 // MakeExceptionIfFinalized(); 633 CheckElectronOccupancy(__func__); 652 CheckElectronOccupancy(__func__); 634 G4ElectronOccupancy newElectronOccupancy(*fE 653 G4ElectronOccupancy newElectronOccupancy(*fElectronOccupancy); 635 654 636 if (newElectronOccupancy.GetOccupancy(orbit) 655 if (newElectronOccupancy.GetOccupancy(orbit) != 0) 637 { 656 { 638 newElectronOccupancy.RemoveElectron(orbit, 657 newElectronOccupancy.RemoveElectron(orbit, number); 639 } 658 } 640 else 659 else 641 { 660 { 642 G4String errMsg = "There is already no ele 661 G4String errMsg = "There is already no electron into the orbit " 643 + G4UIcommand::ConvertToString(orbit) 662 + G4UIcommand::ConvertToString(orbit) 644 + " you want to free. The molecule's n 663 + " you want to free. The molecule's name is " + GetName(); 645 G4Exception("G4MolecularConfiguration::Rem 664 G4Exception("G4MolecularConfiguration::RemoveElectron", 646 "", 665 "", 647 JustWarning, 666 JustWarning, 648 errMsg); 667 errMsg); 649 PrintState(); 668 PrintState(); 650 } 669 } 651 670 652 return ChangeConfiguration(newElectronOccupa 671 return ChangeConfiguration(newElectronOccupancy); 653 } 672 } 654 673 655 //____________________________________________ 674 //______________________________________________________________________________ 656 675 657 G4MolecularConfiguration* 676 G4MolecularConfiguration* 658 G4MolecularConfiguration::MoveOneElectron(G4in 677 G4MolecularConfiguration::MoveOneElectron(G4int orbitToFree, 659 G4in 678 G4int orbitToFill) const 660 { 679 { 661 // MakeExceptionIfFinalized(); 680 // MakeExceptionIfFinalized(); 662 CheckElectronOccupancy(__func__); 681 CheckElectronOccupancy(__func__); 663 G4ElectronOccupancy newElectronOccupancy(*fE 682 G4ElectronOccupancy newElectronOccupancy(*fElectronOccupancy); 664 683 665 if (newElectronOccupancy.GetOccupancy(orbitT 684 if (newElectronOccupancy.GetOccupancy(orbitToFree) >= 1) 666 { 685 { 667 newElectronOccupancy.RemoveElectron(orbitT 686 newElectronOccupancy.RemoveElectron(orbitToFree, 1); 668 newElectronOccupancy.AddElectron(orbitToFi 687 newElectronOccupancy.AddElectron(orbitToFill, 1); 669 } 688 } 670 else 689 else 671 { 690 { 672 G4String errMsg = "There is no electron on 691 G4String errMsg = "There is no electron on the orbit " 673 + G4UIcommand::ConvertToString(orbitTo 692 + G4UIcommand::ConvertToString(orbitToFree) 674 + " you want to free. The molecule's n 693 + " you want to free. The molecule's name is " + GetName(); 675 G4Exception("G4MolecularConfiguration::Mov 694 G4Exception("G4MolecularConfiguration::MoveOneElectron", 676 "", 695 "", 677 FatalErrorInArgument, 696 FatalErrorInArgument, 678 errMsg); 697 errMsg); 679 PrintState(); 698 PrintState(); 680 } 699 } 681 700 682 return ChangeConfiguration(newElectronOccupa 701 return ChangeConfiguration(newElectronOccupancy); 683 } 702 } 684 703 685 //____________________________________________ 704 //______________________________________________________________________________ 686 705 687 const G4String& G4MolecularConfiguration::GetN 706 const G4String& G4MolecularConfiguration::GetName() const 688 { 707 { 689 return fName; 708 return fName; 690 } 709 } 691 710 692 //____________________________________________ 711 //______________________________________________________________________________ 693 712 694 const G4String& G4MolecularConfiguration::GetF 713 const G4String& G4MolecularConfiguration::GetFormatedName() const 695 { 714 { 696 return fFormatedName; 715 return fFormatedName; 697 } 716 } 698 717 699 //____________________________________________ 718 //______________________________________________________________________________ 700 719 701 G4int G4MolecularConfiguration::GetAtomsNumber 720 G4int G4MolecularConfiguration::GetAtomsNumber() const 702 { 721 { 703 return fMoleculeDefinition->GetAtomsNumber() 722 return fMoleculeDefinition->GetAtomsNumber(); 704 } 723 } 705 724 706 //____________________________________________ 725 //______________________________________________________________________________ 707 726 708 G4double G4MolecularConfiguration::GetNbElectr 727 G4double G4MolecularConfiguration::GetNbElectrons() const 709 { 728 { 710 CheckElectronOccupancy(__func__); 729 CheckElectronOccupancy(__func__); 711 return fElectronOccupancy->GetTotalOccupancy 730 return fElectronOccupancy->GetTotalOccupancy(); 712 } 731 } 713 732 714 //____________________________________________ 733 //______________________________________________________________________________ 715 734 716 void G4MolecularConfiguration::PrintState() co 735 void G4MolecularConfiguration::PrintState() const 717 { 736 { 718 G4cout << "-------------- Start Printing Sta 737 G4cout << "-------------- Start Printing State " << GetName() 719 << " ---------------" << G4endl; 738 << " ---------------" << G4endl; 720 739 721 if (fElectronOccupancy != nullptr) << 740 if (fElectronOccupancy) 722 { 741 { 723 G4cout << "--------------Print electronic 742 G4cout << "--------------Print electronic state of " << GetName() 724 << "---------------" << G4endl; 743 << "---------------" << G4endl; 725 fElectronOccupancy->DumpInfo(); 744 fElectronOccupancy->DumpInfo(); 726 if(fElectronOccupancy==fMoleculeDefinition 745 if(fElectronOccupancy==fMoleculeDefinition->GetGroundStateElectronOccupancy()) 727 { 746 { 728 G4cout<<"At ground state"<<G4endl; 747 G4cout<<"At ground state"<<G4endl; 729 } 748 } 730 } 749 } 731 else 750 else 732 { 751 { 733 G4cout << "--- No electron occupancy set u 752 G4cout << "--- No electron occupancy set up ---" << G4endl; 734 } 753 } 735 754 736 G4cout << "Charge :" 755 G4cout << "Charge :" 737 << fDynCharge 756 << fDynCharge 738 << G4endl; 757 << G4endl; 739 758 740 if(fLabel != nullptr) << 759 if(fLabel) 741 { 760 { 742 G4cout << "Label :" 761 G4cout << "Label :" 743 << GetLabel() 762 << GetLabel() 744 << G4endl; 763 << G4endl; 745 } 764 } 746 G4cout << "-------------- End Of State " << 765 G4cout << "-------------- End Of State " << GetName() 747 << " -----------------------" << G4e 766 << " -----------------------" << G4endl; 748 } 767 } 749 768 750 //____________________________________________ 769 //______________________________________________________________________________ 751 770 752 // added - to be transformed in a "Decay metho 771 // added - to be transformed in a "Decay method" 753 const vector<const G4MolecularDissociationChan 772 const vector<const G4MolecularDissociationChannel*>* 754 G4MolecularConfiguration::GetDissociationCha 773 G4MolecularConfiguration::GetDissociationChannels() const 755 { 774 { 756 // if (fElectronOccupancy == 0) return 0; 775 // if (fElectronOccupancy == 0) return 0; 757 return fMoleculeDefinition->GetDecayChannels 776 return fMoleculeDefinition->GetDecayChannels(this); 758 } 777 } 759 778 760 //____________________________________________ 779 //______________________________________________________________________________ 761 780 762 G4int G4MolecularConfiguration::GetFakeParticl 781 G4int G4MolecularConfiguration::GetFakeParticleID() const 763 { 782 { 764 if(fMoleculeDefinition != nullptr) return fM << 783 if(fMoleculeDefinition) return fMoleculeDefinition->GetPDGEncoding(); 765 G4Exception("G4MolecularConfiguration::GetMo << 784 else G4Exception("G4MolecularConfiguration::GetMoleculeID", 766 "", 785 "", 767 FatalErrorInArgument, 786 FatalErrorInArgument, 768 "You should first enter a m 787 "You should first enter a molecule definition"); 769 788 770 return INT_MAX; 789 return INT_MAX; 771 } 790 } 772 791 773 //____________________________________________ 792 //______________________________________________________________________________ 774 793 775 const char* removePath(const char* path) 794 const char* removePath(const char* path) 776 { 795 { 777 const char* pDelimeter = strrchr(path, '\\') 796 const char* pDelimeter = strrchr(path, '\\'); 778 if (pDelimeter != nullptr) path = pDelimeter << 797 if (pDelimeter) path = pDelimeter + 1; 779 798 780 pDelimeter = strrchr(path, '/'); 799 pDelimeter = strrchr(path, '/'); 781 if (pDelimeter != nullptr) path = pDelimeter << 800 if (pDelimeter) path = pDelimeter + 1; 782 801 783 return path; 802 return path; 784 } 803 } 785 804 786 //____________________________________________ 805 //______________________________________________________________________________ 787 806 788 void G4MolecularConfiguration::CheckElectronOc 807 void G4MolecularConfiguration::CheckElectronOccupancy(const char* function) const 789 { 808 { 790 if (fElectronOccupancy == nullptr) << 809 if (fElectronOccupancy == 0) 791 { 810 { 792 G4String functionName(function); 811 G4String functionName(function); 793 G4ExceptionDescription description; 812 G4ExceptionDescription description; 794 description 813 description 795 << "No G4ElectronOccupancy was defined 814 << "No G4ElectronOccupancy was defined for molecule definition : " 796 << fMoleculeDefinition->GetName() 815 << fMoleculeDefinition->GetName() 797 << ". The definition was probably defi 816 << ". The definition was probably defined using the charge state, " 798 "rather than electron state."; 817 "rather than electron state."; 799 818 800 G4Exception(functionName, "", FatalErrorIn 819 G4Exception(functionName, "", FatalErrorInArgument, description); 801 } 820 } 802 } 821 } 803 822 804 //____________________________________________ 823 //______________________________________________________________________________ 805 824 806 void G4MolecularConfiguration::G4MolecularConf 825 void G4MolecularConfiguration::G4MolecularConfigurationManager:: 807 RecordNewlyLabeledConfiguration(G4MolecularCon 826 RecordNewlyLabeledConfiguration(G4MolecularConfiguration* molConf) 808 { 827 { 809 //G4AutoLock lock(&fMoleculeCreationMutex); 828 //G4AutoLock lock(&fMoleculeCreationMutex); 810 829 811 LabelTable& tmpMap = fLabelTable[molConf->fM 830 LabelTable& tmpMap = fLabelTable[molConf->fMoleculeDefinition]; 812 831 813 auto it = tmpMap.find(*molConf->fLabel); << 832 LabelTable::iterator it = tmpMap.find(*molConf->fLabel); 814 833 815 if(it == tmpMap.end()) 834 if(it == tmpMap.end()) 816 { 835 { 817 tmpMap[*(molConf->fLabel)] = molConf; 836 tmpMap[*(molConf->fLabel)] = molConf; 818 } 837 } 819 else 838 else 820 { 839 { 821 G4ExceptionDescription errMsg; 840 G4ExceptionDescription errMsg; 822 errMsg << "The same molecular configuratio 841 errMsg << "The same molecular configuration seemed to be recorded twice"; 823 G4Exception("G4MolecularConfigurationManag 842 G4Exception("G4MolecularConfigurationManager::" 824 "SetMolecularConfiguration(con 843 "SetMolecularConfiguration(const G4MoleculeDefinition* molDef," 825 "const G4String& label," 844 "const G4String& label," 826 "G4MolecularConfiguration* mol 845 "G4MolecularConfiguration* molConf)", 827 "", FatalException, errMsg); 846 "", FatalException, errMsg); 828 } 847 } 829 848 830 //lock.unlock(); 849 //lock.unlock(); 831 } 850 } 832 851 833 void G4MolecularConfiguration::G4MolecularConf 852 void G4MolecularConfiguration::G4MolecularConfigurationManager::AddUserID(const G4String& userID, 834 853 G4MolecularConfiguration* molecule) 835 { 854 { 836 auto it = fUserIDTable.find(userID); << 855 UserIDTable::iterator it = fUserIDTable.find(userID); 837 856 838 if(it == fUserIDTable.end()) 857 if(it == fUserIDTable.end()) 839 { 858 { 840 fUserIDTable[userID] = molecule; 859 fUserIDTable[userID] = molecule; 841 } 860 } 842 else if(molecule != it->second) 861 else if(molecule != it->second) 843 { 862 { 844 // TODO improve exception 863 // TODO improve exception 845 // exception 864 // exception 846 G4ExceptionDescription description; 865 G4ExceptionDescription description; 847 description << "The user identifier " << u 866 description << "The user identifier " << userID 848 << " was already given in anot 867 << " was already given in another configuration in the table" 849 << G4endl; 868 << G4endl; 850 G4Exception("G4MolecularConfiguration::G4Mol 869 G4Exception("G4MolecularConfiguration::G4MolecularConfigurationManager::AddUserID", 851 "CONF_ALREADY_RECORDED", 870 "CONF_ALREADY_RECORDED", 852 FatalException, 871 FatalException, 853 description); 872 description); 854 } 873 } 855 } 874 } 856 875 857 //____________________________________________ 876 //______________________________________________________________________________ 858 877 859 void G4MolecularConfiguration::G4MolecularConf 878 void G4MolecularConfiguration::G4MolecularConfigurationManager:: 860 RemoveMolecularConfigurationFromTable(G4Molecu 879 RemoveMolecularConfigurationFromTable(G4MolecularConfiguration* configuration) 861 { 880 { 862 auto it1 = << 881 MolElectronConfTable::iterator it1 = 863 fElecOccTable.find(configuration->GetDef 882 fElecOccTable.find(configuration->GetDefinition()); 864 auto end = fElecOccTable.end(); << 883 MolElectronConfTable::iterator end = fElecOccTable.end(); 865 884 866 if (it1 == end) return; 885 if (it1 == end) return; 867 886 868 auto it2 = << 887 std::map<G4ElectronOccupancy, G4MolecularConfiguration*, comparator>:: >> 888 iterator it2 = 869 it1->second.find(*configuration->GetElec 889 it1->second.find(*configuration->GetElectronOccupancy()); 870 890 871 if (it2 == it1->second.end()) return; 891 if (it2 == it1->second.end()) return; 872 892 873 it2->second = 0; 893 it2->second = 0; 874 // it1->second.erase(it2); 894 // it1->second.erase(it2); 875 895 876 configuration->fElectronOccupancy = nullptr; << 896 configuration->fElectronOccupancy = 0; 877 } 897 } 878 898 879 //____________________________________________ 899 //______________________________________________________________________________ 880 900 881 G4MolecularConfiguration* 901 G4MolecularConfiguration* 882 G4MolecularConfiguration::G4MolecularConfigura 902 G4MolecularConfiguration::G4MolecularConfigurationManager:: 883 GetMolecularConfiguration(const G4MoleculeDefi 903 GetMolecularConfiguration(const G4MoleculeDefinition* molDef, 884 const G4String& labe 904 const G4String& label) 885 { 905 { 886 //G4AutoLock lock(&fMoleculeCreationMutex); 906 //G4AutoLock lock(&fMoleculeCreationMutex); 887 907 888 auto it1 = fLabelTable.find(molDef); << 908 MolLabelConfTable::iterator it1 = fLabelTable.find(molDef); 889 909 890 if(it1 == fLabelTable.end()) return nullptr; << 910 if(it1 == fLabelTable.end()) return 0; 891 911 892 LabelTable& table2 = it1->second; 912 LabelTable& table2 = it1->second; 893 913 894 auto it2 = table2.find(label); << 914 LabelTable::iterator it2 = table2.find(label); 895 915 896 //lock.unlock(); 916 //lock.unlock(); 897 917 898 if(it2 == table2.end()) return nullptr; << 918 if(it2 == table2.end()) return 0; 899 return it2->second; 919 return it2->second; 900 } 920 } 901 921 902 //____________________________________________ 922 //______________________________________________________________________________ 903 923 904 G4MolecularConfiguration* 924 G4MolecularConfiguration* 905 G4MolecularConfiguration::G4MolecularConfigura 925 G4MolecularConfiguration::G4MolecularConfigurationManager:: 906 GetMolecularConfiguration(int moleculeID) 926 GetMolecularConfiguration(int moleculeID) 907 { 927 { 908 if(moleculeID > (int) fMolConfPerID.size() | 928 if(moleculeID > (int) fMolConfPerID.size() || 909 moleculeID < 0) return nullptr; << 929 moleculeID < 0) return 0; 910 930 911 return fMolConfPerID[moleculeID]; 931 return fMolConfPerID[moleculeID]; 912 } 932 } 913 933 914 //____________________________________________ 934 //______________________________________________________________________________ 915 935 916 G4int 936 G4int 917 G4MolecularConfiguration::G4MolecularConfigura 937 G4MolecularConfiguration::G4MolecularConfigurationManager:: 918 Insert(const G4MoleculeDefinition* molDef, 938 Insert(const G4MoleculeDefinition* molDef, 919 const G4String& l 939 const G4String& label, 920 G4MolecularConfig 940 G4MolecularConfiguration* molConf) 921 { 941 { 922 G4AutoLock lock(&fMoleculeCreationMutex); 942 G4AutoLock lock(&fMoleculeCreationMutex); 923 LabelTable& tmpMap = fLabelTable[molDef]; 943 LabelTable& tmpMap = fLabelTable[molDef]; 924 auto it = tmpMap.find(label); << 944 LabelTable::iterator it = tmpMap.find(label); 925 945 926 if(it == tmpMap.end()) 946 if(it == tmpMap.end()) 927 { 947 { 928 fLastMoleculeID++; 948 fLastMoleculeID++; 929 tmpMap[label] = molConf; 949 tmpMap[label] = molConf; 930 lock.unlock(); 950 lock.unlock(); 931 } 951 } 932 else 952 else 933 { 953 { 934 lock.unlock(); 954 lock.unlock(); 935 G4ExceptionDescription errMsg; 955 G4ExceptionDescription errMsg; 936 errMsg << "The same molecular configuratio 956 errMsg << "The same molecular configuration seemed to be recorded twice"; 937 G4Exception("G4MolecularConfigurationManag 957 G4Exception("G4MolecularConfigurationManager::" 938 "SetMolecularConfiguration(con 958 "SetMolecularConfiguration(const G4MoleculeDefinition* molDef," 939 "const G4String& label," 959 "const G4String& label," 940 "G4MolecularConfiguration* mol 960 "G4MolecularConfiguration* molConf)", 941 "", FatalException, errMsg); 961 "", FatalException, errMsg); 942 } 962 } 943 963 944 fMolConfPerID.push_back(molConf); 964 fMolConfPerID.push_back(molConf); 945 965 946 return fLastMoleculeID; 966 return fLastMoleculeID; 947 } 967 } 948 968 949 //____________________________________________ 969 //______________________________________________________________________________ 950 970 951 G4MolecularConfiguration* 971 G4MolecularConfiguration* 952 G4MolecularConfiguration::GetMolecularConfigur 972 G4MolecularConfiguration::GetMolecularConfiguration(const G4MoleculeDefinition* molDef, 953 973 const G4String& label) 954 { 974 { 955 return GetManager()->GetMolecularConfigurati 975 return GetManager()->GetMolecularConfiguration(molDef, label); 956 } 976 } 957 977 958 //____________________________________________ 978 //______________________________________________________________________________ 959 979 960 G4MolecularConfiguration* 980 G4MolecularConfiguration* 961 G4MolecularConfiguration::GetMolecularConfigur 981 G4MolecularConfiguration::GetMolecularConfiguration(int moleculeID) 962 { 982 { 963 return GetManager()->GetMolecularConfigurati 983 return GetManager()->GetMolecularConfiguration(moleculeID); 964 } 984 } 965 985 966 //____________________________________________ 986 //______________________________________________________________________________ 967 987 968 G4MolecularConfiguration* 988 G4MolecularConfiguration* 969 G4MolecularConfiguration::CreateMolecularConfi 989 G4MolecularConfiguration::CreateMolecularConfiguration(const G4String& userIdentifier, 970 990 const G4MoleculeDefinition* molDef, 971 991 int charge, 972 992 const G4String& label, 973 993 bool& wasAlreadyCreated) 974 { 994 { 975 wasAlreadyCreated = false; 995 wasAlreadyCreated = false; 976 G4MolecularConfiguration* molConf = 996 G4MolecularConfiguration* molConf = 977 GetManager()->GetMolecularConfiguration( 997 GetManager()->GetMolecularConfiguration(molDef, charge); 978 998 979 if (molConf != nullptr) << 999 if (molConf) 980 { 1000 { 981 if(molConf->fLabel == nullptr) << 1001 if(molConf->fLabel == 0) 982 { 1002 { 983 molConf->SetLabel(label); 1003 molConf->SetLabel(label); 984 G4ExceptionDescription wMsg ; 1004 G4ExceptionDescription wMsg ; 985 wMsg << "The molecular configuration for 1005 wMsg << "The molecular configuration for the definition named " 986 << molDef->GetName() 1006 << molDef->GetName() 987 << " with charge " << charge << " 1007 << " with charge " << charge << " has already been created " 988 "but with NO label"; 1008 "but with NO label"; 989 G4Exception("G4MolecularConfiguration::C 1009 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration", 990 "DOUBLE_CREATION", 1010 "DOUBLE_CREATION", 991 JustWarning, 1011 JustWarning, 992 wMsg); 1012 wMsg); 993 } 1013 } 994 else if(molConf->fLabel->empty() ) << 1014 else if(*(molConf->fLabel) == "" ) 995 { 1015 { 996 molConf->SetLabel(label); 1016 molConf->SetLabel(label); 997 } 1017 } 998 else if(*(molConf->fLabel) != label) 1018 else if(*(molConf->fLabel) != label) 999 { 1019 { 1000 G4ExceptionDescription errMsg ; 1020 G4ExceptionDescription errMsg ; 1001 errMsg << "The molecular configuration 1021 errMsg << "The molecular configuration for the definition named " 1002 << molDef->GetName() 1022 << molDef->GetName() 1003 << " with charge " << charge << 1023 << " with charge " << charge << " has already been created " 1004 "but with a different label 1024 "but with a different label :" 1005 << molConf->GetLabel(); 1025 << molConf->GetLabel(); 1006 G4Exception("G4MolecularConfiguration:: 1026 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration", 1007 "DOUBLE_CREATION", 1027 "DOUBLE_CREATION", 1008 FatalErrorInArgument, 1028 FatalErrorInArgument, 1009 errMsg); 1029 errMsg); 1010 // KILL APP 1030 // KILL APP 1011 } 1031 } 1012 1032 1013 if(molConf->fUserIdentifier.empty()) << 1033 if(molConf->fUserIdentifier == "") 1014 { 1034 { 1015 molConf->fUserIdentifier = userIdentifi 1035 molConf->fUserIdentifier = userIdentifier; 1016 1036 1017 G4ExceptionDescription wMsg ; 1037 G4ExceptionDescription wMsg ; 1018 wMsg << "The molecular configuration fo 1038 wMsg << "The molecular configuration for the definition named " 1019 << molDef->GetName() 1039 << molDef->GetName() 1020 << " with label " << label << " 1040 << " with label " << label << " has already been created."; 1021 G4Exception("G4MolecularConfiguration:: 1041 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration", 1022 "DOUBLE_CREATION", 1042 "DOUBLE_CREATION", 1023 JustWarning, 1043 JustWarning, 1024 wMsg); 1044 wMsg); 1025 } 1045 } 1026 else if(molConf->fUserIdentifier != userI 1046 else if(molConf->fUserIdentifier != userIdentifier) 1027 { 1047 { 1028 G4ExceptionDescription errMsg ; 1048 G4ExceptionDescription errMsg ; 1029 errMsg << "The molecular configuration 1049 errMsg << "The molecular configuration for the definition named " 1030 << molDef->GetName() 1050 << molDef->GetName() 1031 << " with label " << label << " 1051 << " with label " << label << " has already been created " 1032 "BUT with a different user I 1052 "BUT with a different user ID :" 1033 << molConf->fUserIdentifier; 1053 << molConf->fUserIdentifier; 1034 G4Exception("G4MolecularConfiguration:: 1054 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration", 1035 "DOUBLE_CREATION", 1055 "DOUBLE_CREATION", 1036 FatalErrorInArgument, 1056 FatalErrorInArgument, 1037 errMsg); 1057 errMsg); 1038 // KILL APP 1058 // KILL APP 1039 } 1059 } 1040 1060 1041 wasAlreadyCreated = true; 1061 wasAlreadyCreated = true; 1042 return molConf; 1062 return molConf; 1043 } 1063 } 1044 << 1064 else 1045 auto newConf = << 1065 { 1046 new G4MolecularConfiguration(molDef, la << 1066 G4MolecularConfiguration* newConf = 1047 newConf->fUserIdentifier = userIdentifier; << 1067 new G4MolecularConfiguration(molDef, label, charge); >> 1068 newConf->fUserIdentifier = userIdentifier; 1048 1069 1049 GetManager()->AddUserID(userIdentifier, new << 1070 GetManager()->AddUserID(userIdentifier, newConf); 1050 1071 1051 // G4MoleculeTable::Instance()->RecordMole 1072 // G4MoleculeTable::Instance()->RecordMolecularConfiguration(userIdentifier, 1052 // 1073 // newConf); 1053 return newConf; << 1074 return newConf; >> 1075 } 1054 } 1076 } 1055 1077 1056 //___________________________________________ 1078 //______________________________________________________________________________ 1057 1079 1058 G4MolecularConfiguration* 1080 G4MolecularConfiguration* 1059 G4MolecularConfiguration:: 1081 G4MolecularConfiguration:: 1060 CreateMolecularConfiguration(const G4String& 1082 CreateMolecularConfiguration(const G4String& userIdentifier, 1061 const G4Molecule 1083 const G4MoleculeDefinition* molDef, 1062 bool& wasAlready 1084 bool& wasAlreadyCreated) 1063 { 1085 { 1064 wasAlreadyCreated = false; 1086 wasAlreadyCreated = false; 1065 G4MolecularConfiguration* preRegisteredMolC 1087 G4MolecularConfiguration* preRegisteredMolConf = 1066 GetManager()->GetMolecularConfiguration 1088 GetManager()->GetMolecularConfiguration(userIdentifier); 1067 1089 1068 if(preRegisteredMolConf != nullptr) << 1090 if(preRegisteredMolConf) 1069 { 1091 { 1070 if(preRegisteredMolConf->GetDefinition() 1092 if(preRegisteredMolConf->GetDefinition() == molDef) 1071 { 1093 { 1072 wasAlreadyCreated = true; 1094 wasAlreadyCreated = true; 1073 return preRegisteredMolConf; 1095 return preRegisteredMolConf; 1074 } 1096 } 1075 } 1097 } 1076 1098 1077 if(molDef->GetGroundStateElectronOccupancy( << 1099 if(molDef->GetGroundStateElectronOccupancy()) 1078 { 1100 { 1079 const G4ElectronOccupancy& elecOcc = *mol 1101 const G4ElectronOccupancy& elecOcc = *molDef 1080 ->GetGroundStateElectronOccupancy(); 1102 ->GetGroundStateElectronOccupancy(); 1081 G4MolecularConfiguration* molConf = 1103 G4MolecularConfiguration* molConf = 1082 GetManager()->GetMolecularConfigurati 1104 GetManager()->GetMolecularConfiguration(molDef, elecOcc); 1083 1105 1084 if(molConf != nullptr) << 1106 if(molConf) 1085 { 1107 { 1086 if(molConf->fUserIdentifier.empty()) << 1108 if(molConf->fUserIdentifier == "") 1087 { 1109 { 1088 molConf->fUserIdentifier = userIdenti 1110 molConf->fUserIdentifier = userIdentifier; 1089 } 1111 } 1090 else if(molConf->fUserIdentifier != use 1112 else if(molConf->fUserIdentifier != userIdentifier) 1091 { 1113 { 1092 G4ExceptionDescription errMsg; 1114 G4ExceptionDescription errMsg; 1093 errMsg << "A molecular configuration 1115 errMsg << "A molecular configuration for the definition named " 1094 << molDef->GetName() << " has 1116 << molDef->GetName() << " has already been created " 1095 "and recorded with a different 1117 "and recorded with a different user ID " 1096 << molConf->fUserIdentifier; 1118 << molConf->fUserIdentifier; 1097 G4Exception("G4MolecularConfiguration 1119 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration", 1098 "DOUBLE_CREATION", 1120 "DOUBLE_CREATION", 1099 FatalErrorInArgument, 1121 FatalErrorInArgument, 1100 errMsg); 1122 errMsg); 1101 } 1123 } 1102 // TODO exception 1124 // TODO exception 1103 G4ExceptionDescription errMsg; 1125 G4ExceptionDescription errMsg; 1104 errMsg << "A molecular configuration fo 1126 errMsg << "A molecular configuration for the definition named " 1105 << molDef->GetName() << " has al 1127 << molDef->GetName() << " has already been created."; 1106 G4Exception("G4MolecularConfiguration:: 1128 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration", 1107 "DOUBLE_CREATION", 1129 "DOUBLE_CREATION", 1108 JustWarning, 1130 JustWarning, 1109 errMsg); 1131 errMsg); 1110 wasAlreadyCreated = true; 1132 wasAlreadyCreated = true; 1111 return molConf; 1133 return molConf; 1112 } 1134 } 1113 << 1135 else 1114 // G4cout << "Create molConf for " << mol << 1136 { 1115 auto newConf = new G4MolecularConfigurat << 1137 // G4cout << "Create molConf for " << molDef->GetName() << G4endl; 1116 << 1138 G4MolecularConfiguration* newConf = new G4MolecularConfiguration(molDef, 1117 newConf->fUserIdentifier = userIdentifier << 1139 elecOcc); >> 1140 newConf->fUserIdentifier = userIdentifier; 1118 1141 1119 GetManager()->AddUserID(userIdentifier, n << 1142 GetManager()->AddUserID(userIdentifier, newConf); 1120 1143 1121 // G4MoleculeTable::Instance()->RecordMo 1144 // G4MoleculeTable::Instance()->RecordMolecularConfiguration(userIdentifier, 1122 // 1145 // newConf); 1123 return newConf; << 1146 return newConf; >> 1147 } >> 1148 } >> 1149 else >> 1150 { >> 1151 return CreateMolecularConfiguration(userIdentifier, >> 1152 molDef, >> 1153 molDef->GetName(), >> 1154 molDef->GetCharge(), >> 1155 wasAlreadyCreated); 1124 } 1156 } 1125 << 1126 return CreateMolecularConfiguration(userIde << 1127 molDef, << 1128 molDef- << 1129 molDef- << 1130 wasAlre << 1131 } 1157 } 1132 1158 1133 //___________________________________________ 1159 //______________________________________________________________________________ 1134 1160 1135 G4MolecularConfiguration* 1161 G4MolecularConfiguration* 1136 G4MolecularConfiguration:: 1162 G4MolecularConfiguration:: 1137 CreateMolecularConfiguration(const G4String& 1163 CreateMolecularConfiguration(const G4String& userIdentifier, 1138 const G4Molecule 1164 const G4MoleculeDefinition* molDef, 1139 const G4String& 1165 const G4String& label, 1140 bool& wasAlready 1166 bool& wasAlreadyCreated) 1141 { 1167 { 1142 assert(label != ""); 1168 assert(label != ""); 1143 wasAlreadyCreated = false; 1169 wasAlreadyCreated = false; 1144 1170 1145 G4MolecularConfiguration* molConf = 1171 G4MolecularConfiguration* molConf = 1146 GetManager()->GetMolecularConfiguration 1172 GetManager()->GetMolecularConfiguration(molDef, label); 1147 if(molConf != nullptr) << 1173 if(molConf) 1148 { 1174 { 1149 if((molConf->fLabel != nullptr) << 1175 if(molConf->fLabel 1150 && *molConf->fLabel == label) 1176 && *molConf->fLabel == label) 1151 { 1177 { 1152 wasAlreadyCreated = true; 1178 wasAlreadyCreated = true; 1153 return molConf; 1179 return molConf; 1154 } 1180 } 1155 if(molConf->fLabel == nullptr) << 1181 else if(molConf->fLabel == 0) 1156 { 1182 { 1157 wasAlreadyCreated = true; 1183 wasAlreadyCreated = true; 1158 molConf->SetLabel(label); 1184 molConf->SetLabel(label); 1159 return molConf; 1185 return molConf; 1160 } 1186 } 1161 if(molConf->fLabel->empty()) << 1187 else if(*molConf->fLabel == "") 1162 { 1188 { 1163 wasAlreadyCreated = true; 1189 wasAlreadyCreated = true; 1164 molConf->SetLabel(label); 1190 molConf->SetLabel(label); 1165 return molConf; 1191 return molConf; 1166 } 1192 } 1167 1193 1168 molConf->PrintState(); 1194 molConf->PrintState(); 1169 G4ExceptionDescription errMsg ; 1195 G4ExceptionDescription errMsg ; 1170 errMsg << "A molecular configuration for 1196 errMsg << "A molecular configuration for the definition named " 1171 << molDef->GetName() 1197 << molDef->GetName() 1172 << " has already been created " 1198 << " has already been created " 1173 "with user ID " 1199 "with user ID " 1174 << molConf->fUserIdentifier << " a 1200 << molConf->fUserIdentifier << " and label " 1175 << molConf->GetLabel(); 1201 << molConf->GetLabel(); 1176 G4Exception("G4MolecularConfiguration::Cr 1202 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration", 1177 "DOUBLE_CREATION", 1203 "DOUBLE_CREATION", 1178 FatalErrorInArgument, 1204 FatalErrorInArgument, 1179 errMsg); 1205 errMsg); 1180 // KILL APP 1206 // KILL APP 1181 } 1207 } 1182 else 1208 else 1183 { 1209 { 1184 auto newConf = << 1210 G4MolecularConfiguration* newConf = 1185 new G4MolecularConfiguration(molDef, 1211 new G4MolecularConfiguration(molDef, 1186 label, 1212 label, 1187 molDef->Ge 1213 molDef->GetCharge()); 1188 newConf->fUserIdentifier = userIdentifier 1214 newConf->fUserIdentifier = userIdentifier; 1189 1215 1190 GetManager()->AddUserID(userIdentifier, n 1216 GetManager()->AddUserID(userIdentifier, newConf); 1191 1217 1192 // G4MoleculeTable::Instance()-> 1218 // G4MoleculeTable::Instance()-> 1193 // RecordMolecularConfiguration(userId 1219 // RecordMolecularConfiguration(userIdentifier, newConf); 1194 return newConf; 1220 return newConf; 1195 } 1221 } 1196 return molConf; 1222 return molConf; 1197 } 1223 } 1198 1224 1199 //___________________________________________ 1225 //______________________________________________________________________________ 1200 1226 1201 G4MolecularConfiguration* 1227 G4MolecularConfiguration* 1202 G4MolecularConfiguration:: 1228 G4MolecularConfiguration:: 1203 CreateMolecularConfiguration(const G4String& 1229 CreateMolecularConfiguration(const G4String& userIdentifier, 1204 const G4Molecule 1230 const G4MoleculeDefinition* molDef, 1205 const G4String& 1231 const G4String& label, 1206 const G4Electron 1232 const G4ElectronOccupancy& eOcc, 1207 bool& wasAlready 1233 bool& wasAlreadyCreated) 1208 { 1234 { 1209 assert(label != ""); 1235 assert(label != ""); 1210 wasAlreadyCreated = false; 1236 wasAlreadyCreated = false; 1211 1237 1212 G4MolecularConfiguration* molConf = 1238 G4MolecularConfiguration* molConf = 1213 GetManager()->GetMolecularConfiguration 1239 GetManager()->GetMolecularConfiguration(molDef, eOcc); 1214 1240 1215 if(molConf != nullptr) << 1241 if(molConf) 1216 { 1242 { 1217 if(molConf->GetElectronOccupancy() != nul << 1243 if(molConf->GetElectronOccupancy()) 1218 { 1244 { 1219 if(*molConf->GetElectronOccupancy() == 1245 if(*molConf->GetElectronOccupancy() == eOcc) 1220 { 1246 { 1221 if((molConf->fLabel != nullptr) && *m << 1247 if(molConf->fLabel && *molConf->fLabel == label) 1222 { 1248 { 1223 wasAlreadyCreated = true; 1249 wasAlreadyCreated = true; 1224 return molConf; 1250 return molConf; 1225 } 1251 } 1226 if(molConf->fLabel == nullptr) << 1252 else if(molConf->fLabel == 0) 1227 { 1253 { 1228 wasAlreadyCreated = true; 1254 wasAlreadyCreated = true; 1229 molConf->SetLabel(label); 1255 molConf->SetLabel(label); 1230 return molConf; 1256 return molConf; 1231 } 1257 } 1232 if(molConf->fLabel->empty()) << 1258 else if(*molConf->fLabel == "") 1233 { 1259 { 1234 wasAlreadyCreated = true; 1260 wasAlreadyCreated = true; 1235 molConf->SetLabel(label); 1261 molConf->SetLabel(label); 1236 return molConf; 1262 return molConf; 1237 } 1263 } 1238 } 1264 } 1239 } 1265 } 1240 1266 1241 1267 1242 molConf->PrintState(); 1268 molConf->PrintState(); 1243 G4ExceptionDescription errMsg ; 1269 G4ExceptionDescription errMsg ; 1244 errMsg << "A molecular configuration for 1270 errMsg << "A molecular configuration for the definition named " 1245 << molDef->GetName() 1271 << molDef->GetName() 1246 << " has already been created " 1272 << " has already been created " 1247 "with user ID " 1273 "with user ID " 1248 << molConf->fUserIdentifier 1274 << molConf->fUserIdentifier 1249 << " and possible different electr 1275 << " and possible different electronic state"; 1250 G4Exception("G4MolecularConfiguration::Cr 1276 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration", 1251 "DOUBLE_CREATION", 1277 "DOUBLE_CREATION", 1252 FatalErrorInArgument, 1278 FatalErrorInArgument, 1253 errMsg); 1279 errMsg); 1254 } 1280 } 1255 else 1281 else 1256 { 1282 { 1257 auto newConf = << 1283 G4MolecularConfiguration* newConf = 1258 new G4MolecularConfiguration(molDef, 1284 new G4MolecularConfiguration(molDef, 1259 eOcc, 1285 eOcc, 1260 label); 1286 label); 1261 newConf->fUserIdentifier = userIdentifier 1287 newConf->fUserIdentifier = userIdentifier; 1262 1288 1263 GetManager()->AddUserID(userIdentifier, n 1289 GetManager()->AddUserID(userIdentifier, newConf); 1264 1290 1265 // G4MoleculeTable::Instance()-> 1291 // G4MoleculeTable::Instance()-> 1266 // RecordMolecularConfiguration(userId 1292 // RecordMolecularConfiguration(userIdentifier, newConf); 1267 return newConf; 1293 return newConf; 1268 } 1294 } 1269 return molConf; 1295 return molConf; 1270 } 1296 } 1271 1297 1272 1298 1273 //___________________________________________ 1299 //______________________________________________________________________________ 1274 1300 1275 G4MolecularConfiguration* 1301 G4MolecularConfiguration* 1276 G4MolecularConfiguration::G4MolecularConfigur 1302 G4MolecularConfiguration::G4MolecularConfigurationManager:: 1277 GetOrCreateMolecularConfiguration(const G4Mol 1303 GetOrCreateMolecularConfiguration(const G4MoleculeDefinition* molDef, 1278 const G4Ele 1304 const G4ElectronOccupancy& eOcc) 1279 { 1305 { 1280 auto it1 = fElecOccTable.find(molDef); << 1306 MolElectronConfTable::iterator it1 = fElecOccTable.find(molDef); 1281 1307 1282 if(it1 == fElecOccTable.end()) 1308 if(it1 == fElecOccTable.end()) 1283 { 1309 { 1284 return new G4MolecularConfiguration(molDe 1310 return new G4MolecularConfiguration(molDef, eOcc); 1285 } 1311 } 1286 1312 1287 ElectronOccupancyTable& table2 = it1->secon 1313 ElectronOccupancyTable& table2 = it1->second; 1288 auto it = table2.find(eOcc); << 1314 ElectronOccupancyTable::iterator it = table2.find(eOcc); 1289 1315 1290 if(it == table2.end()) 1316 if(it == table2.end()) 1291 { 1317 { 1292 auto molConf = << 1318 G4MolecularConfiguration* molConf = 1293 new G4MolecularConfiguration(molDef, 1319 new G4MolecularConfiguration(molDef, eOcc); 1294 // molConf->Finalize(); 1320 // molConf->Finalize(); 1295 return molConf; 1321 return molConf; 1296 } 1322 } 1297 << 1323 else 1298 return it->second; << 1324 { >> 1325 return it->second; >> 1326 } >> 1327 >> 1328 return 0; 1299 } 1329 } 1300 1330 1301 //___________________________________________ 1331 //______________________________________________________________________________ 1302 1332 1303 G4MolecularConfiguration* 1333 G4MolecularConfiguration* 1304 G4MolecularConfiguration::G4MolecularConfigur 1334 G4MolecularConfiguration::G4MolecularConfigurationManager:: 1305 GetOrCreateMolecularConfiguration(const G4Mol 1335 GetOrCreateMolecularConfiguration(const G4MoleculeDefinition* molDef, 1306 int charge) 1336 int charge) 1307 { 1337 { 1308 auto it1 = fChargeTable.find(molDef); << 1338 MolChargeConfTable::iterator it1 = fChargeTable.find(molDef); 1309 1339 1310 if(it1 == fChargeTable.end()) 1340 if(it1 == fChargeTable.end()) 1311 { 1341 { 1312 G4AutoLock lock(&fMoleculeCreationMutex); 1342 G4AutoLock lock(&fMoleculeCreationMutex); 1313 1343 1314 auto newConf = new G4MolecularConfigurat << 1344 G4MolecularConfiguration* newConf = new G4MolecularConfiguration(molDef, charge); 1315 return newConf ; 1345 return newConf ; 1316 } 1346 } 1317 1347 1318 ChargeTable& table2 = it1->second; 1348 ChargeTable& table2 = it1->second; 1319 auto it = table2.find(charge); << 1349 ChargeTable::iterator it = table2.find(charge); 1320 1350 1321 if(it == table2.end()) 1351 if(it == table2.end()) 1322 { 1352 { 1323 G4AutoLock lock(&fMoleculeCreationMutex); 1353 G4AutoLock lock(&fMoleculeCreationMutex); 1324 1354 1325 auto newConf = << 1355 G4MolecularConfiguration* newConf = 1326 new G4MolecularConfiguration(molDef, 1356 new G4MolecularConfiguration(molDef, charge); 1327 // newConf->Finalize(); 1357 // newConf->Finalize(); 1328 return newConf ; 1358 return newConf ; 1329 } 1359 } 1330 << 1360 else 1331 return it->second; << 1361 { >> 1362 return it->second; >> 1363 } >> 1364 >> 1365 return 0; 1332 } 1366 } 1333 1367 1334 //___________________________________________ 1368 //______________________________________________________________________________ 1335 1369 1336 void G4MolecularConfiguration::Serialize(std: 1370 void G4MolecularConfiguration::Serialize(std::ostream& out) 1337 { 1371 { 1338 G4String moleculeName = fMoleculeDefinition 1372 G4String moleculeName = fMoleculeDefinition->GetName(); 1339 WRITE(out, moleculeName); 1373 WRITE(out, moleculeName); 1340 1374 1341 // if(fLabel) 1375 // if(fLabel) 1342 // out << fLabel; 1376 // out << fLabel; 1343 // else 1377 // else 1344 // out << ""; 1378 // out << ""; 1345 WRITE(out,fDynDiffusionCoefficient); 1379 WRITE(out,fDynDiffusionCoefficient); 1346 WRITE(out,fDynVanDerVaalsRadius); 1380 WRITE(out,fDynVanDerVaalsRadius); 1347 WRITE(out,fDynDecayTime); 1381 WRITE(out,fDynDecayTime); 1348 WRITE(out,fDynMass); 1382 WRITE(out,fDynMass); 1349 WRITE(out,fDynCharge); 1383 WRITE(out,fDynCharge); 1350 WRITE(out,fMoleculeID); 1384 WRITE(out,fMoleculeID); 1351 WRITE(out,fFormatedName); 1385 WRITE(out,fFormatedName); 1352 WRITE(out,fName); 1386 WRITE(out,fName); 1353 WRITE(out,fIsFinalized); 1387 WRITE(out,fIsFinalized); 1354 } 1388 } 1355 1389 1356 //___________________________________________ 1390 //______________________________________________________________________________ 1357 1391 1358 void G4MolecularConfiguration::Unserialize(st 1392 void G4MolecularConfiguration::Unserialize(std::istream& in) 1359 { 1393 { 1360 G4String moleculeName; 1394 G4String moleculeName; 1361 READ(in, moleculeName); 1395 READ(in, moleculeName); 1362 fMoleculeDefinition = 1396 fMoleculeDefinition = 1363 G4MoleculeTable::Instance()->GetMolecul 1397 G4MoleculeTable::Instance()->GetMoleculeDefinition(moleculeName); 1364 1398 1365 // G4String label; 1399 // G4String label; 1366 // 1400 // 1367 // in.read((char*)(&label), sizeof(label)); 1401 // in.read((char*)(&label), sizeof(label)); 1368 // 1402 // 1369 // if(label) 1403 // if(label) 1370 // fLabel = new G4String(label); 1404 // fLabel = new G4String(label); 1371 // else 1405 // else 1372 // fLabel = 0; 1406 // fLabel = 0; 1373 READ(in,fDynDiffusionCoefficient); 1407 READ(in,fDynDiffusionCoefficient); 1374 READ(in,fDynVanDerVaalsRadius); 1408 READ(in,fDynVanDerVaalsRadius); 1375 READ(in,fDynDecayTime); 1409 READ(in,fDynDecayTime); 1376 READ(in,fDynMass); 1410 READ(in,fDynMass); 1377 READ(in,fDynCharge); 1411 READ(in,fDynCharge); 1378 READ(in,fMoleculeID); 1412 READ(in,fMoleculeID); 1379 READ(in,fFormatedName); 1413 READ(in,fFormatedName); 1380 READ(in,fName); 1414 READ(in,fName); 1381 READ(in,fIsFinalized); 1415 READ(in,fIsFinalized); 1382 } 1416 } 1383 1417 1384 //___________________________________________ 1418 //______________________________________________________________________________ 1385 1419 1386 G4MolecularConfiguration* G4MolecularConfigur 1420 G4MolecularConfiguration* G4MolecularConfiguration::Load(std::istream& in) 1387 { 1421 { 1388 return new G4MolecularConfiguration(in); 1422 return new G4MolecularConfiguration(in); 1389 } 1423 } 1390 1424 1391 //___________________________________________ 1425 //______________________________________________________________________________ 1392 1426 1393 G4MolecularConfiguration::G4MolecularConfigur 1427 G4MolecularConfiguration::G4MolecularConfiguration(std::istream& in) 1394 { 1428 { 1395 fLabel = nullptr; // TODO: for now not seri << 1429 fLabel = 0; // TODO: for now not serialized 1396 Unserialize(in); 1430 Unserialize(in); 1397 fMoleculeDefinition = nullptr; << 1431 fMoleculeDefinition = 0; 1398 fElectronOccupancy = nullptr; << 1432 fElectronOccupancy = 0; 1399 if(fElectronOccupancy != nullptr) << 1433 if(fElectronOccupancy) 1400 { 1434 { 1401 GetManager()->Insert(fMoleculeDefinition, 1435 GetManager()->Insert(fMoleculeDefinition, *fElectronOccupancy, this); 1402 fElectronOccupancy = 1436 fElectronOccupancy = 1403 GetManager()->FindCommonElectronOccup 1437 GetManager()->FindCommonElectronOccupancy(fMoleculeDefinition, 1404 1438 *fElectronOccupancy); 1405 1439 1406 if(fLabel != nullptr) << 1440 if(fLabel) 1407 { 1441 { 1408 GetManager()->RecordNewlyLabeledConfigu 1442 GetManager()->RecordNewlyLabeledConfiguration(this); 1409 } 1443 } 1410 } 1444 } 1411 else if(fLabel != nullptr) << 1445 else if(fLabel) 1412 { 1446 { 1413 fMoleculeID = GetManager()->Insert(fMolec 1447 fMoleculeID = GetManager()->Insert(fMoleculeDefinition, *fLabel, this); 1414 } 1448 } 1415 else if(fDynCharge != 0) << 1449 else if(fDynCharge) 1416 { 1450 { 1417 fMoleculeID = GetManager()->Insert(fMolec 1451 fMoleculeID = GetManager()->Insert(fMoleculeDefinition, fDynCharge, this); 1418 } 1452 } 1419 } 1453 } 1420 1454 1421 //___________________________________________ 1455 //______________________________________________________________________________ 1422 1456 1423 void G4MolecularConfiguration::SetUserID(cons 1457 void G4MolecularConfiguration::SetUserID(const G4String& userID) 1424 { 1458 { 1425 fUserIdentifier = userID; 1459 fUserIdentifier = userID; 1426 GetManager()->AddUserID(userID, this); 1460 GetManager()->AddUserID(userID, this); 1427 // G4MoleculeTable::Instance()->RecordMolecu 1461 // G4MoleculeTable::Instance()->RecordMolecularConfiguration(userID, this); 1428 } 1462 } 1429 1463 1430 //___________________________________________ 1464 //______________________________________________________________________________ 1431 1465 1432 double G4MolecularConfiguration::DiffCoeffWat 1466 double G4MolecularConfiguration::DiffCoeffWater(double temperature_K) 1433 { 1467 { 1434 return pow(10, 4.311 1468 return pow(10, 4.311 1435 - 2.722e3/temperature_K 1469 - 2.722e3/temperature_K 1436 + 8.565e5/(temperature_K *temper 1470 + 8.565e5/(temperature_K *temperature_K) 1437 - 1.181e8/(temperature_K*tempera 1471 - 1.181e8/(temperature_K*temperature_K*temperature_K ))*1e-9*m2/s; 1438 } 1472 } 1439 1473 1440 //___________________________________________ 1474 //______________________________________________________________________________ 1441 1475 1442 void 1476 void 1443 G4MolecularConfiguration:: 1477 G4MolecularConfiguration:: 1444 ScaleAllDiffusionCoefficientsOnWater(double t 1478 ScaleAllDiffusionCoefficientsOnWater(double temperature_K) 1445 { 1479 { 1446 double D_water_0 = DiffCoeffWater(fgTempera 1480 double D_water_0 = DiffCoeffWater(fgTemperature); 1447 double D_water_f = DiffCoeffWater(temperatu 1481 double D_water_f = DiffCoeffWater(temperature_K); 1448 1482 1449 G4cout << "Scaling factor = " << D_water_f/ 1483 G4cout << "Scaling factor = " << D_water_f/D_water_0 << G4endl; 1450 1484 1451 G4ConfigurationIterator it = 1485 G4ConfigurationIterator it = 1452 G4MoleculeTable::Instance()->GetConfigu 1486 G4MoleculeTable::Instance()->GetConfigurationIterator(); 1453 1487 1454 while(it()) 1488 while(it()) 1455 { 1489 { 1456 G4MolecularConfiguration* conf = it.value 1490 G4MolecularConfiguration* conf = it.value(); 1457 double D_0 = conf->GetDiffusionCoefficien 1491 double D_0 = conf->GetDiffusionCoefficient() ; 1458 double D_f = D_water_f * D_0 /D_water_0; 1492 double D_f = D_water_f * D_0 /D_water_0; 1459 conf->SetDiffusionCoefficient(D_f); 1493 conf->SetDiffusionCoefficient(D_f); 1460 }; 1494 }; 1461 } 1495 } 1462 1496 1463 //___________________________________________ 1497 //______________________________________________________________________________ 1464 1498 1465 void G4MolecularConfiguration::CreateDefaultD 1499 void G4MolecularConfiguration::CreateDefaultDiffCoeffParam() 1466 { 1500 { 1467 if(!static_cast<bool>(fDiffParam)) << 1501 if(bool(fDiffParam) == false) 1468 { 1502 { 1469 fDiffParam = &G4MolecularConfiguration::R 1503 fDiffParam = &G4MolecularConfiguration::ReturnDefaultDiffCoeff; 1470 } 1504 } 1471 } 1505 } 1472 1506 1473 //___________________________________________ 1507 //______________________________________________________________________________ 1474 1508 1475 void G4MolecularConfiguration::SetGlobalTempe 1509 void G4MolecularConfiguration::SetGlobalTemperature(G4double temperature) 1476 { 1510 { 1477 ScaleAllDiffusionCoefficientsOnWater(temper 1511 ScaleAllDiffusionCoefficientsOnWater(temperature); 1478 fgTemperature = temperature; 1512 fgTemperature = temperature; 1479 } 1513 } 1480 1514 1481 //___________________________________________ 1515 //______________________________________________________________________________ 1482 1516 1483 G4double G4MolecularConfiguration::GetGlobalT 1517 G4double G4MolecularConfiguration::GetGlobalTemperature() 1484 { 1518 { 1485 return fgTemperature; 1519 return fgTemperature; 1486 } 1520 } 1487 1521 1488 //___________________________________________ 1522 //______________________________________________________________________________ 1489 1523 1490 G4MolecularConfiguration* 1524 G4MolecularConfiguration* 1491 G4MolecularConfiguration:: 1525 G4MolecularConfiguration:: 1492 G4MolecularConfigurationManager::GetMolecular 1526 G4MolecularConfigurationManager::GetMolecularConfiguration(const G4String& userID) 1493 { 1527 { 1494 for(auto it : fMolConfPerID) 1528 for(auto it : fMolConfPerID) 1495 { 1529 { 1496 if(it->GetUserID() == userID) return it; 1530 if(it->GetUserID() == userID) return it; 1497 } 1531 } 1498 return nullptr; << 1532 return 0; 1499 } 1533 } 1500 1534 1501 //___________________________________________ 1535 //______________________________________________________________________________ 1502 1536 1503 G4MolecularConfiguration* 1537 G4MolecularConfiguration* 1504 G4MolecularConfiguration::GetMolecularConfigu 1538 G4MolecularConfiguration::GetMolecularConfiguration(const G4String& userID) 1505 { 1539 { 1506 return GetManager()->GetMolecularConfigurat 1540 return GetManager()->GetMolecularConfiguration(userID); 1507 } 1541 } 1508 1542 1509 //___________________________________________ 1543 //______________________________________________________________________________ 1510 1544 1511 void G4MolecularConfiguration::FinalizeAll() 1545 void G4MolecularConfiguration::FinalizeAll() 1512 { 1546 { 1513 const std::vector<G4MolecularConfiguration* 1547 const std::vector<G4MolecularConfiguration*>& species = 1514 GetManager()->GetAllSpecies(); 1548 GetManager()->GetAllSpecies(); 1515 1549 1516 for(auto specie : species) << 1550 for(std::size_t i = 0; i < species.size() ; ++i) 1517 { 1551 { 1518 specie->Finalize(); << 1552 species[i]->Finalize(); 1519 } 1553 } 1520 1554 1521 } 1555 } 1522 1556 1523 void G4MolecularConfiguration::PrintAll() //h 1557 void G4MolecularConfiguration::PrintAll() //hoang added 1524 { 1558 { 1525 const std::vector<G4MolecularConfiguration* 1559 const std::vector<G4MolecularConfiguration*>& species = 1526 GetManager()->GetAllSpecies(); 1560 GetManager()->GetAllSpecies(); 1527 G4cout<<G4endl; 1561 G4cout<<G4endl; 1528 G4cout<<"Molecular Config"<<std::setw(25)<< 1562 G4cout<<"Molecular Config"<<std::setw(25)<<" | Diffusion Coefficient (m2 / s) "<<std::setw(20)<<" | Radius (nm) "<<G4endl; 1529 G4cout<<"__________________________________ 1563 G4cout<<"__________________________________________" 1530 "________________________________ 1564 "___________________________________"<<G4endl; 1531 for(auto specie : species) << 1565 for(std::size_t i = 0; i < species.size() ; ++i) 1532 { 1566 { 1533 G4cout<<specie->GetName() << 1567 G4cout<<species[i]->GetName() 1534 <<std::setw(G4int(30 - specie->Get << 1568 <<std::setw(G4int(30 - species[i]->GetName().length())) 1535 <<right<<specie->GetDiffusionCoeff << 1569 <<right<<species[i]->GetDiffusionCoefficient() * 1.0e3<<std::setw(30) 1536 <<specie->GetVanDerVaalsRadius()/C << 1570 <<species[i]->GetVanDerVaalsRadius()/CLHEP::nm<<G4endl; 1537 G4cout<<"________________________________ 1571 G4cout<<"__________________________________________" 1538 "______________________________ 1572 "___________________________________"<<G4endl; 1539 } 1573 } 1540 1574 1541 } 1575 } 1542 1576