Geant4  10.01.p02
G4NeutronHPHash.hh
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 #ifndef G4NeutronHPHash_h
27 #define G4NeutronHPHash_h
28 
29 #include "globals.hh"
30 #include <vector>
31 
33 {
34 public:
36  {
37  theUpper = 0;
38  prepared = false;
39  }
40 
42  {
43  if(theUpper) delete theUpper;
44  }
45 
47  {
48  theIndex = aHash.theIndex;
49  theData = aHash.theData;
50  if(aHash.theUpper != 0)
51  {
52  theUpper = new G4NeutronHPHash(*(aHash.theUpper));
53  }
54  else
55  {
56  theUpper = 0;
57  }
58  }
59 
61  {
62  if(&aHash != this)
63  {
64  theIndex = aHash.theIndex;
65  theData = aHash.theData;
66  if(aHash.theUpper != 0)
67  {
68  theUpper = new G4NeutronHPHash(*(aHash.theUpper));
69  }
70  else
71  {
72  theUpper = 0;
73  }
74  }
75  return *this;
76  }
77 
78  void Clear()
79  {
80  if(theUpper)
81  {
82  theUpper->Clear();
83  delete theUpper;
84  theUpper = 0;
85  }
86  theIndex.clear();
87  theData.clear();
88  prepared = false;
89  }
90 
91  G4bool Prepared() const {return prepared;}
92  inline void SetData(G4int index, G4double x, G4double y)
93  {
94  prepared = true;
95  G4NeutronHPDataPoint aPoint;
96  aPoint.SetData(x, y);
97  theData.push_back(aPoint);
98  theIndex.push_back(index);
99  if(0 == theData.size()%10 && 0!=theData.size())
100  {
101  if(0 == theUpper) theUpper = new G4NeutronHPHash();
102  theUpper->SetData(theData.size()-1, x, y);
103  }
104  }
105 
107  {
108  G4int result=-1;
109  if(theData.size() == 0) return 0;
110  if(theData[0].GetX()>e) return 0;
111 
112  G4int lower=0;
113  if(theUpper != 0)
114  {
115  lower = theUpper->GetMinIndex(e);
116  }
117  unsigned int i;
118  for(i=lower; i<theData.size(); i++)
119  {
120  if(theData[i].GetX()>e)
121  {
122  result = theIndex[i-1];
123  break;
124  }
125  }
126  if(result == -1) result = theIndex[theIndex.size()-1];
127  return result;
128  }
129 
130 private:
131 
134  std::vector<int> theIndex;
135  std::vector<G4NeutronHPDataPoint> theData; // the data
136 };
137 #endif
G4int GetMinIndex(G4double e) const
void SetData(G4double e, G4double x)
int G4int
Definition: G4Types.hh:78
void SetData(G4int index, G4double x, G4double y)
G4NeutronHPHash(const G4NeutronHPHash &aHash)
G4NeutronHPHash * theUpper
bool G4bool
Definition: G4Types.hh:79
G4NeutronHPHash & operator=(const G4NeutronHPHash &aHash)
G4bool Prepared() const
double G4double
Definition: G4Types.hh:76
std::vector< int > theIndex
std::vector< G4NeutronHPDataPoint > theData