G4InterpolationManager.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 //
00027 // $Id$
00028 //
00029 #ifndef G4InterpolationManager_h
00030 #define G4InterpolationManager_h 1
00031 
00032 #include "globals.hh"
00033 #include "G4InterpolationScheme.hh"
00034 #include "G4ios.hh"
00035 #include <fstream>
00036 #include "G4HadronicException.hh"
00037 
00038 class G4InterpolationManager
00039 {
00040    public:
00041    
00042    friend class G4InterpolationIterator;
00043    
00044    G4InterpolationManager()
00045    {
00046      nRanges = 1;
00047      start = new G4int[1];
00048      start[0] = 0;
00049      range = new G4int[1];
00050      range [0] = 100000;
00051      scheme = new G4InterpolationScheme[1];
00052      scheme[0] = LINLIN;
00053      nEntries = 0;
00054    }
00055    
00056    ~G4InterpolationManager()
00057    {
00058      if(start!=0) delete [] start;
00059      if(range!=0) delete [] range;
00060      if(scheme!=0) delete [] scheme;
00061    }
00062    
00063    G4InterpolationManager & operator= (const G4InterpolationManager & aManager)
00064    {
00065      if(this != &aManager)
00066      {
00067        nRanges = aManager.nRanges;
00068        nEntries = aManager.nEntries;
00069        if(scheme!=0) delete [] scheme;
00070        if(start!=0) delete [] start;
00071        if(range!=0) delete [] range;
00072        scheme = new G4InterpolationScheme[nRanges];
00073        start = new G4int[nRanges];
00074        range = new G4int[nRanges];
00075        for(G4int i=0; i<nRanges; i++)
00076        {
00077          scheme[i]=aManager.scheme[i];
00078          start[i]=aManager.start[i];
00079          range[i]=aManager.range[i];
00080        }
00081      }
00082      return *this;
00083    }
00084    
00085    inline void Init(G4int aScheme, G4int aRange)
00086    {
00087      nRanges = 1;
00088      start[0] = 0;
00089      range [0] = aRange;
00090      scheme[0] = MakeScheme(aScheme);
00091      nEntries = aRange;
00092    }
00093    inline void Init(G4InterpolationScheme aScheme, G4int aRange)
00094    {
00095      nRanges = 1;
00096      start[0] = 0;
00097      range [0] = aRange;
00098      scheme[0] = aScheme;
00099      nEntries = aRange;
00100    }
00101    
00102    inline void Init(std::ifstream & aDataFile)
00103    {
00104      delete [] start;
00105      delete [] range;
00106      delete [] scheme;
00107      aDataFile >> nRanges;
00108      start = new G4int[nRanges];
00109      range = new G4int[nRanges];
00110      scheme = new G4InterpolationScheme[nRanges];
00111      start[0] = 0;
00112      G4int it;
00113      for(G4int i=0; i<nRanges; i++)
00114      {
00115        aDataFile>>range[i];
00116        //***************************************************************
00117        //EMendoza -> there is a bug here.
00118        /*
00119        if(i!=0) start[i] = start[i-1]+range[i-1];
00120        */
00121        //***************************************************************
00122        if(i!=0) start[i] = range[i-1];
00123        //***************************************************************
00124        aDataFile>>it;
00125        scheme[i] = MakeScheme(it);
00126      }
00127      nEntries = start[nRanges-1]+range[nRanges-1];
00128    }
00129    
00130    G4InterpolationScheme MakeScheme(G4int it);
00131    
00132    inline G4InterpolationScheme GetScheme(G4int index) const
00133    {
00134      G4int it = 0;
00135      for(G4int i=1; i<nRanges; i++)
00136      {
00137        if(index<start[i]) break;
00138        it = i;
00139      }
00140      return scheme[it];
00141    }
00142    
00143    inline void CleanUp()
00144    {
00145      nRanges = 0;
00146      nEntries = 0;
00147    }
00148    
00149    inline G4InterpolationScheme GetInverseScheme(G4int index)
00150    {
00151      G4InterpolationScheme result = GetScheme(index);
00152      if(result == HISTO) 
00153      {
00154        result = RANDOM;
00155      }
00156      else if(result == LINLOG)  
00157      {
00158        result = LOGLIN;
00159      }
00160      else if(result == LOGLIN)  
00161      {
00162        result = LINLOG;
00163      }
00164      else if(result == CHISTO) 
00165      {
00166        result = CRANDOM;
00167      }
00168      else if(result == CLINLOG) 
00169      {
00170        result = CLOGLIN;
00171      }
00172      else if(result == CLOGLIN) 
00173      {
00174        result = CLINLOG;
00175      }
00176      else if(result == UHISTO) 
00177      {
00178        result = URANDOM;
00179      }
00180      else if(result == ULINLOG) 
00181      {
00182        result = ULOGLIN;
00183      }
00184      else if(result == ULOGLIN) 
00185      {
00186        result = ULINLOG;
00187      }
00188      return result;
00189    }
00190    
00191    void AppendScheme(G4int aPoint, const G4InterpolationScheme & aScheme);
00192    
00193    private:
00194    
00195    G4int nRanges;
00196    G4InterpolationScheme * scheme;
00197    G4int * start;
00198    G4int * range;  
00199    G4int nEntries;
00200     
00201 };
00202 #endif

Generated on Mon May 27 17:48:38 2013 for Geant4 by  doxygen 1.4.7