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

#include <G4LatticeReader.hh>

Public Member Functions

 G4LatticeReader (G4int vb=0)
 
 ~G4LatticeReader ()
 
void SetVerboseLevel (G4int vb)
 
G4LatticeLogicalMakeLattice (const G4String &filepath)
 

Protected Member Functions

G4bool OpenFile (const G4String &filepath)
 
G4bool ProcessToken ()
 
G4bool ProcessValue (const G4String &name)
 
G4bool ProcessConstants ()
 
G4bool ProcessMap ()
 
G4bool ProcessNMap ()
 
G4bool ReadMapInfo ()
 
G4bool SkipComments ()
 
void CloseFile ()
 

Detailed Description

Definition at line 42 of file G4LatticeReader.hh.

Constructor & Destructor Documentation

◆ G4LatticeReader()

G4LatticeReader::G4LatticeReader ( G4int vb = 0)

Definition at line 54 of file G4LatticeReader.cc.

55 : verboseLevel(vb), psLatfile(0), pLattice(0), fMapPath(""),
56 fToken(""), fValue(0.), fMap(""), fsPol(""), fPol(-1), fNX(0), fNY(0) {;}

◆ ~G4LatticeReader()

G4LatticeReader::~G4LatticeReader ( )

Definition at line 58 of file G4LatticeReader.cc.

58 {
59 delete psLatfile; psLatfile = 0;
60}

Member Function Documentation

◆ CloseFile()

void G4LatticeReader::CloseFile ( )
protected

Definition at line 125 of file G4LatticeReader.cc.

125 {
126 if (psLatfile) psLatfile->close();
127 delete psLatfile;
128 psLatfile = 0;
129}

Referenced by MakeLattice(), and OpenFile().

◆ MakeLattice()

G4LatticeLogical * G4LatticeReader::MakeLattice ( const G4String & filepath)

Definition at line 65 of file G4LatticeReader.cc.

65 {
66 if (verboseLevel) G4cout << "G4LatticeReader " << filename << G4endl;
67
68 if (!OpenFile(filename)) {
70 msg << "Unable to open " << filename;
71 G4Exception("G4LatticeReader::MakeLattice", "Lattice001",
72 FatalException, msg);
73 return 0;
74 }
75
76 pLattice = new G4LatticeLogical; // Create lattice to be filled
77
78 G4bool goodLattice = true;
79 while (!psLatfile->eof()) {
80 goodLattice &= ProcessToken();
81 }
82 CloseFile();
83
84 if (!goodLattice) {
86 msg << "Error reading lattice from " << filename;
87 G4Exception("G4LatticeReader::MakeLattice", "Lattice002",
88 FatalException, msg);
89 delete pLattice;
90 pLattice = 0;
91 }
92
93 return pLattice; // Lattice complete; return pointer with ownership
94}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
bool G4bool
Definition G4Types.hh:86
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
G4bool OpenFile(const G4String &filepath)

Referenced by G4LatticeManager::LoadLattice().

◆ OpenFile()

G4bool G4LatticeReader::OpenFile ( const G4String & filepath)
protected

Definition at line 99 of file G4LatticeReader.cc.

99 {
100 if (verboseLevel)
101 G4cout << "G4LatticeReader::OpenFile " << filename << G4endl;
102
103 G4String filepath = filename;
104 psLatfile = new std::ifstream(filepath);
105 if (!psLatfile->good()) { // Local file not found
106 filepath = fDataDir + "/" + filename;
107 psLatfile->open(filepath); // Try data directory
108 if (!psLatfile->good()) {
109 CloseFile();
110 return false;
111 }
112 if (verboseLevel>1) G4cout << " Found file " << filepath << G4endl;
113 }
114
115 // Extract path from filename to use in finding .ssv map files
116 size_t lastdir = filepath.rfind('/');
117 if (lastdir == std::string::npos) fMapPath = "."; // No path at all
118 else fMapPath = filepath.substr(0,lastdir);
119
120 return true;
121}

Referenced by MakeLattice().

◆ ProcessConstants()

G4bool G4LatticeReader::ProcessConstants ( )
protected

Definition at line 184 of file G4LatticeReader.cc.

184 {
185 G4double beta=0., gamma=0., lambda=0., mu=0.;
186 *psLatfile >> beta >> gamma >> lambda >> mu;
187 if (verboseLevel>1)
188 G4cout << " ProcessConstants " << beta << " " << gamma
189 << " " << lambda << " " << mu << G4endl;
190
191 pLattice->SetDynamicalConstants(beta, gamma, lambda, mu);
192 return psLatfile->good();
193}
double G4double
Definition G4Types.hh:83
void SetDynamicalConstants(G4double Beta, G4double Gamma, G4double Lambda, G4double Mu)

Referenced by ProcessToken().

◆ ProcessMap()

G4bool G4LatticeReader::ProcessMap ( )
protected

Definition at line 231 of file G4LatticeReader.cc.

231 {
232 if (!ReadMapInfo()) { // Get specific parameters for map to load
233 G4cerr << "G4LatticeReader: Unable to process mapfile directive." << G4endl;
234 return false;
235 }
236
237 return pLattice->LoadMap(fNX, fNY, fPol, fMap);
238}
G4GLOB_DLL std::ostream G4cerr
G4bool LoadMap(G4int, G4int, G4int, G4String)

Referenced by ProcessToken().

◆ ProcessNMap()

G4bool G4LatticeReader::ProcessNMap ( )
protected

Definition at line 240 of file G4LatticeReader.cc.

240 {
241 if (!ReadMapInfo()) { // Get specific parameters for map to load
242 G4cerr << "G4LatticeReader: Unable to process mapfile directive." << G4endl;
243 return false;
244 }
245
246 return pLattice->Load_NMap(fNX, fNY, fPol, fMap);
247}
G4bool Load_NMap(G4int, G4int, G4int, G4String)

Referenced by ProcessToken().

◆ ProcessToken()

G4bool G4LatticeReader::ProcessToken ( )
protected

Definition at line 134 of file G4LatticeReader.cc.

134 {
135 fToken = "";
136 *psLatfile >> fToken;
137 if (fToken.empty() || psLatfile->eof()) return true; // End of file reached
138
139 if (verboseLevel>1) G4cout << " ProcessToken " << fToken << G4endl;
140
141 G4StrUtil::to_lower(fToken);
142 if (G4StrUtil::contains(fToken, '#')) return SkipComments(); // Ignore rest of line
143 if (fToken == "vdir") return ProcessNMap(); // Direction vector map
144 if (fToken == "vg") return ProcessMap(); // Velocity magnitudes
145 if (fToken == "dyn") return ProcessConstants(); // Dynamical parameters
146 return ProcessValue(fToken); // Single numeric value
147}
G4bool ProcessValue(const G4String &name)

Referenced by MakeLattice().

◆ ProcessValue()

G4bool G4LatticeReader::ProcessValue ( const G4String & name)
protected

Definition at line 158 of file G4LatticeReader.cc.

158 {
159 *psLatfile >> fValue;
160 if (verboseLevel>1) G4cout << " ProcessValue " << fValue << G4endl;
161
162 G4bool good = true;
163 /***** NOTE: Individual Set functions not included in Release 10.0
164 if (name == "beta") pLattice->SetBeta(fValue);
165 else if (name == "gamma") pLattice->SetGamma(fValue);
166 else if (name == "lambda") pLattice->SetLambda(fValue);
167 else if (name == "mu") pLattice->SetMu(fValue);
168 else *****/
169 if (name == "scat") pLattice->SetScatteringConstant(fValue*s*s*s);
170 else if (name == "b") pLattice->SetScatteringConstant(fValue*s*s*s);
171 else if (name == "decay") pLattice->SetAnhDecConstant(fValue*s*s*s*s);
172 else if (name == "a") pLattice->SetAnhDecConstant(fValue*s*s*s*s);
173 else if (name == "ldos") pLattice->SetLDOS(fValue);
174 else if (name == "stdos") pLattice->SetSTDOS(fValue);
175 else if (name == "ftdos") pLattice->SetFTDOS(fValue);
176 else {
177 G4cerr << "G4LatticeReader: Unrecognized token " << name << G4endl;
178 good = false;
179 }
180
181 return good;
182}
void SetLDOS(G4double LDOS)
void SetAnhDecConstant(G4double a)
void SetFTDOS(G4double FTDOS)
void SetSTDOS(G4double STDOS)
void SetScatteringConstant(G4double b)
const char * name(G4int ptype)

Referenced by ProcessToken().

◆ ReadMapInfo()

G4bool G4LatticeReader::ReadMapInfo ( )
protected

Definition at line 197 of file G4LatticeReader.cc.

197 {
198 *psLatfile >> fMap >> fsPol >> fNX >> fNY;
199 if (verboseLevel>1)
200 G4cout << " ReadMapInfo " << fMap << " " << fsPol
201 << " " << fNX << " " << fNY << G4endl;
202
203 if (fNX < 0 || fNX >= G4LatticeLogical::MAXRES) {
204 G4cerr << "G4LatticeReader: Invalid map theta dimension " << fNX << G4endl;
205 return false;
206 }
207
208 if (fNY < 0 || fNY >= G4LatticeLogical::MAXRES) {
209 G4cerr << "G4LatticeReader: Invalid map phi dimension " << fNY << G4endl;
210 return false;
211 }
212
213 // Prepend path to data files to map filename
214 fMap = fMapPath + "/" + fMap;
215
216 // Convert string code (L,ST,LT) to polarization index
217 G4StrUtil::to_lower(fsPol);
218 fPol = ( (fsPol=="l") ? 0 : // Longitudinal
219 (fsPol=="st") ? 1 : // Slow-transverse
220 (fsPol=="ft") ? 2 : // Fast-transverse
221 -1 ); // Invalid code
222
223 if (fPol<0 || fPol>2) {
224 G4cerr << "G4LatticeReader: Invalid polarization code " << fsPol << G4endl;
225 return false;
226 }
227
228 return true;
229}

Referenced by ProcessMap(), and ProcessNMap().

◆ SetVerboseLevel()

void G4LatticeReader::SetVerboseLevel ( G4int vb)
inline

Definition at line 47 of file G4LatticeReader.hh.

47{ verboseLevel = vb; }

◆ SkipComments()

G4bool G4LatticeReader::SkipComments ( )
protected

Definition at line 151 of file G4LatticeReader.cc.

151 {
152 psLatfile->ignore(std::numeric_limits<std::streamsize>::max(), '\n');
153 return true; // Never fails
154}

Referenced by ProcessToken().


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