Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 /* 26 /* 27 * G4MoleculeTable.cc 27 * G4MoleculeTable.cc 28 * 28 * 29 * Created on: 23 oct. 2013 29 * Created on: 23 oct. 2013 30 * Author: kara 30 * Author: kara 31 */ 31 */ 32 32 33 #include "G4MoleculeTable.hh" 33 #include "G4MoleculeTable.hh" 34 #include "G4MolecularConfiguration.hh" << 35 #include "G4MoleculeDefinition.hh" << 36 #include "G4MoleculeTableMessenger.hh" << 37 34 38 G4MoleculeTable* G4MoleculeTable::fpgMoleculeT << 35 G4MoleculeTable* G4MoleculeTable::fpgMoleculeTable(0); 39 << 40 //-------------------------------------------- << 41 36 42 G4MoleculeTable::G4MoleculeTable() 37 G4MoleculeTable::G4MoleculeTable() 43 : fMoleculeDefTableMessenger(new G4MoleculeT << 44 { 38 { 45 } << 39 // TODO Auto-generated constructor stub 46 40 47 //-------------------------------------------- << 41 } 48 42 49 G4MoleculeTable::~G4MoleculeTable() 43 G4MoleculeTable::~G4MoleculeTable() 50 = default; << 44 { 51 << 45 // TODO Auto-generated destructor stub 52 //-------------------------------------------- << 46 } 53 47 54 G4MoleculeTable* G4MoleculeTable::Instance() 48 G4MoleculeTable* G4MoleculeTable::Instance() 55 { 49 { 56 if (fpgMoleculeTable == nullptr) fpgMolecule << 50 if (!fpgMoleculeTable) fpgMoleculeTable = new G4MoleculeTable; 57 return fpgMoleculeTable; 51 return fpgMoleculeTable; 58 } 52 } 59 53 60 //-------------------------------------------- << 61 << 62 G4MoleculeTable* G4MoleculeTable::GetMoleculeT 54 G4MoleculeTable* G4MoleculeTable::GetMoleculeTable() 63 { 55 { 64 return Instance(); 56 return Instance(); 65 } 57 } 66 58 67 //-------------------------------------------- << 59 G4MoleculeDefinition* G4MoleculeTable::CreateMoleculeDefinition(const G4String& name, >> 60 double diffusion_coefficient) >> 61 { >> 62 MoleculeDefTable::iterator it = fMoleculeDefTable.find(name); >> 63 G4MoleculeDefinition* definition(0); >> 64 if (it == fMoleculeDefTable.end()) >> 65 { >> 66 definition = new G4MoleculeDefinition(name, -1 /* mass*/, >> 67 diffusion_coefficient); >> 68 fMoleculeDefTable[name] = definition; >> 69 } >> 70 else >> 71 { >> 72 // exception >> 73 G4ExceptionDescription description; >> 74 description << "The molecule definition " << name >> 75 << " was already recorded in the table" << G4endl; >> 76 G4Exception("G4MoleculeTable::CreateMoleculeDefinition", >> 77 "DEFINITION_ALREADY_CREATED", FatalException, description); >> 78 } >> 79 return definition; >> 80 } 68 81 69 G4MoleculeDefinition* << 82 G4Molecule* G4MoleculeTable::CreateMoleculeModel(const G4String& name, 70 G4MoleculeTable::CreateMoleculeDefinition(cons << 83 G4MoleculeDefinition* molDef, 71 doub << 84 int charge, >> 85 double diffusion_coefficient) 72 { 86 { 73 return new G4MoleculeDefinition(name, -1 /* << 87 74 diffusion_co << 88 G4Molecule* molecule = new G4Molecule(molDef, charge); >> 89 if (diffusion_coefficient != -1) molecule->SetDiffusionCoefficient( >> 90 diffusion_coefficient); >> 91 >> 92 RecordMoleculeModel(name, molecule); >> 93 >> 94 return molecule; 75 } 95 } 76 96 77 //-------------------------------------------- << 97 G4Molecule* G4MoleculeTable::CreateMoleculeModel(const G4String& name, >> 98 G4MoleculeDefinition* molDef) >> 99 { >> 100 >> 101 G4Molecule* molecule = new G4Molecule(molDef); >> 102 RecordMoleculeModel(name, molecule); >> 103 >> 104 return molecule; >> 105 } 78 106 79 G4MoleculeDefinition* << 107 G4MoleculeDefinition* G4MoleculeTable::GetMoleculeDefinition(const G4String& name, bool mustExist) 80 G4MoleculeTable::GetMoleculeDefinition(const G << 81 bool mu << 82 { 108 { 83 auto it = fMoleculeDefTable.find(name); << 109 MoleculeDefTable::iterator it = fMoleculeDefTable.find(name); 84 G4MoleculeDefinition* definition(nullptr); << 110 G4MoleculeDefinition* definition(0); 85 if (it != fMoleculeDefTable.end()) 111 if (it != fMoleculeDefTable.end()) 86 { 112 { 87 definition = it->second; 113 definition = it->second; 88 } 114 } 89 else if(mustExist) 115 else if(mustExist) 90 { 116 { 91 // exception 117 // exception 92 G4ExceptionDescription description; 118 G4ExceptionDescription description; 93 description << "The molecule definition " << 119 description << "The molecule defintion " << name 94 << " was NOT recorded in the t 120 << " was NOT recorded in the table" << G4endl; 95 G4Exception("G4MoleculeTable::CreateMolecu << 121 G4Exception("G4MoleculeTable::CreateMoleculeModel", "MOLECULE_DEFINITION_NOT_CREATED", 96 "MOLECULE_DEFINITION_NOT_CREAT << 122 FatalException, description); 97 FatalException, << 98 description); << 99 } 123 } 100 return definition; 124 return definition; 101 } 125 } 102 126 103 //-------------------------------------------- << 127 void G4MoleculeTable::RecordMoleculeModel(const G4String& name, 104 << 128 G4Molecule* molecule) 105 G4MolecularConfiguration* << 106 G4MoleculeTable::GetConfiguration(const G4Stri << 107 { 129 { 108 G4MolecularConfiguration* species = << 130 MoleculeTable::iterator it = fMoleculeTable.find(name); 109 G4MolecularConfiguration::GetMolecularCo << 131 >> 132 G4int id = molecule->GetMoleculeID(); >> 133 MoleculeTablePerID::iterator it_perID = fMoleculeTablePerID.find(id); 110 134 111 if(species == nullptr && mustExist) << 135 if (it == fMoleculeTable.end() && it_perID == fMoleculeTablePerID.end()) >> 136 { >> 137 fMoleculeTable[name] = molecule; >> 138 fMoleculeTablePerID[id] = molecule; >> 139 } >> 140 else if(it != fMoleculeTable.end()) 112 { 141 { 113 // exception 142 // exception 114 G4ExceptionDescription description; 143 G4ExceptionDescription description; 115 description << "The configuration " << nam << 144 description << "The molecule model " << name 116 << " was not recorded in the t << 145 << " was already recorded in the table" << G4endl; 117 G4Exception("G4MoleculeTable::GetConfigura << 146 G4Exception("G4MoleculeTable::CreateMoleculeModel", "MODEL_ALREADY_CREATED", 118 "CONF_NOT_CREATED", << 147 FatalException, description); 119 FatalException, << 148 } 120 description); << 149 else if(it != fMoleculeTable.end()) >> 150 { >> 151 // exception >> 152 G4ExceptionDescription description; >> 153 description << "The molecule model " << name >> 154 << " was already recorded per ID (" << id<<") in the table" >> 155 << G4endl; >> 156 G4Exception("G4MoleculeTable::CreateMoleculeModel", "MODEL_ALREADY_CREATED", >> 157 FatalException, description); 121 } 158 } 122 << 123 return species; << 124 } 159 } 125 160 126 //-------------------------------------------- << 161 G4Molecule* G4MoleculeTable::GetMoleculeModel(const G4String& name, bool mustExist) 127 << 128 G4MolecularConfiguration* << 129 G4MoleculeTable::GetConfiguration(G4int id) << 130 { 162 { 131 G4MolecularConfiguration* species = << 163 MoleculeTable::iterator it = fMoleculeTable.find(name); 132 G4MolecularConfiguration::GetMolecular << 164 G4Molecule* molecule(0); 133 << 165 if (it != fMoleculeTable.end()) 134 return species; << 166 { >> 167 molecule = it->second; >> 168 } >> 169 else if(mustExist) >> 170 { >> 171 // exception >> 172 G4ExceptionDescription description; >> 173 description << "The molecule model " << name >> 174 << " was already recorded in the table" << G4endl; >> 175 G4Exception("G4MoleculeTable::CreateMoleculeModel", "MODEL_ALREADY_CREATED", >> 176 FatalException, description); >> 177 } >> 178 return molecule; 135 } 179 } 136 180 137 //-------------------------------------------- << 181 G4Molecule* G4MoleculeTable::GetMoleculeModel(G4int id) >> 182 { >> 183 MoleculeTablePerID::iterator it = fMoleculeTablePerID.find(id); >> 184 G4Molecule* molecule(0); >> 185 if (it != fMoleculeTablePerID.end()) >> 186 { >> 187 molecule = it->second; >> 188 } >> 189 else >> 190 { >> 191 // exception >> 192 return 0; >> 193 } >> 194 return molecule; >> 195 } 138 196 139 void G4MoleculeTable::Insert(G4MoleculeDefinit 197 void G4MoleculeTable::Insert(G4MoleculeDefinition* moleculeDefinition) 140 { 198 { 141 199 142 const G4String& name = moleculeDefinition->G 200 const G4String& name = moleculeDefinition->GetName(); 143 auto it = fMoleculeDefTable.find(name); << 201 MoleculeDefTable::iterator it = fMoleculeDefTable.find(name); 144 if (it == fMoleculeDefTable.end()) 202 if (it == fMoleculeDefTable.end()) 145 { 203 { 146 fMoleculeDefTable[name] = moleculeDefiniti 204 fMoleculeDefTable[name] = moleculeDefinition; 147 } 205 } 148 else 206 else 149 { 207 { 150 // exception 208 // exception 151 G4ExceptionDescription description; 209 G4ExceptionDescription description; 152 description << "The molecule definition " 210 description << "The molecule definition " << name 153 << " was already recorded in t 211 << " was already recorded in the table" << G4endl; 154 G4Exception("G4MoleculeTable::CreateMolecu 212 G4Exception("G4MoleculeTable::CreateMoleculeDefinition", 155 "DEFINITION_ALREADY_CREATED", 213 "DEFINITION_ALREADY_CREATED", FatalException, description); 156 } 214 } 157 } << 158 << 159 //-------------------------------------------- << 160 << 161 void G4MoleculeTable::PrepareMolecularConfigur << 162 { << 163 auto it = fMoleculeDefTable.begin(); << 164 << 165 for(; it != fMoleculeDefTable.end() ; ++it) << 166 { << 167 G4MolecularConfiguration::GetOrCreateMolec << 168 } << 169 } << 170 << 171 //-------------------------------------------- << 172 << 173 G4MolecularConfiguration* << 174 G4MoleculeTable::CreateConfiguration(const G4S << 175 G4Molecul << 176 { << 177 bool alreadyCreated(false); << 178 << 179 G4MolecularConfiguration* molConf = << 180 G4MolecularConfiguration::CreateMolecula << 181 << 182 << 183 << 184 return molConf; << 185 } << 186 << 187 //-------------------------------------------- << 188 << 189 G4MolecularConfiguration* << 190 G4MoleculeTable::CreateConfiguration(const G4S << 191 G4Molecul << 192 const G4S << 193 int charg << 194 { << 195 bool alreadyCreated(false); << 196 << 197 G4MolecularConfiguration* molConf = << 198 G4MolecularConfiguration::CreateMolecula << 199 << 200 << 201 << 202 << 203 << 204 return molConf; << 205 } << 206 << 207 //-------------------------------------------- << 208 << 209 G4MolecularConfiguration* << 210 G4MoleculeTable::CreateConfiguration(const G4S << 211 G4Molecul << 212 int charg << 213 double di << 214 { << 215 bool alreadyCreated(false); << 216 << 217 G4MolecularConfiguration* molConf = << 218 G4MolecularConfiguration::CreateMolecu << 219 << 220 << 221 << 222 << 223 << 224 if(diffusion_coefficient!=-1) // TODO << 225 { << 226 molConf->SetDiffusionCoefficient(diffusion << 227 } << 228 return molConf; << 229 } << 230 << 231 //-------------------------------------------- << 232 << 233 G4MolecularConfiguration* << 234 G4MoleculeTable::CreateConfiguration(const G4S << 235 const G4M << 236 const G4S << 237 const G4E << 238 { << 239 bool alreadyCreated(false); << 240 << 241 G4MolecularConfiguration* molConf = << 242 G4MolecularConfiguration::CreateMolecula << 243 << 244 << 245 << 246 << 247 << 248 return molConf; << 249 } << 250 << 251 //-------------------------------------------- << 252 << 253 void G4MoleculeTable::Finalize() << 254 { << 255 G4MolecularConfiguration::FinalizeAll(); << 256 } << 257 << 258 //-------------------------------------------- << 259 << 260 G4ConfigurationIterator G4MoleculeTable::GetCo << 261 { << 262 return G4ConfigurationIterator(G4MolecularCo << 263 } << 264 << 265 //-------------------------------------------- << 266 << 267 int G4MoleculeTable::GetNumberOfDefinedSpecies << 268 { << 269 return G4MolecularConfiguration::GetNumberOf << 270 } 215 } 271 216