G4NeutronHPHash.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
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; // the data
00135 };
00136 #endif

Generated on Mon May 27 17:49:01 2013 for Geant4 by  doxygen 1.4.7