55 bool validFile = file.rdbuf()->is_open();
57 bool validFile = file.is_open();
60 {
throw BDSException(__METHOD_NAME__,
"Invalid file name or no such file named \"" + fileName +
"\"");}
62 {G4cout <<
"Loading \"" << fileName <<
"\"" << G4endl;}
74 std::vector<G4String> keys;
75 std::vector<G4String> units;
78 G4bool intoData =
false;
79 G4bool pastNStep =
false;
80 G4bool dataFinished =
false;
85 while (std::getline(file, line))
89 if (std::all_of(line.begin(), line.end(), isspace))
98 std::istringstream liness(line);
100 std::vector<G4float> lineData(nColumns);
101 for (G4int i = 0; i < nColumns; ++i)
111 (*result)(indX,indY) = fv;
131 std::regex min(
"^.*?\\(Xmin,Ymin\\)\\s*=\\s*", std::regex_constants::icase);
132 if (std::regex_search(line, min))
134 std::regex minValues(
"\\(([0-9eE.+-]+),([0-9eE.+-]+)\\)");
136 std::regex_search(line, match, minValues);
137 xMin = std::stod(match[1])*CLHEP::cm;
138 yMin = std::stod(match[2])*CLHEP::cm;
143 std::regex max(
"^.*?\\(Xmax,Ymax\\)\\s*=\\s*", std::regex_constants::icase);
144 if (std::regex_search(line, max))
146 std::regex maxValues(
"\\(([0-9eE.+-]+),([0-9eE.+-]+)\\)");
148 std::regex_search(line, match, maxValues);
149 xMax = std::stod(match[1])*CLHEP::cm;
150 yMax = std::stod(match[2])*CLHEP::cm;
155 std::regex incr(
"\\s*X\\s*and\\s*Y", std::regex_constants::icase);
156 if (std::regex_search(line, incr))
158 std::regex nStepValues(
":\\s*([0-9eE.+-]+)\\s*([0-9eE.+-]+)");
160 std::regex_search(line, match, nStepValues);
161 nX = std::stoi(match[1]) + 1;
162 nY = std::stoi(match[2]) + 1;
168 std::regex noNumbers(
"^(\\D)*$");
169 G4bool noNumbersR = std::regex_search(line, noNumbers);
170 G4bool hasParenthesis = (line.find(
"(") != std::string::npos) || (line.find(
")") != std::string::npos);
171 G4bool hasNoParenthesis = !hasParenthesis;
172 if (pastNStep && noNumbersR && hasNoParenthesis)
174 std::istringstream liness(line);
175 for (G4String key; liness >> key;)
176 {keys.push_back(key);}
177 nColumns = G4int(std::distance(keys.begin(), keys.end()));
182 if (pastNStep && noNumbersR && hasParenthesis)
185 std::regex unitsRE(
"[\\(](\\w+\\-*\\/*\\w*)[\\)]");
187 std::regex_search(line, match, unitsRE);
188 for (
const auto& u : match)
189 {units.push_back(G4String(u));}
199 {
throw BDSException(__METHOD_NAME__,
"Invalid file contents - no column header found");}