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