Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4NuclearPolarizationStore.cc
이 파일의 문서화 페이지로 가기
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 // $Id: G4NuclearPolarizationStore.cc 97302 2016-06-01 09:30:11Z gcosmo $
27 //
28 // 23-Jan-2009 V.Ivanchenko make the class to be a singleton
29 // 17-Aug-2012 V.Ivanchenko added hadronic model factories
30 
32 #include "G4SystemOfUnits.hh"
33 
36 
38 {
39  if(nullptr == instance) {
41  instance = inst.Instance();
42  }
43  return instance;
44 }
45 
47 {
48  for(G4int i=0; i<maxNumStates; ++i) { nuclist[i] = nullptr; }
49  oldIdx = 0;
50 }
51 
53 {
54  for(G4int i=0; i<maxNumStates; ++i) {
55  delete nuclist[i];
56  nuclist[i] = nullptr;
57  }
58 }
59 
61 {
62  G4int idx = -1;
63  for(G4int i=0; i<maxNumStates; ++i) {
64  if(ptr == nuclist[i]) { return; }
65  if(nullptr == nuclist[i]) { idx = i; }
66  }
67  if(idx >= 0) {
68  nuclist[idx] = ptr;
69  return;
70  }
71  // delete oldest object
72  delete nuclist[oldIdx];
73  nuclist[oldIdx] = ptr;
74  // redefine oldIdx
75  ++oldIdx;
76  if(oldIdx >= maxNumStates) { oldIdx = 0; }
77 }
78 
81 {
82  static const G4double tolerance = 10.*CLHEP::eV;
83  for(G4int i=0; i<maxNumStates; ++i) {
84  auto nucp = nuclist[i];
85  if(nucp && Z == nucp->GetZ() && A == nucp->GetA() &&
86  std::abs(Eexc - nucp->GetExcitationEnergy()) < tolerance) {
87  return nucp;
88  }
89  }
90  G4NuclearPolarization* ptr = new G4NuclearPolarization(Z, A, Eexc);
91  Register(ptr);
92  return ptr;
93 }
94 
96 {
97  for(G4int i=0; i<maxNumStates; ++i) {
98  if(ptr == nuclist[i]) {
99  delete ptr;
100  nuclist[i] = nullptr;
101  // do we need redefine oldIdx?
102  if(i == oldIdx) {
103  for(G4int j=0; j<maxNumStates; ++j) {
104  if(j != i && nullptr != nuclist[j]) {
105  oldIdx = j;
106  return;
107  }
108  }
109  oldIdx = i;
110  }
111  return;
112  }
113  }
114 }
static G4NuclearPolarizationStore * GetInstance()
void Register(G4NuclearPolarization *ptr)
#define G4ThreadLocal
Definition: tls.hh:69
Float_t Z
double G4double
Definition: G4Types.hh:76
G4NuclearPolarization * nuclist[maxNumStates]
double A(double temperature)
static constexpr double eV
void RemoveMe(G4NuclearPolarization *ptr)
int G4int
Definition: G4Types.hh:78
G4NuclearPolarization * FindOrBuild(G4int Z, G4int A, G4double Eexc)
static G4ThreadLocal G4NuclearPolarizationStore * instance
const G4int maxNumStates