Geant4  10.01.p03
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 //
27 // $Id: G4ElectronOccupancy.cc 79357 2014-02-25 10:06:54Z 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
38 // ---------------------------------------------------------------
39 
40 #include "G4ElectronOccupancy.hh"
41 #include <sstream>
42 
44 
46  : theSizeOfOrbit(sizeOrbit)
47 {
48  // check size
49  if ( (theSizeOfOrbit <1 ) || (theSizeOfOrbit > MaxSizeOfOrbit) ) {
51  }
52 
53  // allocate and clear the array of theOccupancies
55  G4int index =0;
56  for (index = 0; index < theSizeOfOrbit; index++) {
57  theOccupancies[index] =0;
58  }
59 
61 }
62 
64 {
65  theSizeOfOrbit = -1;
66 
67  delete [] theOccupancies;
68  theOccupancies =0;
70 }
71 
73 {
75 
76  // allocate and clear the array of theOccupancies
78  G4int index =0;
79  for (index = 0; index < theSizeOfOrbit; index++) {
80  theOccupancies[index] = right.theOccupancies[index];
81  }
82 
84 }
85 
87 {
88  if ( this != &right) {
90 
91  // allocate and clear the array of theOccupancies
92  if ( theOccupancies != 0 ) delete [] theOccupancies;
94  G4int index =0;
95  for (index = 0; index < theSizeOfOrbit; index++) {
96  theOccupancies[index] = right.theOccupancies[index];
97  }
98 
100  }
101  return *this;
102 }
103 
105 {
106  G4int index;
107  G4bool value = true;
108  for (index = 0; index < MaxSizeOfOrbit; index++) {
109  if ( (index < theSizeOfOrbit ) && ( index < right.theSizeOfOrbit) ) {
110  value = value &&
111  (theOccupancies[index] == right.theOccupancies[index]) ;
112  } else if ((index < theSizeOfOrbit ) && ( index >= right.theSizeOfOrbit)) {
113  value = value && (theOccupancies[index] == 0);
114  } else if ((index >= theSizeOfOrbit ) && ( index <right.theSizeOfOrbit)) {
115  value = value && (right.theOccupancies[index] == 0);
116  }
117  }
118  return value;
119 }
120 
122 {
123  return !(*this == right);
124 }
125 
127 {
128  G4cout << " -- Electron Occupancy -- " << G4endl;
129  G4int index;
130  for (index = 0; index < theSizeOfOrbit; index++) {
131  G4cout << " " << index << "-th orbit "
132  << theOccupancies[index] << G4endl;
133  }
134 }
135 
137 {
138  G4int value =0;
139  if (orbit>=theSizeOfOrbit){
140  std::ostringstream smsg;
141  smsg<< "Orbit (" << orbit
142  <<") exceeds the maximum("
143  <<theSizeOfOrbit-1<<") ";
144  G4String msg = smsg.str();
145  G4Exception("G4ElectronOccupancy::AddElectron()","PART131",
146  JustWarning, msg);
147  } else if (orbit >=0) {
148  theOccupancies[orbit] += number;
149  theTotalOccupancy += number;
150  value = number;
151  }
152  return value;
153 }
154 
156 {
157  G4int value =0;
158  if (orbit>=theSizeOfOrbit){
159  std::ostringstream smsg;
160  smsg<< "Orbit (" << orbit
161  <<") exceeds the maximum("
162  <<theSizeOfOrbit-1 <<") ";
163  G4String msg = smsg.str();
164  G4Exception("G4ElectronOccupancy::RemoveElectron()","PART131",
165  JustWarning, msg);
166  } else if (orbit >=0) {
167  if ( theOccupancies[orbit] < number ) number = theOccupancies[orbit];
168  theOccupancies[orbit] -= number;
169  theTotalOccupancy -= number;
170  value = number;
171  }
172  return value;
173 }
G4ThreadLocal G4Allocator< G4ElectronOccupancy > * aElectronOccupancyAllocator
G4ElectronOccupancy(G4int sizeOrbit=MaxSizeOfOrbit)
G4int operator==(const G4ElectronOccupancy &right) const
#define G4ThreadLocal
Definition: tls.hh:89
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
G4int AddElectron(G4int orbit, G4int number=1)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4int operator!=(const G4ElectronOccupancy &right) const
#define G4endl
Definition: G4ios.hh:61
G4ElectronOccupancy & operator=(const G4ElectronOccupancy &right)
G4int RemoveElectron(G4int orbit, G4int number=1)