35 : mod_m(modulo), filename_m(filename), dvarName_m(dvarName), globalSize_m(0)
46 std::size_t validLines = 0;
47 while (std::getline(in, line)) {
48 if (!line.empty()) ++validLines;
50 if (validLines == 0) {
61 ind->genes[i] =
getNext(ind->id);
66 if (!file.is_open()) {
72 std::string headerLine;
73 if (!std::getline(file, headerLine)) {
75 "Empty file or error reading header in '" +
filename_m +
"'.");
78 std::istringstream headerStream(headerLine);
79 std::vector<std::string> dvars{std::istream_iterator<std::string>{headerStream},
80 std::istream_iterator<std::string>{}};
84 if (it == dvars.end()) {
89 const std::size_t columnIndex = std::distance(dvars.begin(), it);
94 std::size_t lineNumber = 2;
95 while (std::getline(file, line)) {
101 std::istringstream lineStream(line);
102 std::vector<std::string> tokens{std::istream_iterator<std::string>{lineStream},
103 std::istream_iterator<std::string>{}};
105 if (columnIndex >= tokens.size()) {
107 "Line " + std::to_string(lineNumber) +
" in file '" +
filename_m +
108 "' has fewer columns (" + std::to_string(tokens.size()) +
109 ") than expected (index " + std::to_string(columnIndex) +
").");
113 chain_m.push_back(std::stod(tokens[columnIndex]));
114 }
catch (
const std::exception&
e) {
116 "Conversion error at line " + std::to_string(lineNumber) +
129 "No valid numeric data found for DVAR '" +
dvarName_m +
std::shared_ptr< CmdArguments > CmdArguments_t
const T * find(const T table[], const std::string &name)
Look up name.
constexpr double e
The value of.
bundles all communicators for a specific role/pid
void allocate(const CmdArguments_t &args, const Comm::Bundle_t &comm) override
Parses and loads the data from the file into memory.
std::size_t mod_m
Modulo used to wrap indices.
std::size_t globalSize_m
Number of lines in the file (including header)
unsigned int getSize() const
Get the number of lines in the file (including the header).
std::vector< double > chain_m
The values for the selected design variable loaded from the file.
std::string dvarName_m
Name of the design variable to extract.
void create(std::shared_ptr< SampleIndividual > &ind, std::size_t i) override
Assign a sampled value to an individual's gene.
std::string filename_m
File name where samples are read from.
double getNext(unsigned int id)
Returns the next value for the given individual ID.
FromFile(const std::string &filename, const std::string &dvarName, std::size_t modulo)
The base class for all OPAL exceptions.