Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 // 27 // ------------------------------------------------------------------- 28 // 29 // GEANT4 Class file 30 // 31 // File name: G4EmDataHandler 32 // 33 // Author: V. Ivanchenko 34 // 35 // Creation date: 16 August 2017 36 // 37 // Modifications: 38 // 39 // ------------------------------------------------------------------- 40 // 41 // 42 43 #include "G4EmDataHandler.hh" 44 #include "G4EmDataRegistry.hh" 45 #include "G4ParticleDefinition.hh" 46 #include "G4EmParameters.hh" 47 #include "G4PhysicsTableHelper.hh" 48 #include "G4VEmProcess.hh" 49 #include "G4VEnergyLossProcess.hh" 50 51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 52 53 G4EmDataHandler::G4EmDataHandler(std::size_t n, const G4String& nam) 54 : tLength(n), fName(nam) 55 { 56 data.resize(n, nullptr); 57 fMaxXS = new std::vector<G4double>; 58 fXSpeaks = new std::vector<G4TwoPeaksXS*>; 59 G4EmDataRegistry::Instance()->Register(this); 60 } 61 62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 63 64 G4EmDataHandler::~G4EmDataHandler() 65 { 66 if (!fUseBaseParticleTable) { 67 for (std::size_t i=0; i<tLength; ++i) { 68 CleanTable(i); 69 } 70 delete fMaxXS; 71 delete fXSpeaks; 72 } 73 if (!fElemSelectors.empty()) { 74 for (auto const & ptr : fElemSelectors) { 75 if (nullptr != ptr) { 76 for (auto const & p : *ptr) { delete p; } 77 } 78 } 79 } 80 81 } 82 83 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 84 85 std::size_t G4EmDataHandler::SetTable(G4PhysicsTable* ptr) 86 { 87 for (std::size_t i=0; i<tLength; ++i) { 88 if (ptr == data[i]) { return i; } 89 } 90 data.push_back(ptr); 91 ++tLength; 92 return tLength-1; 93 } 94 95 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 96 97 void G4EmDataHandler::UpdateTable(G4PhysicsTable* ptr, std::size_t idx) 98 { 99 // update table pointer but not delete previous 100 if (idx < tLength) { 101 if (ptr != data[idx]) { data[idx] = ptr; } 102 data[idx] = G4PhysicsTableHelper::PreparePhysicsTable(data[idx]); 103 } else { 104 G4cout << "### G4EmDataHandler::UpdateTable fail for idx=" << idx 105 << " length=" << tLength << G4endl; 106 } 107 } 108 109 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 110 111 void G4EmDataHandler::SaveTable(G4PhysicsTable* ptr, std::size_t idx) 112 { 113 if (idx < tLength) { 114 data[idx] = ptr; 115 } 116 } 117 118 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 119 120 G4PhysicsTable* G4EmDataHandler::MakeTable(std::size_t i) 121 { 122 std::size_t idx = i; 123 if (idx >= tLength) { 124 data.push_back(nullptr); 125 idx = tLength; 126 ++tLength; 127 } 128 data[idx] = G4PhysicsTableHelper::PreparePhysicsTable(data[idx]); 129 return data[idx]; 130 } 131 132 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 133 134 G4PhysicsTable* G4EmDataHandler::MakeTable(G4PhysicsTable* ptr, std::size_t i) 135 { 136 std::size_t idx = i; 137 // create new table only if index corresponds to the 138 // position in the vector 139 if (idx < tLength) { 140 if (ptr != data[idx]) { 141 CleanTable(idx); 142 data[idx] = ptr; 143 } 144 } else { 145 data.push_back(ptr); 146 idx = tLength; 147 ++tLength; 148 } 149 data[idx] = G4PhysicsTableHelper::PreparePhysicsTable(data[idx]); 150 return data[idx]; 151 } 152 153 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 154 155 void G4EmDataHandler::CleanTable(std::size_t i) 156 { 157 if (i < tLength && nullptr != data[i]) { 158 auto ptr = data[i]; 159 ptr->clearAndDestroy(); 160 delete ptr; 161 for (std::size_t j=0; j<tLength; ++j) { 162 if (ptr == data[j]) { data[j] = nullptr; } 163 } 164 } 165 } 166 167 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 168 169 G4bool G4EmDataHandler::StorePhysicsTable(std::size_t idx, 170 const G4ParticleDefinition* part, 171 const G4String& fname, 172 G4bool ascii) 173 { 174 G4bool yes = true; 175 if(nullptr != data[idx]) { 176 yes = data[idx]->StorePhysicsTable(fname, ascii); 177 178 if ( yes ) { 179 G4cout << "### Physics table is stored for " 180 << part->GetParticleName() 181 << " <" << fname << "> " << G4endl; 182 } else { 183 G4cout << "### Fail to store Physics Table for " 184 << part->GetParticleName() 185 << " <" << fname << "> " << G4endl; 186 } 187 } 188 return yes; 189 } 190 191 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 192 193 G4bool G4EmDataHandler::RetrievePhysicsTable(std::size_t idx, 194 const G4ParticleDefinition* part, 195 const G4String& fname, 196 G4bool ascii, G4bool spline) 197 { 198 G4PhysicsTable* table = Table(idx); 199 G4bool yes = G4PhysicsTableHelper::RetrievePhysicsTable(table, fname, ascii, spline); 200 G4EmParameters* param = G4EmParameters::Instance(); 201 if ( yes ) { 202 if (0 < param->Verbose()) { 203 G4cout << "### Physics table " << idx << " for " 204 << part->GetParticleName() 205 << " is retrieved from <" << fname << ">" 206 << G4endl; 207 } 208 } else if (1 < param->Verbose()) { 209 G4cout << "### Fail to retrieve physics table " << idx << " for " 210 << part->GetParticleName() << " from <" 211 << fname << ">" << G4endl; 212 } 213 return yes; 214 } 215 216 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 217 218 void G4EmDataHandler::SetMasterProcess(const G4VEmProcess* ptr) 219 { 220 masterProcess.push_back(ptr); 221 } 222 223 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 224 225 const G4VEmProcess* G4EmDataHandler::GetMasterProcess(std::size_t idx) const 226 { 227 return (idx < masterProcess.size()) ? masterProcess[idx] : nullptr; 228 } 229 230 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 231 232 void G4EmDataHandler::SetElementSelectors(std::vector<G4EmElementSelector*>* p, 233 std::size_t i) 234 { 235 if (i < eLength) { 236 if (fElemSelectors[i] != p) { 237 delete fElemSelectors[i]; 238 } 239 fElemSelectors[i] = p; 240 } else { 241 fElemSelectors.push_back(p); 242 ++eLength; 243 } 244 } 245 246 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 247