OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
FromFile.cpp
Go to the documentation of this file.
1//
2// Struct FromFile
3// Simple functor that reads vector data from a file. If the file contains
4// more than one value the sum is returned.
5// \f[
6// result = \sum_{i=0}^n value_i
7// \f]
8//
9// Copyright (c) 2010 - 2013, Yves Ineichen, ETH Zürich
10// All rights reserved
11//
12// Implemented as part of the PhD thesis
13// "Toward massively parallel multi-objective optimization with application to
14// particle accelerators" (https://doi.org/10.3929/ethz-a-009792359)
15//
16// This file is part of OPAL.
17//
18// OPAL is free software: you can redistribute it and/or modify
19// it under the terms of the GNU General Public License as published by
20// the Free Software Foundation, either version 3 of the License, or
21// (at your option) any later version.
22//
23// You should have received a copy of the GNU General Public License
24// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
25//
26#include "Expression/FromFile.h"
27
30
31 values_.clear();
32
33 std::ifstream file;
34 file.open(filename_.c_str(), std::ios::in);
35 if(!file) {
36 throw OptPilotException("FromFile::readValues()",
37 "Error opening file " + filename_);
38 }
39
40 std::copy(std::istream_iterator<double>(file),
41 std::istream_iterator<double>(),
42 std::back_inserter(values_));
43
44 file.close();
45}
46
std::string filename_
Definition: FromFile.h:76
void readValues()
reads a simple list of double values
Definition: FromFile.cpp:29
std::vector< double > values_
Definition: FromFile.h:74