19#include "BDSException.hh"
20#include "BDSImportanceFileLoader.hh"
36#include "src-external/gzstream/gzstream.h"
56 bool validFile = file.rdbuf()->is_open();
58 bool validFile = file.is_open();
62 {
throw BDSException(__METHOD_NAME__,
"Cannot open file \"" + fileName +
"\"");}
64 {G4cout <<
"BDSImportanceFileLoader::Load> loading \"" << fileName <<
"\"" << G4endl;}
67 std::map<G4String, G4double> importance;
69 while (std::getline(file, line))
71 std::istringstream liness(line);
73 std::string importanceValueString;
76 if (std::all_of(line.begin(), line.end(), isspace))
79 liness >> volume >> importanceValueString;
84 std::string remainder;
86 G4String message =
"Error: Unknown value \"" + remainder +
"\" in line " + std::to_string(lineNum) +
" of the importanceMapFile";
91 if (importanceValueString.empty())
93 G4String message =
"No importance value was found for cell \"" + volume +
"\" in the importanceMapFile.";
97 G4double importanceValue = 0;
99 {importanceValue = std::stod(importanceValueString);}
102 G4String message =
"Error: Cell \"" + volume +
"\" has importance value \"" + importanceValueString +
"\",";
103 message +=
" importance value must be numeric.";
107 importance[volume] = importanceValue;
114 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.