Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 43 of file G4LatticeReader.hh.

Constructor & Destructor Documentation

G4LatticeReader::G4LatticeReader ( G4int  vb = 0)

Definition at line 55 of file G4LatticeReader.cc.

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

Definition at line 59 of file G4LatticeReader.cc.

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

Member Function Documentation

void G4LatticeReader::CloseFile ( )
protected

Definition at line 126 of file G4LatticeReader.cc.

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

Here is the caller graph for this function:

G4LatticeLogical * G4LatticeReader::MakeLattice ( const G4String filepath)

Definition at line 66 of file G4LatticeReader.cc.

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

Here is the call graph for this function:

Here is the caller graph for this function:

G4bool G4LatticeReader::OpenFile ( const G4String filepath)
protected

Definition at line 100 of file G4LatticeReader.cc.

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

Here is the call graph for this function:

Here is the caller graph for this function:

G4bool G4LatticeReader::ProcessConstants ( )
protected

Definition at line 185 of file G4LatticeReader.cc.

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

Here is the call graph for this function:

Here is the caller graph for this function:

G4bool G4LatticeReader::ProcessMap ( )
protected

Definition at line 232 of file G4LatticeReader.cc.

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

Here is the call graph for this function:

Here is the caller graph for this function:

G4bool G4LatticeReader::ProcessNMap ( )
protected

Definition at line 241 of file G4LatticeReader.cc.

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

Here is the call graph for this function:

Here is the caller graph for this function:

G4bool G4LatticeReader::ProcessToken ( )
protected

Definition at line 135 of file G4LatticeReader.cc.

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

Here is the call graph for this function:

Here is the caller graph for this function:

G4bool G4LatticeReader::ProcessValue ( const G4String name)
protected

Definition at line 159 of file G4LatticeReader.cc.

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

Here is the call graph for this function:

Here is the caller graph for this function:

G4bool G4LatticeReader::ReadMapInfo ( )
protected

Definition at line 198 of file G4LatticeReader.cc.

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

Here is the call graph for this function:

Here is the caller graph for this function:

void G4LatticeReader::SetVerboseLevel ( G4int  vb)
inline

Definition at line 48 of file G4LatticeReader.hh.

48 { verboseLevel = vb; }
G4bool G4LatticeReader::SkipComments ( )
protected

Definition at line 152 of file G4LatticeReader.cc.

152  {
153  psLatfile->ignore(std::numeric_limits<std::streamsize>::max(), '\n');
154  return true; // Never fails
155 }
T max(const T t1, const T t2)
brief Return the largest of the two arguments

Here is the call graph for this function:

Here is the caller graph for this function:


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