Belle II Software  release-06-01-15
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. Square brackets []
  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 91 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 224 of file GeneralCut.h.

225  {
226  str = preprocess(str);
227  if (str.empty()) {
228  m_operation = EMPTY;
229  return;
230  }
231 
232  if (not processLogicConditions(str)) {
233  if (not processTernaryNumericConditions(str)) {
234  if (not processBinaryNumericConditions(str)) {
235  m_operation = NONE;
236  try {
237  m_number = Belle2::convertString<double>(str);
238  m_isNumeric = true;
239  } catch (std::invalid_argument&) {
240  m_isNumeric = false;
241  processVariable(str);
242  }
243  }
244  }
245  }
246  }
enum Belle2::GeneralCut::Operation m_operation
Operation which connects left and right cut.
std::string preprocess(std::string str) const
Preprocess cut string.
Definition: GeneralCut.h:261
bool processTernaryNumericConditions(std::string str)
Look for numeric ternary conditions (e.g.
Definition: GeneralCut.h:347
bool processLogicConditions(std::string str)
Look for logical conditions in the given cut string.
Definition: GeneralCut.h:276
bool processBinaryNumericConditions(std::string str)
Look for numeric binary conditions (e.g.
Definition: GeneralCut.h:301
double m_number
literal number contained in the cut
Definition: GeneralCut.h:415
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:375
bool m_isNumeric
if there was a literal number in this cut
Definition: GeneralCut.h:416

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 113 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 104 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 173 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 261 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 301 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 347 of file GeneralCut.h.


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