Belle II Software light-2406-ragdoll
GeneralCut< AVariableManager > Class Template Reference

This class implements a common way to implement cut/selection functionality for arbitrary objects. More...

#include <GeneralCut.h>

Collaboration diagram for GeneralCut< AVariableManager >:

Public Member Functions

bool check (const Object *p) const
 Check if the current cuts are passed by the given object.
 
void print () const
 Print cut tree.
 
std::string decompile () const
 Do the compilation from a string in return.
 

Static Public Member Functions

static std::unique_ptr< GeneralCutcompile (const std::string &cut)
 Creates an instance of a cut and returns a unique_ptr to it, if you need a copy-able object instead you can cast it to a shared_ptr using std::shared_ptr<Variable::Cut>(Cut::compile(cutString))
 

Private Types

typedef AVariableManager::Object Object
 Object, that can be checked. This depends on the VariableManager, as the returned variables from the manager must calculate their values on pointers of these objects.
 
typedef AVariableManager::Var Var
 Variable returned by the variable manager.
 

Private Member Functions

 GeneralCut (Nodetuple tuple)
 Constructor of the cut.
 
 GeneralCut (const GeneralCut &)=delete
 Delete Copy constructor.
 
GeneralCutoperator= (const GeneralCut &)=delete
 Delete assign operator.
 

Private Attributes

std::unique_ptr< const AbstractBooleanNode< AVariableManager > > m_root
 cut root node
 

Detailed Description

template<class AVariableManager>
class Belle2::GeneralCut< AVariableManager >

This class implements a common way to implement cut/selection functionality for arbitrary objects.

Every module which wants to perform cuts should use this object. As a parameter the module requires a std::string with the written cut. This std::string has to be passed as an argument to the static Compile method of the Cut class, which returns a unique_ptr to the Cut object. Cuts can be performed via the check method.

Valid cuts can contain:

  1. Logic conditions: and, or
  2. Numeric conditions: <, <=, >, >=, ==, !=
  3. Square brackets [] nesting boolean statements
  4. Parenthesis () for grouping expressions
  5. Floats
  6. Variables registered in the general "Variable Manager" which are used as a template argument to this class.

For example when using the analysis VariableManager for particles, valid cuts are: 1.2 < M < 1.5 daughter(0, M) < daughter(1, M) [M > 1.5 or M < 0.5] and 0.2 < getExtraInfo(SignalProbability) < 0.7

== and != conditions are evaluated not exactly because we deal with floating point values instead two floating point number are equal if their distance in their integral ordering is less than 3.

The general "Variable Manager" passed as a template argument to this class has to have some properties:

  • public typedef Object: Which objects can be handled by the variable manager - a pointer on this type ob objects will be required by the check method of the cut.
  • public typedef Var: The type of objects, that are returned by the variable manager, when you ask it for a variable (by giving a name to getVariable)
  • public static function getInstance: so the variable manager has to be a singleton.
  • public function getVariable(const std::string& name): which should return a pointer to an object of type AVariableManager::Var which are used to get the value corresponding to this name. Whenever this value is needed, the function called "function" is called with a pointer to a Object, that is given in the check function of this cut.

The best example for a VariableManager, that has all these parameters, is probably the analysis VariableManager with VariableManager::var equals to the analysis variable and the VariableManager::Object equal to a Particle. For a more slim example of a valid variable manager, see the generalCut.cc test, where a mock variable manager is created.

Definition at line 71 of file GeneralCut.h.

Member Typedef Documentation

◆ Object

typedef AVariableManager::Object Object
private

Object, that can be checked. This depends on the VariableManager, as the returned variables from the manager must calculate their values on pointers of these objects.

Definition at line 73 of file GeneralCut.h.

◆ Var

typedef AVariableManager::Var Var
private

Variable returned by the variable manager.

Definition at line 75 of file GeneralCut.h.

Constructor & Destructor Documentation

◆ GeneralCut()

GeneralCut ( Nodetuple  tuple)
inlineexplicitprivate

Constructor of the cut.

Call init with given Nodetuple

Parameters
tuple(const boost::python::tuple&) constructed by the python parser from cut.

Definition at line 132 of file GeneralCut.h.

132: m_root{NodeFactory::compile_boolean_node<AVariableManager>(tuple)} {}
std::unique_ptr< const AbstractBooleanNode< AVariableManager > > m_root
cut root node
Definition: GeneralCut.h:144

Member Function Documentation

◆ check()

bool check ( const Object p) const
inline

Check if the current cuts are passed by the given object.

Parameters
ppointer to the object, that should be checked. All formerly received variables from the variable manager (from the type Var), are asked for their value using var->function(p).

Definition at line 102 of file GeneralCut.h.

103 {
104 if (m_root != nullptr) return m_root->check(p);
105 throw std::runtime_error("GeneralCut m_root is not initialized.");
106 }

◆ compile()

static std::unique_ptr< GeneralCut > compile ( const std::string &  cut)
inlinestatic

Creates an instance of a cut and returns a unique_ptr to it, if you need a copy-able object instead you can cast it to a shared_ptr using std::shared_ptr<Variable::Cut>(Cut::compile(cutString))

Parameters
cutthe string defining the cut
Returns
std::unique_ptr<Cut>

Definition at line 84 of file GeneralCut.h.

85 {
86 // Here we parse
87 Py_Initialize();
88 try {
89 py::object b2parser_namespace = py::import("b2parser");
90 py::tuple tuple = py::extract<py::tuple>(b2parser_namespace.attr("parse")(cut));
91 return std::unique_ptr<GeneralCut>(new GeneralCut(tuple));
92 } catch (py::error_already_set&) {
93 PyErr_Print();
94 B2FATAL("Parsing error on cutstring:\n" + cut);
95 }
96 }
GeneralCut(Nodetuple tuple)
Constructor of the cut.
Definition: GeneralCut.h:132

◆ decompile()

std::string decompile ( ) const
inline

Do the compilation from a string in return.

In principle, compile(decompile()) should give the same result again.

Definition at line 119 of file GeneralCut.h.

120 {
121 std::stringstream stringstream;
122 stringstream << m_root->decompile();
123 return stringstream.str();
124 }

◆ print()

void print ( ) const
inline

Print cut tree.

Definition at line 111 of file GeneralCut.h.

112 {
113 m_root->print();
114 }

Member Data Documentation

◆ m_root

std::unique_ptr<const AbstractBooleanNode<AVariableManager> > m_root
private

cut root node

Definition at line 144 of file GeneralCut.h.


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