Belle II Software  release-05-01-25
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. More...
 
void print () const
 Print cut tree.
 
std::string decompile () const
 Do the compilation from a string in return. More...
 

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)) More...
 

Private Types

enum  Operation {
  EMPTY = 0,
  NONE,
  AND,
  OR,
  LT,
  LE,
  GT,
  GE,
  EQ,
  NE
}
 Enum with the allowed operations of the Cut Tree.
 
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 (std::string str)
 Constructor of the cut. More...
 
 GeneralCut (const GeneralCut &)=delete
 Delete Copy constructor.
 
GeneralCutoperator= (const GeneralCut &)=delete
 Delete assign operator.
 
std::string preprocess (std::string str) const
 Preprocess cut string. More...
 
bool processLogicConditions (std::string str)
 Look for logical conditions in the given cut string.
 
bool processBinaryNumericConditions (std::string str)
 Look for numeric binary conditions (e.g. More...
 
bool processTernaryNumericConditions (std::string str)
 Look for numeric ternary conditions (e.g. More...
 
void processVariable (const std::string &str)
 Get a variable with the given name from the variable manager using its getVariable(name) function.
 
double get (const Object *p) const
 Returns stored number or Variable value for the given object.
 

Private Attributes

enum Belle2::GeneralCut::Operation m_operation
 Operation which connects left and right cut.
 
const Varm_var
 set if there was a valid variable in this cut
 
double m_number
 literal number contained in the cut
 
bool m_isNumeric
 if there was a literal number in this cut
 
std::unique_ptr< GeneralCutm_left
 Left-side cut.
 
std::unique_ptr< GeneralCutm_right
 Right-side cut.
 

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. Parenthesis []
  4. Floats
  5. 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 daughter0(M) < daughter1(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 101 of file GeneralCut.h.

Constructor & Destructor Documentation

◆ GeneralCut()

GeneralCut ( std::string  str)
inlineexplicitprivate

Constructor of the cut.

Call init with given string

Parameters
strCut is initalized with the specified cuts. Default are no cuts

Definition at line 234 of file GeneralCut.h.

234  {
235  if (not processTernaryNumericConditions(str)) {
236  if (not processBinaryNumericConditions(str)) {
237  m_operation = NONE;
238  try {
239  m_number = Belle2::convertString<double>(str);
240  m_isNumeric = true;
241  } catch (std::invalid_argument&) {
242  m_isNumeric = false;
243  processVariable(str);
244  }
245  }
246  }
247  }
248  }
249 
253  GeneralCut(const GeneralCut&) = delete;
254 

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 123 of file GeneralCut.h.

◆ 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 114 of file GeneralCut.h.

◆ 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 183 of file GeneralCut.h.

◆ preprocess()

std::string preprocess ( std::string  str) const
inlineprivate

Preprocess cut string.

Trim string and delete global parenthesis

Definition at line 271 of file GeneralCut.h.

◆ processBinaryNumericConditions()

bool processBinaryNumericConditions ( std::string  str)
inlineprivate

Look for numeric binary conditions (e.g.

1.2 < M ) in the given cut string

Definition at line 311 of file GeneralCut.h.

◆ processTernaryNumericConditions()

bool processTernaryNumericConditions ( std::string  str)
inlineprivate

Look for numeric ternary conditions (e.g.

1.2 < M < 1.5 ) in the given cut string

Definition at line 357 of file GeneralCut.h.


The documentation for this class was generated from the following file:
Belle2::GeneralCut::m_operation
enum Belle2::GeneralCut::Operation m_operation
Operation which connects left and right cut.
Belle2::GeneralCut::m_isNumeric
bool m_isNumeric
if there was a literal number in this cut
Definition: GeneralCut.h:426
Belle2::GeneralCut::m_number
double m_number
literal number contained in the cut
Definition: GeneralCut.h:425
Belle2::GeneralCut::processTernaryNumericConditions
bool processTernaryNumericConditions(std::string str)
Look for numeric ternary conditions (e.g.
Definition: GeneralCut.h:357
Belle2::GeneralCut::processVariable
void processVariable(const std::string &str)
Get a variable with the given name from the variable manager using its getVariable(name) function.
Definition: GeneralCut.h:385
Belle2::GeneralCut::processBinaryNumericConditions
bool processBinaryNumericConditions(std::string str)
Look for numeric binary conditions (e.g.
Definition: GeneralCut.h:311
Belle2::GeneralCut::GeneralCut
GeneralCut(std::string str)
Constructor of the cut.
Definition: GeneralCut.h:234