Index: trunk/source/processes/hadronic/models/cascade/cascade/include/G4CascadeData.hh
===================================================================
--- trunk/source/processes/hadronic/models/cascade/cascade/include/G4CascadeData.hh	(revision 967)
+++ trunk/source/processes/hadronic/models/cascade/cascade/include/G4CascadeData.hh	(revision 967)
@@ -0,0 +1,107 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+#ifndef G4_CASCADE_DATA_HH
+#define G4_CASCADE_DATA_HH
+
+#include "globals.hh"
+
+template <int n2, int n3, int n4, int n5, int n6, int n7, int nxs>
+struct G4CascadeData
+{
+  G4double *  tot;
+
+  typedef G4double multiplicities_t[31];
+  multiplicities_t * multiplicities;
+
+  typedef G4int index_t[2];
+  index_t const * index;
+
+  typedef G4int x2bfs_t[2];
+  x2bfs_t const * x2bfs;
+
+  typedef G4int x3bfs_t[3];
+  x3bfs_t const * x3bfs;
+
+  typedef G4int x4bfs_t[4];
+  x4bfs_t const * x4bfs;
+
+  typedef G4int x5bfs_t[5];
+  x5bfs_t const * x5bfs;
+
+  typedef G4int x6bfs_t[6];
+  x6bfs_t const * x6bfs;
+
+  typedef G4int x7bfs_t[7];
+  x7bfs_t const * x7bfs;
+
+  typedef G4float crossSections_t[31];
+  crossSections_t const * crossSections;
+
+  void initialize();
+
+//   G4double tot[31];
+//   G4double multiplicities[6][31];
+
+//   G4int index[6][2];
+//   G4int x2bfs[n2][2];
+//   G4int x3bfs[n3][3];
+//   G4int x4bfs[n4][4];
+//   G4int x5bfs[n5][5];
+//   G4int x6bfs[n6][6];
+//   G4int x7bfs[n7][7];
+
+//   G4float crossSections[nxs][31];
+};
+
+template <int n2, int n3, int n4, int n5, int n6, int n7, int nxs>
+inline
+void
+G4CascadeData<n2, n3, n4, n5, n6, n7, nxs>::initialize()
+{
+  // Initialize multiplicity array
+  
+  for (G4int m = 0; m < 6; m++) {
+    G4int start = index[m][0];
+    G4int stop = index[m][1];
+    for (G4int k = 0; k < 31; k++) {
+      multiplicities[m][k] = 0.0;
+      for (G4int i = start; i < stop; i++) {
+ 	multiplicities[m][k] += crossSections[i][k];
+      }
+    }
+  }
+  
+  // Initialize total cross section array
+  
+  for (G4int k = 0; k < 31; k++) {
+    tot[k] = 0.0;
+    for (G4int m = 0; m < 6; m++) {
+      tot[k] += multiplicities[m][k];
+    }
+  }
+}
+
+#endif
Index: trunk/source/processes/hadronic/models/cascade/cascade/include/G4CascadeFunctions.hh
===================================================================
--- trunk/source/processes/hadronic/models/cascade/cascade/include/G4CascadeFunctions.hh	(revision 967)
+++ trunk/source/processes/hadronic/models/cascade/cascade/include/G4CascadeFunctions.hh	(revision 967)
@@ -0,0 +1,121 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+#ifndef G4_CASCADE_FUNCTIONS_HH
+#define G4_CASCADE_FUNCTIONS_HH
+
+#include <vector>
+#include "globals.hh"
+#include "G4CascadeChannel.hh"
+
+template <class T>
+class G4CascadeFunctions
+{
+public:
+  static G4double getCrossSection(double ke);
+  static G4int getMultiplicity(G4double ke);
+  static std::vector<G4int> getOutgoingParticleTypes(G4int mult, G4double ke);
+};
+
+template <class T>
+inline
+G4double 
+G4CascadeFunctions<T>::getCrossSection(double ke)
+{
+  std::pair<G4int, G4double> epair = G4CascadeChannel::interpolateEnergy(ke);
+  G4int k = epair.first;
+  G4double fraction = epair.second;
+  return T::data.tot[k] + fraction*(T::data.tot[k+1] - T::data.tot[k]);
+}
+
+template <class T>
+inline
+G4int 
+G4CascadeFunctions<T>::getMultiplicity(G4double ke)
+{
+  G4double multint(0.0);
+  std::vector<G4double> sigma;
+
+  std::pair<G4int, G4double> epair = G4CascadeChannel::interpolateEnergy(ke);
+  G4int k = epair.first;
+  G4double fraction = epair.second;
+
+  for (G4int m = 0; m < 6; ++m)
+    {
+      multint = T::data.multiplicities[m][k]
+	+ fraction * (T::data.multiplicities[m][k+1] - T::data.multiplicities[m][k]);
+      sigma.push_back(multint);
+    }
+  
+  return G4CascadeChannel::sampleFlat(sigma);
+}
+
+template <class T>
+inline
+std::vector<G4int> 
+G4CascadeFunctions<T>::getOutgoingParticleTypes(G4int mult, G4double ke)
+{
+  G4int i;
+  G4double sigint(0.);
+  std::vector<G4double> sigma;
+  
+  std::pair<G4int, G4double> epair = G4CascadeChannel::interpolateEnergy(ke);
+  G4int k = epair.first;
+  G4double fraction = epair.second;
+
+  G4int start = T::data.index[mult-2][0];
+  G4int stop = T::data.index[mult-2][1];
+ 
+  for (i = start; i < stop; i++) {
+    sigint = T::data.crossSections[i][k] 
+      + fraction*(T::data.crossSections[i][k+1] - T::data.crossSections[i][k]);
+    sigma.push_back(sigint);
+  }
+ 
+  G4int channel = G4CascadeChannel::sampleFlat(sigma);
+
+  std::vector<G4int> kinds;
+
+  if (mult == 2) {
+    for(i = 0; i < mult; i++) kinds.push_back(T::data.x2bfs[channel][i]);
+  } else if (mult == 3) {
+    for(i = 0; i < mult; i++) kinds.push_back(T::data.x3bfs[channel][i]);
+  } else if (mult == 4) {
+    for(i = 0; i < mult; i++) kinds.push_back(T::data.x4bfs[channel][i]);
+  } else if (mult == 5) {
+    for(i = 0; i < mult; i++) kinds.push_back(T::data.x5bfs[channel][i]);
+  } else if (mult == 6) {
+    for(i = 0; i < mult; i++) kinds.push_back(T::data.x6bfs[channel][i]);
+  } else if (mult == 7) {
+    for(i = 0; i < mult; i++) kinds.push_back(T::data.x7bfs[channel][i]);
+  } else {
+    G4cout << " Illegal multiplicity " << G4endl;
+  }
+
+  return kinds;
+}
+
+
+#endif
Index: trunk/source/processes/hadronic/models/cascade/cascade/include/G4CascadeMomentum.hh
===================================================================
--- trunk/source/processes/hadronic/models/cascade/cascade/include/G4CascadeMomentum.hh	(revision 967)
+++ trunk/source/processes/hadronic/models/cascade/cascade/include/G4CascadeMomentum.hh	(revision 967)
@@ -0,0 +1,69 @@
+//
+// ********************************************************************
+// * License and Disclaimer                                           *
+// *                                                                  *
+// * The  Geant4 software  is  copyright of the Copyright Holders  of *
+// * the Geant4 Collaboration.  It is provided  under  the terms  and *
+// * conditions of the Geant4 Software License,  included in the file *
+// * LICENSE and available at  http://cern.ch/geant4/license .  These *
+// * include a list of copyright holders.                             *
+// *                                                                  *
+// * Neither the authors of this software system, nor their employing *
+// * institutes,nor the agencies providing financial support for this *
+// * work  make  any representation or  warranty, express or implied, *
+// * regarding  this  software system or assume any liability for its *
+// * use.  Please see the license in the file  LICENSE  and URL above *
+// * for the full disclaimer and the limitation of liability.         *
+// *                                                                  *
+// * This  code  implementation is the result of  the  scientific and *
+// * technical work of the GEANT4 collaboration.                      *
+// * By using,  copying,  modifying or  distributing the software (or *
+// * any work based  on the software)  you  agree  to acknowledge its *
+// * use  in  resulting  scientific  publications,  and indicate your *
+// * acceptance of all terms of the Geant4 Software license.          *
+// ********************************************************************
+//
+// $Id: G4CascadeMomentum.hh,v 1.1 2008/09/22 10:06:32 gcosmo Exp $
+// GEANT4 tag $Name: geant4-09-02-ref-02 $
+//
+//
+// Class G4CascadeMomentum
+//
+// Class description:
+//
+// A simple wrapper class meant to replace the widespread use of
+// std::vector<double> in the cascade mode code, which causes
+// problems for performance due to excess memory allocations.
+
+// Author: Peter Elmer, Princeton University                  7-Aug-2008
+// --------------------------------------------------------------------
+#ifndef G4CASCADE_MOMENTUM_HH
+#define G4CASCADE_MOMENTUM_HH
+
+#include <cassert>
+
+#include "G4Types.hh"
+
+class G4CascadeMomentum
+{
+  public:
+
+    G4CascadeMomentum() {for (int i=0; i<4; ++i) data_[i]=0.0;}
+
+    G4double& operator[](int i)
+    {
+      assert(i>=0 && i<4);
+      return data_[i];
+    }
+    const G4double& operator[](int i) const
+    {
+      assert(i>=0 && i<4);
+      return data_[i];
+    }
+
+  private:
+
+    G4double data_[4];
+};
+#endif
+
