source: trunk/source/processes/hadronic/models/neutron_hp/include/G4NeutronHPHash.hh @ 1337

Last change on this file since 1337 was 819, checked in by garnier, 16 years ago

import all except CVS

File size: 3.7 KB
Line 
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
32class G4NeutronHPHash
33{
34public:
35  G4NeutronHPHash() 
36  {
37    theUpper = 0;
38    prepared = false;
39  }
40 
41  ~G4NeutronHPHash()
42  {
43    if(theUpper) delete theUpper;
44  }
45 
46  G4NeutronHPHash(const G4NeutronHPHash & aHash)
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 
60  G4NeutronHPHash & operator = (const G4NeutronHPHash & aHash)
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   
105  G4int GetMinIndex(G4double e) const
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 
129private:
130
131  G4bool prepared;
132  G4NeutronHPHash * theUpper;
133  std::vector<int> theIndex;
134  std::vector<G4NeutronHPDataPoint> theData; // the data
135};
136#endif
Note: See TracBrowser for help on using the repository browser.