gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
yaml_parser_base.hpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
29 
30 #ifndef __yaml_parser_base_hpp__
31 #define __yaml_parser_base_hpp__
32 
36 
37 #include "yaml-cpp/yaml.h"
38 #include <limits>
39 
40 
41 namespace Gambit
42 {
43 
44  namespace IniParser
45  {
46 
48  class Parser
49  {
50 
51  public:
52 
54  virtual void readFile(str filename);
55 
58  YAML::Node getParametersNode() const;
59  YAML::Node getPriorsNode() const;
60  YAML::Node getPrinterNode() const;
61  YAML::Node getScannerNode() const;
62  YAML::Node getLoggerNode() const;
63  YAML::Node getKeyValuePairNode() const;
64 
65  template <typename... args>
66  bool hasKey(args... keys) const
67  {
68  return getVariadicNode(keyValuePairNode, keys...);
69  }
70 
71  template<typename TYPE, typename... args> TYPE getValue(args... keys) const
72  {
73  const YAML::Node node = getVariadicNode(keyValuePairNode, keys...);
74  if (not node) inifile_error().raise(LOCAL_INFO,"No inifile entry for [" + stringifyVariadic(keys...) + "]");
75  return NodeUtility::getNode<TYPE>(node);
76  }
77 
78  template<typename TYPE, typename... args> TYPE getValueOrDef(TYPE def, const args&... keys) const
79  {
80  const YAML::Node node = getVariadicNode(keyValuePairNode, keys...);
81  if (not node)
82  {
83  return def;
84  }
85  return NodeUtility::getNode<TYPE>(node);
86  }
88 
91  template<typename TYPE> TYPE getModelParameterEntry(str model, str param, str key) const
92  {
93  if (not parametersNode[model][param][key]) inifile_error().raise(LOCAL_INFO,model + "." + param + "." + key + "not found in inifile.");
94  return parametersNode[model][param][key].as<TYPE>();
95  }
96  bool hasModelParameterEntry(str model, str param, str key) const;
98  const std::set<str> getModelNames() const;
99  const std::vector<str> getModelParameters(str model) const;
101 
103  const Options getOptions(str key) const;
104 
105  protected:
106 
108  YAML::Node filename_to_node(str);
109 
111  void basicParse(YAML::Node,str);
112 
113  private:
114 
115  YAML::Node keyValuePairNode;
116  YAML::Node parametersNode;
117  YAML::Node priorsNode;
118  YAML::Node printerNode;
119  YAML::Node scannerNode;
120  YAML::Node logNode;
121  };
122 
123 
124  }
125 
126 }
127 
128 #endif /* defined(__yaml_parser_base_hpp__) */
TYPE getValueOrDef(TYPE def, const args &... keys) const
#define LOCAL_INFO
Definition: local_info.hpp:34
General small utility classes, typedefs, etc.
YAML::Node filename_to_node(str)
Read in the actual YAML file.
const std::string stringifyVariadic()
Declarations for the YAML options class.
const std::vector< str > getModelParameters(str model) const
const Options getOptions(str key) const
Getter for options.
YAML::Node getPriorsNode() const
const YAML::Node getVariadicNode(const YAML::Node &node)
bool hasKey(args... keys) const
YAML::Node getPrinterNode() const
Inifile parser base class.
std::string str
Shorthand for a standard string.
Definition: Analysis.hpp:35
virtual void readFile(str filename)
Read in the YAML file.
TYPE getModelParameterEntry(str model, str param, str key) const
Getters for model/parameter section.
bool hasModelParameterEntry(str model, str param, str key) const
Getters for model/parameter section.
Exception objects required for standalone compilation.
YAML::Node getScannerNode() const
const std::set< str > getModelNames() const
Return list of model names (without "adhoc" model!)
error & inifile_error()
IniFile errors.
YAML::Node getLoggerNode() const
YAML::Node getParametersNode() const
Getters for key/value section.
void basicParse(YAML::Node, str)
Do the basic parsing of the YAML file.
TODO: see if we can use this one:
Definition: Analysis.hpp:33
A small wrapper object for &#39;options&#39; nodes.
TYPE getValue(args... keys) const
YAML::Node getKeyValuePairNode() const