[822] | 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 | // $Id: G4Isotope.cc,v 1.21 2007/10/18 11:14:33 vnivanch Exp $ |
---|
| 28 | // GEANT4 tag $Name: $ |
---|
| 29 | // |
---|
| 30 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 31 | |
---|
| 32 | // 26.06.96: Code uses operators (+=, *=, ++, -> etc.) correctly, P. Urban |
---|
| 33 | // 29.01.97: Forbidden to create Isotope with Z<1 or N<Z, M.Maire |
---|
| 34 | // 03.05.01: flux.precision(prec) at begin/end of operator<< |
---|
| 35 | // 17.07.01: migration to STL. M. Verderi. |
---|
| 36 | // 13.09.01: suppression of the data member fIndexInTable |
---|
| 37 | // 14.09.01: fCountUse: nb of elements which use this isotope |
---|
| 38 | // 26.02.02: fIndexInTable renewed |
---|
| 39 | // 17.10.06: if fA is not defined in the constructor, it is computed from |
---|
| 40 | // NistManager v.Ivanchenko |
---|
| 41 | |
---|
| 42 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 43 | |
---|
| 44 | #include "G4Isotope.hh" |
---|
| 45 | #include "G4NistManager.hh" |
---|
| 46 | #include <iomanip> |
---|
| 47 | |
---|
| 48 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 49 | |
---|
| 50 | G4IsotopeTable G4Isotope::theIsotopeTable; |
---|
| 51 | |
---|
| 52 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 53 | |
---|
| 54 | // Create an isotope |
---|
| 55 | // |
---|
| 56 | G4Isotope::G4Isotope(const G4String& Name, G4int Z, G4int N, G4double A) |
---|
| 57 | : fName(Name), fZ(Z), fN(N), fA(A), fCountUse(0) |
---|
| 58 | { |
---|
| 59 | if (Z<1) G4Exception |
---|
| 60 | (" ERROR! It is not allowed to create an Isotope with Z < 1" ); |
---|
| 61 | |
---|
| 62 | if (N<Z) G4Exception |
---|
| 63 | (" ERROR! Attempt to create an Isotope with N < Z !!!" ); |
---|
| 64 | |
---|
| 65 | if (A<=DBL_MIN) |
---|
| 66 | fA = (G4NistManager::Instance()->GetIsotopeMass(Z,N))*g/(mole*amu_c2); |
---|
| 67 | |
---|
| 68 | theIsotopeTable.push_back(this); |
---|
| 69 | fIndexInTable = theIsotopeTable.size() - 1; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 73 | |
---|
| 74 | // Fake default constructor - sets only member data and allocates memory |
---|
| 75 | // for usage restricted to object persistency |
---|
| 76 | |
---|
| 77 | G4Isotope::G4Isotope(__void__&) |
---|
| 78 | : fZ(0), fN(0), fA(0), fCountUse(0) |
---|
| 79 | { |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 83 | |
---|
| 84 | G4Isotope::~G4Isotope() |
---|
| 85 | { |
---|
| 86 | /* |
---|
| 87 | if (fCountUse != 0) |
---|
| 88 | G4cout << "--> warning from ~G4Isotope(): the isotope " << fName |
---|
| 89 | << " is still referenced by " << fCountUse << " G4Elements \n" |
---|
| 90 | << G4endl; |
---|
| 91 | */ |
---|
| 92 | //remove this isotope from theIsotopeTable |
---|
| 93 | theIsotopeTable[fIndexInTable] = 0; |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 97 | |
---|
| 98 | G4Isotope::G4Isotope(G4Isotope& right) |
---|
| 99 | { |
---|
| 100 | *this = right; |
---|
| 101 | |
---|
| 102 | //insert this new isotope in table |
---|
| 103 | theIsotopeTable.push_back(this); |
---|
| 104 | fIndexInTable = theIsotopeTable.size() - 1; |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 108 | |
---|
| 109 | G4Isotope & G4Isotope::operator=(const G4Isotope& right) |
---|
| 110 | { |
---|
| 111 | if (this != &right) |
---|
| 112 | { |
---|
| 113 | fName = right.fName; |
---|
| 114 | fZ = right.fZ; |
---|
| 115 | fN = right.fN; |
---|
| 116 | fA = right.fA; |
---|
| 117 | } |
---|
| 118 | return *this; |
---|
| 119 | } |
---|
| 120 | |
---|
| 121 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 122 | |
---|
| 123 | G4int G4Isotope::operator==(const G4Isotope &right) const |
---|
| 124 | { |
---|
| 125 | return (this == (G4Isotope *) &right); |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 129 | |
---|
| 130 | G4int G4Isotope::operator!=(const G4Isotope &right) const |
---|
| 131 | { |
---|
| 132 | return (this != (G4Isotope *) &right); |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 136 | |
---|
| 137 | std::ostream& operator<<(std::ostream& flux, G4Isotope* isotope) |
---|
| 138 | { |
---|
| 139 | std::ios::fmtflags mode = flux.flags(); |
---|
| 140 | flux.setf(std::ios::fixed,std::ios::floatfield); |
---|
| 141 | G4long prec = flux.precision(3); |
---|
| 142 | |
---|
| 143 | flux |
---|
| 144 | << " Isotope: " << std::setw(5) << isotope->fName |
---|
| 145 | << " Z = " << std::setw(2) << isotope->fZ |
---|
| 146 | << " N = " << std::setw(3) << isotope->fN |
---|
| 147 | << " A = " << std::setw(6) << std::setprecision(2) |
---|
| 148 | << (isotope->fA)/(g/mole) << " g/mole"; |
---|
| 149 | |
---|
| 150 | flux.precision(prec); |
---|
| 151 | flux.setf(mode,std::ios::floatfield); |
---|
| 152 | return flux; |
---|
| 153 | } |
---|
| 154 | |
---|
| 155 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 156 | |
---|
| 157 | std::ostream& operator<<(std::ostream& flux, G4Isotope& isotope) |
---|
| 158 | { |
---|
| 159 | flux << &isotope; |
---|
| 160 | return flux; |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 164 | |
---|
| 165 | std::ostream& operator<<(std::ostream& flux, G4IsotopeTable IsotopeTable) |
---|
| 166 | { |
---|
| 167 | //Dump info for all known isotopes |
---|
| 168 | flux |
---|
| 169 | << "\n***** Table : Nb of isotopes = " << IsotopeTable.size() |
---|
| 170 | << " *****\n" << G4endl; |
---|
| 171 | |
---|
| 172 | for (size_t i=0; i<IsotopeTable.size(); i++) |
---|
| 173 | flux << IsotopeTable[i] << G4endl; |
---|
| 174 | |
---|
| 175 | return flux; |
---|
| 176 | } |
---|
| 177 | |
---|
| 178 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 179 | |
---|
| 180 | const G4IsotopeTable* G4Isotope::GetIsotopeTable() |
---|
| 181 | { |
---|
| 182 | return &theIsotopeTable; |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 186 | |
---|
| 187 | size_t G4Isotope::GetNumberOfIsotopes() |
---|
| 188 | { |
---|
| 189 | return theIsotopeTable.size(); |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|
| 193 | |
---|
| 194 | G4Isotope* G4Isotope::GetIsotope(G4String isotopeName, G4bool warning) |
---|
| 195 | { |
---|
| 196 | // search the isotope by its name |
---|
| 197 | for (size_t J=0 ; J<theIsotopeTable.size() ; J++) |
---|
| 198 | { |
---|
| 199 | if (theIsotopeTable[J]->GetName() == isotopeName) |
---|
| 200 | return theIsotopeTable[J]; |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | // the isotope does not exist in the table |
---|
| 204 | if (warning) { |
---|
| 205 | G4cout << "\n---> warning from G4Isotope::GetIsotope(). The isotope: " |
---|
| 206 | << isotopeName << " does not exist in the table. Return NULL pointer." |
---|
| 207 | << G4endl; |
---|
| 208 | } |
---|
| 209 | return 0; |
---|
| 210 | } |
---|
| 211 | |
---|
| 212 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... |
---|