global/management/src/G4PhysicsVector.cc

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: G4PhysicsVector.cc,v 1.17 2006/06/29 19:04:25 gunter Exp $
00028 // GEANT4 tag $Name: geant4-09-01-patch-01 $
00029 //
00030 // 
00031 // --------------------------------------------------------------
00032 //      GEANT 4 class implementation file
00033 //
00034 //  G4PhysicsVector.cc
00035 //
00036 //  History:
00037 //    02 Dec. 1995, G.Cosmo : Structure created based on object model
00038 //    03 Mar. 1996, K.Amako : Implemented the 1st version
00039 //    01 Jul. 1996, K.Amako : Hidden bin from the user introduced
00040 //    12 Nov. 1998, K.Amako : A bug in GetVectorLength() fixed
00041 //    11 Nov. 2000, H.Kurashige : use STL vector for dataVector and binVector
00042 //    18 Jan. 2001, H.Kurashige : removed ptrNextTable
00043 //    09 Mar. 2001, H.Kurashige : added G4PhysicsVector type 
00044 // --------------------------------------------------------------
00045 
00046 #include "G4PhysicsVector.hh"
00047 #include <iomanip>
00048 
00049 G4PhysicsVector::G4PhysicsVector()
00050  : type(T_G4PhysicsVector),
00051    edgeMin(0.), edgeMax(0.), numberOfBin(0),
00052    lastEnergy(0.), lastValue(0.), lastBin(0)
00053 {
00054 }
00055 
00056 G4PhysicsVector::~G4PhysicsVector() 
00057 {
00058   dataVector.clear();
00059   binVector.clear();
00060   type = T_G4PhysicsVector;
00061 }
00062 
00063 G4PhysicsVector::G4PhysicsVector(const G4PhysicsVector& right)
00064 {
00065   *this=right;
00066 }
00067 
00068 G4PhysicsVector& G4PhysicsVector::operator=(const G4PhysicsVector& right)
00069 {
00070   if (&right==this)  { return *this; }
00071   if (type != right.type)  { return *this; }
00072 
00073   type = right.type;
00074   edgeMin = right.edgeMin;
00075   edgeMax = right.edgeMax;
00076   numberOfBin = right.numberOfBin;
00077   lastEnergy = right.lastEnergy;
00078   lastValue = right.lastValue;
00079   lastBin = right.lastBin;
00080   dataVector = right.dataVector;
00081   binVector = right.binVector;
00082   comment = right.comment;
00083   return *this;
00084 }
00085 
00086 G4int G4PhysicsVector::operator==(const G4PhysicsVector &right) const
00087 {
00088   return (this == &right);
00089 }
00090 
00091 G4int G4PhysicsVector::operator!=(const G4PhysicsVector &right) const
00092 {
00093   return (this != &right);
00094 }
00095 
00096 G4double G4PhysicsVector::GetLowEdgeEnergy(size_t binNumber) const
00097 {
00098   return binVector[binNumber];
00099 }
00100 
00101 G4bool G4PhysicsVector::Store(std::ofstream& fOut, G4bool ascii)
00102 {
00103   // Ascii mode
00104   if (ascii)
00105   {
00106     fOut << *this;
00107     return true;
00108   } 
00109   // Binary Mode
00110 
00111   // binning
00112   fOut.write((char*)(&edgeMin), sizeof edgeMin);
00113   fOut.write((char*)(&edgeMax), sizeof edgeMax);
00114   fOut.write((char*)(&numberOfBin), sizeof numberOfBin);
00115 
00116   // contents
00117   size_t size = dataVector.size(); 
00118   fOut.write((char*)(&size), sizeof size);
00119 
00120   G4double* value = new G4double[2*size];
00121   for(size_t i = 0; i < size; i++)
00122   {
00123     value[2*i]  =  binVector[i];
00124     value[2*i+1]=  dataVector[i];
00125   }
00126   fOut.write((char*)(value), 2*size*(sizeof (G4double)));
00127   delete [] value;
00128 
00129   return true;
00130 }
00131 
00132 G4bool G4PhysicsVector::Retrieve(std::ifstream& fIn, G4bool ascii)
00133 {
00134   // clear properties;
00135   lastEnergy=0.;
00136   lastValue =0.;
00137   lastBin   =0;
00138   dataVector.clear();
00139   binVector.clear();
00140   comment = "";
00141 
00142   // retrieve in ascii mode
00143   if (ascii)
00144   {
00145     // binning
00146     fIn >> edgeMin >> edgeMax >> numberOfBin; 
00147     if (fIn.fail())  { return false; }
00148     // contents
00149     size_t size=0;
00150     fIn >> size;
00151     if (fIn.fail())  { return false; }
00152 
00153     binVector.reserve(size);
00154     dataVector.reserve(size);
00155     for(size_t i = 0; i < size ; i++)
00156     {
00157       G4double vBin=0., vData=0.;
00158       fIn >> vBin >> vData;
00159       if (fIn.fail())  { return false; }
00160       binVector.push_back(vBin);
00161       dataVector.push_back(vData);
00162     }
00163     return true ;
00164   }
00165 
00166   // retrieve in binary mode
00167   // binning
00168   fIn.read((char*)(&edgeMin), sizeof edgeMin);
00169   fIn.read((char*)(&edgeMax), sizeof edgeMax);
00170   fIn.read((char*)(&numberOfBin), sizeof numberOfBin ); 
00171  
00172   // contents
00173   size_t size;
00174   fIn.read((char*)(&size), sizeof size); 
00175  
00176   G4double* value = new G4double[2*size];
00177   fIn.read((char*)(value),  2*size*(sizeof(G4double)) );
00178   if (G4int(fIn.gcount()) != G4int(2*size*(sizeof(G4double))) ){
00179     delete [] value;
00180     return false;
00181   }
00182 
00183   binVector.reserve(size);
00184   dataVector.reserve(size);
00185   for(size_t i = 0; i < size; i++) {
00186     binVector.push_back(value[2*i]);
00187     dataVector.push_back(value[2*i+1]);
00188   }
00189   delete [] value;
00190   return true;
00191 }
00192     
00193 std::ostream& operator<<(std::ostream& out, const G4PhysicsVector& pv)
00194 {
00195   // binning
00196   out << std::setprecision(12) << pv.edgeMin;
00197   out <<" " << pv.edgeMax <<" "  << pv.numberOfBin << G4endl; 
00198 
00199   // contents
00200   out << pv.dataVector.size() << G4endl; 
00201   for(size_t i = 0; i < pv.dataVector.size(); i++)
00202   {
00203     out << std::setprecision(12) << pv.binVector[i] << "  "
00204         << pv.dataVector[i] << G4endl;
00205   }
00206   return out;
00207 }

Generated on Fri Apr 11 17:09:57 2008 for Geant4 by  doxygen 1.4.7