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