20#include "BDSException.hh"
21#include "BDSImportanceFileLoader.hh"
37#include "src-external/gzstream/gzstream.h"
57 bool validFile = file.rdbuf()->is_open();
59 bool validFile = file.is_open();
63 {
throw BDSException(__METHOD_NAME__,
"Cannot open file \"" + fileName +
"\"");}
65 {G4cout <<
"BDSImportanceFileLoader::Load> loading \"" << fileName <<
"\"" << G4endl;}
68 std::map<G4String, G4double> importance;
70 while (std::getline(file, line))
72 std::istringstream liness(line);
74 std::string importanceValueString;
77 if (std::all_of(line.begin(), line.end(), isspace))
80 liness >> volume >> importanceValueString;
85 std::string remainder;
87 G4String message =
"Error: Unknown value \"" + remainder +
"\" in line " + std::to_string(lineNum) +
" of the importanceMapFile";
92 if (importanceValueString.empty())
94 G4String message =
"No importance value was found for cell \"" + volume +
"\" in the importanceMapFile.";
98 G4double importanceValue = 0;
100 {importanceValue = std::stod(importanceValueString);}
103 G4String message =
"Error: Cell \"" + volume +
"\" has importance value \"" + importanceValueString +
"\",";
104 message +=
" importance value must be numeric.";
108 importance[volume] = importanceValue;
115 G4cout <<
"BDSImportanceFileLoader::Load> loaded " << importance.size() <<
" importance entries" << G4endl;
General exception with possible name of object and message.
A loader for importance values used in importance sampling.