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 67971 2013-03-13 10:13:24Z gcosmo $ >> 28 // >> 29 // >> 30 // ---------------------------------------------------------------------- >> 31 // GEANT 4 class implementation file >> 32 // >> 33 // History: first implementation, based on object model of >> 34 // Hisaya Kurashige, 17 Aug 1999 >> 35 // ---------------------------------------------------------------- >> 36 // This class has information of occupation of electrons >> 37 // in atomic orbits 29 // ------------------------------------------- 38 // --------------------------------------------------------------- 30 39 31 #include "G4ElectronOccupancy.hh" 40 #include "G4ElectronOccupancy.hh" 32 41 33 #include <sstream> << 42 G4ThreadLocal G4Allocator<G4ElectronOccupancy> *aElectronOccupancyAllocator = 0; 34 << 35 G4Allocator<G4ElectronOccupancy>*& aElectronOc << 36 { << 37 G4ThreadLocalStatic G4Allocator<G4ElectronOc << 38 return _instance; << 39 } << 40 43 41 G4ElectronOccupancy::G4ElectronOccupancy(G4int << 44 G4ElectronOccupancy::G4ElectronOccupancy(G4int sizeOrbit ) >> 45 : theSizeOfOrbit(sizeOrbit) 42 { 46 { 43 // check size 47 // check size 44 if ((theSizeOfOrbit < 1) || (theSizeOfOrbit << 48 if ( (theSizeOfOrbit <1 ) || (theSizeOfOrbit > MaxSizeOfOrbit) ) { 45 theSizeOfOrbit = MaxSizeOfOrbit; 49 theSizeOfOrbit = MaxSizeOfOrbit; 46 } 50 } 47 51 48 // allocate and clear the array of theOccupa << 52 // allocate and clear the array of theOccupancies 49 theOccupancies = new G4int[theSizeOfOrbit]; 53 theOccupancies = new G4int[theSizeOfOrbit]; 50 for (G4int index = 0; index < theSizeOfOrbit << 54 G4int index =0; 51 theOccupancies[index] = 0; << 55 for (index = 0; index < theSizeOfOrbit; index++) { >> 56 theOccupancies[index] =0; 52 } 57 } 53 58 54 theTotalOccupancy = 0; << 59 theTotalOccupancy =0; 55 } 60 } 56 61 57 G4ElectronOccupancy::~G4ElectronOccupancy() 62 G4ElectronOccupancy::~G4ElectronOccupancy() 58 { 63 { 59 theSizeOfOrbit = -1; << 64 theSizeOfOrbit = -1; 60 65 61 delete[] theOccupancies; << 66 delete [] theOccupancies; 62 theOccupancies = nullptr; << 67 theOccupancies =0; 63 theTotalOccupancy = 0; << 68 theTotalOccupancy =0; 64 } 69 } 65 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 118 void G4ElectronOccupancy::DumpInfo() const 125 void G4ElectronOccupancy::DumpInfo() const 119 { 126 { 120 G4cout << " -- Electron Occupancy -- " << G 127 G4cout << " -- Electron Occupancy -- " << G4endl; 121 for (G4int index = 0; index < theSizeOfOrbit << 128 G4int index; 122 G4cout << " " << index << "-th orbit << 129 for (index = 0; index < theSizeOfOrbit; index++) { 123 } << 130 G4cout << " " << index << "-th orbit " 124 } << 131 << theOccupancies[index] << G4endl; 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 } 132 } 158 return value; << 159 } 133 } 160 134