Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  delete theUpper;
83  theUpper = 0;
84  }
85  theIndex.clear();
86  theData.clear();
87  prepared = false;
88  }
89 
90  G4bool Prepared() const {return prepared;}
91  inline void SetData(G4int index, G4double x, G4double y)
92  {
93  prepared = true;
94  G4NeutronHPDataPoint aPoint;
95  aPoint.SetData(x, y);
96  theData.push_back(aPoint);
97  theIndex.push_back(index);
98  if(0 == theData.size()%10 && 0!=theData.size())
99  {
100  if(0 == theUpper) theUpper = new G4NeutronHPHash();
101  theUpper->SetData(theData.size()-1, x, y);
102  }
103  }
104 
106  {
107  G4int result=-1;
108  if(theData.size() == 0) return 0;
109  if(theData[0].GetX()>e) return 0;
110 
111  G4int lower=0;
112  if(theUpper != 0)
113  {
114  lower = theUpper->GetMinIndex(e);
115  }
116  unsigned int i;
117  for(i=lower; i<theData.size(); i++)
118  {
119  if(theData[i].GetX()>e)
120  {
121  result = theIndex[i-1];
122  break;
123  }
124  }
125  if(result == -1) result = theIndex[theIndex.size()-1];
126  return result;
127  }
128 
129 private:
130 
131  G4bool prepared;
132  G4NeutronHPHash * theUpper;
133  std::vector<int> theIndex;
134  std::vector<G4NeutronHPDataPoint> theData; // the data
135 };
136 #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)
bool G4bool
Definition: G4Types.hh:79
G4NeutronHPHash & operator=(const G4NeutronHPHash &aHash)
G4bool Prepared() const
double G4double
Definition: G4Types.hh:76