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