2#include <pybind11/pybind11.h>
3#include <pybind11/stl.h>
7#include "yaml-cpp/yaml.h"
9namespace py = pybind11;
13 auto m_manager = m.def_submodule(
"manager");
15 "This is a Python binding of MaCh3s C++ based manager library.";
19 py::enum_<YAML::NodeType::value>(m_manager,
"NodeType")
20 .value(
"Undefined", YAML::NodeType::Undefined)
21 .value(
"Null", YAML::NodeType::Null)
22 .value(
"Scalar", YAML::NodeType::Scalar)
23 .value(
"Sequence", YAML::NodeType::Sequence)
24 .value(
"Map", YAML::NodeType::Map);
26 py::class_<YAML::Node>(m_manager,
"YamlNode")
27 .def(py::init<const std::string &>())
30 [](
const YAML::Node node){
31 if ( node.Type() != YAML::NodeType::Scalar )
33 throw MaCh3Exception(__FILE__, __LINE__,
"Attempting to access the data of non-scalar yaml node. This is undefined.");
37 "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.")
40 [](
const YAML::Node node,
const std::string& key){
45 [](
const YAML::Node node,
const int& key){
46 if ( node.Type() != YAML::NodeType::Sequence)
48 throw MaCh3Exception(__FILE__, __LINE__,
"Trying to access a non sequence yaml node with integer index");
54 [](
const YAML::Node &node) {
55 return py::make_iterator(node.begin(), node.end());},
56 py::keep_alive<0, 1>())
59 [](
const YAML::Node& node) {
62 return std::string(out.c_str());
65 .def(
"type", &YAML::Node::Type)
67 .def(
"__len__", &YAML::Node::size)
70 py::class_<YAML::detail::iterator_value, YAML::Node>(m_manager,
"_YamlDetailIteratorValue")
72 .def(
"first", [](YAML::detail::iterator_value& val) {
return val.first;})
73 .def(
"second", [](YAML::detail::iterator_value& val) {
return val.second;})
76 m.def(
"load_file", &YAML::LoadFile,
"");
78 py::class_<manager>(m_manager,
"Manager")
80 py::init<std::string const &>(),
81 "create a Manager object with a specified *config_file*",
82 py::arg(
"config_file")
88 "Print currently used config."
94 "Get the raw yaml config."
100 "Get the test statistic that was specified in the config file."
void Print()
Print currently used config.
int GetMCStatLLH()
Get likelihood type defined in the config.
YAML::Node const & raw()
Return config.
void initManager(py::module &m)