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

A small wrapper object for 'options' nodes. More...

#include <yaml_options.hpp>

Public Member Functions

 Options ()
 Default constructor. More...
 
 Options (const YAML::Node &options)
 Copy constructor. More...
 
 Options (YAML::Node &&options)
 Move constructor. More...
 
template<typename TYPE >
std::vector< TYPE > getVector (std::string key) const
 Get a std::vector of a particular type. More...
 
template<typename... args>
const std::vector< strgetNames (const args &... keys) const
 Retrieve values from key-value pairs in options node. More...
 
const std::vector< strgetNames () const
 Retrieve values from all key-value pairs in options node. More...
 
template<typename... args>
const Options getOptions (const args &... keys) const
 Recursive options retrieval. More...
 
template<typename... args>
YAML::Node getNode (const args &... keys) const
 Retrieve raw YAML node. More...
 
template<typename... args>
YAML::Node loadFromFile (const args &... keys) const
 Get YAML node from file. More...
 
YAML::const_iterator begin () const
 Return begin and end of options. More...
 
YAML::const_iterator end () const
 
template<typename... args>
bool hasKey (const args &... keys) const
 Getters for key/value pairs (which is all the options node should contain) More...
 
template<typename TYPE , typename... args>
TYPE getValue (const args &... keys) const
 
template<typename TYPE , typename... args>
TYPE getValueOrDef (TYPE def, const args &... keys) const
 
template<typename KEYTYPE , typename VALTYPE >
void setValue (const KEYTYPE &key, const VALTYPE &val)
 Basic setter, for adding extra options. More...
 

Private Attributes

YAML::Node options
 

Detailed Description

A small wrapper object for 'options' nodes.

These can be extracted from the prior, observable/likelihood and rules sections of the inifile, or set by hand in module standalone mode.

Definition at line 50 of file yaml_options.hpp.

Constructor & Destructor Documentation

◆ Options() [1/3]

Gambit::Options::Options ( )
inline

Default constructor.

Definition at line 56 of file yaml_options.hpp.

Referenced by getOptions().

56 {}
Here is the caller graph for this function:

◆ Options() [2/3]

Gambit::Options::Options ( const YAML::Node &  options)
inline

Copy constructor.

Definition at line 59 of file yaml_options.hpp.

59 : options(options) {}
YAML::Node options

◆ Options() [3/3]

Gambit::Options::Options ( YAML::Node &&  options)
inline

Move constructor.

Definition at line 62 of file yaml_options.hpp.

References find_all_gambit_bits::args.

62 : options(std::move(options)) {}
YAML::Node options

Member Function Documentation

◆ begin()

YAML::const_iterator Gambit::Options::begin ( ) const
inline

Return begin and end of options.

Definition at line 239 of file yaml_options.hpp.

References options.

239 { return options.begin(); }
YAML::Node options

◆ end()

YAML::const_iterator Gambit::Options::end ( ) const
inline

Definition at line 240 of file yaml_options.hpp.

References options.

Referenced by getNames().

240 { return options.end(); }
YAML::Node options
Here is the caller graph for this function:

◆ getNames() [1/2]

template<typename... args>
const std::vector<str> Gambit::Options::getNames ( const args &...  keys) const
inline

Retrieve values from key-value pairs in options node.

Works for an arbitrary set of input keys (of any type), and returns all values as strings.

Definition at line 165 of file yaml_options.hpp.

References end(), Gambit::getVariadicNode(), and options.

Referenced by Gambit::ColliderBit::checkOptions_getYAMLCrossSection(), Gambit::Priors::CompositePrior::CompositePrior(), and Gambit::SpecBit::run_FS_spectrum_generator().

166  {
167  std::vector<str> result;
168  const YAML::Node node = getVariadicNode(options, keys...);
169 
170  if (node.IsMap())
171  {
172  for (auto it = node.begin(), end = node.end(); it != end; ++it)
173  {
174  result.push_back( it->first.as<str>() );
175  }
176  }
177 
178  return result;
179  }
const YAML::Node getVariadicNode(const YAML::Node &node)
YAML::Node options
std::string str
Shorthand for a standard string.
Definition: Analysis.hpp:35
YAML::const_iterator end() const
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getNames() [2/2]

const std::vector<str> Gambit::Options::getNames ( ) const
inline

Retrieve values from all key-value pairs in options node.

Returns all keys as strings.

Definition at line 183 of file yaml_options.hpp.

References find_all_gambit_bits::args, end(), and options.

184  {
185  std::vector<str> result;
186 
187  for (auto it = options.begin(), end = options.end(); it != end; ++it)
188  {
189  result.push_back( it->first.as<str>() );
190  }
191 
192  return result;
193  }
YAML::Node options
std::string str
Shorthand for a standard string.
Definition: Analysis.hpp:35
YAML::const_iterator end() const
Here is the call graph for this function:

◆ getNode()

template<typename... args>
YAML::Node Gambit::Options::getNode ( const args &...  keys) const
inline

Retrieve raw YAML node.

Definition at line 212 of file yaml_options.hpp.

References find_all_gambit_bits::args, Gambit::getVariadicNode(), LOCAL_INFO, options, Gambit::stringifyVariadic(), and Gambit::utils_error().

Referenced by Gambit::Priors::CompositePrior::CompositePrior(), Gambit::Priors::FixedPrior::FixedPrior(), getVector(), Gambit::Scanner::Scan_Manager::Run(), and Gambit::Scanner::Scan_Manager::Scan_Manager().

213  {
214  const YAML::Node node = getVariadicNode(options, keys...);
215  if (not node)
216  {
217  std::ostringstream os;
218  os << "No options entry for [" << stringifyVariadic(keys...) << "]\n Node contents: " << options;
219  utils_error().raise(LOCAL_INFO,os.str());
220  }
221  return node;
222  }
EXPORT_SYMBOLS error & utils_error()
Utility errors.
#define LOCAL_INFO
Definition: local_info.hpp:34
const std::string stringifyVariadic()
const YAML::Node getVariadicNode(const YAML::Node &node)
YAML::Node options
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getOptions()

template<typename... args>
const Options Gambit::Options::getOptions ( const args &...  keys) const
inline

Recursive options retrieval.

Definition at line 197 of file yaml_options.hpp.

References find_all_gambit_bits::args, Gambit::getVariadicNode(), Options(), and options.

Referenced by Gambit::Priors::CompositePrior::CompositePrior().

198  {
199  const YAML::Node node = getVariadicNode(options, keys...);
200  if (node["options"])
201  {
202  return Options(node["options"]);
203  }
204  else
205  {
206  return Options(node);
207  }
208  }
Options()
Default constructor.
const YAML::Node getVariadicNode(const YAML::Node &node)
YAML::Node options
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getValue()

template<typename TYPE , typename... args>
TYPE Gambit::Options::getValue ( const args &...  keys) const
inline

Definition at line 73 of file yaml_options.hpp.

References find_all_gambit_bits::args, Gambit::getVariadicNode(), LOCAL_INFO, options, Gambit::stringifyVariadic(), and Gambit::utils_error().

Referenced by Gambit::Priors::Cauchy::Cauchy(), Gambit::Printers::asciiPrinter::common_constructor(), Gambit::Printers::HDF5Printer::common_constructor(), Gambit::Priors::CompositePrior::CompositePrior(), Gambit::Priors::DoubleLogFlatJoin::DoubleLogFlatJoin(), Gambit::Priors::FixedPrior::FixedPrior(), Gambit::Priors::Gaussian::Gaussian(), Gambit::Printers::HDF5Printer2::get_filename(), Gambit::Priors::DoubleLogFlatJoin::get_option(), Gambit::ColliderBit::getAndReplaceSLHAContent(), Gambit::ColliderBit::getPy8Collider(), Gambit::Printers::HDF5Printer2::HDF5Printer2(), Gambit::Scanner::Plugins::pluginInfo::iniFile(), Gambit::Priors::LogNormal::LogNormal(), main(), Gambit::Priors::MultiPriors::MultiPriors(), Gambit::Printers::PrinterManager::new_stream(), Gambit::Printers::nonePrinter::nonePrinter(), Gambit::functor::notifyOfSubCaps(), Gambit::ColliderBit::operateLHCLoop(), Gambit::Priors::Plugin::Plugin(), Gambit::Priors::RangePrior1D< T >::RangePrior1D(), Gambit::SpecBit::run_FS_spectrum_generator(), Gambit::Scanner::Scan_Manager::Scan_Manager(), Gambit::Printers::SQLitePrinter::SQLitePrinter(), and Gambit::Printers::SQLiteReader::SQLiteReader().

74  {
75  const YAML::Node node = getVariadicNode(options, keys...);
76  TYPE result;
77  if (not node)
78  {
79  std::ostringstream os;
80  os << "No options entry for [" << stringifyVariadic(keys...) << "]\n Node contents: " << options;
81  utils_error().raise(LOCAL_INFO,os.str());
82  result = TYPE();
83  }
84  else
85  {
86  try
87  {
88  result = NodeUtility::getNode<TYPE>(node);
89  }
90  catch(YAML::Exception& e)
91  {
92  std::string nodestr;
93  try
94  {
95  nodestr = node.as<std::string>();
96  }
97  catch(YAML::Exception& e)
98  {
99  nodestr = "<Couldn't even convert to string!>";
100  }
101  std::ostringstream os;
102  os << "Error retrieving options entry for [" << stringifyVariadic(keys...)
103  << "] as type " << typeid(TYPE).name() << " (template parameter: see below). String form of node value was: "
104  << nodestr << std::endl
105  << "YAML message follows: " << std::endl
106  << e.what();
107  utils_error().raise(LOCAL_INFO,os.str());
108  result = TYPE();
109  }
110  }
111  return result;
112  }
EXPORT_SYMBOLS error & utils_error()
Utility errors.
#define LOCAL_INFO
Definition: local_info.hpp:34
const std::string stringifyVariadic()
const YAML::Node getVariadicNode(const YAML::Node &node)
YAML::Node options
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getValueOrDef()

template<typename TYPE , typename... args>
TYPE Gambit::Options::getValueOrDef ( TYPE  def,
const args &...  keys 
) const
inline

◆ getVector()

template<typename TYPE >
std::vector<TYPE> Gambit::Options::getVector ( std::string  key) const
inline

Get a std::vector of a particular type.

If the entry is a scalar rather than a vector, try to convert it to a size one std::vector

Definition at line 149 of file yaml_options.hpp.

References find_all_gambit_bits::args, and getNode().

Referenced by Gambit::Priors::Cauchy::Cauchy(), Gambit::Priors::Gaussian::Gaussian(), and Gambit::Priors::LogNormal::LogNormal().

150  {
151  if (getNode(key).IsScalar())
152  {
153  return {getValue<TYPE>(key)};
154  }
155  else
156  {
157  return getValue<std::vector<TYPE>>(key);
158  }
159  }
YAML::Node getNode(const args &... keys) const
Retrieve raw YAML node.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasKey()

template<typename... args>
bool Gambit::Options::hasKey ( const args &...  keys) const
inline

◆ loadFromFile()

template<typename... args>
YAML::Node Gambit::Options::loadFromFile ( const args &...  keys) const
inline

Get YAML node from file.

Definition at line 226 of file yaml_options.hpp.

References Gambit::getVariadicNode(), LOCAL_INFO, options, Gambit::stringifyVariadic(), and Gambit::utils_error().

227  {
228  const YAML::Node node = getVariadicNode(options, keys...);
229  if (not node)
230  {
231  std::ostringstream os;
232  os << "No options entry for [" << stringifyVariadic(keys...) << "]\n Node contents: " << options;
233  utils_error().raise(LOCAL_INFO,os.str());
234  }
235  return YAML::LoadFile(node.as<std::string>().c_str());
236  }
EXPORT_SYMBOLS error & utils_error()
Utility errors.
#define LOCAL_INFO
Definition: local_info.hpp:34
const std::string stringifyVariadic()
const YAML::Node getVariadicNode(const YAML::Node &node)
YAML::Node options
Here is the call graph for this function:

◆ setValue()

template<typename KEYTYPE , typename VALTYPE >
void Gambit::Options::setValue ( const KEYTYPE &  key,
const VALTYPE &  val 
)
inline

Member Data Documentation

◆ options

YAML::Node Gambit::Options::options
private

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