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: G4DNAMolecularMaterial.cc 101354 2016-11-15 08:27:51Z gcosmo $ 26 // 27 // 27 // Author: Mathieu Karamitros 28 // Author: Mathieu Karamitros 28 // 29 // 29 << 30 #include "G4DNAMolecularMaterial.hh" 30 #include "G4DNAMolecularMaterial.hh" 31 << 32 #include "G4AutoLock.hh" << 33 #include "G4Material.hh" 31 #include "G4Material.hh" 34 #include "G4MoleculeTable.hh" << 32 #include <utility> 35 #include "G4StateManager.hh" 33 #include "G4StateManager.hh" 36 #include "G4Threading.hh" 34 #include "G4Threading.hh" 37 << 35 #include "G4AutoLock.hh" 38 #include <utility> << 36 #include "G4StateManager.hh" >> 37 #include "G4MoleculeTable.hh" 39 38 40 using namespace std; 39 using namespace std; 41 40 42 G4DNAMolecularMaterial* G4DNAMolecularMaterial << 41 G4DNAMolecularMaterial* G4DNAMolecularMaterial::fInstance(0); 43 << 42 G4Mutex aMutex = G4MUTEX_INITIALIZER; 44 namespace << 45 { << 46 G4Mutex aMutex = G4MUTEX_INITIALIZER; << 47 } << 48 43 49 //-------------------------------------------- 44 //------------------------------------------------------------------------------ 50 45 51 bool CompareMaterial::operator()(const G4Mater 46 bool CompareMaterial::operator()(const G4Material* mat1, 52 const G4Mater 47 const G4Material* mat2) const 53 { 48 { 54 if (mat1 == nullptr && mat2 == nullptr) retu << 49 if (mat1 == 0 && mat2 == 0) return false; //(mat1 == mat2) 55 if (mat1 == nullptr) return true; // mat1 < << 50 if (mat1 == 0) return true; // mat1 < mat2 56 if (mat2 == nullptr) return false; //mat2 < << 51 if (mat2 == 0) return false; //mat2 < mat1 57 52 58 const G4Material* baseMat1 = mat1->GetBaseMa 53 const G4Material* baseMat1 = mat1->GetBaseMaterial(); 59 const G4Material* baseMat2 = mat2->GetBaseMa 54 const G4Material* baseMat2 = mat2->GetBaseMaterial(); 60 55 61 if ((baseMat1 == nullptr) && (baseMat2 == nu << 56 if ((baseMat1 || baseMat2) == 0){ 62 // None of the materials derives from a ba 57 // None of the materials derives from a base material 63 return mat1 < mat2; 58 return mat1 < mat2; 64 } 59 } 65 if ((baseMat1 != nullptr) && (baseMat2 != nu << 60 else if (baseMat1 && baseMat2){ 66 // Both materials derive from a base mater 61 // Both materials derive from a base material 67 return baseMat1 < baseMat2; 62 return baseMat1 < baseMat2; 68 } 63 } 69 64 70 if ((baseMat1 != nullptr) && (baseMat2 == nu << 65 else if (baseMat1 && (baseMat2 == 0)){ 71 // Only the material 1 derives from a base 66 // Only the material 1 derives from a base material 72 return baseMat1 < mat2; 67 return baseMat1 < mat2; 73 } 68 } 74 // only case baseMat1==nullptr && baseMat2 r << 69 // only case baseMat1==0 && baseMat2 remains 75 return mat1 < baseMat2; 70 return mat1 < baseMat2; 76 } 71 } 77 72 78 //-------------------------------------------- 73 //------------------------------------------------------------------------------ 79 74 80 G4DNAMolecularMaterial* G4DNAMolecularMaterial 75 G4DNAMolecularMaterial* G4DNAMolecularMaterial::Instance() 81 { 76 { 82 if (fInstance == nullptr) fInstance = new G4 << 77 if (!fInstance) new G4DNAMolecularMaterial(); 83 return fInstance; 78 return fInstance; 84 } 79 } 85 80 86 //-------------------------------------------- 81 //------------------------------------------------------------------------------ 87 82 >> 83 void G4DNAMolecularMaterial::DeleteInstance() >> 84 { >> 85 if (fInstance){ >> 86 delete fInstance; >> 87 fInstance = 0; >> 88 } >> 89 } >> 90 >> 91 //------------------------------------------------------------------------------ >> 92 88 void G4DNAMolecularMaterial::Create() 93 void G4DNAMolecularMaterial::Create() 89 { 94 { 90 fpCompFractionTable = nullptr; << 95 fpCompFractionTable = 0; 91 fpCompDensityTable = nullptr; << 96 fpCompDensityTable = 0; 92 fpCompNumMolPerVolTable = nullptr; << 97 fpCompNumMolPerVolTable = 0; 93 fIsInitialized = false; 98 fIsInitialized = false; 94 fNMaterials = 0; 99 fNMaterials = 0; >> 100 fInstance = this; 95 } 101 } 96 102 97 //-------------------------------------------- 103 //------------------------------------------------------------------------------ 98 104 99 void G4DNAMolecularMaterial::Clear() 105 void G4DNAMolecularMaterial::Clear() 100 { 106 { 101 G4AutoLock l2(&aMutex); << 107 if (fpCompFractionTable){ 102 if (fpCompFractionTable != nullptr){ << 103 fpCompFractionTable->clear(); 108 fpCompFractionTable->clear(); 104 delete fpCompFractionTable; 109 delete fpCompFractionTable; 105 fpCompFractionTable = nullptr; << 110 fpCompFractionTable = 0; 106 } 111 } 107 if (fpCompDensityTable != nullptr){ << 112 if (fpCompDensityTable){ 108 fpCompDensityTable->clear(); 113 fpCompDensityTable->clear(); 109 delete fpCompDensityTable; 114 delete fpCompDensityTable; 110 fpCompDensityTable = nullptr; << 115 fpCompDensityTable = 0; 111 } 116 } 112 if (fpCompNumMolPerVolTable != nullptr){ << 117 if (fpCompNumMolPerVolTable){ 113 fpCompNumMolPerVolTable->clear(); 118 fpCompNumMolPerVolTable->clear(); 114 delete fpCompNumMolPerVolTable; 119 delete fpCompNumMolPerVolTable; 115 fpCompNumMolPerVolTable = nullptr; << 120 fpCompNumMolPerVolTable = 0; 116 } 121 } 117 122 118 std::map<const G4Material*, std::vector<G4do << 123 map<const G4Material*, std::vector<double>*, CompareMaterial>::iterator it; 119 124 120 for (it = fAskedDensityTable.begin(); it != << 125 for (it = fAskedDensityTable.begin(); it != fAskedDensityTable.end(); it++){ 121 if (it->second != nullptr){ << 126 if (it->second){ 122 delete it->second; 127 delete it->second; 123 it->second = nullptr; << 128 it->second = 0; 124 } 129 } 125 } 130 } 126 131 127 for (it = fAskedNumPerVolTable.begin(); it ! << 132 for (it = fAskedNumPerVolTable.begin(); it != fAskedNumPerVolTable.end(); 128 if (it->second != nullptr){ << 133 it++){ >> 134 if (it->second){ 129 delete it->second; 135 delete it->second; 130 it->second = nullptr; << 136 it->second = 0; 131 } 137 } 132 } 138 } 133 l2.unlock(); << 134 } 139 } 135 140 136 << 137 //-------------------------------------------- 141 //------------------------------------------------------------------------------ 138 142 139 G4DNAMolecularMaterial::G4DNAMolecularMaterial << 143 G4DNAMolecularMaterial::G4DNAMolecularMaterial() : >> 144 G4VStateDependent() 140 { 145 { 141 Create(); 146 Create(); >> 147 fInstance = this; 142 } 148 } 143 149 144 //-------------------------------------------- 150 //------------------------------------------------------------------------------ 145 151 146 G4bool G4DNAMolecularMaterial::Notify(G4Applic 152 G4bool G4DNAMolecularMaterial::Notify(G4ApplicationState requestedState) 147 { 153 { 148 if (requestedState == G4State_Idle && G4Stat 154 if (requestedState == G4State_Idle && G4StateManager::GetStateManager() 149 ->GetPreviousState() == G4State_PreInit) 155 ->GetPreviousState() == G4State_PreInit){ 150 Initialize(); 156 Initialize(); 151 } 157 } >> 158 else if (requestedState == G4State_Quit){ >> 159 // G4cout << "G4DNAMolecularMaterial::Notify ---> received G4State_Quit" >> 160 // << G4endl; >> 161 Clear(); >> 162 //DeleteInstance(); >> 163 } 152 return true; 164 return true; 153 } 165 } 154 166 155 //-------------------------------------------- 167 //------------------------------------------------------------------------------ 156 168 >> 169 G4DNAMolecularMaterial::G4DNAMolecularMaterial( >> 170 const G4DNAMolecularMaterial& /*rhs*/) : >> 171 G4VStateDependent() >> 172 { >> 173 Create(); >> 174 } >> 175 >> 176 //------------------------------------------------------------------------------ >> 177 >> 178 G4DNAMolecularMaterial& >> 179 G4DNAMolecularMaterial::operator=(const G4DNAMolecularMaterial& rhs) >> 180 { >> 181 if (this == &rhs) return *this; >> 182 Create(); >> 183 return *this; >> 184 } >> 185 >> 186 //------------------------------------------------------------------------------ >> 187 157 G4DNAMolecularMaterial::~G4DNAMolecularMateria 188 G4DNAMolecularMaterial::~G4DNAMolecularMaterial() 158 { 189 { >> 190 // G4cout << "Deleting G4DNAMolecularMaterial" << G4endl; 159 Clear(); 191 Clear(); >> 192 fInstance = 0; >> 193 //assert(G4StateManager::GetStateManager()->DeregisterDependent(this) == true); 160 } 194 } 161 195 162 //-------------------------------------------- 196 //------------------------------------------------------------------------------ 163 197 164 void G4DNAMolecularMaterial::Initialize() 198 void G4DNAMolecularMaterial::Initialize() 165 { 199 { >> 200 G4AutoLock l(&aMutex); 166 if (fIsInitialized){ 201 if (fIsInitialized){ 167 return; 202 return; 168 } 203 } 169 204 170 const G4MaterialTable* materialTable = G4Mat 205 const G4MaterialTable* materialTable = G4Material::GetMaterialTable(); 171 206 172 fNMaterials = materialTable->size(); 207 fNMaterials = materialTable->size(); 173 // This is to prevent segment fault if mater 208 // This is to prevent segment fault if materials are created later on 174 // Actually this creation should not be done 209 // Actually this creation should not be done 175 210 176 G4AutoLock l1(&aMutex); << 211 if (fpCompFractionTable == 0){ 177 if (fpCompFractionTable == nullptr){ << 178 fpCompFractionTable = new vector<Component 212 fpCompFractionTable = new vector<ComponentMap>(materialTable->size()); 179 } 213 } 180 214 181 G4Material* mat(nullptr); << 215 G4Material* mat(0); 182 216 183 for (std::size_t i = 0; i < fNMaterials; ++i << 217 for (size_t i = 0; i < fNMaterials; i++){ 184 mat = materialTable->at(i); 218 mat = materialTable->at(i); 185 SearchMolecularMaterial(mat, mat, 1); 219 SearchMolecularMaterial(mat, mat, 1); >> 220 >> 221 mat = 0; 186 } 222 } 187 223 188 InitializeDensity(); 224 InitializeDensity(); 189 InitializeNumMolPerVol(); 225 InitializeNumMolPerVol(); 190 l1.unlock(); << 191 226 192 fIsInitialized = true; 227 fIsInitialized = true; 193 } 228 } 194 229 195 //-------------------------------------------- 230 //------------------------------------------------------------------------------ 196 231 197 void G4DNAMolecularMaterial::InitializeDensity 232 void G4DNAMolecularMaterial::InitializeDensity() 198 { 233 { 199 if (fpCompFractionTable != nullptr){ << 234 if (fpCompFractionTable){ 200 const G4MaterialTable* materialTable = G4M 235 const G4MaterialTable* materialTable = G4Material::GetMaterialTable(); 201 fpCompDensityTable = new vector<ComponentM 236 fpCompDensityTable = new vector<ComponentMap>( 202 G4Material::GetMaterialTable()->size() 237 G4Material::GetMaterialTable()->size()); 203 238 204 G4Material* parentMat; 239 G4Material* parentMat; 205 const G4Material* compMat(nullptr); << 240 const G4Material* compMat(0); 206 G4double massFraction = -1; << 241 double massFraction = -1; 207 G4double parentDensity = -1; << 242 double parentDensity = -1; 208 243 209 for (std::size_t i = 0; i < fNMaterials; + << 244 for (size_t i = 0; i < fNMaterials; i++){ 210 parentMat = materialTable->at(i); 245 parentMat = materialTable->at(i); 211 ComponentMap& massFractionComp = (*fpCom 246 ComponentMap& massFractionComp = (*fpCompFractionTable)[i]; 212 ComponentMap& densityComp = (*fpCompDens 247 ComponentMap& densityComp = (*fpCompDensityTable)[i]; 213 248 214 parentDensity = parentMat->GetDensity(); 249 parentDensity = parentMat->GetDensity(); 215 250 216 for (const auto& it : massFractionComp){ << 251 for (ComponentMap::iterator it = massFractionComp.begin(); 217 compMat = it.first; << 252 it != massFractionComp.end(); it++){ 218 massFraction = it.second; << 253 compMat = it->first; >> 254 massFraction = it->second; 219 densityComp[compMat] = massFraction * 255 densityComp[compMat] = massFraction * parentDensity; 220 compMat = nullptr; << 256 compMat = 0; 221 massFraction = -1; 257 massFraction = -1; 222 } 258 } 223 } 259 } 224 } 260 } 225 else{ 261 else{ 226 G4ExceptionDescription exceptionDescriptio 262 G4ExceptionDescription exceptionDescription; 227 exceptionDescription << "The pointer fpCom 263 exceptionDescription << "The pointer fpCompFractionTable is not initialized" 228 << G4endl; 264 << G4endl; 229 G4Exception("G4DNAMolecularMaterial::Initi 265 G4Exception("G4DNAMolecularMaterial::InitializeDensity", 230 "G4DNAMolecularMaterial001", F 266 "G4DNAMolecularMaterial001", FatalException, 231 exceptionDescription); 267 exceptionDescription); 232 } 268 } 233 } 269 } 234 270 235 //-------------------------------------------- 271 //------------------------------------------------------------------------------ 236 272 237 void G4DNAMolecularMaterial::InitializeNumMolP 273 void G4DNAMolecularMaterial::InitializeNumMolPerVol() 238 { 274 { 239 if (fpCompDensityTable != nullptr){ << 275 if (fpCompDensityTable){ 240 fpCompNumMolPerVolTable = new vector<Compo 276 fpCompNumMolPerVolTable = new vector<ComponentMap>(fNMaterials); 241 277 242 const G4Material* compMat(nullptr); << 278 const G4Material* compMat(0); 243 279 244 for (std::size_t i = 0; i < fNMaterials; + << 280 for (size_t i = 0; i < fNMaterials; i++){ 245 ComponentMap& massFractionComp = (*fpCom 281 ComponentMap& massFractionComp = (*fpCompFractionTable)[i]; 246 ComponentMap& densityComp = (*fpCompDens 282 ComponentMap& densityComp = (*fpCompDensityTable)[i]; 247 ComponentMap& numMolPerVol = (*fpCompNum 283 ComponentMap& numMolPerVol = (*fpCompNumMolPerVolTable)[i]; 248 284 249 for (auto& it : massFractionComp){ << 285 for (ComponentMap::iterator it = massFractionComp.begin(); 250 compMat = it.first; << 286 it != massFractionComp.end(); it++){ >> 287 compMat = it->first; 251 numMolPerVol[compMat] = densityComp[co 288 numMolPerVol[compMat] = densityComp[compMat] 252 / compMat->GetMassOfMolecule(); 289 / compMat->GetMassOfMolecule(); 253 compMat = nullptr; << 290 compMat = 0; 254 } 291 } 255 } 292 } 256 } 293 } 257 else{ 294 else{ 258 G4ExceptionDescription exceptionDescriptio 295 G4ExceptionDescription exceptionDescription; 259 exceptionDescription << "The pointer fpCom 296 exceptionDescription << "The pointer fpCompDensityTable is not initialized" 260 << G4endl; 297 << G4endl; 261 G4Exception("G4DNAMolecularMaterial::Initi 298 G4Exception("G4DNAMolecularMaterial::InitializeNumMolPerVol", 262 "G4DNAMolecularMaterial002", F 299 "G4DNAMolecularMaterial002", FatalException, 263 exceptionDescription); 300 exceptionDescription); 264 } 301 } 265 } 302 } 266 303 267 //-------------------------------------------- 304 //------------------------------------------------------------------------------ 268 305 269 void 306 void 270 G4DNAMolecularMaterial::RecordMolecularMateria 307 G4DNAMolecularMaterial::RecordMolecularMaterial(G4Material* parentMaterial, 271 308 G4Material* molecularMaterial, 272 309 G4double fraction) 273 { 310 { 274 ComponentMap& matComponent = 311 ComponentMap& matComponent = 275 (*fpCompFractionTable)[parentMaterial->G 312 (*fpCompFractionTable)[parentMaterial->GetIndex()]; 276 313 277 if (matComponent.empty()){ 314 if (matComponent.empty()){ 278 matComponent[molecularMaterial] = fraction 315 matComponent[molecularMaterial] = fraction; 279 return; 316 return; 280 } 317 } 281 318 282 auto it = matComponent.find(molecularMateria << 319 ComponentMap::iterator it = matComponent.find(molecularMaterial); 283 320 284 if (it == matComponent.cend()){ << 321 if (it == matComponent.end()){ 285 matComponent[molecularMaterial] = fraction 322 matComponent[molecularMaterial] = fraction; 286 } 323 } 287 else{ 324 else{ 288 matComponent[molecularMaterial] = it->seco 325 matComponent[molecularMaterial] = it->second + fraction; 289 // handle "base material" << 290 } 326 } 291 } 327 } 292 328 293 //-------------------------------------------- 329 //------------------------------------------------------------------------------ 294 330 295 void G4DNAMolecularMaterial::SearchMolecularMa 331 void G4DNAMolecularMaterial::SearchMolecularMaterial(G4Material* parentMaterial, 296 332 G4Material* material, 297 << 333 double currentFraction) 298 { 334 { 299 if (material->GetMassOfMolecule() != 0.0){ / << 335 if (material->GetMassOfMolecule() != 0.0){ 300 RecordMolecularMaterial(parentMaterial, ma 336 RecordMolecularMaterial(parentMaterial, material, currentFraction); 301 return; 337 return; 302 } 338 } 303 339 304 G4Material* compMat(nullptr); << 340 G4Material* compMat(0); 305 G4double fraction = -1.; << 341 G4double fraction = -1; 306 std::map<G4Material*, G4double> matComponent 342 std::map<G4Material*, G4double> matComponent = material->GetMatComponents(); 307 auto it = matComponent.cbegin(); << 343 std::map<G4Material*, G4double>::iterator it = matComponent.begin(); 308 344 309 for (; it != matComponent.cend(); ++it){ << 345 for (; it != matComponent.end(); it++){ 310 compMat = it->first; 346 compMat = it->first; 311 fraction = it->second; 347 fraction = it->second; 312 if (compMat->GetMassOfMolecule() == 0.0){ << 348 if (compMat->GetMassOfMolecule() == 0.0){ 313 SearchMolecularMaterial(parentMaterial, 349 SearchMolecularMaterial(parentMaterial, compMat, 314 currentFraction 350 currentFraction * fraction); 315 } 351 } 316 else{ // is a molecular material << 352 else{ 317 RecordMolecularMaterial(parentMaterial, 353 RecordMolecularMaterial(parentMaterial, compMat, 318 currentFraction 354 currentFraction * fraction); 319 } 355 } >> 356 >> 357 //compMat = 0; >> 358 //fraction = -1; 320 } 359 } 321 } 360 } 322 361 323 //-------------------------------------------- 362 //------------------------------------------------------------------------------ 324 363 325 const std::vector<G4double>* << 364 const std::vector<double>* 326 G4DNAMolecularMaterial:: 365 G4DNAMolecularMaterial:: 327 GetDensityTableFor(const G4Material* lookForMa 366 GetDensityTableFor(const G4Material* lookForMaterial) const 328 { 367 { 329 if (fpCompDensityTable == nullptr){ << 368 if (!fpCompDensityTable){ 330 if (fIsInitialized){ 369 if (fIsInitialized){ 331 G4ExceptionDescription exceptionDescript 370 G4ExceptionDescription exceptionDescription; 332 exceptionDescription 371 exceptionDescription 333 << "The pointer fpCompDensityTable i 372 << "The pointer fpCompDensityTable is not initialized will the " 334 "singleton of G4DNAMolecularMaterial 373 "singleton of G4DNAMolecularMaterial " 335 << "has already been initialized." < 374 << "has already been initialized." << G4endl; 336 G4Exception("G4DNAMolecularMaterial::Get 375 G4Exception("G4DNAMolecularMaterial::GetDensityTableFor", 337 "G4DNAMolecularMaterial003", 376 "G4DNAMolecularMaterial003", FatalException, 338 exceptionDescription); 377 exceptionDescription); 339 } 378 } 340 379 341 if (G4StateManager::GetStateManager()->Get << 380 if (G4StateManager::GetStateManager()->GetCurrentState() == G4State_Idle){ 342 const_cast<G4DNAMolecularMaterial*>(this 381 const_cast<G4DNAMolecularMaterial*>(this)->Initialize(); 343 } 382 } 344 else{ 383 else{ 345 G4ExceptionDescription exceptionDescript 384 G4ExceptionDescription exceptionDescription; 346 exceptionDescription 385 exceptionDescription 347 << "The geant4 application is at the 386 << "The geant4 application is at the wrong state. State must be: " 348 "G4State_Init." << 387 "G4State_Idle." 349 << G4endl; 388 << G4endl; 350 G4Exception("G4DNAMolecularMaterial::Get 389 G4Exception("G4DNAMolecularMaterial::GetDensityTableFor", 351 "G4DNAMolecularMaterial_WRON 390 "G4DNAMolecularMaterial_WRONG_STATE_APPLICATION", 352 FatalException, exceptionDes 391 FatalException, exceptionDescription); 353 } 392 } 354 } 393 } 355 394 356 auto it_askedDensityTable = fAskedDensityTab << 395 std::map<const G4Material*, std::vector<double>*, CompareMaterial>:: >> 396 const_iterator it_askedDensityTable = >> 397 fAskedDensityTable.find(lookForMaterial); 357 398 358 if (it_askedDensityTable != fAskedDensityTab << 399 if (it_askedDensityTable != fAskedDensityTable.end()){ 359 return it_askedDensityTable->second; 400 return it_askedDensityTable->second; 360 } 401 } 361 402 362 const G4MaterialTable* materialTable = G4Mat 403 const G4MaterialTable* materialTable = G4Material::GetMaterialTable(); 363 404 364 auto output = new std::vector<G4double>(mat << 405 std::vector<double>* output = new std::vector<double>(materialTable->size()); 365 406 366 ComponentMap::const_iterator it; 407 ComponentMap::const_iterator it; 367 408 368 G4bool materialWasNotFound = true; 409 G4bool materialWasNotFound = true; 369 410 370 for (std::size_t i = 0; i < fNMaterials; ++i << 411 for (size_t i = 0; i < fNMaterials; i++){ 371 ComponentMap& densityTable = (*fpCompDensi 412 ComponentMap& densityTable = (*fpCompDensityTable)[i]; 372 413 373 it = densityTable.find(lookForMaterial); 414 it = densityTable.find(lookForMaterial); 374 415 375 if (it == densityTable.cend()){ << 416 if (it == densityTable.end()){ 376 (*output)[i] = 0.0; 417 (*output)[i] = 0.0; 377 } 418 } 378 else{ 419 else{ 379 materialWasNotFound = false; 420 materialWasNotFound = false; 380 (*output)[i] = it->second; 421 (*output)[i] = it->second; 381 } 422 } 382 } 423 } 383 424 384 if (materialWasNotFound){ 425 if (materialWasNotFound){ 385 PrintNotAMolecularMaterial("G4DNAMolecular 426 PrintNotAMolecularMaterial("G4DNAMolecularMaterial::GetDensityTableFor", 386 lookForMaterial 427 lookForMaterial); 387 } 428 } 388 429 389 fAskedDensityTable.insert(make_pair(lookForM 430 fAskedDensityTable.insert(make_pair(lookForMaterial, output)); 390 431 391 return output; 432 return output; 392 } 433 } 393 434 394 //-------------------------------------------- 435 //------------------------------------------------------------------------------ 395 436 396 const std::vector<G4double>* G4DNAMolecularMat << 437 const std::vector<double>* G4DNAMolecularMaterial::GetNumMolPerVolTableFor( 397 const G4Material* lookForMaterial) const 438 const G4Material* lookForMaterial) const 398 { 439 { 399 if(lookForMaterial==nullptr) return nullptr; << 440 if(lookForMaterial==0) return nullptr; 400 << 441 401 if (fpCompNumMolPerVolTable == nullptr){ << 442 if (!fpCompNumMolPerVolTable){ 402 if (fIsInitialized){ 443 if (fIsInitialized){ 403 G4ExceptionDescription exceptionDescript 444 G4ExceptionDescription exceptionDescription; 404 exceptionDescription 445 exceptionDescription 405 << "The pointer fpCompNumMolPerVolTa 446 << "The pointer fpCompNumMolPerVolTable is not initialized whereas " 406 "the singleton of G4DNAMolecularMate 447 "the singleton of G4DNAMolecularMaterial " 407 << "has already been initialized." < 448 << "has already been initialized." << G4endl; 408 G4Exception("G4DNAMolecularMaterial::Get 449 G4Exception("G4DNAMolecularMaterial::GetNumMolPerVolTableFor", 409 "G4DNAMolecularMaterial005", 450 "G4DNAMolecularMaterial005", FatalException, 410 exceptionDescription); 451 exceptionDescription); 411 } 452 } 412 453 413 if (G4StateManager::GetStateManager()->Get << 454 if (G4StateManager::GetStateManager()->GetCurrentState() == G4State_Idle){ 414 const_cast<G4DNAMolecularMaterial*>(this 455 const_cast<G4DNAMolecularMaterial*>(this)->Initialize(); 415 } 456 } 416 else{ 457 else{ 417 G4ExceptionDescription exceptionDescript 458 G4ExceptionDescription exceptionDescription; 418 exceptionDescription 459 exceptionDescription 419 << "The geant4 application is at the 460 << "The geant4 application is at the wrong state. State must be : " 420 "G4State_Init." << 461 "G4State_Idle." 421 << G4endl; 462 << G4endl; 422 G4Exception("G4DNAMolecularMaterial::Get 463 G4Exception("G4DNAMolecularMaterial::GetNumMolPerVolTableFor", 423 "G4DNAMolecularMaterial_WRON 464 "G4DNAMolecularMaterial_WRONG_STATE_APPLICATION", 424 FatalException, exceptionDes 465 FatalException, exceptionDescription); 425 } 466 } 426 } 467 } 427 468 428 auto it_askedNumMolPerVolTable = fAskedNumPe << 469 std::map<const G4Material*, std::vector<double>*, CompareMaterial>:: 429 if (it_askedNumMolPerVolTable != fAskedNumPe << 470 const_iterator it_askedNumMolPerVolTable = >> 471 fAskedNumPerVolTable.find(lookForMaterial); >> 472 if (it_askedNumMolPerVolTable != fAskedNumPerVolTable.end()){ 430 return it_askedNumMolPerVolTable->second; 473 return it_askedNumMolPerVolTable->second; 431 } 474 } 432 475 433 const G4MaterialTable* materialTable = G4Mat 476 const G4MaterialTable* materialTable = G4Material::GetMaterialTable(); 434 477 435 auto output = new std::vector<G4double>(mat << 478 std::vector<double>* output = new std::vector<double>(materialTable->size()); 436 479 437 ComponentMap::const_iterator it; 480 ComponentMap::const_iterator it; 438 481 439 G4bool materialWasNotFound = true; 482 G4bool materialWasNotFound = true; 440 483 441 for (std::size_t i = 0; i < fNMaterials; ++i << 484 for (size_t i = 0; i < fNMaterials; i++){ 442 ComponentMap& densityTable = (*fpCompNumMo 485 ComponentMap& densityTable = (*fpCompNumMolPerVolTable)[i]; 443 486 444 it = densityTable.find(lookForMaterial); 487 it = densityTable.find(lookForMaterial); 445 488 446 if (it == densityTable.cend()){ << 489 if (it == densityTable.end()){ 447 (*output)[i] = 0.0; 490 (*output)[i] = 0.0; 448 } 491 } 449 else{ 492 else{ 450 materialWasNotFound = false; 493 materialWasNotFound = false; 451 (*output)[i] = it->second; 494 (*output)[i] = it->second; 452 } 495 } 453 } 496 } 454 497 455 if (materialWasNotFound){ 498 if (materialWasNotFound){ 456 PrintNotAMolecularMaterial( 499 PrintNotAMolecularMaterial( 457 "G4DNAMolecularMaterial::GetNumMolPerV 500 "G4DNAMolecularMaterial::GetNumMolPerVolTableFor", lookForMaterial); 458 } 501 } 459 502 460 fAskedNumPerVolTable.insert(make_pair(lookFo 503 fAskedNumPerVolTable.insert(make_pair(lookForMaterial, output)); 461 504 462 return output; 505 return output; 463 } 506 } 464 507 465 //-------------------------------------------- 508 //------------------------------------------------------------------------------ 466 509 467 void G4DNAMolecularMaterial:: 510 void G4DNAMolecularMaterial:: 468 PrintNotAMolecularMaterial(const char* methodN 511 PrintNotAMolecularMaterial(const char* methodName, 469 const G4Material* l 512 const G4Material* lookForMaterial) const 470 { 513 { 471 auto it = fWarningPrinted.find(lookForMateri << 514 std::map<const G4Material*, bool, CompareMaterial>::iterator it = >> 515 fWarningPrinted.find(lookForMaterial); 472 516 473 if (it == fWarningPrinted.cend()){ << 517 if (it == fWarningPrinted.end()){ 474 G4ExceptionDescription exceptionDescriptio 518 G4ExceptionDescription exceptionDescription; 475 exceptionDescription << "The material " << 519 exceptionDescription << "The material " << lookForMaterial->GetName() 476 << " is not defined a 520 << " is not defined as a molecular material." 477 << G4endl 521 << G4endl 478 << "Meaning: The elem 522 << "Meaning: The elements should be added to the " 479 "material using atom 523 "material using atom count rather than mass fraction " 480 "(cf. G4Material)" 524 "(cf. G4Material)" 481 << G4endl 525 << G4endl 482 << "If you want to use DNA processes on li 526 << "If you want to use DNA processes on liquid water, you should better use " 483 "the NistManager to create the water mater 527 "the NistManager to create the water material." 484 << G4endl 528 << G4endl 485 << "Since this message is displayed, it me 529 << "Since this message is displayed, it means that the DNA models will not " 486 "be called." 530 "be called." 487 << "Please note that this message will onl 531 << "Please note that this message will only appear once even if you are " 488 "using other methods of G4DNAMolecularMate 532 "using other methods of G4DNAMolecularMaterial." 489 << G4endl; 533 << G4endl; 490 534 491 G4Exception(methodName, "MATERIAL_NOT_DEFI 535 G4Exception(methodName, "MATERIAL_NOT_DEFINE_USING_ATOM_COUNT", JustWarning, 492 exceptionDescription); 536 exceptionDescription); 493 fWarningPrinted[lookForMaterial] = true; 537 fWarningPrinted[lookForMaterial] = true; 494 } 538 } 495 } 539 } 496 540 497 //-------------------------------------------- 541 //------------------------------------------------------------------------------ 498 542 499 G4MolecularConfiguration* 543 G4MolecularConfiguration* 500 G4DNAMolecularMaterial:: 544 G4DNAMolecularMaterial:: 501 GetMolecularConfiguration(const G4Material* ma 545 GetMolecularConfiguration(const G4Material* material) const 502 { 546 { 503 auto material_id = (G4int)material->GetInde << 547 int material_id = material->GetIndex(); 504 auto it = fMaterialToMolecularConf.find(mate 548 auto it = fMaterialToMolecularConf.find(material_id); 505 if(it == fMaterialToMolecularConf.cend()) re << 549 if(it == fMaterialToMolecularConf.end()) return 0; 506 return it->second; 550 return it->second; 507 } 551 } 508 552 509 //-------------------------------------------- 553 //------------------------------------------------------------------------------ 510 554 511 void 555 void 512 G4DNAMolecularMaterial:: 556 G4DNAMolecularMaterial:: 513 SetMolecularConfiguration(const G4Material* ma 557 SetMolecularConfiguration(const G4Material* material, 514 G4MolecularConfigura 558 G4MolecularConfiguration* molConf) 515 { 559 { 516 assert(material != nullptr); << 560 assert(material != 0); 517 auto material_id = (G4int)material->GetInde << 561 int material_id = material->GetIndex(); 518 fMaterialToMolecularConf[material_id] = molC 562 fMaterialToMolecularConf[material_id] = molConf; 519 } 563 } 520 564 521 //-------------------------------------------- 565 //------------------------------------------------------------------------------ 522 566 523 void 567 void 524 G4DNAMolecularMaterial::SetMolecularConfigurat 568 G4DNAMolecularMaterial::SetMolecularConfiguration(const G4Material* material, 525 569 const G4String& molUserID) 526 { 570 { 527 assert(material != nullptr); << 571 assert(material != 0); 528 auto material_id = (G4int)material->GetInde << 572 int material_id = material->GetIndex(); 529 fMaterialToMolecularConf[material_id] = 573 fMaterialToMolecularConf[material_id] = 530 G4MoleculeTable::Instance()->GetConfigurat 574 G4MoleculeTable::Instance()->GetConfiguration(molUserID, true); 531 } 575 } 532 576 533 //-------------------------------------------- 577 //------------------------------------------------------------------------------ 534 578 535 void 579 void 536 G4DNAMolecularMaterial::SetMolecularConfigurat 580 G4DNAMolecularMaterial::SetMolecularConfiguration(const G4String& materialName, 537 581 const G4String& molUserID) 538 { 582 { 539 G4Material* material = G4Material::GetMateri 583 G4Material* material = G4Material::GetMaterial(materialName); 540 << 584 541 if(material == nullptr){ << 585 if(material == 0){ 542 G4cout<< "Material " << materialName 586 G4cout<< "Material " << materialName 543 << " was not found and therefore won 587 << " was not found and therefore won't be linked to " 544 << molUserID << G4endl; 588 << molUserID << G4endl; 545 return; 589 return; 546 } 590 } 547 SetMolecularConfiguration(material, molUserI 591 SetMolecularConfiguration(material, molUserID); 548 } << 549 << 550 //-------------------------------------------- << 551 << 552 G4double << 553 G4DNAMolecularMaterial:: << 554 GetNumMoleculePerVolumeUnitForMaterial(const G << 555 { << 556 G4Exception("G4DNAMolecularMaterial::GetNumM << 557 "DEPRECATED", << 558 FatalException,"Use standard met << 559 " at the run initialization to r << 560 " during stepping. The method is << 561 return 0.; << 562 } << 563 << 564 //-------------------------------------------- << 565 << 566 G4double << 567 G4DNAMolecularMaterial:: << 568 GetNumMolPerVolForComponentInComposite(const G << 569 const G << 570 G4doubl << 571 { << 572 G4Exception("G4DNAMolecularMaterial::GetNumM << 573 "DEPRECATED", << 574 FatalException,"Use standard me << 575 " at the run initialization to r << 576 " during stepping. The method is << 577 return 0.; << 578 } 592 } 579 593