Geant4-11
G4ElectronOccupancy.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// G4ElectronOccupancy class implementation
27//
28// Author: Hisaya Kurashige, 17 Aug 1999
29// ---------------------------------------------------------------
30
32#include <sstream>
33
35{
37 return _instance;
38}
39
41 : theSizeOfOrbit(sizeOrbit)
42{
43 // check size
45 {
47 }
48
49 // allocate and clear the array of theOccupancies
51 for (G4int index = 0; index < theSizeOfOrbit; ++index)
52 {
53 theOccupancies[index] = 0;
54 }
55
57}
58
60{
61 theSizeOfOrbit = -1;
62
63 delete [] theOccupancies;
64 theOccupancies = nullptr;
66}
67
69{
71
72 // allocate and clear the array of theOccupancies
74 for (G4int index = 0; index < theSizeOfOrbit; ++index)
75 {
76 theOccupancies[index] = right.theOccupancies[index];
77 }
78
80}
81
84{
85 if ( this != &right)
86 {
88
89 // allocate and clear the array of theOccupancies
90 if ( theOccupancies != nullptr ) delete [] theOccupancies;
92 for (G4int index = 0; index < theSizeOfOrbit; ++index)
93 {
94 theOccupancies[index] = right.theOccupancies[index];
95 }
96
98 }
99 return *this;
100}
101
103{
104 G4bool value = true;
105 for (G4int index = 0; index < MaxSizeOfOrbit; ++index)
106 {
107 if ( (index < theSizeOfOrbit ) && ( index < right.theSizeOfOrbit) )
108 {
109 value = value &&
110 (theOccupancies[index] == right.theOccupancies[index]) ;
111 }
112 else if ((index < theSizeOfOrbit ) && ( index >= right.theSizeOfOrbit))
113 {
114 value = value && (theOccupancies[index] == false);
115 }
116 else if ((index >= theSizeOfOrbit ) && ( index <right.theSizeOfOrbit))
117 {
118 value = value && (right.theOccupancies[index] == false);
119 }
120 }
121 return value;
122}
123
125{
126 return !(*this == right);
127}
128
130{
131 G4cout << " -- Electron Occupancy -- " << G4endl;
132 for (G4int index = 0; index < theSizeOfOrbit; ++index)
133 {
134 G4cout << " " << index << "-th orbit "
135 << theOccupancies[index] << G4endl;
136 }
137}
138
140{
141 G4int value =0;
142 if (orbit>=theSizeOfOrbit)
143 {
144 std::ostringstream smsg;
145 smsg<< "Orbit (" << orbit
146 <<") exceeds the maximum("
147 <<theSizeOfOrbit-1<<") ";
148 G4String msg = smsg.str();
149 G4Exception("G4ElectronOccupancy::AddElectron()","PART131",
150 JustWarning, msg);
151 }
152 else if (orbit >=0)
153 {
154 theOccupancies[orbit] += number;
155 theTotalOccupancy += number;
156 value = number;
157 }
158 return value;
159}
160
162{
163 G4int value =0;
164 if (orbit>=theSizeOfOrbit)
165 {
166 std::ostringstream smsg;
167 smsg<< "Orbit (" << orbit
168 <<") exceeds the maximum("
169 <<theSizeOfOrbit-1 <<") ";
170 G4String msg = smsg.str();
171 G4Exception("G4ElectronOccupancy::RemoveElectron()","PART131",
172 JustWarning, msg);
173 }
174 else if (orbit >=0)
175 {
176 if ( theOccupancies[orbit] < number ) number = theOccupancies[orbit];
177 theOccupancies[orbit] -= number;
178 theTotalOccupancy -= number;
179 value = number;
180 }
181 return value;
182}
G4Allocator< G4ElectronOccupancy > *& aElectronOccupancyAllocator()
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4bool operator!=(const G4ElectronOccupancy &right) const
G4int AddElectron(G4int orbit, G4int number=1)
G4int RemoveElectron(G4int orbit, G4int number=1)
G4bool operator==(const G4ElectronOccupancy &right) const
G4ElectronOccupancy(G4int sizeOrbit=MaxSizeOfOrbit)
G4ElectronOccupancy & operator=(const G4ElectronOccupancy &right)
#define G4ThreadLocalStatic
Definition: tls.hh:76