gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
Gambit::ASCIItableReader Class Reference

#include <ascii_table_reader.hpp>

Collaboration diagram for Gambit::ASCIItableReader:

Public Member Functions

 ASCIItableReader (std::string filename)
 
 ASCIItableReader ()
 
 ~ASCIItableReader ()
 
int read (std::string filename)
 
void setcolnames (std::vector< std::string > names)
 
template<typename... Args>
void setcolnames (std::string name, Args... args)
 
template<typename... Args>
void setcolnames (std::vector< std::string > vec, std::string name, Args... args)
 
const std::vector< double > & operator[] (int i)
 
const std::vector< double > & operator[] (std::string name)
 
int getncol ()
 
int getnrow ()
 

Private Attributes

std::vector< std::vector< double > > data
 
std::map< std::string, intcolnames
 
int ncol
 
int nrow
 

Detailed Description

Definition at line 39 of file ascii_table_reader.hpp.

Constructor & Destructor Documentation

◆ ASCIItableReader() [1/2]

Gambit::ASCIItableReader::ASCIItableReader ( std::string  filename)
inline

Definition at line 42 of file ascii_table_reader.hpp.

References data, ncol, nrow, and read().

43  {
44  read(filename);
45  ncol = data.size();
46  nrow = data[0].size();
47  };
std::vector< std::vector< double > > data
int read(std::string filename)
Here is the call graph for this function:

◆ ASCIItableReader() [2/2]

Gambit::ASCIItableReader::ASCIItableReader ( )
inline

Definition at line 48 of file ascii_table_reader.hpp.

48 : ncol(0), nrow(0) {}; // Dummy initializer

◆ ~ASCIItableReader()

Gambit::ASCIItableReader::~ASCIItableReader ( )
inline

Definition at line 49 of file ascii_table_reader.hpp.

References read(), and setcolnames().

49 {}
Here is the call graph for this function:

Member Function Documentation

◆ getncol()

int Gambit::ASCIItableReader::getncol ( )
inline

Definition at line 70 of file ascii_table_reader.hpp.

References ncol.

◆ getnrow()

int Gambit::ASCIItableReader::getnrow ( )
inline

Definition at line 71 of file ascii_table_reader.hpp.

References nrow.

Referenced by Gambit::virtual_SMHiggs_widths().

Here is the caller graph for this function:

◆ operator[]() [1/2]

const std::vector<double>& Gambit::ASCIItableReader::operator[] ( int  i)
inline

Definition at line 68 of file ascii_table_reader.hpp.

References data.

68 { return data[i]; };
std::vector< std::vector< double > > data

◆ operator[]() [2/2]

const std::vector<double>& Gambit::ASCIItableReader::operator[] ( std::string  name)
inline

Definition at line 69 of file ascii_table_reader.hpp.

References colnames, and data.

69 { return data[colnames[name]]; };
std::map< std::string, int > colnames
std::vector< std::vector< double > > data

◆ read()

int Gambit::ASCIItableReader::read ( std::string  filename)

Definition at line 23 of file ascii_table_reader.cpp.

References data, LOCAL_INFO, and Gambit::utils_error().

Referenced by ASCIItableReader(), and ~ASCIItableReader().

24  {
25  std::ifstream in(filename.c_str(), std::ios::binary);
26  if (in.fail())
27  {
28  std::ostringstream errmsg;
29  errmsg << "Failed to read file '"<< filename <<"'. Check if file exists.";
30  utils_error().raise(LOCAL_INFO, errmsg.str());
31  }
32  std::string line;
33  while(std::getline(in, line))
34  {
35  if (line[0] == '#') continue; // Ignore comments lines, starting with "#"
36  std::stringstream ss(line);
37 
38  size_t i = 0;
39  double tmp;
40  while(ss >> tmp)
41  {
42  if ( i+1 > data.size() ) data.resize(i+1);
43  data[i].push_back(tmp);
44  i++;
45  }
46  }
47  in.close();
48  return 0;
49  }
EXPORT_SYMBOLS error & utils_error()
Utility errors.
#define LOCAL_INFO
Definition: local_info.hpp:34
std::vector< std::vector< double > > data
Here is the call graph for this function:
Here is the caller graph for this function:

◆ setcolnames() [1/3]

void Gambit::ASCIItableReader::setcolnames ( std::vector< std::string >  names)

Definition at line 52 of file ascii_table_reader.cpp.

References colnames, and ncol.

Referenced by Gambit::DecayBit::get_Higgs_invWidth_chi2(), setcolnames(), Gambit::virtual_SMHiggs_widths(), and ~ASCIItableReader().

53  {
54  if ( (int) names.size() == ncol )
55  {
56  size_t i = 0;
57  for (auto it = names.begin(); it != names.end(); it++)
58  {
59  colnames[*it] = i;
60  i++;
61  }
62  }
63  else
64  {
65  std::cout << "Warning in ASCIItableReader: Column number incompatible." << std::endl;
66  }
67  }
std::map< std::string, int > colnames
Here is the caller graph for this function:

◆ setcolnames() [2/3]

template<typename... Args>
void Gambit::ASCIItableReader::setcolnames ( std::string  name,
Args...  args 
)
inline

Definition at line 55 of file ascii_table_reader.hpp.

References find_all_gambit_bits::args, setcolnames(), and daFunk::vec().

56  {
57  std::vector<std::string> vec;
58  vec.push_back(name);
59  setcolnames(vec, args...);
60  }
void setcolnames(std::vector< std::string > names)
std::vector< T > vec(std::vector< T > vector)
Definition: daFunk.hpp:142
Here is the call graph for this function:

◆ setcolnames() [3/3]

template<typename... Args>
void Gambit::ASCIItableReader::setcolnames ( std::vector< std::string >  vec,
std::string  name,
Args...  args 
)
inline

Definition at line 62 of file ascii_table_reader.hpp.

References find_all_gambit_bits::args, and setcolnames().

63  {
64  vec.push_back(name);
65  setcolnames(vec, args...);
66  }
void setcolnames(std::vector< std::string > names)
Here is the call graph for this function:

Member Data Documentation

◆ colnames

std::map<std::string, int> Gambit::ASCIItableReader::colnames
private

Definition at line 75 of file ascii_table_reader.hpp.

Referenced by operator[](), and setcolnames().

◆ data

std::vector<std::vector<double> > Gambit::ASCIItableReader::data
private

Definition at line 74 of file ascii_table_reader.hpp.

Referenced by ASCIItableReader(), operator[](), and read().

◆ ncol

int Gambit::ASCIItableReader::ncol
private

Definition at line 76 of file ascii_table_reader.hpp.

Referenced by ASCIItableReader(), getncol(), and setcolnames().

◆ nrow

int Gambit::ASCIItableReader::nrow
private

Definition at line 77 of file ascii_table_reader.hpp.

Referenced by ASCIItableReader(), and getnrow().


The documentation for this class was generated from the following files: