Index: trunk/source/processes/electromagnetic/utils/include/G4LossTableManager.hh
===================================================================
--- trunk/source/processes/electromagnetic/utils/include/G4LossTableManager.hh	(revision 1228)
+++ trunk/source/processes/electromagnetic/utils/include/G4LossTableManager.hh	(revision 1315)
@@ -24,6 +24,6 @@
 // ********************************************************************
 //
-// $Id: G4LossTableManager.hh,v 1.55 2009/10/29 19:25:28 vnivanch Exp $
-// GEANT4 tag $Name: geant4-09-03 $
+// $Id: G4LossTableManager.hh,v 1.58 2010/04/27 16:59:52 vnivanch Exp $
+// GEANT4 tag $Name: geant4-09-04-beta-cand-01 $
 //
 //
@@ -61,4 +61,5 @@
 // 12-02-07 Add SetSkin, SetLinearLossLimit (V.Ivanchenko)
 // 18-06-07 Move definition of msc parameters to G4EmProcessOptions (V.Ivanchenko)
+// 12-04-10 Added PreparePhsyicsTables and BuildPhysicsTables entries (V.Ivanchenko)
 //
 // Class Description:
@@ -93,4 +94,5 @@
 class G4EmConfigurator;
 class G4LossTableBuilder;
+class G4Region;
 
 class G4LossTableManager
@@ -103,7 +105,29 @@
   ~G4LossTableManager();
 
+  //-------------------------------------------------
+  // called from destructor
+  //-------------------------------------------------
+
   void Clear();
 
-  // get the DEDX or the range for a given particle/energy/material
+  //-------------------------------------------------
+  // initialisation before a new run
+  //-------------------------------------------------
+
+  void PreparePhysicsTable(const G4ParticleDefinition* aParticle,
+			   G4VEnergyLossProcess* p);
+  void PreparePhysicsTable(const G4ParticleDefinition* aParticle,
+			   G4VEmProcess* p);
+  void PreparePhysicsTable(const G4ParticleDefinition* aParticle,
+			   G4VMultipleScattering* p);
+  void BuildPhysicsTable(const G4ParticleDefinition* aParticle);
+  void BuildPhysicsTable(const G4ParticleDefinition* aParticle, 
+			 G4VEnergyLossProcess* p);
+
+  //-------------------------------------------------
+  // Run time access to DEDX, range, energy for a given particle, 
+  // energy, and G4MaterialCutsCouple
+  //-------------------------------------------------
+
   inline G4double GetDEDX(
     const G4ParticleDefinition *aParticle,
@@ -141,5 +165,8 @@
           G4double& length);
 
-  // to be called only by energy loss processes
+  //-------------------------------------------------
+  // Methods to be called only at initialisation
+  //-------------------------------------------------
+
   void Register(G4VEnergyLossProcess* p);
 
@@ -162,7 +189,4 @@
   void DeRegister(G4VEmFluctuationModel* p);
 
-  void EnergyLossProcessIsInitialised(const G4ParticleDefinition* aParticle, 
-				      G4VEnergyLossProcess* p);
-  
   void RegisterIon(const G4ParticleDefinition* aParticle, 
 		   G4VEnergyLossProcess* p);
@@ -171,10 +195,7 @@
 			     G4VEnergyLossProcess* p);
 
-  void BuildPhysicsTable(const G4ParticleDefinition* aParticle, 
-			 G4VEnergyLossProcess* p);
-
   void SetLossFluctuations(G4bool val);
 
-  void SetSubCutoff(G4bool val);
+  void SetSubCutoff(G4bool val, const G4Region* r=0);
 
   void SetIntegral(G4bool val);
@@ -198,4 +219,6 @@
   void SetLambdaBinning(G4int val);
 
+  G4int GetNumberOfBinsPerDecade() const;
+
   void SetStepFunction(G4double v1, G4double v2);
 
@@ -214,4 +237,8 @@
   void SetVerbose(G4int val);
 
+  //-------------------------------------------------
+  // Access methods
+  //-------------------------------------------------
+
   G4EnergyLossMessenger* GetMessenger();
 
@@ -241,4 +268,8 @@
 
 private:
+
+  //-------------------------------------------------
+  // Private methods and members
+  //-------------------------------------------------
 
   G4LossTableManager();
@@ -251,13 +282,13 @@
   void ParticleHaveNoLoss(const G4ParticleDefinition* aParticle);
 
-  void SetParameters(G4VEnergyLossProcess*);
+  void SetParameters(const G4ParticleDefinition* aParticle,
+		     G4VEnergyLossProcess*);
 
   void CopyDEDXTables();
 
-private:
-
   static G4LossTableManager* theInstance;
 
   typedef const G4ParticleDefinition* PD;
+
   std::map<PD,G4VEnergyLossProcess*,std::less<PD> > loss_map;
 
@@ -279,4 +310,5 @@
   PD                    currentParticle;
   PD                    theElectron;
+  PD                    firstParticle;
 
   G4int n_loss;
@@ -284,5 +316,6 @@
 
   G4bool all_tables_are_built;
-  //  G4bool first_entry;
+  G4bool startInitialisation;
+
   G4bool lossFluctuationFlag;
   G4bool subCutoffFlag;
@@ -290,5 +323,4 @@
   G4bool integral;
   G4bool integralActive;
-  G4bool all_tables_are_stored;
   G4bool buildCSDARange;
   G4bool minEnergyActive;
@@ -314,5 +346,6 @@
   G4EmConfigurator*           emConfigurator;
 
-  const G4ParticleDefinition* firstParticle;
+  G4int nbinsLambda;
+  G4int nbinsPerDecade;
   G4int verbose;
 
@@ -322,4 +355,22 @@
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.....
 
+inline G4VEnergyLossProcess* G4LossTableManager::GetEnergyLossProcess(
+          const G4ParticleDefinition *aParticle)
+{
+  if(aParticle != currentParticle) {
+    currentParticle = aParticle;
+    std::map<PD,G4VEnergyLossProcess*,std::less<PD> >::const_iterator pos;
+    if ((pos = loss_map.find(aParticle)) != loss_map.end()) {
+      currentLoss = (*pos).second;
+    } else {
+      currentLoss = 0;
+     // ParticleHaveNoLoss(aParticle);
+    }
+  }
+  return currentLoss;
+}
+
+//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
+
 inline G4double G4LossTableManager::GetDEDX(
           const G4ParticleDefinition *aParticle,
@@ -327,9 +378,9 @@
           const G4MaterialCutsCouple *couple)
 {
-  if(aParticle != currentParticle) GetEnergyLossProcess(aParticle);
+  if(aParticle != currentParticle) { GetEnergyLossProcess(aParticle); }
   G4double x;
-  if(currentLoss) x = currentLoss->GetDEDX(kineticEnergy, couple);
-  else            x = G4EnergyLossTables::GetDEDX(
-                      currentParticle,kineticEnergy,couple,false);
+  if(currentLoss) { x = currentLoss->GetDEDX(kineticEnergy, couple); }
+  else            { x = G4EnergyLossTables::GetDEDX(currentParticle,
+						    kineticEnergy,couple,false); }
   return x;
 }
@@ -342,7 +393,7 @@
           const G4MaterialCutsCouple *couple)
 {
-  if(aParticle != currentParticle) GetEnergyLossProcess(aParticle);
+  if(aParticle != currentParticle) { GetEnergyLossProcess(aParticle); }
   G4double x = 0.0;
-  if(currentLoss) x = currentLoss->GetDEDXForSubsec(kineticEnergy, couple);
+  if(currentLoss) { x = currentLoss->GetDEDXForSubsec(kineticEnergy, couple); }
   return x;
 }
@@ -355,7 +406,7 @@
           const G4MaterialCutsCouple *couple)
 {
-  if(aParticle != currentParticle) GetEnergyLossProcess(aParticle);
+  if(aParticle != currentParticle) { GetEnergyLossProcess(aParticle); }
   G4double x = DBL_MAX;
-  if(currentLoss) x = currentLoss->GetCSDARange(kineticEnergy, couple);
+  if(currentLoss) { x = currentLoss->GetCSDARange(kineticEnergy, couple); }
   return x;
 }
@@ -368,9 +419,9 @@
           const G4MaterialCutsCouple *couple)
 {
-  if(aParticle != currentParticle) GetEnergyLossProcess(aParticle);
+  if(aParticle != currentParticle) { GetEnergyLossProcess(aParticle); }
   G4double x;
-  if(currentLoss) x = currentLoss->GetRangeForLoss(kineticEnergy, couple);
-  else    
-    x = G4EnergyLossTables::GetRange(currentParticle,kineticEnergy,couple,false);
+  if(currentLoss) { x = currentLoss->GetRangeForLoss(kineticEnergy, couple); }
+  else { x = G4EnergyLossTables::GetRange(currentParticle,kineticEnergy,
+					  couple,false); }
   return x;
 }
@@ -383,9 +434,9 @@
           const G4MaterialCutsCouple *couple)
 {
-  if(aParticle != currentParticle) GetEnergyLossProcess(aParticle);
+  if(aParticle != currentParticle) { GetEnergyLossProcess(aParticle); }
   G4double x;
-  if(currentLoss) x = currentLoss->GetRange(kineticEnergy, couple);
-  else    
-    x = G4EnergyLossTables::GetRange(currentParticle,kineticEnergy,couple,false);
+  if(currentLoss) { x = currentLoss->GetRange(kineticEnergy, couple); }
+  else { x = G4EnergyLossTables::GetRange(currentParticle,kineticEnergy,
+					  couple,false); }
   return x;
 }
@@ -398,9 +449,9 @@
           const G4MaterialCutsCouple *couple)
 {
-  if(aParticle != currentParticle) GetEnergyLossProcess(aParticle);
+  if(aParticle != currentParticle) { GetEnergyLossProcess(aParticle); }
   G4double x;
-  if(currentLoss) x = currentLoss->GetKineticEnergy(range, couple);
-  else            x = G4EnergyLossTables::GetPreciseEnergyFromRange(
-                      currentParticle,range,couple,false);
+  if(currentLoss) { x = currentLoss->GetKineticEnergy(range, couple); }
+  else { x = G4EnergyLossTables::GetPreciseEnergyFromRange(currentParticle,range,
+							   couple,false); }
   return x;
 }
@@ -428,22 +479,4 @@
 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
 
-inline G4VEnergyLossProcess* G4LossTableManager::GetEnergyLossProcess(
-          const G4ParticleDefinition *aParticle)
-{
-  if(aParticle != currentParticle) {
-    currentParticle = aParticle;
-    std::map<PD,G4VEnergyLossProcess*,std::less<PD> >::const_iterator pos;
-    if ((pos = loss_map.find(aParticle)) != loss_map.end()) {
-      currentLoss = (*pos).second;
-    } else {
-      currentLoss = 0;
-     // ParticleHaveNoLoss(aParticle);
-    }
-  }
-  return currentLoss;
-}
-
-//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
-
 #endif
 
