10#include <boost/python.hpp>
12#include <analysis/VariableManager/Manager.h>
13#include <analysis/VariableManager/Utility.h>
14#include <framework/utilities/CutNodes.h>
15#include <framework/utilities/TestHelpers.h>
17#include <gtest/gtest.h>
22 namespace py = boost::python;
26 struct MockObjectType {
28 explicit MockObjectType(
const double& d) : m_value{d} {}
29 explicit MockObjectType(
const int& i) : m_value{i} {}
30 explicit MockObjectType(
const bool& b) : m_value{b} {}
39 class MockVariableType {
42 VarVariant function(
const MockObjectType*
object)
const
44 return m_function(
object);
46 explicit MockVariableType(
const std::string& name) : m_name{name}
48 m_function = [](
const MockObjectType * object) -> VarVariant {
49 if (
object !=
nullptr)
51 return object->m_value;
54 return std::numeric_limits<double>::quiet_NaN();
59 MockVariableType(
const std::string& name, std::function<VarVariant(
const MockObjectType*)> function) : m_name{name}, m_function{function}
64 std::function<VarVariant(
const MockObjectType*)> m_function;
71 class MockVariableManager {
74 using Object = MockObjectType;
76 using Var = MockVariableType;
79 typedef std::variant<double, int, bool> VarVariant;
83 static MockVariableManager& Instance()
85 static MockVariableManager instance;
90 Var* getVariable(
const std::string& name)
92 if (name ==
"mocking_variable") {
93 return &m_mocking_variable;
99 Var* getVariable(
const std::string& functionName,
const std::vector<std::string>& functionArguments)
102 (void) functionArguments;
103 return &m_mocking_variable;
107 Var m_mocking_variable{
"mocking_variable"};
115 py::tuple tuple = py::tuple();
116 EXPECT_B2FATAL(Belle2::NodeFactory::compile_expression_node<MockVariableManager>(tuple));
119 tuple = py::make_tuple(
static_cast<int>(NodeType::UnaryExpressionNode));
120 EXPECT_B2FATAL(Belle2::NodeFactory::compile_expression_node<MockVariableManager>(tuple));
123 tuple = py::make_tuple(
static_cast<int>(NodeType::BinaryExpressionNode));
124 EXPECT_B2FATAL(Belle2::NodeFactory::compile_expression_node<MockVariableManager>(tuple));
127 tuple = py::make_tuple(
static_cast<int>(NodeType::IntegerNode));
128 EXPECT_B2FATAL(Belle2::NodeFactory::compile_expression_node<MockVariableManager>(tuple));
131 tuple = py::make_tuple(
static_cast<int>(NodeType::DoubleNode));
132 EXPECT_B2FATAL(Belle2::NodeFactory::compile_expression_node<MockVariableManager>(tuple));
135 tuple = py::make_tuple(
static_cast<int>(NodeType::BooleanNode));
136 EXPECT_B2FATAL(Belle2::NodeFactory::compile_expression_node<MockVariableManager>(tuple));
139 tuple = py::make_tuple(
static_cast<int>(NodeType::IdentifierNode));
140 EXPECT_B2FATAL(Belle2::NodeFactory::compile_expression_node<MockVariableManager>(tuple));
143 tuple = py::make_tuple(
static_cast<int>(NodeType::FunctionNode));
144 EXPECT_B2FATAL(Belle2::NodeFactory::compile_expression_node<MockVariableManager>(tuple));
147 tuple = py::make_tuple(
static_cast<int>(NodeType::IdentifierNode),
"THISDOESNOTEXIST");
148 EXPECT_THROW(Belle2::NodeFactory::compile_expression_node<MockVariableManager>(tuple), std::runtime_error);
Wrapper class for static node compile functions.
Global list of available variables.
std::variant< double, int, bool > VarVariant
NOTE: the python interface is documented manually in analysis/doc/Variables.rst (because we use ROOT ...
Abstract base class for different kinds of events.