00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef G4NeutronHPHash_h
00027 #define G4NeutronHPHash_h
00028
00029 #include "globals.hh"
00030 #include <vector>
00031
00032 class G4NeutronHPHash
00033 {
00034 public:
00035 G4NeutronHPHash()
00036 {
00037 theUpper = 0;
00038 prepared = false;
00039 }
00040
00041 ~G4NeutronHPHash()
00042 {
00043 if(theUpper) delete theUpper;
00044 }
00045
00046 G4NeutronHPHash(const G4NeutronHPHash & aHash)
00047 {
00048 theIndex = aHash.theIndex;
00049 theData = aHash.theData;
00050 if(aHash.theUpper != 0)
00051 {
00052 theUpper = new G4NeutronHPHash(*(aHash.theUpper));
00053 }
00054 else
00055 {
00056 theUpper = 0;
00057 }
00058 }
00059
00060 G4NeutronHPHash & operator = (const G4NeutronHPHash & aHash)
00061 {
00062 if(&aHash != this)
00063 {
00064 theIndex = aHash.theIndex;
00065 theData = aHash.theData;
00066 if(aHash.theUpper != 0)
00067 {
00068 theUpper = new G4NeutronHPHash(*(aHash.theUpper));
00069 }
00070 else
00071 {
00072 theUpper = 0;
00073 }
00074 }
00075 return *this;
00076 }
00077
00078 void Clear()
00079 {
00080 if(theUpper)
00081 {
00082 delete theUpper;
00083 theUpper = 0;
00084 }
00085 theIndex.clear();
00086 theData.clear();
00087 prepared = false;
00088 }
00089
00090 G4bool Prepared() const {return prepared;}
00091 inline void SetData(G4int index, G4double x, G4double y)
00092 {
00093 prepared = true;
00094 G4NeutronHPDataPoint aPoint;
00095 aPoint.SetData(x, y);
00096 theData.push_back(aPoint);
00097 theIndex.push_back(index);
00098 if(0 == theData.size()%10 && 0!=theData.size())
00099 {
00100 if(0 == theUpper) theUpper = new G4NeutronHPHash();
00101 theUpper->SetData(theData.size()-1, x, y);
00102 }
00103 }
00104
00105 G4int GetMinIndex(G4double e) const
00106 {
00107 G4int result=-1;
00108 if(theData.size() == 0) return 0;
00109 if(theData[0].GetX()>e) return 0;
00110
00111 G4int lower=0;
00112 if(theUpper != 0)
00113 {
00114 lower = theUpper->GetMinIndex(e);
00115 }
00116 unsigned int i;
00117 for(i=lower; i<theData.size(); i++)
00118 {
00119 if(theData[i].GetX()>e)
00120 {
00121 result = theIndex[i-1];
00122 break;
00123 }
00124 }
00125 if(result == -1) result = theIndex[theIndex.size()-1];
00126 return result;
00127 }
00128
00129 private:
00130
00131 G4bool prepared;
00132 G4NeutronHPHash * theUpper;
00133 std::vector<int> theIndex;
00134 std::vector<G4NeutronHPDataPoint> theData;
00135 };
00136 #endif