MaCh3  2.5.0
Reference Guide
Functions
manager.h File Reference
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include "Manager/Manager.h"
#include "yaml-cpp/yaml.h"
Include dependency graph for manager.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void initManagerModule (py::module &m_manager)
 

Detailed Description

Author
Ewan Miller

Definition in file manager.h.

Function Documentation

◆ initManagerModule()

void initManagerModule ( py::module &  m_manager)

Definition at line 16 of file manager.h.

16  {
17 
18  // Bind some of the cpp-yaml library
19  // shamelessly stolen from stackoverflow: https://stackoverflow.com/questions/62347521/using-pybind11-to-wrap-yaml-cpp-iterator
20  py::enum_<YAML::NodeType::value>(m_manager, "NodeType")
21  .value("Undefined", YAML::NodeType::Undefined)
22  .value("Null", YAML::NodeType::Null)
23  .value("Scalar", YAML::NodeType::Scalar)
24  .value("Sequence", YAML::NodeType::Sequence)
25  .value("Map", YAML::NodeType::Map);
26 
27  py::class_<YAML::Node>(m_manager, "YamlNode")
28  .def(py::init<const std::string &>())
29 
30  .def("data",
31  [](const YAML::Node node){
32  if ( node.Type() != YAML::NodeType::Scalar )
33  {
34  throw MaCh3Exception(__FILE__, __LINE__, "Attempting to access the data of non-scalar yaml node. This is undefined.");
35  }
36  return node.Scalar();
37  },
38  "Access the data stored in the node. This is only valid if the node is a 'scalar' type, i.e. it is a leaf of the yaml tree structure.")
39 
40  .def("__getitem__",
41  [](const YAML::Node node, const std::string& key){
42  return node[key];
43  })
44 
45  .def("__getitem__",
46  [](const YAML::Node node, const int& key){
47  if ( node.Type() != YAML::NodeType::Sequence)
48  {
49  throw MaCh3Exception(__FILE__, __LINE__, "Trying to access a non sequence yaml node with integer index");
50  }
51  return node[key];
52  })
53 
54  .def("__iter__",
55  [](const YAML::Node &node) {
56  return py::make_iterator(node.begin(), node.end());},
57  py::keep_alive<0, 1>())
58 
59  .def("__str__",
60  [](const YAML::Node& node) {
61  YAML::Emitter out;
62  out << node;
63  return std::string(out.c_str());
64  })
65 
66  .def("type", &YAML::Node::Type)
67 
68  .def("__len__", &YAML::Node::size)
69  ;
70 
71  py::class_<YAML::detail::iterator_value, YAML::Node>(m_manager, "_YamlDetailIteratorValue")
72  .def(py::init<>())
73  .def("first", [](YAML::detail::iterator_value& val) { return val.first;})
74  .def("second", [](YAML::detail::iterator_value& val) { return val.second;})
75  ;
76 
77  m_manager.def("load_file", &YAML::LoadFile, "");
78 
79  py::class_<Manager>(m_manager, "Manager")
80  .def(
81  py::init<std::string const &>(),
82  "create a Manager object with a specified *config_file*",
83  py::arg("config_file")
84  )
85 
86  .def(
87  "print",
89  "Print currently used config."
90  )
91 
92  .def(
93  "raw",
94  &Manager::raw,
95  "Get the raw yaml config."
96  )
97 
98  .def(
99  "get_test_stat",
101  "Get the test statistic that was specified in the config file."
102  )
103  ;
104 }
int GetMCStatLLH() const
Get likelihood type defined in the config.
Definition: Manager.cpp:89
YAML::Node const & raw() const
Return config.
Definition: Manager.h:47
void Print() const
Print currently used config.
Definition: Manager.cpp:81