source: trunk/source/global/management/src/G4PhysicsVector.cc@ 833

Last change on this file since 833 was 833, checked in by garnier, 17 years ago

import all except CVS

File size: 6.0 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// $Id: G4PhysicsVector.cc,v 1.17 2006/06/29 19:04:25 gunter Exp $
28// GEANT4 tag $Name: geant4-09-01-patch-02 $
29//
30//
31// --------------------------------------------------------------
32// GEANT 4 class implementation file
33//
34// G4PhysicsVector.cc
35//
36// History:
37// 02 Dec. 1995, G.Cosmo : Structure created based on object model
38// 03 Mar. 1996, K.Amako : Implemented the 1st version
39// 01 Jul. 1996, K.Amako : Hidden bin from the user introduced
40// 12 Nov. 1998, K.Amako : A bug in GetVectorLength() fixed
41// 11 Nov. 2000, H.Kurashige : use STL vector for dataVector and binVector
42// 18 Jan. 2001, H.Kurashige : removed ptrNextTable
43// 09 Mar. 2001, H.Kurashige : added G4PhysicsVector type
44// --------------------------------------------------------------
45
46#include "G4PhysicsVector.hh"
47#include <iomanip>
48
49G4PhysicsVector::G4PhysicsVector()
50 : type(T_G4PhysicsVector),
51 edgeMin(0.), edgeMax(0.), numberOfBin(0),
52 lastEnergy(0.), lastValue(0.), lastBin(0)
53{
54}
55
56G4PhysicsVector::~G4PhysicsVector()
57{
58 dataVector.clear();
59 binVector.clear();
60 type = T_G4PhysicsVector;
61}
62
63G4PhysicsVector::G4PhysicsVector(const G4PhysicsVector& right)
64{
65 *this=right;
66}
67
68G4PhysicsVector& G4PhysicsVector::operator=(const G4PhysicsVector& right)
69{
70 if (&right==this) { return *this; }
71 if (type != right.type) { return *this; }
72
73 type = right.type;
74 edgeMin = right.edgeMin;
75 edgeMax = right.edgeMax;
76 numberOfBin = right.numberOfBin;
77 lastEnergy = right.lastEnergy;
78 lastValue = right.lastValue;
79 lastBin = right.lastBin;
80 dataVector = right.dataVector;
81 binVector = right.binVector;
82 comment = right.comment;
83 return *this;
84}
85
86G4int G4PhysicsVector::operator==(const G4PhysicsVector &right) const
87{
88 return (this == &right);
89}
90
91G4int G4PhysicsVector::operator!=(const G4PhysicsVector &right) const
92{
93 return (this != &right);
94}
95
96G4double G4PhysicsVector::GetLowEdgeEnergy(size_t binNumber) const
97{
98 return binVector[binNumber];
99}
100
101G4bool G4PhysicsVector::Store(std::ofstream& fOut, G4bool ascii)
102{
103 // Ascii mode
104 if (ascii)
105 {
106 fOut << *this;
107 return true;
108 }
109 // Binary Mode
110
111 // binning
112 fOut.write((char*)(&edgeMin), sizeof edgeMin);
113 fOut.write((char*)(&edgeMax), sizeof edgeMax);
114 fOut.write((char*)(&numberOfBin), sizeof numberOfBin);
115
116 // contents
117 size_t size = dataVector.size();
118 fOut.write((char*)(&size), sizeof size);
119
120 G4double* value = new G4double[2*size];
121 for(size_t i = 0; i < size; i++)
122 {
123 value[2*i] = binVector[i];
124 value[2*i+1]= dataVector[i];
125 }
126 fOut.write((char*)(value), 2*size*(sizeof (G4double)));
127 delete [] value;
128
129 return true;
130}
131
132G4bool G4PhysicsVector::Retrieve(std::ifstream& fIn, G4bool ascii)
133{
134 // clear properties;
135 lastEnergy=0.;
136 lastValue =0.;
137 lastBin =0;
138 dataVector.clear();
139 binVector.clear();
140 comment = "";
141
142 // retrieve in ascii mode
143 if (ascii)
144 {
145 // binning
146 fIn >> edgeMin >> edgeMax >> numberOfBin;
147 if (fIn.fail()) { return false; }
148 // contents
149 size_t size=0;
150 fIn >> size;
151 if (fIn.fail()) { return false; }
152
153 binVector.reserve(size);
154 dataVector.reserve(size);
155 for(size_t i = 0; i < size ; i++)
156 {
157 G4double vBin=0., vData=0.;
158 fIn >> vBin >> vData;
159 if (fIn.fail()) { return false; }
160 binVector.push_back(vBin);
161 dataVector.push_back(vData);
162 }
163 return true ;
164 }
165
166 // retrieve in binary mode
167 // binning
168 fIn.read((char*)(&edgeMin), sizeof edgeMin);
169 fIn.read((char*)(&edgeMax), sizeof edgeMax);
170 fIn.read((char*)(&numberOfBin), sizeof numberOfBin );
171
172 // contents
173 size_t size;
174 fIn.read((char*)(&size), sizeof size);
175
176 G4double* value = new G4double[2*size];
177 fIn.read((char*)(value), 2*size*(sizeof(G4double)) );
178 if (G4int(fIn.gcount()) != G4int(2*size*(sizeof(G4double))) ){
179 delete [] value;
180 return false;
181 }
182
183 binVector.reserve(size);
184 dataVector.reserve(size);
185 for(size_t i = 0; i < size; i++) {
186 binVector.push_back(value[2*i]);
187 dataVector.push_back(value[2*i+1]);
188 }
189 delete [] value;
190 return true;
191}
192
193std::ostream& operator<<(std::ostream& out, const G4PhysicsVector& pv)
194{
195 // binning
196 out << std::setprecision(12) << pv.edgeMin;
197 out <<" " << pv.edgeMax <<" " << pv.numberOfBin << G4endl;
198
199 // contents
200 out << pv.dataVector.size() << G4endl;
201 for(size_t i = 0; i < pv.dataVector.size(); i++)
202 {
203 out << std::setprecision(12) << pv.binVector[i] << " "
204 << pv.dataVector[i] << G4endl;
205 }
206 return out;
207}
Note: See TracBrowser for help on using the repository browser.