gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
yaml_parser.cpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
22 
24 
25 namespace Gambit
26 {
27 
28  namespace IniParser
29  {
30 
31  // Implementations of main inifile class
32 
33  void IniFile::readFile(std::string filename)
34  {
35 
36  // Perform the basic read and parse operations defined by the parent.
37  YAML::Node root = filename_to_node(filename);
38  basicParse(root,filename);
39 
40  // Get the observables and rules sections
41  YAML::Node outputNode = root["ObsLikes"];
42  YAML::Node rulesNode = root["Rules"];
43 
44  // Read likelihood/observables
45  for(YAML::const_iterator it=outputNode.begin(); it!=outputNode.end(); ++it)
46  {
47  observables.push_back((*it).as<Types::Observable>());
48  }
49 
50  // Read rules
51  for(YAML::const_iterator it=rulesNode.begin(); it!=rulesNode.end(); ++it)
52  {
53  rules.push_back((*it).as<Types::Observable>());
54  }
55 
56  // Read KeyValue section, find the default path entry, and pass this on
57  // to the Scanner, Logger, and Printer nodes
58  YAML::Node keyvalue = getKeyValuePairNode();
59  YAML::Node scanNode = getScannerNode();
60  YAML::Node printerNode = getPrinterNode();
61  YAML::Node logNode = getLoggerNode();
62 
63  }
64 
68  const ObservablesType& IniFile::getRules() const { return rules; }
70 
71  }
72 
73 }
74 
75 // Methods for converting from inifile to Observable format
76 namespace YAML
77 {
78  using namespace Gambit::IniParser::Types;
79 
80  bool convert<Observable>::decode(const Node& node, Observable& rhs)
81  {
82  #define READ(NAME) if (node[#NAME].IsDefined()) rhs.NAME = node[#NAME].as<std::string>();
83  READ(purpose)
84  READ(capability)
85  READ(type)
86  READ(function)
87  READ(module)
88  READ(backend)
89  READ(version)
90  #undef READ
91 
92  if (node.Tag() == "!weak" or node.Tag() == "!weakrule")
93  rhs.weakrule = true;
94  else
95  rhs.weakrule = false;
96 
97  // Strip leading "Gambit::" namespaces and whitespace, but preserve "const ".
99 
100  if (node["printme"].IsDefined())
101  rhs.printme = node["printme"].as<bool>();
102 
103  if (node["options"].IsDefined())
104  rhs.options = Gambit::Options(node["options"]);
105 
106  if (node["sub_capabilities"].IsDefined())
107  rhs.subcaps = node["sub_capabilities"];
108 
109  if (node["functionChain"].IsDefined())
110  rhs.functionChain = node["functionChain"].as<std::vector<std::string>>();
111 
112  for(YAML::const_iterator it=node["dependencies"].begin();
113  it!=node["dependencies"].end(); ++it)
114  {
115  rhs.dependencies.push_back((*it).as<Observable>());
116  }
117 
118  for(YAML::const_iterator it=node["backends"].begin();
119  it!=node["backends"].end(); ++it)
120  {
121  rhs.backends.push_back((*it).as<Observable>());
122  }
123 
124  return true;
125  }
126 
127 }
const ObservablesType & getObservables() const
Getters for private observable and rules entries.
Definition: yaml_parser.cpp:67
std::vector< std::string > functionChain
Definition: yaml_parser.hpp:63
std::vector< Observable > backends
Definition: yaml_parser.hpp:62
YAML::Node filename_to_node(str)
Read in the actual YAML file.
virtual void readFile(str filename)
Read in the YAML file.
Definition: yaml_parser.cpp:33
const ObservablesType & getRules() const
Definition: yaml_parser.cpp:68
#define READ(NAME)
ObservablesType observables
YAML overloads for mass cut and mass cut ratio constituents.
std::vector< ObservableType > ObservablesType
Definition: yaml_parser.hpp:86
YAML::Node getPrinterNode() const
std::vector< Observable > dependencies
Definition: yaml_parser.hpp:61
Ini-file parser based on yaml-cpp.
YAML::Node getScannerNode() const
YAML::Node getLoggerNode() const
str fix_type(str)
Clean out whitespace and strip Gambit and default BOSSed class namespaces.
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.
YAML::Node getKeyValuePairNode() const