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 // G4ElectronOccupancy class implementation << 27 // 26 // 28 // Author: Hisaya Kurashige, 17 Aug 1999 << 27 // >> 28 // >> 29 // ---------------------------------------------------------------------- >> 30 // GEANT 4 class implementation file >> 31 // >> 32 // History: first implementation, based on object model of >> 33 // Hisaya Kurashige, 17 Aug 1999 >> 34 // ---------------------------------------------------------------- >> 35 // This class has information of occupation of electrons >> 36 // in atomic orbits 29 // ------------------------------------------- 37 // --------------------------------------------------------------- 30 38 31 #include "G4ElectronOccupancy.hh" 39 #include "G4ElectronOccupancy.hh" 32 << 33 #include <sstream> 40 #include <sstream> 34 41 35 G4Allocator<G4ElectronOccupancy>*& aElectronOc 42 G4Allocator<G4ElectronOccupancy>*& aElectronOccupancyAllocator() 36 { 43 { 37 G4ThreadLocalStatic G4Allocator<G4ElectronOc << 44 G4ThreadLocalStatic G4Allocator<G4ElectronOccupancy>* _instance = nullptr; 38 return _instance; << 45 return _instance; 39 } 46 } 40 47 41 G4ElectronOccupancy::G4ElectronOccupancy(G4int << 48 G4ElectronOccupancy::G4ElectronOccupancy(G4int sizeOrbit ) >> 49 : theSizeOfOrbit(sizeOrbit) 42 { 50 { 43 // check size 51 // check size 44 if ((theSizeOfOrbit < 1) || (theSizeOfOrbit << 52 if ( (theSizeOfOrbit <1 ) || (theSizeOfOrbit > MaxSizeOfOrbit) ) { 45 theSizeOfOrbit = MaxSizeOfOrbit; 53 theSizeOfOrbit = MaxSizeOfOrbit; 46 } 54 } 47 55 48 // allocate and clear the array of theOccupa << 56 // allocate and clear the array of theOccupancies 49 theOccupancies = new G4int[theSizeOfOrbit]; 57 theOccupancies = new G4int[theSizeOfOrbit]; 50 for (G4int index = 0; index < theSizeOfOrbit << 58 G4int index =0; 51 theOccupancies[index] = 0; << 59 for (index = 0; index < theSizeOfOrbit; index++) { >> 60 theOccupancies[index] =0; 52 } 61 } 53 62 54 theTotalOccupancy = 0; << 63 theTotalOccupancy =0; 55 } 64 } 56 65 57 G4ElectronOccupancy::~G4ElectronOccupancy() 66 G4ElectronOccupancy::~G4ElectronOccupancy() 58 { 67 { 59 theSizeOfOrbit = -1; << 68 theSizeOfOrbit = -1; 60 69 61 delete[] theOccupancies; << 70 delete [] theOccupancies; 62 theOccupancies = nullptr; << 71 theOccupancies =0; 63 theTotalOccupancy = 0; << 72 theTotalOccupancy =0; 64 } 73 } 65 74 66 G4ElectronOccupancy::G4ElectronOccupancy(const 75 G4ElectronOccupancy::G4ElectronOccupancy(const G4ElectronOccupancy& right) 67 { 76 { 68 theSizeOfOrbit = right.theSizeOfOrbit; 77 theSizeOfOrbit = right.theSizeOfOrbit; 69 78 70 // allocate and clear the array of theOccupa << 79 // allocate and clear the array of theOccupancies 71 theOccupancies = new G4int[theSizeOfOrbit]; 80 theOccupancies = new G4int[theSizeOfOrbit]; 72 for (G4int index = 0; index < theSizeOfOrbit << 81 G4int index =0; >> 82 for (index = 0; index < theSizeOfOrbit; index++) { 73 theOccupancies[index] = right.theOccupanci 83 theOccupancies[index] = right.theOccupancies[index]; 74 } 84 } 75 85 76 theTotalOccupancy = right.theTotalOccupancy; 86 theTotalOccupancy = right.theTotalOccupancy; 77 } 87 } 78 88 79 G4ElectronOccupancy& G4ElectronOccupancy::oper 89 G4ElectronOccupancy& G4ElectronOccupancy::operator=(const G4ElectronOccupancy& right) 80 { 90 { 81 if (this != &right) { << 91 if ( this != &right) { 82 theSizeOfOrbit = right.theSizeOfOrbit; 92 theSizeOfOrbit = right.theSizeOfOrbit; 83 << 93 84 // allocate and clear the array of theOccu << 94 // allocate and clear the array of theOccupancies 85 delete[] theOccupancies; << 95 if ( theOccupancies != 0 ) delete [] theOccupancies; 86 theOccupancies = new G4int[theSizeOfOrbit] 96 theOccupancies = new G4int[theSizeOfOrbit]; 87 for (G4int index = 0; index < theSizeOfOrb << 97 G4int index =0; >> 98 for (index = 0; index < theSizeOfOrbit; index++) { 88 theOccupancies[index] = right.theOccupan 99 theOccupancies[index] = right.theOccupancies[index]; 89 } 100 } 90 << 101 91 theTotalOccupancy = right.theTotalOccupanc 102 theTotalOccupancy = right.theTotalOccupancy; 92 } 103 } 93 return *this; 104 return *this; 94 } 105 } 95 106 96 G4bool G4ElectronOccupancy::operator==(const G 107 G4bool G4ElectronOccupancy::operator==(const G4ElectronOccupancy& right) const 97 { 108 { >> 109 G4int index; 98 G4bool value = true; 110 G4bool value = true; 99 for (G4int index = 0; index < MaxSizeOfOrbit << 111 for (index = 0; index < MaxSizeOfOrbit; index++) { 100 if ((index < theSizeOfOrbit) && (index < r << 112 if ( (index < theSizeOfOrbit ) && ( index < right.theSizeOfOrbit) ) { 101 value = value && (theOccupancies[index] << 113 value = value && 102 } << 114 (theOccupancies[index] == right.theOccupancies[index]) ; 103 else if ((index < theSizeOfOrbit) && (inde << 115 } else if ((index < theSizeOfOrbit ) && ( index >= right.theSizeOfOrbit)) { 104 value = value && (!static_cast<G4bool>(t << 116 value = value && (theOccupancies[index] == false); 105 } << 117 } else if ((index >= theSizeOfOrbit ) && ( index <right.theSizeOfOrbit)) { 106 else if ((index >= theSizeOfOrbit) && (ind << 118 value = value && (right.theOccupancies[index] == false); 107 value = value && (!static_cast<G4bool>(r << 108 } 119 } 109 } 120 } 110 return value; 121 return value; 111 } 122 } 112 123 113 G4bool G4ElectronOccupancy::operator!=(const G 124 G4bool G4ElectronOccupancy::operator!=(const G4ElectronOccupancy& right) const 114 { 125 { 115 return !(*this == right); 126 return !(*this == right); 116 } 127 } 117 128 118 void G4ElectronOccupancy::DumpInfo() const 129 void G4ElectronOccupancy::DumpInfo() const 119 { 130 { 120 G4cout << " -- Electron Occupancy -- " << G 131 G4cout << " -- Electron Occupancy -- " << G4endl; 121 for (G4int index = 0; index < theSizeOfOrbit << 132 G4int index; 122 G4cout << " " << index << "-th orbit << 133 for (index = 0; index < theSizeOfOrbit; index++) { >> 134 G4cout << " " << index << "-th orbit " >> 135 << theOccupancies[index] << G4endl; 123 } 136 } 124 } 137 } 125 138 126 G4int G4ElectronOccupancy::AddElectron(G4int o << 139 G4int G4ElectronOccupancy::AddElectron(G4int orbit, G4int number) 127 { 140 { 128 G4int value = 0; << 141 G4int value =0; 129 if (orbit >= theSizeOfOrbit) { << 142 if (orbit>=theSizeOfOrbit){ 130 std::ostringstream smsg; 143 std::ostringstream smsg; 131 smsg << "Orbit (" << orbit << ") exceeds t << 144 smsg<< "Orbit (" << orbit >> 145 <<") exceeds the maximum(" >> 146 <<theSizeOfOrbit-1<<") "; 132 G4String msg = smsg.str(); 147 G4String msg = smsg.str(); 133 G4Exception("G4ElectronOccupancy::AddElect << 148 G4Exception("G4ElectronOccupancy::AddElectron()","PART131", 134 } << 149 JustWarning, msg); 135 else if (orbit >= 0) { << 150 } else if (orbit >=0) { 136 theOccupancies[orbit] += number; 151 theOccupancies[orbit] += number; 137 theTotalOccupancy += number; << 152 theTotalOccupancy += number; 138 value = number; << 153 value = number; 139 } 154 } 140 return value; 155 return value; 141 } 156 } 142 157 143 G4int G4ElectronOccupancy::RemoveElectron(G4in << 158 G4int G4ElectronOccupancy::RemoveElectron(G4int orbit, G4int number) 144 { 159 { 145 G4int value = 0; << 160 G4int value =0; 146 if (orbit >= theSizeOfOrbit) { << 161 if (orbit>=theSizeOfOrbit){ 147 std::ostringstream smsg; 162 std::ostringstream smsg; 148 smsg << "Orbit (" << orbit << ") exceeds t << 163 smsg<< "Orbit (" << orbit >> 164 <<") exceeds the maximum(" >> 165 <<theSizeOfOrbit-1 <<") "; 149 G4String msg = smsg.str(); 166 G4String msg = smsg.str(); 150 G4Exception("G4ElectronOccupancy::RemoveEl << 167 G4Exception("G4ElectronOccupancy::RemoveElectron()","PART131", 151 } << 168 JustWarning, msg); 152 else if (orbit >= 0) { << 169 } else if (orbit >=0) { 153 if (theOccupancies[orbit] < number) number << 170 if ( theOccupancies[orbit] < number ) number = theOccupancies[orbit]; 154 theOccupancies[orbit] -= number; 171 theOccupancies[orbit] -= number; 155 theTotalOccupancy -= number; << 172 theTotalOccupancy -= number; 156 value = number; 173 value = number; 157 } 174 } 158 return value; 175 return value; 159 } 176 } 160 177