Geant4-11
Public Member Functions | Protected Member Functions | Private Attributes | Static Private Attributes
G4LatticeReader Class Reference

#include <G4LatticeReader.hh>

Public Member Functions

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

Protected Member Functions

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

Private Attributes

G4String fMap
 
G4String fMapPath
 
G4int fNX
 
G4int fNY
 
G4int fPol
 
G4String fsPol
 
G4String fToken
 
G4double fValue
 
G4LatticeLogicalpLattice
 
std::ifstream * psLatfile
 
G4int verboseLevel
 

Static Private Attributes

static const G4String fDataDir
 

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) {;}
G4LatticeLogical * pLattice
std::ifstream * psLatfile

◆ ~G4LatticeReader()

G4LatticeReader::~G4LatticeReader ( )

Definition at line 58 of file G4LatticeReader.cc.

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

References psLatfile.

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}

References psLatfile.

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)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
bool G4bool
Definition: G4Types.hh:86
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4bool OpenFile(const G4String &filepath)

References CloseFile(), FatalException, G4cout, G4endl, G4Exception(), OpenFile(), pLattice, ProcessToken(), psLatfile, and verboseLevel.

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}
static const G4String fDataDir

References CloseFile(), fDataDir, fMapPath, G4cout, G4endl, psLatfile, and verboseLevel.

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
192 return psLatfile->good();
193}
double G4double
Definition: G4Types.hh:83
void SetDynamicalConstants(G4double Beta, G4double Gamma, G4double Lambda, G4double Mu)

References anonymous_namespace{G4PionRadiativeDecayChannel.cc}::beta, G4cout, G4endl, G4InuclParticleNames::lambda, pLattice, psLatfile, G4LatticeLogical::SetDynamicalConstants(), and verboseLevel.

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)

References fMap, fNX, fNY, fPol, G4cerr, G4endl, G4LatticeLogical::LoadMap(), pLattice, and ReadMapInfo().

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)

References fMap, fNX, fNY, fPol, G4cerr, G4endl, G4LatticeLogical::Load_NMap(), pLattice, and ReadMapInfo().

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
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)
G4bool ProcessConstants()
G4bool contains(const G4String &str, std::string_view ss)
Check if a string contains a given substring.
void to_lower(G4String &str)
Convert string to lowercase.

References G4StrUtil::contains(), fToken, G4cout, G4endl, ProcessConstants(), ProcessMap(), ProcessNMap(), ProcessValue(), psLatfile, SkipComments(), G4StrUtil::to_lower(), and verboseLevel.

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}
static constexpr double s
Definition: G4SIunits.hh:154
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)

References fValue, G4cerr, G4cout, G4endl, G4InuclParticleNames::name(), pLattice, psLatfile, s, G4LatticeLogical::SetAnhDecConstant(), G4LatticeLogical::SetFTDOS(), G4LatticeLogical::SetLDOS(), G4LatticeLogical::SetScatteringConstant(), G4LatticeLogical::SetSTDOS(), and verboseLevel.

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
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}

References fMap, fMapPath, fNX, fNY, fPol, fsPol, G4cerr, G4cout, G4endl, G4LatticeLogical::MAXRES, psLatfile, G4StrUtil::to_lower(), and verboseLevel.

Referenced by ProcessMap(), and ProcessNMap().

◆ SetVerboseLevel()

void G4LatticeReader::SetVerboseLevel ( G4int  vb)
inline

Definition at line 47 of file G4LatticeReader.hh.

47{ verboseLevel = vb; }

References verboseLevel.

◆ SkipComments()

G4bool G4LatticeReader::SkipComments ( )
protected

Definition at line 151 of file G4LatticeReader.cc.

151 {
153 return true; // Never fails
154}
T max(const T t1, const T t2)
brief Return the largest of the two arguments

References G4INCL::Math::max(), and psLatfile.

Referenced by ProcessToken().

Field Documentation

◆ fDataDir

const G4String G4LatticeReader::fDataDir
staticprivate
Initial value:
=
std::getenv("G4LATTICEDATA") ? (const char*)std::getenv("G4LATTICEDATA") : "./CrystalMaps"

Definition at line 74 of file G4LatticeReader.hh.

Referenced by OpenFile().

◆ fMap

G4String G4LatticeReader::fMap
private

Definition at line 71 of file G4LatticeReader.hh.

Referenced by ProcessMap(), ProcessNMap(), and ReadMapInfo().

◆ fMapPath

G4String G4LatticeReader::fMapPath
private

Definition at line 68 of file G4LatticeReader.hh.

Referenced by OpenFile(), and ReadMapInfo().

◆ fNX

G4int G4LatticeReader::fNX
private

Definition at line 72 of file G4LatticeReader.hh.

Referenced by ProcessMap(), ProcessNMap(), and ReadMapInfo().

◆ fNY

G4int G4LatticeReader::fNY
private

Definition at line 72 of file G4LatticeReader.hh.

Referenced by ProcessMap(), ProcessNMap(), and ReadMapInfo().

◆ fPol

G4int G4LatticeReader::fPol
private

Definition at line 72 of file G4LatticeReader.hh.

Referenced by ProcessMap(), ProcessNMap(), and ReadMapInfo().

◆ fsPol

G4String G4LatticeReader::fsPol
private

Definition at line 71 of file G4LatticeReader.hh.

Referenced by ReadMapInfo().

◆ fToken

G4String G4LatticeReader::fToken
private

Definition at line 69 of file G4LatticeReader.hh.

Referenced by ProcessToken().

◆ fValue

G4double G4LatticeReader::fValue
private

Definition at line 70 of file G4LatticeReader.hh.

Referenced by ProcessValue().

◆ pLattice

G4LatticeLogical* G4LatticeReader::pLattice
private

◆ psLatfile

std::ifstream* G4LatticeReader::psLatfile
private

◆ verboseLevel

G4int G4LatticeReader::verboseLevel
private

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