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] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /particles/management/src/G4ElectronOccupancy.cc (Version 11.3.0) and /particles/management/src/G4ElectronOccupancy.cc (Version 10.7.p1)


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