Belle II Software  release-08-01-10
NodeFactory Class Reference

Wrapper class for static node compile functions. More...

#include <NodeFactory.h>

Static Public Member Functions

template<class AVariableManager >
static std::unique_ptr< const AbstractBooleanNode< AVariableManager > > compile_boolean_node (Nodetuple tuple)
 This template function creates a boolean node from a boost::python::tuple The Python Parser encodes the node type as int as the first argument of each tuple. More...
 
template<class AVariableManager >
static std::unique_ptr< const AbstractExpressionNode< AVariableManager > > compile_expression_node (Nodetuple tuple)
 This template function creates a ExpressionNode from a boost::python::tuple The Python Parser encodes the node type as int in the first argument of each tuple. More...
 

Detailed Description

Wrapper class for static node compile functions.

Definition at line 64 of file NodeFactory.h.

Member Function Documentation

◆ compile_boolean_node()

static std::unique_ptr<const AbstractBooleanNode<AVariableManager> > compile_boolean_node ( Nodetuple  tuple)
inlinestatic

This template function creates a boolean node from a boost::python::tuple The Python Parser encodes the node type as int as the first argument of each tuple.

Node types are decoded via the NodeType enum defined in framework/utilities/include/AbstractNodes.h e.g (2, (11, True)) is a UnaryRelationalNode (nodetype value 2), which has a BooleanNode(nodetype value 11) as a child. List of Nodes:

Definition at line 80 of file NodeFactory.h.

81  {
82  if (py::len(tuple) == 0) B2FATAL("BooleanNode tuple is empty, this is invalid.");
83  // First argument of every NodeTuple is an integer indicating the NodeType
84  NodeType node_type = static_cast<NodeType>(static_cast<int>(py::extract<int>(tuple[0])));
85 
86  if (node_type == NodeType::UnaryBooleanNode) {
87  // Extract first child tuple
88  if (py::len(tuple) != 4) B2FATAL("UnaryBooleanNode tuple has to have length 4." << LogVar("actual length", py::len(tuple)));
89  Nodetuple child = static_cast<const py::tuple>(tuple[1]);
90  bool negation = py::extract<bool>(tuple[2]);
91  bool bracketized = py::extract<bool>(tuple[3]);
92  return std::unique_ptr<const AbstractBooleanNode<AVariableManager>>(new UnaryBooleanNode<AVariableManager>(child, negation,
93  bracketized));
94 
95  } else if (node_type == NodeType::BinaryBooleanNode) {
96  if (py::len(tuple) != 4) B2FATAL("BinaryBooleanNode tuple has to have length 4." << LogVar("actual length", py::len(tuple)));
97  Nodetuple left_node = static_cast<const py::tuple>(tuple[1]);
98  Nodetuple right_node = static_cast<const py::tuple>(tuple[2]);
99  BooleanOperator boperator = static_cast<BooleanOperator>(static_cast<int>(py::extract<int>(tuple[3])));
100  return std::unique_ptr<const AbstractBooleanNode<AVariableManager>>(new BinaryBooleanNode<AVariableManager>(left_node, right_node,
101  boperator));
102  } else if (node_type == NodeType::UnaryRelationalNode) {
103  if (py::len(tuple) != 2) B2FATAL("UnaryRelationalNode tuple has to have length 2." << LogVar("actual length", py::len(tuple)));
104  Nodetuple node = static_cast<const py::tuple>(tuple[1]);
105  return std::unique_ptr<const AbstractBooleanNode<AVariableManager>>(new UnaryRelationalNode<AVariableManager>(node));
106  } else if (node_type == NodeType::BinaryRelationalNode) {
107  if (py::len(tuple) != 4) B2FATAL("BinaryRelationalNode tuple has to have length 4." << LogVar("actual length", py::len(tuple)));
108  Nodetuple left_node = static_cast<const py::tuple>(tuple[1]);
109  Nodetuple right_node = static_cast<const py::tuple>(tuple[2]);
110  ComparisonOperator coperator = static_cast<ComparisonOperator>(static_cast<int>(py::extract<int>(tuple[3])));
111  return std::unique_ptr<const AbstractBooleanNode<AVariableManager>>(new BinaryRelationalNode<AVariableManager>(left_node,
112  right_node, coperator));
113  } else if (node_type == NodeType::TernaryRelationalNode) {
114  if (py::len(tuple) != 6) B2FATAL("TernaryRelationalNode tuple has to have length 6." << LogVar("actual length", py::len(tuple)));
115  Nodetuple left_node = static_cast<const py::tuple>(tuple[1]);
116  Nodetuple center_node = static_cast<const py::tuple>(tuple[2]);
117  Nodetuple right_node = static_cast<const py::tuple>(tuple[3]);
118  ComparisonOperator lc_coperator = static_cast<ComparisonOperator>(static_cast<int>(py::extract<int>(tuple[4])));
119  ComparisonOperator cr_coperator = static_cast<ComparisonOperator>(static_cast<int>(py::extract<int>(tuple[5])));
120 
121  return std::unique_ptr<const AbstractBooleanNode<AVariableManager>>(new TernaryRelationalNode<AVariableManager>(left_node,
122  center_node, right_node,
123  lc_coperator, cr_coperator));
124  } else {
125  throw std::runtime_error("error NodeFactory::compile_boolean_node: got invalid boolean NodeType.");
126  }
127  }
Class to store variables with their name which were sent to the logging service.
NodeType
Enum of possible Nodes in parsing tree.
ComparisonOperator
Enum for decoding the comparison operator type.
BooleanOperator
Enum for decoding the boolean operator type.

◆ compile_expression_node()

static std::unique_ptr<const AbstractExpressionNode<AVariableManager> > compile_expression_node ( Nodetuple  tuple)
inlinestatic

This template function creates a ExpressionNode from a boost::python::tuple The Python Parser encodes the node type as int in the first argument of each tuple.

Node types are decoded via the NodeType enum defined in framework/utilities/include/AbstractNodes.h e.g (9, 1.2) is a DataNode<double> with value 1.2 List of Nodes:

Definition at line 141 of file NodeFactory.h.


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