Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4PhysicsTable Class Reference

#include <G4PhysicsTable.hh>

+ Inheritance diagram for G4PhysicsTable:

Public Member Functions

 G4PhysicsTable ()=default
 
 G4PhysicsTable (size_t cap)
 
virtual ~G4PhysicsTable ()
 
 G4PhysicsTable (const G4PhysicsTable &)=delete
 
G4PhysicsTableoperator= (const G4PhysicsTable &)=delete
 
G4PhysicsVector *& operator() (std::size_t)
 
G4PhysicsVector *const & operator() (std::size_t) const
 
void clearAndDestroy ()
 
void push_back (G4PhysicsVector *)
 
void insert (G4PhysicsVector *)
 
void insertAt (std::size_t, G4PhysicsVector *)
 
void resize (std::size_t, G4PhysicsVector *vec=nullptr)
 
std::size_t entries () const
 
std::size_t length () const
 
G4bool isEmpty () const
 
G4bool ExistPhysicsTable (const G4String &fileName) const
 
G4bool StorePhysicsTable (const G4String &filename, G4bool ascii=false)
 
G4bool RetrievePhysicsTable (const G4String &filename, G4bool ascii=false, G4bool spline=false)
 
void ResetFlagArray ()
 
G4bool GetFlag (std::size_t i) const
 
void ClearFlag (std::size_t i)
 

Protected Member Functions

G4PhysicsVectorCreatePhysicsVector (G4int type, G4bool spline)
 

Protected Attributes

G4FlagCollection vecFlag
 

Friends

std::ostream & operator<< (std::ostream &out, G4PhysicsTable &table)
 

Detailed Description

Definition at line 55 of file G4PhysicsTable.hh.

Constructor & Destructor Documentation

◆ G4PhysicsTable() [1/3]

G4PhysicsTable::G4PhysicsTable ( )
default

◆ G4PhysicsTable() [2/3]

G4PhysicsTable::G4PhysicsTable ( size_t  cap)
explicit

◆ ~G4PhysicsTable()

G4PhysicsTable::~G4PhysicsTable ( )
virtual

Definition at line 54 of file G4PhysicsTable.cc.

55{
56 G4PhysCollection::clear();
57 vecFlag.clear();
58}
G4FlagCollection vecFlag

◆ G4PhysicsTable() [3/3]

G4PhysicsTable::G4PhysicsTable ( const G4PhysicsTable )
delete

Member Function Documentation

◆ clearAndDestroy()

◆ ClearFlag()

◆ CreatePhysicsVector()

G4PhysicsVector * G4PhysicsTable::CreatePhysicsVector ( G4int  type,
G4bool  spline 
)
protected

Definition at line 263 of file G4PhysicsTable.cc.

264{
265 G4PhysicsVector* pVector = nullptr;
266 switch(type)
267 {
269 pVector = new G4PhysicsLinearVector(spline);
270 break;
271
273 pVector = new G4PhysicsLogVector(spline);
274 break;
275
276 default:
277 pVector = new G4PhysicsVector(spline);
278 break;
279 }
280 return pVector;
281}
@ T_G4PhysicsLinearVector
@ T_G4PhysicsLogVector

Referenced by RetrievePhysicsTable().

◆ entries()

◆ ExistPhysicsTable()

G4bool G4PhysicsTable::ExistPhysicsTable ( const G4String fileName) const

Definition at line 123 of file G4PhysicsTable.cc.

124{
125 std::ifstream fIn;
126 G4bool value = true;
127 // open input file
128 fIn.open(fileName, std::ios::in);
129
130 // check if the file has been opened successfully
131 if(!fIn)
132 {
133 value = false;
134 }
135 fIn.close();
136 return value;
137}
bool G4bool
Definition: G4Types.hh:86

◆ GetFlag()

G4bool G4PhysicsTable::GetFlag ( std::size_t  i) const

◆ insert()

void G4PhysicsTable::insert ( G4PhysicsVector )

◆ insertAt()

◆ isEmpty()

G4bool G4PhysicsTable::isEmpty ( ) const

◆ length()

std::size_t G4PhysicsTable::length ( ) const

◆ operator()() [1/2]

G4PhysicsVector *& G4PhysicsTable::operator() ( std::size_t  )

◆ operator()() [2/2]

G4PhysicsVector *const & G4PhysicsTable::operator() ( std::size_t  ) const

◆ operator=()

G4PhysicsTable & G4PhysicsTable::operator= ( const G4PhysicsTable )
delete

◆ push_back()

◆ ResetFlagArray()

void G4PhysicsTable::ResetFlagArray ( )

Definition at line 252 of file G4PhysicsTable.cc.

253{
254 size_t tableSize = G4PhysCollection::size();
255 vecFlag.clear();
256 for(std::size_t idx = 0; idx < tableSize; ++idx)
257 {
258 vecFlag.push_back(true);
259 }
260}

Referenced by G4PhysicsTableHelper::PreparePhysicsTable().

◆ resize()

void G4PhysicsTable::resize ( std::size_t  siz,
G4PhysicsVector vec = nullptr 
)

Definition at line 61 of file G4PhysicsTable.cc.

62{
63 G4PhysCollection::resize(siz, vec);
64 vecFlag.resize(siz, true);
65}

Referenced by G4NeutronGeneralProcess::PreparePhysicsTable(), and G4PhysicsTableHelper::PreparePhysicsTable().

◆ RetrievePhysicsTable()

G4bool G4PhysicsTable::RetrievePhysicsTable ( const G4String filename,
G4bool  ascii = false,
G4bool  spline = false 
)

Definition at line 140 of file G4PhysicsTable.cc.

142{
143 std::ifstream fIn;
144 // open input file
145 if(ascii)
146 {
147 fIn.open(fileName, std::ios::in | std::ios::binary);
148 }
149 else
150 {
151 fIn.open(fileName, std::ios::in);
152 }
153
154 // check if the file has been opened successfully
155 if(!fIn.is_open())
156 {
157#ifdef G4VERBOSE
158 G4cerr << "G4PhysicsTable::RetrievePhysicsTable():";
159 G4cerr << " Cannot open file: " << fileName << G4endl;
160#endif
161 fIn.close();
162 return false;
163 }
164
165 // clear
167
168 // Number of elements
169 std::size_t tableSize = 0;
170 if(!ascii)
171 {
172 fIn.read((char*) (&tableSize), sizeof tableSize);
173 }
174 else
175 {
176 fIn >> tableSize;
177 }
178 reserve(tableSize);
179 vecFlag.clear();
180
181 // Physics Vector
182 for(std::size_t idx = 0; idx < tableSize; ++idx)
183 {
184 G4int vType = 0;
185 if(!ascii)
186 {
187 fIn.read((char*) (&vType), sizeof vType);
188 }
189 else
190 {
191 fIn >> vType;
192 }
193 G4PhysicsVector* pVec = CreatePhysicsVector(vType, spline);
194 if(pVec == nullptr)
195 {
196#ifdef G4VERBOSE
197 G4cerr << "G4PhysicsTable::RetrievePhysicsTable():";
198 G4cerr << " Illegal Physics Vector type: " << vType << " in: ";
199 G4cerr << fileName << G4endl;
200#endif
201 fIn.close();
202 return false;
203 }
204
205 if(!(pVec->Retrieve(fIn, ascii)))
206 {
207#ifdef G4VERBOSE
208 G4cerr << "G4PhysicsTable::RetrievePhysicsTable():";
209 G4cerr << " Rrror in retreiving " << idx
210 << "-th Physics Vector from file: ";
211 G4cerr << fileName << G4endl;
212#endif
213 fIn.close();
214 return false;
215 }
216
217 // add a PhysicsVector to this PhysicsTable
218 G4PhysCollection::push_back(pVec);
219 vecFlag.push_back(true);
220 }
221 fIn.close();
222 return true;
223}
int G4int
Definition: G4Types.hh:85
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
void clearAndDestroy()
G4PhysicsVector * CreatePhysicsVector(G4int type, G4bool spline)
G4bool Retrieve(std::ifstream &fIn, G4bool ascii=false)

Referenced by G4DNABornExcitationModel2::Initialise(), and G4PhysicsTableHelper::RetrievePhysicsTable().

◆ StorePhysicsTable()

G4bool G4PhysicsTable::StorePhysicsTable ( const G4String filename,
G4bool  ascii = false 
)

Definition at line 68 of file G4PhysicsTable.cc.

69{
70 std::ofstream fOut;
71
72 // open output file
73 if(!ascii)
74 {
75 fOut.open(fileName, std::ios::out | std::ios::binary);
76 }
77 else
78 {
79 fOut.open(fileName, std::ios::out);
80 }
81
82 // check if the file has been opened successfully
83 if(!fOut.is_open())
84 {
85#ifdef G4VERBOSE
86 G4cerr << "G4PhysicsTable::StorePhysicsTable():";
87 G4cerr << " Cannot open file: " << fileName << G4endl;
88#endif
89 fOut.close();
90 return false;
91 }
92
93 // Number of elements
94 std::size_t tableSize = size();
95 if(!ascii)
96 {
97 fOut.write((char*) (&tableSize), sizeof tableSize);
98 }
99 else
100 {
101 fOut << tableSize << G4endl;
102 }
103
104 // Physics Vector
105 for(const auto itr : *this)
106 {
107 G4int vType = itr->GetType();
108 if(!ascii)
109 {
110 fOut.write((char*) (&vType), sizeof vType);
111 }
112 else
113 {
114 fOut << vType << G4endl;
115 }
116 itr->Store(fOut, ascii);
117 }
118 fOut.close();
119 return true;
120}

Referenced by G4EmTableUtil::StoreMscTable(), and G4EmTableUtil::StoreTable().

Friends And Related Function Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  out,
G4PhysicsTable table 
)
friend

Definition at line 226 of file G4PhysicsTable.cc.

227{
228 // Printout Physics Vector
229 std::size_t i = 0;
230 for(auto itr = right.cbegin(); itr != right.cend(); ++itr)
231 {
232 out << std::setw(8) << i << "-th Vector ";
233 out << ": Type " << G4int((*itr)->GetType());
234 out << ": Flag ";
235 if(right.GetFlag(i))
236 {
237 out << " T";
238 }
239 else
240 {
241 out << " F";
242 }
243 out << G4endl;
244 out << *(*itr);
245 ++i;
246 }
247 out << G4endl;
248 return out;
249}

Member Data Documentation

◆ vecFlag

G4FlagCollection G4PhysicsTable::vecFlag
protected

Definition at line 119 of file G4PhysicsTable.hh.

Referenced by ResetFlagArray(), resize(), RetrievePhysicsTable(), and ~G4PhysicsTable().


The documentation for this class was generated from the following files: