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; >> 260 } >> 261 else >> 262 { >> 263 return it->second; 259 } 264 } 260 << 265 261 return it->second; << 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; >> 322 } >> 323 else >> 324 { >> 325 return it->second; 317 } 326 } 318 << 327 319 return it->second; << 328 return 0; 320 << 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 { >> 708 // if (fName.isNull()) >> 709 // { >> 710 // fName = fMoleculeDefinition->GetName(); >> 711 // fName += "^"; >> 712 // // fName+= "{"; >> 713 // fName += G4UIcommand::ConvertToString(fDynCharge); >> 714 // // fName+= "}"; >> 715 // } 689 return fName; 716 return fName; 690 } 717 } 691 718 692 //____________________________________________ 719 //______________________________________________________________________________ 693 720 694 const G4String& G4MolecularConfiguration::GetF 721 const G4String& G4MolecularConfiguration::GetFormatedName() const 695 { 722 { >> 723 // if (fFormatedName.isNull()) >> 724 // { >> 725 // fFormatedName = fMoleculeDefinition->GetFormatedName(); >> 726 // fFormatedName += "^"; >> 727 // fFormatedName += "{"; >> 728 // fFormatedName += G4UIcommand::ConvertToString(fDynCharge); >> 729 // fFormatedName += "}"; >> 730 // } 696 return fFormatedName; 731 return fFormatedName; 697 } 732 } 698 733 699 //____________________________________________ 734 //______________________________________________________________________________ 700 735 701 G4int G4MolecularConfiguration::GetAtomsNumber 736 G4int G4MolecularConfiguration::GetAtomsNumber() const 702 { 737 { 703 return fMoleculeDefinition->GetAtomsNumber() 738 return fMoleculeDefinition->GetAtomsNumber(); 704 } 739 } 705 740 706 //____________________________________________ 741 //______________________________________________________________________________ 707 742 708 G4double G4MolecularConfiguration::GetNbElectr 743 G4double G4MolecularConfiguration::GetNbElectrons() const 709 { 744 { 710 CheckElectronOccupancy(__func__); 745 CheckElectronOccupancy(__func__); 711 return fElectronOccupancy->GetTotalOccupancy 746 return fElectronOccupancy->GetTotalOccupancy(); 712 } 747 } 713 748 714 //____________________________________________ 749 //______________________________________________________________________________ 715 750 716 void G4MolecularConfiguration::PrintState() co 751 void G4MolecularConfiguration::PrintState() const 717 { 752 { 718 G4cout << "-------------- Start Printing Sta 753 G4cout << "-------------- Start Printing State " << GetName() 719 << " ---------------" << G4endl; 754 << " ---------------" << G4endl; 720 755 721 if (fElectronOccupancy != nullptr) << 756 if (fElectronOccupancy) 722 { 757 { 723 G4cout << "--------------Print electronic 758 G4cout << "--------------Print electronic state of " << GetName() 724 << "---------------" << G4endl; 759 << "---------------" << G4endl; 725 fElectronOccupancy->DumpInfo(); 760 fElectronOccupancy->DumpInfo(); 726 if(fElectronOccupancy==fMoleculeDefinition 761 if(fElectronOccupancy==fMoleculeDefinition->GetGroundStateElectronOccupancy()) 727 { 762 { 728 G4cout<<"At ground state"<<G4endl; 763 G4cout<<"At ground state"<<G4endl; 729 } 764 } 730 } 765 } 731 else 766 else 732 { 767 { 733 G4cout << "--- No electron occupancy set u 768 G4cout << "--- No electron occupancy set up ---" << G4endl; 734 } 769 } 735 770 736 G4cout << "Charge :" 771 G4cout << "Charge :" 737 << fDynCharge 772 << fDynCharge 738 << G4endl; 773 << G4endl; 739 774 740 if(fLabel != nullptr) << 775 if(fLabel) 741 { 776 { 742 G4cout << "Label :" 777 G4cout << "Label :" 743 << GetLabel() 778 << GetLabel() 744 << G4endl; 779 << G4endl; 745 } 780 } 746 G4cout << "-------------- End Of State " << 781 G4cout << "-------------- End Of State " << GetName() 747 << " -----------------------" << G4e 782 << " -----------------------" << G4endl; 748 } 783 } 749 784 750 //____________________________________________ 785 //______________________________________________________________________________ 751 786 752 // added - to be transformed in a "Decay metho 787 // added - to be transformed in a "Decay method" 753 const vector<const G4MolecularDissociationChan 788 const vector<const G4MolecularDissociationChannel*>* 754 G4MolecularConfiguration::GetDissociationCha 789 G4MolecularConfiguration::GetDissociationChannels() const 755 { 790 { 756 // if (fElectronOccupancy == 0) return 0; 791 // if (fElectronOccupancy == 0) return 0; 757 return fMoleculeDefinition->GetDecayChannels 792 return fMoleculeDefinition->GetDecayChannels(this); 758 } 793 } 759 794 760 //____________________________________________ 795 //______________________________________________________________________________ 761 796 762 G4int G4MolecularConfiguration::GetFakeParticl 797 G4int G4MolecularConfiguration::GetFakeParticleID() const 763 { 798 { 764 if(fMoleculeDefinition != nullptr) return fM << 799 if(fMoleculeDefinition) return fMoleculeDefinition->GetPDGEncoding(); 765 G4Exception("G4MolecularConfiguration::GetMo << 800 else G4Exception("G4MolecularConfiguration::GetMoleculeID", 766 "", 801 "", 767 FatalErrorInArgument, 802 FatalErrorInArgument, 768 "You should first enter a m 803 "You should first enter a molecule definition"); 769 804 770 return INT_MAX; 805 return INT_MAX; 771 } 806 } 772 807 773 //____________________________________________ 808 //______________________________________________________________________________ 774 809 775 const char* removePath(const char* path) 810 const char* removePath(const char* path) 776 { 811 { 777 const char* pDelimeter = strrchr(path, '\\') 812 const char* pDelimeter = strrchr(path, '\\'); 778 if (pDelimeter != nullptr) path = pDelimeter << 813 if (pDelimeter) path = pDelimeter + 1; 779 814 780 pDelimeter = strrchr(path, '/'); 815 pDelimeter = strrchr(path, '/'); 781 if (pDelimeter != nullptr) path = pDelimeter << 816 if (pDelimeter) path = pDelimeter + 1; 782 817 783 return path; 818 return path; 784 } 819 } 785 820 786 //____________________________________________ 821 //______________________________________________________________________________ 787 822 788 void G4MolecularConfiguration::CheckElectronOc 823 void G4MolecularConfiguration::CheckElectronOccupancy(const char* function) const 789 { 824 { 790 if (fElectronOccupancy == nullptr) << 825 if (fElectronOccupancy == 0) 791 { 826 { 792 G4String functionName(function); 827 G4String functionName(function); 793 G4ExceptionDescription description; 828 G4ExceptionDescription description; 794 description 829 description 795 << "No G4ElectronOccupancy was defined 830 << "No G4ElectronOccupancy was defined for molecule definition : " 796 << fMoleculeDefinition->GetName() 831 << fMoleculeDefinition->GetName() 797 << ". The definition was probably defi 832 << ". The definition was probably defined using the charge state, " 798 "rather than electron state."; 833 "rather than electron state."; 799 834 800 G4Exception(functionName, "", FatalErrorIn 835 G4Exception(functionName, "", FatalErrorInArgument, description); 801 } 836 } 802 } 837 } 803 838 804 //____________________________________________ 839 //______________________________________________________________________________ 805 840 806 void G4MolecularConfiguration::G4MolecularConf 841 void G4MolecularConfiguration::G4MolecularConfigurationManager:: 807 RecordNewlyLabeledConfiguration(G4MolecularCon 842 RecordNewlyLabeledConfiguration(G4MolecularConfiguration* molConf) 808 { 843 { 809 //G4AutoLock lock(&fMoleculeCreationMutex); 844 //G4AutoLock lock(&fMoleculeCreationMutex); 810 845 811 LabelTable& tmpMap = fLabelTable[molConf->fM 846 LabelTable& tmpMap = fLabelTable[molConf->fMoleculeDefinition]; 812 847 813 auto it = tmpMap.find(*molConf->fLabel); << 848 LabelTable::iterator it = tmpMap.find(*molConf->fLabel); 814 849 815 if(it == tmpMap.end()) 850 if(it == tmpMap.end()) 816 { 851 { 817 tmpMap[*(molConf->fLabel)] = molConf; 852 tmpMap[*(molConf->fLabel)] = molConf; 818 } 853 } 819 else 854 else 820 { 855 { 821 G4ExceptionDescription errMsg; 856 G4ExceptionDescription errMsg; 822 errMsg << "The same molecular configuratio 857 errMsg << "The same molecular configuration seemed to be recorded twice"; 823 G4Exception("G4MolecularConfigurationManag 858 G4Exception("G4MolecularConfigurationManager::" 824 "SetMolecularConfiguration(con 859 "SetMolecularConfiguration(const G4MoleculeDefinition* molDef," 825 "const G4String& label," 860 "const G4String& label," 826 "G4MolecularConfiguration* mol 861 "G4MolecularConfiguration* molConf)", 827 "", FatalException, errMsg); 862 "", FatalException, errMsg); 828 } 863 } 829 864 830 //lock.unlock(); 865 //lock.unlock(); 831 } 866 } 832 867 833 void G4MolecularConfiguration::G4MolecularConf 868 void G4MolecularConfiguration::G4MolecularConfigurationManager::AddUserID(const G4String& userID, 834 869 G4MolecularConfiguration* molecule) 835 { 870 { 836 auto it = fUserIDTable.find(userID); << 871 UserIDTable::iterator it = fUserIDTable.find(userID); 837 872 838 if(it == fUserIDTable.end()) 873 if(it == fUserIDTable.end()) 839 { 874 { 840 fUserIDTable[userID] = molecule; 875 fUserIDTable[userID] = molecule; 841 } 876 } 842 else if(molecule != it->second) 877 else if(molecule != it->second) 843 { 878 { 844 // TODO improve exception 879 // TODO improve exception 845 // exception 880 // exception 846 G4ExceptionDescription description; 881 G4ExceptionDescription description; 847 description << "The user identifier " << u 882 description << "The user identifier " << userID 848 << " was already given in anot 883 << " was already given in another configuration in the table" 849 << G4endl; 884 << G4endl; 850 G4Exception("G4MolecularConfiguration::G4Mol 885 G4Exception("G4MolecularConfiguration::G4MolecularConfigurationManager::AddUserID", 851 "CONF_ALREADY_RECORDED", 886 "CONF_ALREADY_RECORDED", 852 FatalException, 887 FatalException, 853 description); 888 description); 854 } 889 } 855 } 890 } 856 891 857 //____________________________________________ 892 //______________________________________________________________________________ 858 893 859 void G4MolecularConfiguration::G4MolecularConf 894 void G4MolecularConfiguration::G4MolecularConfigurationManager:: 860 RemoveMolecularConfigurationFromTable(G4Molecu 895 RemoveMolecularConfigurationFromTable(G4MolecularConfiguration* configuration) 861 { 896 { 862 auto it1 = << 897 MolElectronConfTable::iterator it1 = 863 fElecOccTable.find(configuration->GetDef 898 fElecOccTable.find(configuration->GetDefinition()); 864 auto end = fElecOccTable.end(); << 899 MolElectronConfTable::iterator end = fElecOccTable.end(); 865 900 866 if (it1 == end) return; 901 if (it1 == end) return; 867 902 868 auto it2 = << 903 std::map<G4ElectronOccupancy, G4MolecularConfiguration*, comparator>:: >> 904 iterator it2 = 869 it1->second.find(*configuration->GetElec 905 it1->second.find(*configuration->GetElectronOccupancy()); 870 906 871 if (it2 == it1->second.end()) return; 907 if (it2 == it1->second.end()) return; 872 908 873 it2->second = 0; 909 it2->second = 0; 874 // it1->second.erase(it2); 910 // it1->second.erase(it2); 875 911 876 configuration->fElectronOccupancy = nullptr; << 912 configuration->fElectronOccupancy = 0; 877 } 913 } 878 914 879 //____________________________________________ 915 //______________________________________________________________________________ 880 916 881 G4MolecularConfiguration* 917 G4MolecularConfiguration* 882 G4MolecularConfiguration::G4MolecularConfigura 918 G4MolecularConfiguration::G4MolecularConfigurationManager:: 883 GetMolecularConfiguration(const G4MoleculeDefi 919 GetMolecularConfiguration(const G4MoleculeDefinition* molDef, 884 const G4String& labe 920 const G4String& label) 885 { 921 { 886 //G4AutoLock lock(&fMoleculeCreationMutex); 922 //G4AutoLock lock(&fMoleculeCreationMutex); 887 923 888 auto it1 = fLabelTable.find(molDef); << 924 MolLabelConfTable::iterator it1 = fLabelTable.find(molDef); 889 925 890 if(it1 == fLabelTable.end()) return nullptr; << 926 if(it1 == fLabelTable.end()) return 0; 891 927 892 LabelTable& table2 = it1->second; 928 LabelTable& table2 = it1->second; 893 929 894 auto it2 = table2.find(label); << 930 LabelTable::iterator it2 = table2.find(label); 895 931 896 //lock.unlock(); 932 //lock.unlock(); 897 933 898 if(it2 == table2.end()) return nullptr; << 934 if(it2 == table2.end()) return 0; 899 return it2->second; 935 return it2->second; 900 } 936 } 901 937 902 //____________________________________________ 938 //______________________________________________________________________________ 903 939 904 G4MolecularConfiguration* 940 G4MolecularConfiguration* 905 G4MolecularConfiguration::G4MolecularConfigura 941 G4MolecularConfiguration::G4MolecularConfigurationManager:: 906 GetMolecularConfiguration(int moleculeID) 942 GetMolecularConfiguration(int moleculeID) 907 { 943 { 908 if(moleculeID > (int) fMolConfPerID.size() | 944 if(moleculeID > (int) fMolConfPerID.size() || 909 moleculeID < 0) return nullptr; << 945 moleculeID < 0) return 0; 910 946 911 return fMolConfPerID[moleculeID]; 947 return fMolConfPerID[moleculeID]; 912 } 948 } 913 949 914 //____________________________________________ 950 //______________________________________________________________________________ 915 951 916 G4int 952 G4int 917 G4MolecularConfiguration::G4MolecularConfigura 953 G4MolecularConfiguration::G4MolecularConfigurationManager:: 918 Insert(const G4MoleculeDefinition* molDef, 954 Insert(const G4MoleculeDefinition* molDef, 919 const G4String& l 955 const G4String& label, 920 G4MolecularConfig 956 G4MolecularConfiguration* molConf) 921 { 957 { 922 G4AutoLock lock(&fMoleculeCreationMutex); 958 G4AutoLock lock(&fMoleculeCreationMutex); 923 LabelTable& tmpMap = fLabelTable[molDef]; 959 LabelTable& tmpMap = fLabelTable[molDef]; 924 auto it = tmpMap.find(label); << 960 LabelTable::iterator it = tmpMap.find(label); 925 961 926 if(it == tmpMap.end()) 962 if(it == tmpMap.end()) 927 { 963 { 928 fLastMoleculeID++; 964 fLastMoleculeID++; 929 tmpMap[label] = molConf; 965 tmpMap[label] = molConf; 930 lock.unlock(); 966 lock.unlock(); 931 } 967 } 932 else 968 else 933 { 969 { 934 lock.unlock(); 970 lock.unlock(); 935 G4ExceptionDescription errMsg; 971 G4ExceptionDescription errMsg; 936 errMsg << "The same molecular configuratio 972 errMsg << "The same molecular configuration seemed to be recorded twice"; 937 G4Exception("G4MolecularConfigurationManag 973 G4Exception("G4MolecularConfigurationManager::" 938 "SetMolecularConfiguration(con 974 "SetMolecularConfiguration(const G4MoleculeDefinition* molDef," 939 "const G4String& label," 975 "const G4String& label," 940 "G4MolecularConfiguration* mol 976 "G4MolecularConfiguration* molConf)", 941 "", FatalException, errMsg); 977 "", FatalException, errMsg); 942 } 978 } 943 979 944 fMolConfPerID.push_back(molConf); 980 fMolConfPerID.push_back(molConf); 945 981 946 return fLastMoleculeID; 982 return fLastMoleculeID; 947 } 983 } 948 984 949 //____________________________________________ 985 //______________________________________________________________________________ 950 986 951 G4MolecularConfiguration* 987 G4MolecularConfiguration* 952 G4MolecularConfiguration::GetMolecularConfigur 988 G4MolecularConfiguration::GetMolecularConfiguration(const G4MoleculeDefinition* molDef, 953 989 const G4String& label) 954 { 990 { 955 return GetManager()->GetMolecularConfigurati 991 return GetManager()->GetMolecularConfiguration(molDef, label); 956 } 992 } 957 993 958 //____________________________________________ 994 //______________________________________________________________________________ 959 995 960 G4MolecularConfiguration* 996 G4MolecularConfiguration* 961 G4MolecularConfiguration::GetMolecularConfigur 997 G4MolecularConfiguration::GetMolecularConfiguration(int moleculeID) 962 { 998 { 963 return GetManager()->GetMolecularConfigurati 999 return GetManager()->GetMolecularConfiguration(moleculeID); 964 } 1000 } 965 1001 966 //____________________________________________ 1002 //______________________________________________________________________________ 967 1003 968 G4MolecularConfiguration* 1004 G4MolecularConfiguration* 969 G4MolecularConfiguration::CreateMolecularConfi 1005 G4MolecularConfiguration::CreateMolecularConfiguration(const G4String& userIdentifier, 970 1006 const G4MoleculeDefinition* molDef, 971 1007 int charge, 972 1008 const G4String& label, 973 1009 bool& wasAlreadyCreated) 974 { 1010 { 975 wasAlreadyCreated = false; 1011 wasAlreadyCreated = false; 976 G4MolecularConfiguration* molConf = 1012 G4MolecularConfiguration* molConf = 977 GetManager()->GetMolecularConfiguration( 1013 GetManager()->GetMolecularConfiguration(molDef, charge); 978 1014 979 if (molConf != nullptr) << 1015 if (molConf) 980 { 1016 { 981 if(molConf->fLabel == nullptr) << 1017 if(molConf->fLabel == 0) 982 { 1018 { 983 molConf->SetLabel(label); 1019 molConf->SetLabel(label); 984 G4ExceptionDescription wMsg ; 1020 G4ExceptionDescription wMsg ; 985 wMsg << "The molecular configuration for 1021 wMsg << "The molecular configuration for the definition named " 986 << molDef->GetName() 1022 << molDef->GetName() 987 << " with charge " << charge << " 1023 << " with charge " << charge << " has already been created " 988 "but with NO label"; 1024 "but with NO label"; 989 G4Exception("G4MolecularConfiguration::C 1025 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration", 990 "DOUBLE_CREATION", 1026 "DOUBLE_CREATION", 991 JustWarning, 1027 JustWarning, 992 wMsg); 1028 wMsg); 993 } 1029 } 994 else if(molConf->fLabel->empty() ) << 1030 else if(*(molConf->fLabel) == "" ) 995 { 1031 { 996 molConf->SetLabel(label); 1032 molConf->SetLabel(label); 997 } 1033 } 998 else if(*(molConf->fLabel) != label) 1034 else if(*(molConf->fLabel) != label) 999 { 1035 { 1000 G4ExceptionDescription errMsg ; 1036 G4ExceptionDescription errMsg ; 1001 errMsg << "The molecular configuration 1037 errMsg << "The molecular configuration for the definition named " 1002 << molDef->GetName() 1038 << molDef->GetName() 1003 << " with charge " << charge << 1039 << " with charge " << charge << " has already been created " 1004 "but with a different label 1040 "but with a different label :" 1005 << molConf->GetLabel(); 1041 << molConf->GetLabel(); 1006 G4Exception("G4MolecularConfiguration:: 1042 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration", 1007 "DOUBLE_CREATION", 1043 "DOUBLE_CREATION", 1008 FatalErrorInArgument, 1044 FatalErrorInArgument, 1009 errMsg); 1045 errMsg); 1010 // KILL APP 1046 // KILL APP 1011 } 1047 } 1012 1048 1013 if(molConf->fUserIdentifier.empty()) << 1049 if(molConf->fUserIdentifier == "") 1014 { 1050 { 1015 molConf->fUserIdentifier = userIdentifi 1051 molConf->fUserIdentifier = userIdentifier; 1016 1052 1017 G4ExceptionDescription wMsg ; 1053 G4ExceptionDescription wMsg ; 1018 wMsg << "The molecular configuration fo 1054 wMsg << "The molecular configuration for the definition named " 1019 << molDef->GetName() 1055 << molDef->GetName() 1020 << " with label " << label << " 1056 << " with label " << label << " has already been created."; 1021 G4Exception("G4MolecularConfiguration:: 1057 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration", 1022 "DOUBLE_CREATION", 1058 "DOUBLE_CREATION", 1023 JustWarning, 1059 JustWarning, 1024 wMsg); 1060 wMsg); 1025 } 1061 } 1026 else if(molConf->fUserIdentifier != userI 1062 else if(molConf->fUserIdentifier != userIdentifier) 1027 { 1063 { 1028 G4ExceptionDescription errMsg ; 1064 G4ExceptionDescription errMsg ; 1029 errMsg << "The molecular configuration 1065 errMsg << "The molecular configuration for the definition named " 1030 << molDef->GetName() 1066 << molDef->GetName() 1031 << " with label " << label << " 1067 << " with label " << label << " has already been created " 1032 "BUT with a different user I 1068 "BUT with a different user ID :" 1033 << molConf->fUserIdentifier; 1069 << molConf->fUserIdentifier; 1034 G4Exception("G4MolecularConfiguration:: 1070 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration", 1035 "DOUBLE_CREATION", 1071 "DOUBLE_CREATION", 1036 FatalErrorInArgument, 1072 FatalErrorInArgument, 1037 errMsg); 1073 errMsg); 1038 // KILL APP 1074 // KILL APP 1039 } 1075 } 1040 1076 1041 wasAlreadyCreated = true; 1077 wasAlreadyCreated = true; 1042 return molConf; 1078 return molConf; 1043 } 1079 } 1044 << 1080 else 1045 auto newConf = << 1081 { 1046 new G4MolecularConfiguration(molDef, la << 1082 G4MolecularConfiguration* newConf = 1047 newConf->fUserIdentifier = userIdentifier; << 1083 new G4MolecularConfiguration(molDef, label, charge); >> 1084 newConf->fUserIdentifier = userIdentifier; 1048 1085 1049 GetManager()->AddUserID(userIdentifier, new << 1086 GetManager()->AddUserID(userIdentifier, newConf); 1050 1087 1051 // G4MoleculeTable::Instance()->RecordMole 1088 // G4MoleculeTable::Instance()->RecordMolecularConfiguration(userIdentifier, 1052 // 1089 // newConf); 1053 return newConf; << 1090 return newConf; >> 1091 } 1054 } 1092 } 1055 1093 1056 //___________________________________________ 1094 //______________________________________________________________________________ 1057 1095 1058 G4MolecularConfiguration* 1096 G4MolecularConfiguration* 1059 G4MolecularConfiguration:: 1097 G4MolecularConfiguration:: 1060 CreateMolecularConfiguration(const G4String& 1098 CreateMolecularConfiguration(const G4String& userIdentifier, 1061 const G4Molecule 1099 const G4MoleculeDefinition* molDef, 1062 bool& wasAlready 1100 bool& wasAlreadyCreated) 1063 { 1101 { 1064 wasAlreadyCreated = false; 1102 wasAlreadyCreated = false; 1065 G4MolecularConfiguration* preRegisteredMolC 1103 G4MolecularConfiguration* preRegisteredMolConf = 1066 GetManager()->GetMolecularConfiguration 1104 GetManager()->GetMolecularConfiguration(userIdentifier); 1067 1105 1068 if(preRegisteredMolConf != nullptr) << 1106 if(preRegisteredMolConf) 1069 { 1107 { 1070 if(preRegisteredMolConf->GetDefinition() 1108 if(preRegisteredMolConf->GetDefinition() == molDef) 1071 { 1109 { 1072 wasAlreadyCreated = true; 1110 wasAlreadyCreated = true; 1073 return preRegisteredMolConf; 1111 return preRegisteredMolConf; 1074 } 1112 } 1075 } 1113 } 1076 1114 1077 if(molDef->GetGroundStateElectronOccupancy( << 1115 if(molDef->GetGroundStateElectronOccupancy()) 1078 { 1116 { 1079 const G4ElectronOccupancy& elecOcc = *mol 1117 const G4ElectronOccupancy& elecOcc = *molDef 1080 ->GetGroundStateElectronOccupancy(); 1118 ->GetGroundStateElectronOccupancy(); 1081 G4MolecularConfiguration* molConf = 1119 G4MolecularConfiguration* molConf = 1082 GetManager()->GetMolecularConfigurati 1120 GetManager()->GetMolecularConfiguration(molDef, elecOcc); 1083 1121 1084 if(molConf != nullptr) << 1122 if(molConf) 1085 { 1123 { 1086 if(molConf->fUserIdentifier.empty()) << 1124 if(molConf->fUserIdentifier == "") 1087 { 1125 { 1088 molConf->fUserIdentifier = userIdenti 1126 molConf->fUserIdentifier = userIdentifier; 1089 } 1127 } 1090 else if(molConf->fUserIdentifier != use 1128 else if(molConf->fUserIdentifier != userIdentifier) 1091 { 1129 { 1092 G4ExceptionDescription errMsg; 1130 G4ExceptionDescription errMsg; 1093 errMsg << "A molecular configuration 1131 errMsg << "A molecular configuration for the definition named " 1094 << molDef->GetName() << " has 1132 << molDef->GetName() << " has already been created " 1095 "and recorded with a different 1133 "and recorded with a different user ID " 1096 << molConf->fUserIdentifier; 1134 << molConf->fUserIdentifier; 1097 G4Exception("G4MolecularConfiguration 1135 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration", 1098 "DOUBLE_CREATION", 1136 "DOUBLE_CREATION", 1099 FatalErrorInArgument, 1137 FatalErrorInArgument, 1100 errMsg); 1138 errMsg); 1101 } 1139 } 1102 // TODO exception 1140 // TODO exception 1103 G4ExceptionDescription errMsg; 1141 G4ExceptionDescription errMsg; 1104 errMsg << "A molecular configuration fo 1142 errMsg << "A molecular configuration for the definition named " 1105 << molDef->GetName() << " has al 1143 << molDef->GetName() << " has already been created."; 1106 G4Exception("G4MolecularConfiguration:: 1144 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration", 1107 "DOUBLE_CREATION", 1145 "DOUBLE_CREATION", 1108 JustWarning, 1146 JustWarning, 1109 errMsg); 1147 errMsg); 1110 wasAlreadyCreated = true; 1148 wasAlreadyCreated = true; 1111 return molConf; 1149 return molConf; 1112 } 1150 } 1113 << 1151 else 1114 // G4cout << "Create molConf for " << mol << 1152 { 1115 auto newConf = new G4MolecularConfigurat << 1153 // G4cout << "Create molConf for " << molDef->GetName() << G4endl; 1116 << 1154 G4MolecularConfiguration* newConf = new G4MolecularConfiguration(molDef, 1117 newConf->fUserIdentifier = userIdentifier << 1155 elecOcc); >> 1156 newConf->fUserIdentifier = userIdentifier; 1118 1157 1119 GetManager()->AddUserID(userIdentifier, n << 1158 GetManager()->AddUserID(userIdentifier, newConf); 1120 1159 1121 // G4MoleculeTable::Instance()->RecordMo 1160 // G4MoleculeTable::Instance()->RecordMolecularConfiguration(userIdentifier, 1122 // 1161 // newConf); 1123 return newConf; << 1162 return newConf; >> 1163 } >> 1164 } >> 1165 else >> 1166 { >> 1167 return CreateMolecularConfiguration(userIdentifier, >> 1168 molDef, >> 1169 molDef->GetName(), >> 1170 molDef->GetCharge(), >> 1171 wasAlreadyCreated); 1124 } 1172 } 1125 << 1126 return CreateMolecularConfiguration(userIde << 1127 molDef, << 1128 molDef- << 1129 molDef- << 1130 wasAlre << 1131 } 1173 } 1132 1174 1133 //___________________________________________ 1175 //______________________________________________________________________________ 1134 1176 1135 G4MolecularConfiguration* 1177 G4MolecularConfiguration* 1136 G4MolecularConfiguration:: 1178 G4MolecularConfiguration:: 1137 CreateMolecularConfiguration(const G4String& 1179 CreateMolecularConfiguration(const G4String& userIdentifier, 1138 const G4Molecule 1180 const G4MoleculeDefinition* molDef, 1139 const G4String& 1181 const G4String& label, 1140 bool& wasAlready 1182 bool& wasAlreadyCreated) 1141 { 1183 { 1142 assert(label != ""); 1184 assert(label != ""); 1143 wasAlreadyCreated = false; 1185 wasAlreadyCreated = false; 1144 1186 1145 G4MolecularConfiguration* molConf = 1187 G4MolecularConfiguration* molConf = 1146 GetManager()->GetMolecularConfiguration 1188 GetManager()->GetMolecularConfiguration(molDef, label); 1147 if(molConf != nullptr) << 1189 if(molConf) 1148 { 1190 { 1149 if((molConf->fLabel != nullptr) << 1191 if(molConf->fLabel 1150 && *molConf->fLabel == label) 1192 && *molConf->fLabel == label) 1151 { 1193 { 1152 wasAlreadyCreated = true; 1194 wasAlreadyCreated = true; 1153 return molConf; 1195 return molConf; 1154 } 1196 } 1155 if(molConf->fLabel == nullptr) << 1197 else if(molConf->fLabel == 0) 1156 { 1198 { 1157 wasAlreadyCreated = true; 1199 wasAlreadyCreated = true; 1158 molConf->SetLabel(label); 1200 molConf->SetLabel(label); 1159 return molConf; 1201 return molConf; 1160 } 1202 } 1161 if(molConf->fLabel->empty()) << 1203 else if(*molConf->fLabel == "") 1162 { 1204 { 1163 wasAlreadyCreated = true; 1205 wasAlreadyCreated = true; 1164 molConf->SetLabel(label); 1206 molConf->SetLabel(label); 1165 return molConf; 1207 return molConf; 1166 } 1208 } 1167 1209 1168 molConf->PrintState(); 1210 molConf->PrintState(); 1169 G4ExceptionDescription errMsg ; 1211 G4ExceptionDescription errMsg ; 1170 errMsg << "A molecular configuration for 1212 errMsg << "A molecular configuration for the definition named " 1171 << molDef->GetName() 1213 << molDef->GetName() 1172 << " has already been created " 1214 << " has already been created " 1173 "with user ID " 1215 "with user ID " 1174 << molConf->fUserIdentifier << " a 1216 << molConf->fUserIdentifier << " and label " 1175 << molConf->GetLabel(); 1217 << molConf->GetLabel(); 1176 G4Exception("G4MolecularConfiguration::Cr 1218 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration", 1177 "DOUBLE_CREATION", 1219 "DOUBLE_CREATION", 1178 FatalErrorInArgument, 1220 FatalErrorInArgument, 1179 errMsg); 1221 errMsg); 1180 // KILL APP 1222 // KILL APP 1181 } 1223 } 1182 else 1224 else 1183 { 1225 { 1184 auto newConf = << 1226 G4MolecularConfiguration* newConf = 1185 new G4MolecularConfiguration(molDef, 1227 new G4MolecularConfiguration(molDef, 1186 label, 1228 label, 1187 molDef->Ge 1229 molDef->GetCharge()); 1188 newConf->fUserIdentifier = userIdentifier 1230 newConf->fUserIdentifier = userIdentifier; 1189 1231 1190 GetManager()->AddUserID(userIdentifier, n 1232 GetManager()->AddUserID(userIdentifier, newConf); 1191 1233 1192 // G4MoleculeTable::Instance()-> 1234 // G4MoleculeTable::Instance()-> 1193 // RecordMolecularConfiguration(userId 1235 // RecordMolecularConfiguration(userIdentifier, newConf); 1194 return newConf; 1236 return newConf; 1195 } 1237 } 1196 return molConf; 1238 return molConf; 1197 } 1239 } 1198 1240 1199 //___________________________________________ 1241 //______________________________________________________________________________ 1200 1242 1201 G4MolecularConfiguration* 1243 G4MolecularConfiguration* 1202 G4MolecularConfiguration:: 1244 G4MolecularConfiguration:: 1203 CreateMolecularConfiguration(const G4String& 1245 CreateMolecularConfiguration(const G4String& userIdentifier, 1204 const G4Molecule 1246 const G4MoleculeDefinition* molDef, 1205 const G4String& 1247 const G4String& label, 1206 const G4Electron 1248 const G4ElectronOccupancy& eOcc, 1207 bool& wasAlready 1249 bool& wasAlreadyCreated) 1208 { 1250 { 1209 assert(label != ""); 1251 assert(label != ""); 1210 wasAlreadyCreated = false; 1252 wasAlreadyCreated = false; 1211 1253 1212 G4MolecularConfiguration* molConf = 1254 G4MolecularConfiguration* molConf = 1213 GetManager()->GetMolecularConfiguration 1255 GetManager()->GetMolecularConfiguration(molDef, eOcc); 1214 1256 1215 if(molConf != nullptr) << 1257 if(molConf) 1216 { 1258 { 1217 if(molConf->GetElectronOccupancy() != nul << 1259 if(molConf->GetElectronOccupancy()) 1218 { 1260 { 1219 if(*molConf->GetElectronOccupancy() == 1261 if(*molConf->GetElectronOccupancy() == eOcc) 1220 { 1262 { 1221 if((molConf->fLabel != nullptr) && *m << 1263 if(molConf->fLabel && *molConf->fLabel == label) 1222 { 1264 { 1223 wasAlreadyCreated = true; 1265 wasAlreadyCreated = true; 1224 return molConf; 1266 return molConf; 1225 } 1267 } 1226 if(molConf->fLabel == nullptr) << 1268 else if(molConf->fLabel == 0) 1227 { 1269 { 1228 wasAlreadyCreated = true; 1270 wasAlreadyCreated = true; 1229 molConf->SetLabel(label); 1271 molConf->SetLabel(label); 1230 return molConf; 1272 return molConf; 1231 } 1273 } 1232 if(molConf->fLabel->empty()) << 1274 else if(*molConf->fLabel == "") 1233 { 1275 { 1234 wasAlreadyCreated = true; 1276 wasAlreadyCreated = true; 1235 molConf->SetLabel(label); 1277 molConf->SetLabel(label); 1236 return molConf; 1278 return molConf; 1237 } 1279 } 1238 } 1280 } 1239 } 1281 } 1240 1282 1241 1283 1242 molConf->PrintState(); 1284 molConf->PrintState(); 1243 G4ExceptionDescription errMsg ; 1285 G4ExceptionDescription errMsg ; 1244 errMsg << "A molecular configuration for 1286 errMsg << "A molecular configuration for the definition named " 1245 << molDef->GetName() 1287 << molDef->GetName() 1246 << " has already been created " 1288 << " has already been created " 1247 "with user ID " 1289 "with user ID " 1248 << molConf->fUserIdentifier 1290 << molConf->fUserIdentifier 1249 << " and possible different electr 1291 << " and possible different electronic state"; 1250 G4Exception("G4MolecularConfiguration::Cr 1292 G4Exception("G4MolecularConfiguration::CreateMolecularConfiguration", 1251 "DOUBLE_CREATION", 1293 "DOUBLE_CREATION", 1252 FatalErrorInArgument, 1294 FatalErrorInArgument, 1253 errMsg); 1295 errMsg); 1254 } 1296 } 1255 else 1297 else 1256 { 1298 { 1257 auto newConf = << 1299 G4MolecularConfiguration* newConf = 1258 new G4MolecularConfiguration(molDef, 1300 new G4MolecularConfiguration(molDef, 1259 eOcc, 1301 eOcc, 1260 label); 1302 label); 1261 newConf->fUserIdentifier = userIdentifier 1303 newConf->fUserIdentifier = userIdentifier; 1262 1304 1263 GetManager()->AddUserID(userIdentifier, n 1305 GetManager()->AddUserID(userIdentifier, newConf); 1264 1306 1265 // G4MoleculeTable::Instance()-> 1307 // G4MoleculeTable::Instance()-> 1266 // RecordMolecularConfiguration(userId 1308 // RecordMolecularConfiguration(userIdentifier, newConf); 1267 return newConf; 1309 return newConf; 1268 } 1310 } 1269 return molConf; 1311 return molConf; 1270 } 1312 } 1271 1313 1272 1314 1273 //___________________________________________ 1315 //______________________________________________________________________________ 1274 1316 1275 G4MolecularConfiguration* 1317 G4MolecularConfiguration* 1276 G4MolecularConfiguration::G4MolecularConfigur 1318 G4MolecularConfiguration::G4MolecularConfigurationManager:: 1277 GetOrCreateMolecularConfiguration(const G4Mol 1319 GetOrCreateMolecularConfiguration(const G4MoleculeDefinition* molDef, 1278 const G4Ele 1320 const G4ElectronOccupancy& eOcc) 1279 { 1321 { 1280 auto it1 = fElecOccTable.find(molDef); << 1322 MolElectronConfTable::iterator it1 = fElecOccTable.find(molDef); 1281 1323 1282 if(it1 == fElecOccTable.end()) 1324 if(it1 == fElecOccTable.end()) 1283 { 1325 { 1284 return new G4MolecularConfiguration(molDe 1326 return new G4MolecularConfiguration(molDef, eOcc); 1285 } 1327 } 1286 1328 1287 ElectronOccupancyTable& table2 = it1->secon 1329 ElectronOccupancyTable& table2 = it1->second; 1288 auto it = table2.find(eOcc); << 1330 ElectronOccupancyTable::iterator it = table2.find(eOcc); 1289 1331 1290 if(it == table2.end()) 1332 if(it == table2.end()) 1291 { 1333 { 1292 auto molConf = << 1334 G4MolecularConfiguration* molConf = 1293 new G4MolecularConfiguration(molDef, 1335 new G4MolecularConfiguration(molDef, eOcc); 1294 // molConf->Finalize(); 1336 // molConf->Finalize(); 1295 return molConf; 1337 return molConf; 1296 } 1338 } 1297 << 1339 else 1298 return it->second; << 1340 { >> 1341 return it->second; >> 1342 } >> 1343 >> 1344 return 0; 1299 } 1345 } 1300 1346 1301 //___________________________________________ 1347 //______________________________________________________________________________ 1302 1348 1303 G4MolecularConfiguration* 1349 G4MolecularConfiguration* 1304 G4MolecularConfiguration::G4MolecularConfigur 1350 G4MolecularConfiguration::G4MolecularConfigurationManager:: 1305 GetOrCreateMolecularConfiguration(const G4Mol 1351 GetOrCreateMolecularConfiguration(const G4MoleculeDefinition* molDef, 1306 int charge) 1352 int charge) 1307 { 1353 { 1308 auto it1 = fChargeTable.find(molDef); << 1354 MolChargeConfTable::iterator it1 = fChargeTable.find(molDef); 1309 1355 1310 if(it1 == fChargeTable.end()) 1356 if(it1 == fChargeTable.end()) 1311 { 1357 { 1312 G4AutoLock lock(&fMoleculeCreationMutex); 1358 G4AutoLock lock(&fMoleculeCreationMutex); 1313 1359 1314 auto newConf = new G4MolecularConfigurat << 1360 G4MolecularConfiguration* newConf = new G4MolecularConfiguration(molDef, charge); 1315 return newConf ; 1361 return newConf ; 1316 } 1362 } 1317 1363 1318 ChargeTable& table2 = it1->second; 1364 ChargeTable& table2 = it1->second; 1319 auto it = table2.find(charge); << 1365 ChargeTable::iterator it = table2.find(charge); 1320 1366 1321 if(it == table2.end()) 1367 if(it == table2.end()) 1322 { 1368 { 1323 G4AutoLock lock(&fMoleculeCreationMutex); 1369 G4AutoLock lock(&fMoleculeCreationMutex); 1324 1370 1325 auto newConf = << 1371 G4MolecularConfiguration* newConf = 1326 new G4MolecularConfiguration(molDef, 1372 new G4MolecularConfiguration(molDef, charge); 1327 // newConf->Finalize(); 1373 // newConf->Finalize(); 1328 return newConf ; 1374 return newConf ; 1329 } 1375 } 1330 << 1376 else 1331 return it->second; << 1377 { >> 1378 return it->second; >> 1379 } >> 1380 >> 1381 return 0; 1332 } 1382 } 1333 1383 1334 //___________________________________________ 1384 //______________________________________________________________________________ 1335 1385 1336 void G4MolecularConfiguration::Serialize(std: 1386 void G4MolecularConfiguration::Serialize(std::ostream& out) 1337 { 1387 { 1338 G4String moleculeName = fMoleculeDefinition 1388 G4String moleculeName = fMoleculeDefinition->GetName(); 1339 WRITE(out, moleculeName); 1389 WRITE(out, moleculeName); 1340 1390 1341 // if(fLabel) 1391 // if(fLabel) 1342 // out << fLabel; 1392 // out << fLabel; 1343 // else 1393 // else 1344 // out << ""; 1394 // out << ""; 1345 WRITE(out,fDynDiffusionCoefficient); 1395 WRITE(out,fDynDiffusionCoefficient); 1346 WRITE(out,fDynVanDerVaalsRadius); 1396 WRITE(out,fDynVanDerVaalsRadius); 1347 WRITE(out,fDynDecayTime); 1397 WRITE(out,fDynDecayTime); 1348 WRITE(out,fDynMass); 1398 WRITE(out,fDynMass); 1349 WRITE(out,fDynCharge); 1399 WRITE(out,fDynCharge); 1350 WRITE(out,fMoleculeID); 1400 WRITE(out,fMoleculeID); 1351 WRITE(out,fFormatedName); 1401 WRITE(out,fFormatedName); 1352 WRITE(out,fName); 1402 WRITE(out,fName); 1353 WRITE(out,fIsFinalized); 1403 WRITE(out,fIsFinalized); 1354 } 1404 } 1355 1405 1356 //___________________________________________ 1406 //______________________________________________________________________________ 1357 1407 1358 void G4MolecularConfiguration::Unserialize(st 1408 void G4MolecularConfiguration::Unserialize(std::istream& in) 1359 { 1409 { 1360 G4String moleculeName; 1410 G4String moleculeName; 1361 READ(in, moleculeName); 1411 READ(in, moleculeName); 1362 fMoleculeDefinition = 1412 fMoleculeDefinition = 1363 G4MoleculeTable::Instance()->GetMolecul 1413 G4MoleculeTable::Instance()->GetMoleculeDefinition(moleculeName); 1364 1414 1365 // G4String label; 1415 // G4String label; 1366 // 1416 // 1367 // in.read((char*)(&label), sizeof(label)); 1417 // in.read((char*)(&label), sizeof(label)); 1368 // 1418 // 1369 // if(label) 1419 // if(label) 1370 // fLabel = new G4String(label); 1420 // fLabel = new G4String(label); 1371 // else 1421 // else 1372 // fLabel = 0; 1422 // fLabel = 0; 1373 READ(in,fDynDiffusionCoefficient); 1423 READ(in,fDynDiffusionCoefficient); 1374 READ(in,fDynVanDerVaalsRadius); 1424 READ(in,fDynVanDerVaalsRadius); 1375 READ(in,fDynDecayTime); 1425 READ(in,fDynDecayTime); 1376 READ(in,fDynMass); 1426 READ(in,fDynMass); 1377 READ(in,fDynCharge); 1427 READ(in,fDynCharge); 1378 READ(in,fMoleculeID); 1428 READ(in,fMoleculeID); 1379 READ(in,fFormatedName); 1429 READ(in,fFormatedName); 1380 READ(in,fName); 1430 READ(in,fName); 1381 READ(in,fIsFinalized); 1431 READ(in,fIsFinalized); 1382 } 1432 } 1383 1433 1384 //___________________________________________ 1434 //______________________________________________________________________________ 1385 1435 1386 G4MolecularConfiguration* G4MolecularConfigur 1436 G4MolecularConfiguration* G4MolecularConfiguration::Load(std::istream& in) 1387 { 1437 { 1388 return new G4MolecularConfiguration(in); 1438 return new G4MolecularConfiguration(in); 1389 } 1439 } 1390 1440 1391 //___________________________________________ 1441 //______________________________________________________________________________ 1392 1442 1393 G4MolecularConfiguration::G4MolecularConfigur 1443 G4MolecularConfiguration::G4MolecularConfiguration(std::istream& in) 1394 { 1444 { 1395 fLabel = nullptr; // TODO: for now not seri << 1445 fLabel = 0; // TODO: for now not serialized 1396 Unserialize(in); 1446 Unserialize(in); 1397 fMoleculeDefinition = nullptr; << 1447 fMoleculeDefinition = 0; 1398 fElectronOccupancy = nullptr; << 1448 fElectronOccupancy = 0; 1399 if(fElectronOccupancy != nullptr) << 1449 if(fElectronOccupancy) 1400 { 1450 { 1401 GetManager()->Insert(fMoleculeDefinition, 1451 GetManager()->Insert(fMoleculeDefinition, *fElectronOccupancy, this); 1402 fElectronOccupancy = 1452 fElectronOccupancy = 1403 GetManager()->FindCommonElectronOccup 1453 GetManager()->FindCommonElectronOccupancy(fMoleculeDefinition, 1404 1454 *fElectronOccupancy); 1405 1455 1406 if(fLabel != nullptr) << 1456 if(fLabel) 1407 { 1457 { 1408 GetManager()->RecordNewlyLabeledConfigu 1458 GetManager()->RecordNewlyLabeledConfiguration(this); 1409 } 1459 } 1410 } 1460 } 1411 else if(fLabel != nullptr) << 1461 else if(fLabel) 1412 { 1462 { 1413 fMoleculeID = GetManager()->Insert(fMolec 1463 fMoleculeID = GetManager()->Insert(fMoleculeDefinition, *fLabel, this); 1414 } 1464 } 1415 else if(fDynCharge != 0) << 1465 else if(fDynCharge) 1416 { 1466 { 1417 fMoleculeID = GetManager()->Insert(fMolec 1467 fMoleculeID = GetManager()->Insert(fMoleculeDefinition, fDynCharge, this); 1418 } 1468 } 1419 } 1469 } 1420 1470 1421 //___________________________________________ 1471 //______________________________________________________________________________ 1422 1472 1423 void G4MolecularConfiguration::SetUserID(cons 1473 void G4MolecularConfiguration::SetUserID(const G4String& userID) 1424 { 1474 { 1425 fUserIdentifier = userID; 1475 fUserIdentifier = userID; 1426 GetManager()->AddUserID(userID, this); 1476 GetManager()->AddUserID(userID, this); 1427 // G4MoleculeTable::Instance()->RecordMolecu 1477 // G4MoleculeTable::Instance()->RecordMolecularConfiguration(userID, this); 1428 } 1478 } 1429 1479 1430 //___________________________________________ 1480 //______________________________________________________________________________ 1431 1481 1432 double G4MolecularConfiguration::DiffCoeffWat 1482 double G4MolecularConfiguration::DiffCoeffWater(double temperature_K) 1433 { 1483 { 1434 return pow(10, 4.311 1484 return pow(10, 4.311 1435 - 2.722e3/temperature_K 1485 - 2.722e3/temperature_K 1436 + 8.565e5/(temperature_K *temper 1486 + 8.565e5/(temperature_K *temperature_K) 1437 - 1.181e8/(temperature_K*tempera 1487 - 1.181e8/(temperature_K*temperature_K*temperature_K ))*1e-9*m2/s; 1438 } 1488 } 1439 1489 1440 //___________________________________________ 1490 //______________________________________________________________________________ 1441 1491 1442 void 1492 void 1443 G4MolecularConfiguration:: 1493 G4MolecularConfiguration:: 1444 ScaleAllDiffusionCoefficientsOnWater(double t 1494 ScaleAllDiffusionCoefficientsOnWater(double temperature_K) 1445 { 1495 { 1446 double D_water_0 = DiffCoeffWater(fgTempera 1496 double D_water_0 = DiffCoeffWater(fgTemperature); 1447 double D_water_f = DiffCoeffWater(temperatu 1497 double D_water_f = DiffCoeffWater(temperature_K); 1448 1498 1449 G4cout << "Scaling factor = " << D_water_f/ 1499 G4cout << "Scaling factor = " << D_water_f/D_water_0 << G4endl; 1450 1500 1451 G4ConfigurationIterator it = 1501 G4ConfigurationIterator it = 1452 G4MoleculeTable::Instance()->GetConfigu 1502 G4MoleculeTable::Instance()->GetConfigurationIterator(); 1453 1503 1454 while(it()) 1504 while(it()) 1455 { 1505 { 1456 G4MolecularConfiguration* conf = it.value 1506 G4MolecularConfiguration* conf = it.value(); 1457 double D_0 = conf->GetDiffusionCoefficien 1507 double D_0 = conf->GetDiffusionCoefficient() ; 1458 double D_f = D_water_f * D_0 /D_water_0; 1508 double D_f = D_water_f * D_0 /D_water_0; 1459 conf->SetDiffusionCoefficient(D_f); 1509 conf->SetDiffusionCoefficient(D_f); 1460 }; 1510 }; 1461 } 1511 } 1462 1512 1463 //___________________________________________ 1513 //______________________________________________________________________________ 1464 1514 1465 void G4MolecularConfiguration::CreateDefaultD 1515 void G4MolecularConfiguration::CreateDefaultDiffCoeffParam() 1466 { 1516 { 1467 if(!static_cast<bool>(fDiffParam)) << 1517 if(bool(fDiffParam) == false) 1468 { 1518 { 1469 fDiffParam = &G4MolecularConfiguration::R 1519 fDiffParam = &G4MolecularConfiguration::ReturnDefaultDiffCoeff; 1470 } 1520 } 1471 } 1521 } 1472 1522 1473 //___________________________________________ 1523 //______________________________________________________________________________ 1474 1524 1475 void G4MolecularConfiguration::SetGlobalTempe 1525 void G4MolecularConfiguration::SetGlobalTemperature(G4double temperature) 1476 { 1526 { 1477 ScaleAllDiffusionCoefficientsOnWater(temper 1527 ScaleAllDiffusionCoefficientsOnWater(temperature); 1478 fgTemperature = temperature; 1528 fgTemperature = temperature; 1479 } 1529 } 1480 1530 1481 //___________________________________________ 1531 //______________________________________________________________________________ 1482 1532 1483 G4double G4MolecularConfiguration::GetGlobalT 1533 G4double G4MolecularConfiguration::GetGlobalTemperature() 1484 { 1534 { 1485 return fgTemperature; 1535 return fgTemperature; 1486 } 1536 } 1487 1537 1488 //___________________________________________ 1538 //______________________________________________________________________________ 1489 1539 1490 G4MolecularConfiguration* 1540 G4MolecularConfiguration* 1491 G4MolecularConfiguration:: 1541 G4MolecularConfiguration:: 1492 G4MolecularConfigurationManager::GetMolecular 1542 G4MolecularConfigurationManager::GetMolecularConfiguration(const G4String& userID) 1493 { 1543 { 1494 for(auto it : fMolConfPerID) 1544 for(auto it : fMolConfPerID) 1495 { 1545 { 1496 if(it->GetUserID() == userID) return it; 1546 if(it->GetUserID() == userID) return it; 1497 } 1547 } 1498 return nullptr; << 1548 return 0; 1499 } 1549 } 1500 1550 1501 //___________________________________________ 1551 //______________________________________________________________________________ 1502 1552 1503 G4MolecularConfiguration* 1553 G4MolecularConfiguration* 1504 G4MolecularConfiguration::GetMolecularConfigu 1554 G4MolecularConfiguration::GetMolecularConfiguration(const G4String& userID) 1505 { 1555 { 1506 return GetManager()->GetMolecularConfigurat 1556 return GetManager()->GetMolecularConfiguration(userID); 1507 } 1557 } 1508 1558 1509 //___________________________________________ 1559 //______________________________________________________________________________ 1510 1560 1511 void G4MolecularConfiguration::FinalizeAll() 1561 void G4MolecularConfiguration::FinalizeAll() 1512 { 1562 { 1513 const std::vector<G4MolecularConfiguration* 1563 const std::vector<G4MolecularConfiguration*>& species = 1514 GetManager()->GetAllSpecies(); 1564 GetManager()->GetAllSpecies(); 1515 1565 1516 for(auto specie : species) << 1566 for(size_t i = 0; i < species.size() ; ++i) 1517 { 1567 { 1518 specie->Finalize(); << 1568 species[i]->Finalize(); 1519 } << 1520 << 1521 } << 1522 << 1523 void G4MolecularConfiguration::PrintAll() //h << 1524 { << 1525 const std::vector<G4MolecularConfiguration* << 1526 GetManager()->GetAllSpecies(); << 1527 G4cout<<G4endl; << 1528 G4cout<<"Molecular Config"<<std::setw(25)<< << 1529 G4cout<<"__________________________________ << 1530 "________________________________ << 1531 for(auto specie : species) << 1532 { << 1533 G4cout<<specie->GetName() << 1534 <<std::setw(G4int(30 - specie->Get << 1535 <<right<<specie->GetDiffusionCoeff << 1536 <<specie->GetVanDerVaalsRadius()/C << 1537 G4cout<<"________________________________ << 1538 "______________________________ << 1539 } 1569 } 1540 1570 1541 } 1571 } 1542 1572