Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer << 3 // * DISCLAIMER * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th << 5 // * The following disclaimer summarizes all the specific disclaimers * 6 // * the Geant4 Collaboration. It is provided << 6 // * of contributors to this software. The specific disclaimers,which * 7 // * conditions of the Geant4 Software License << 7 // * govern, are listed with their locations in: * 8 // * LICENSE and available at http://cern.ch/ << 8 // * http://cern.ch/geant4/license * 9 // * include a list of copyright holders. << 10 // * 9 // * * 11 // * Neither the authors of this software syst 10 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 11 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 12 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 13 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file << 14 // * use. * 16 // * for the full disclaimer and the limitatio << 17 // * 15 // * * 18 // * This code implementation is the result << 16 // * This code implementation is the intellectual property of the * 19 // * technical work of the GEANT4 collaboratio << 17 // * GEANT4 collaboration. * 20 // * By using, copying, modifying or distri << 18 // * By copying, distributing or modifying the Program (or any work * 21 // * any work based on the software) you ag << 19 // * based on the Program) you indicate your acceptance of this * 22 // * use in resulting scientific publicati << 20 // * statement, and all its terms. * 23 // * acceptance of all terms of the Geant4 Sof << 24 // ******************************************* 21 // ******************************************************************** 25 // 22 // 26 // G4ElectronOccupancy class implementation << 27 // 23 // 28 // Author: Hisaya Kurashige, 17 Aug 1999 << 24 // $Id: G4ElectronOccupancy.cc,v 1.6 2001/07/11 10:01:59 gunter Exp $ >> 25 // GEANT4 tag $Name: geant4-05-01-patch-01 $ >> 26 // >> 27 // >> 28 // ---------------------------------------------------------------------- >> 29 // GEANT 4 class implementation file >> 30 // >> 31 // History: first implementation, based on object model of >> 32 // Hisaya Kurashige, 17 Aug 1999 >> 33 // ---------------------------------------------------------------- >> 34 // This class has information of occupation of electrons >> 35 // in atomic orbits 29 // ------------------------------------------- 36 // --------------------------------------------------------------- 30 37 31 #include "G4ElectronOccupancy.hh" << 32 38 33 #include <sstream> << 39 #include "G4ElectronOccupancy.hh" 34 40 35 G4Allocator<G4ElectronOccupancy>*& aElectronOc << 41 G4Allocator<G4ElectronOccupancy> aElectronOccupancyAllocator; 36 { << 37 G4ThreadLocalStatic G4Allocator<G4ElectronOc << 38 return _instance; << 39 } << 40 42 41 G4ElectronOccupancy::G4ElectronOccupancy(G4int << 43 G4ElectronOccupancy::G4ElectronOccupancy(G4int sizeOrbit ): >> 44 theSizeOfOrbit(sizeOrbit) 42 { 45 { 43 // check size 46 // check size 44 if ((theSizeOfOrbit < 1) || (theSizeOfOrbit << 47 if ( (theSizeOfOrbit <1 ) || (theSizeOfOrbit > MaxSizeOfOrbit) ) { 45 theSizeOfOrbit = MaxSizeOfOrbit; 48 theSizeOfOrbit = MaxSizeOfOrbit; 46 } 49 } 47 50 48 // allocate and clear the array of theOccupa << 51 // allocate and clear the array of theOccupancies 49 theOccupancies = new G4int[theSizeOfOrbit]; 52 theOccupancies = new G4int[theSizeOfOrbit]; 50 for (G4int index = 0; index < theSizeOfOrbit << 53 G4int index =0; 51 theOccupancies[index] = 0; << 54 for (index = 0; index < theSizeOfOrbit; index++) { >> 55 theOccupancies[index] =0; 52 } 56 } 53 57 54 theTotalOccupancy = 0; << 58 theTotalOccupancy =0; 55 } 59 } 56 60 57 G4ElectronOccupancy::~G4ElectronOccupancy() 61 G4ElectronOccupancy::~G4ElectronOccupancy() 58 { 62 { 59 theSizeOfOrbit = -1; << 63 theSizeOfOrbit = -1; 60 64 61 delete[] theOccupancies; << 65 delete [] theOccupancies; 62 theOccupancies = nullptr; << 66 theOccupancies =0; 63 theTotalOccupancy = 0; << 67 theTotalOccupancy =0; 64 } 68 } 65 69 >> 70 66 G4ElectronOccupancy::G4ElectronOccupancy(const 71 G4ElectronOccupancy::G4ElectronOccupancy(const G4ElectronOccupancy& right) 67 { 72 { 68 theSizeOfOrbit = right.theSizeOfOrbit; 73 theSizeOfOrbit = right.theSizeOfOrbit; 69 74 70 // allocate and clear the array of theOccupa << 75 // allocate and clear the array of theOccupancies 71 theOccupancies = new G4int[theSizeOfOrbit]; 76 theOccupancies = new G4int[theSizeOfOrbit]; 72 for (G4int index = 0; index < theSizeOfOrbit << 77 G4int index =0; >> 78 for (index = 0; index < theSizeOfOrbit; index++) { 73 theOccupancies[index] = right.theOccupanci 79 theOccupancies[index] = right.theOccupancies[index]; 74 } 80 } 75 81 76 theTotalOccupancy = right.theTotalOccupancy; 82 theTotalOccupancy = right.theTotalOccupancy; 77 } 83 } 78 84 79 G4ElectronOccupancy& G4ElectronOccupancy::oper 85 G4ElectronOccupancy& G4ElectronOccupancy::operator=(const G4ElectronOccupancy& right) 80 { 86 { 81 if (this != &right) { << 87 if ( this != &right) { 82 theSizeOfOrbit = right.theSizeOfOrbit; 88 theSizeOfOrbit = right.theSizeOfOrbit; 83 << 89 84 // allocate and clear the array of theOccu << 90 // allocate and clear the array of theOccupancies 85 delete[] theOccupancies; << 91 if ( theOccupancies != 0 ) delete [] theOccupancies; 86 theOccupancies = new G4int[theSizeOfOrbit] 92 theOccupancies = new G4int[theSizeOfOrbit]; 87 for (G4int index = 0; index < theSizeOfOrb << 93 G4int index =0; >> 94 for (index = 0; index < theSizeOfOrbit; index++) { 88 theOccupancies[index] = right.theOccupan 95 theOccupancies[index] = right.theOccupancies[index]; 89 } 96 } 90 << 97 91 theTotalOccupancy = right.theTotalOccupanc 98 theTotalOccupancy = right.theTotalOccupancy; 92 } 99 } 93 return *this; 100 return *this; 94 } 101 } 95 102 96 G4bool G4ElectronOccupancy::operator==(const G << 103 G4int G4ElectronOccupancy::operator==(const G4ElectronOccupancy& right) const 97 { 104 { >> 105 G4int index; 98 G4bool value = true; 106 G4bool value = true; 99 for (G4int index = 0; index < MaxSizeOfOrbit << 107 for (index = 0; index < MaxSizeOfOrbit; index++) { 100 if ((index < theSizeOfOrbit) && (index < r << 108 if ( (index < theSizeOfOrbit ) && ( index < right.theSizeOfOrbit) ) { 101 value = value && (theOccupancies[index] << 109 value = value && 102 } << 110 (theOccupancies[index] == right.theOccupancies[index]) ; 103 else if ((index < theSizeOfOrbit) && (inde << 111 } else if ((index < theSizeOfOrbit ) && ( index >= right.theSizeOfOrbit)) { 104 value = value && (!static_cast<G4bool>(t << 112 value = value && (theOccupancies[index] == 0); 105 } << 113 } else if ((index >= theSizeOfOrbit ) && ( index <right.theSizeOfOrbit)) { 106 else if ((index >= theSizeOfOrbit) && (ind << 114 value = value && (right.theOccupancies[index] == 0); 107 value = value && (!static_cast<G4bool>(r << 108 } 115 } 109 } 116 } 110 return value; 117 return value; 111 } 118 } 112 119 113 G4bool G4ElectronOccupancy::operator!=(const G << 120 G4int G4ElectronOccupancy::operator!=(const G4ElectronOccupancy& right) const 114 { 121 { 115 return !(*this == right); 122 return !(*this == right); 116 } 123 } 117 124 >> 125 118 void G4ElectronOccupancy::DumpInfo() const 126 void G4ElectronOccupancy::DumpInfo() const 119 { 127 { 120 G4cout << " -- Electron Occupancy -- " << G 128 G4cout << " -- Electron Occupancy -- " << G4endl; 121 for (G4int index = 0; index < theSizeOfOrbit << 129 G4int index; 122 G4cout << " " << index << "-th orbit << 130 for (index = 0; index < theSizeOfOrbit; index++) { >> 131 G4cout << " " << index << "-th orbit " >> 132 << theOccupancies[index] << G4endl; 123 } 133 } 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 } 134 } 160 135