gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
ascii_table_reader.hpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
10 //
16 
17 #include <iostream>
18 #include <cstdlib>
19 #include <fstream>
20 #include <vector>
21 #include <map>
22 #include <sstream>
23 
26 
27 #ifndef __ASCIItableReader__
28 #define __ASCIItableReader__
29 
30 // Usage:
31 // ASCIItableReader ascii(filename);
32 // ascii.setcolnames("mass", "BR1", "BR2");
33 // std::cout << ascii["mass"][0] << std::endl;
34 // std::cout << ascii["BR1"][1] << std::endl;
35 // std::cout << ascii["BR2"][2] << std::endl;
36 
37 namespace Gambit
38 {
40  {
41  public:
42  ASCIItableReader(std::string filename)
43  {
44  read(filename);
45  ncol = data.size();
46  nrow = data[0].size();
47  };
48  ASCIItableReader() : ncol(0), nrow(0) {}; // Dummy initializer
50 
51  int read(std::string filename);
52  void setcolnames(std::vector<std::string> names);
53 
54  template <typename... Args>
55  void setcolnames(std::string name, Args... args)
56  {
57  std::vector<std::string> vec;
58  vec.push_back(name);
59  setcolnames(vec, args...);
60  }
61  template <typename... Args>
62  void setcolnames(std::vector<std::string> vec, std::string name, Args... args)
63  {
64  vec.push_back(name);
65  setcolnames(vec, args...);
66  }
67 
68  const std::vector<double> & operator[] (int i) { return data[i]; };
69  const std::vector<double> & operator[] (std::string name) { return data[colnames[name]]; };
70  int getncol() { return ncol; }
71  int getnrow() { return nrow; }
72 
73  private:
74  std::vector<std::vector<double> > data;
75  std::map<std::string, int> colnames;
76  int ncol;
77  int nrow;
78  };
79 }
80 
81 #endif // defined __ASCIItableReader__
void setcolnames(std::vector< std::string > names)
LOCAL_INFO macro.
std::map< std::string, int > colnames
ASCIItableReader(std::string filename)
void setcolnames(std::string name, Args... args)
std::vector< std::vector< double > > data
int read(std::string filename)
void setcolnames(std::vector< std::string > vec, std::string name, Args... args)
Exception objects required for standalone compilation.
std::vector< T > vec(std::vector< T > vector)
Definition: daFunk.hpp:142
const std::vector< double > & operator[](int i)
TODO: see if we can use this one:
Definition: Analysis.hpp:33