GooFit  v2.1.3
Eigen.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Eigen/Dense>
4 #include <fstream>
5 #include <string>
6 
7 namespace GooFit {
8 
9 template <typename M>
10 M read_csv(std::string name, bool comma = true) {
11  using namespace Eigen;
12 
13  std::ifstream input(name);
14 
15  std::string line;
16  std::vector<typename M::Scalar> values;
17  size_t rows = 0;
18  while(std::getline(input, line)) {
19  std::stringstream lineStream(line);
20  std::string cell;
21  typename M::Scalar value;
22 
23  if(comma)
24  while(std::getline<char>(lineStream, cell, ','))
25  values.push_back(std::stod(cell));
26  else
27  while(lineStream >> value)
28  values.push_back(value);
29 
30  ++rows;
31  }
32  return Map<const Matrix<typename M::Scalar, M::RowsAtCompileTime, M::ColsAtCompileTime, ColMajor>>(
33  values.data(), values.size() / rows, rows);
34 };
35 
36 } // namespace GooFit
M read_csv(std::string name, bool comma=true)
Definition: Eigen.h:10