11#include <analysis/DecayDescriptor/DecayDescriptor.h>
12#include <framework/logging/Logger.h>
149 Var(
const std::string& n,
FunctionPtr f,
const std::string& d,
const std::string& g =
"",
187 const Var*
getVariable(
const std::string& functionName,
const std::vector<std::string>& functionArguments);
192 std::vector<const Belle2::Variable::Manager::Var*>
getVariables(
const std::vector<std::string>& variables);
197 bool addAlias(
const std::string& alias,
const std::string& variable);
217 bool addCollection(
const std::string& collection,
const std::vector<std::string>& variables);
222 std::vector<std::string>
getCollection(
const std::string& collection);
227 std::vector<std::string>
resolveCollections(
const std::vector<std::string>& variables);
246 void deprecateVariable(
const std::string& name,
bool make_fatal,
const std::string& version,
const std::string& description);
264 std::vector<std::string>
getNames()
const;
285 bool createVariable(
const std::string& fullname,
const std::string& functionName,
286 const std::vector<std::string>& functionArguments);
313 const std::string& unit =
"")
319 const std::string& unit =
"")
344 DeprecateProxy(
const std::string& name,
bool make_fatal,
const std::string& version,
const std::string& description)
351 std::function<T> make_function(T* t)
359 auto func = std::function{t};
360 using ReturnType =
typename decltype(func)::result_type;
361 if (std::is_same_v<ReturnType, double>) {
362 return Belle2::Variable::Manager::VariableDataType::c_double;
363 }
else if (std::is_same_v<ReturnType, int>) {
364 return Belle2::Variable::Manager::VariableDataType::c_int;
365 }
else if (std::is_same_v<ReturnType, bool>) {
366 return Belle2::Variable::Manager::VariableDataType::c_bool;
368 B2FATAL(
"Metavariables must be registered using the REGISTER_METAVARIABLE macro." <<
LogVar(
"Variablename", name));
375#define VARMANAGER_CONCATENATE_DETAIL(x, y) x##y
379#define VARMANAGER_CONCATENATE(x, y) VARMANAGER_CONCATENATE_DETAIL(x, y)
383#define VARMANAGER_MAKE_UNIQUE(x) VARMANAGER_CONCATENATE(x, __LINE__)
390#define REGISTER_VARIABLE_NO_UNIT(name, function, description) \
391 static Proxy VARMANAGER_MAKE_UNIQUE(_variableproxy)(std::string(name), Belle2::Variable::make_function(function), std::string(description), Belle2::Variable::get_function_type(name,function));
398#define REGISTER_VARIABLE_WITH_UNIT(name, function, description, unit) \
399 static Proxy VARMANAGER_MAKE_UNIQUE(_variableproxy)(std::string(name), Belle2::Variable::make_function(function), std::string(description), Belle2::Variable::get_function_type(name,function), std::string(unit));
406#define PICK_FIFTH_ARG(arg1, arg2, arg3, arg4, arg5, ...) arg5
413#define REGISTER_VARIABLE_MACRO_CHOOSER(...) PICK_FIFTH_ARG(__VA_ARGS__, REGISTER_VARIABLE_WITH_UNIT, REGISTER_VARIABLE_NO_UNIT, )
420#define REGISTER_VARIABLE(...) REGISTER_VARIABLE_MACRO_CHOOSER(__VA_ARGS__)(__VA_ARGS__)
427#define REGISTER_METAVARIABLE(name, function, description, variabledatatype) \
428 static Proxy VARMANAGER_MAKE_UNIQUE(_variableproxy)(std::string(name), Belle2::Variable::make_function(function), std::string(description), Belle2::Variable::Manager::VariableDataType(variabledatatype));
435#define VARIABLE_GROUP(groupName) \
436 static GroupProxy VARMANAGER_MAKE_UNIQUE(_variablegroupproxy)(groupName);
443#define MAKE_DEPRECATED(name, make_fatal, version, description) \
444 static DeprecateProxy VARMANAGER_MAKE_UNIQUE(_deprecateproxy)(std::string(name), bool(make_fatal), std::string(version), std::string(description));
Class to store reconstructed particles.
Internal class that registers a variable as deprecated.
DeprecateProxy(const std::string &name, bool make_fatal, const std::string &version, const std::string &description)
constructor.
Internal class that registers a variable group with Manager when constructed.
GroupProxy(const std::string &groupName)
constructor.
Global list of available variables.
std::vector< const Belle2::Variable::Manager::VarBase * > getVariables() const
Return list of all variables (in order registered).
Particle Object
Typedef for the cut, that we use Particles as our base objects.
std::vector< const VarBase * > m_variablesInRegistrationOrder
List of variables in registration order.
std::vector< std::string > getAliasNames() const
Return a list of all variable alias names (in reverse order added).
std::function< VarVariant(const Particle *)> FunctionPtr
functions stored take a const Particle* and return VarVariant.
std::vector< std::string > resolveCollections(const std::vector< std::string > &variables)
Resolve Collection Returns variable names corresponding to the given collection or if it is not a col...
Manager(const Manager &)
Copy constructor disabled (not defined).
std::string m_currentGroup
Group last set via VARIABLE_GROUP().
const Var * getVariable(std::string name)
Get the variable belonging to the given key.
std::variant< double, int, bool > VarVariant
NOTE: the python interface is documented manually in analysis/doc/Variables.rst (because we use ROOT ...
std::map< std::string, std::string > m_alias
List of registered aliases.
std::map< std::string, std::shared_ptr< Var > > m_variables
List of registered variables.
void deprecateVariable(const std::string &name, bool make_fatal, const std::string &version, const std::string &description)
Make a variable deprecated.
std::map< std::string, std::shared_ptr< ParameterVar > > m_parameter_variables
List of registered parameter variables.
static Manager & Instance()
get singleton instance.
void printAliases()
Print existing aliases.
std::map< std::string, std::pair< bool, std::string > > m_deprecated
List of deprecated variables.
bool createVariable(const std::string &name)
Creates and registers a concrete variable (Var) from a MetaVar, ParameterVar or numeric constant.
void assertValidName(const std::string &name)
Abort with B2FATAL if name is not a valid name for a variable.
void clearAliases()
Clear existing aliases.
std::function< FunctionPtr(const std::vector< std::string > &)> MetaFunctionPtr
meta functions stored take a const std::vector<std::string>& and return a FunctionPtr.
std::vector< std::string > getNames() const
Return list of all variable names (in order registered).
std::map< std::string, std::vector< std::string > > m_collection
List of registered collections.
void setVariableGroup(const std::string &groupName)
All variables registered after VARIABLE_GROUP(groupName) will be added to this group.
std::string resolveAlias(const std::string &alias)
Resolve alias Return original variable name.
std::vector< std::string > getCollection(const std::string &collection)
Get Collection Returns variable names corresponding to the given collection.
bool addAlias(const std::string &alias, const std::string &variable)
Add alias Return true if the alias was successfully added.
bool addCollection(const std::string &collection, const std::vector< std::string > &variables)
Add collection Return true if the collection was successfully added.
std::function< VarVariant(const Particle *, const std::vector< double > &)> ParameterFunctionPtr
parameter functions stored take a const Particle*, const std::vector<double>& and return VarVariant.
VariableDataType
data type of variables
void registerVariable(const std::string &name, const Manager::FunctionPtr &f, const std::string &description, const Manager::VariableDataType &v, const std::string &unit="")
Register a variable.
void checkDeprecatedVariable(const std::string &name)
Check if a variable is deprecated.
double evaluate(const std::string &varName, const Particle *p)
evaluate variable 'varName' on given Particle.
std::map< std::string, std::shared_ptr< MetaVar > > m_meta_variables
List of registered meta variables.
Internal class that registers a variable with Manager when constructed.
Proxy(const std::string &name, Manager::ParameterFunctionPtr f, const std::string &description, Manager::VariableDataType v, const std::string &unit="")
constructor.
Proxy(const std::string &name, Manager::MetaFunctionPtr f, const std::string &description, Manager::VariableDataType v)
constructor.
Proxy(const std::string &name, Manager::FunctionPtr f, const std::string &description, Manager::VariableDataType v, const std::string &unit="")
constructor.
Class to store variables with their name which were sent to the logging service.
Abstract base class for different kinds of events.
A variable taking additional floating-point arguments to influence the behaviour.
ParameterVar(const std::string &n, ParameterFunctionPtr f, const std::string &d, const std::string &g="", const VariableDataType &v=VariableDataType::c_double)
ctor
ParameterFunctionPtr function
Pointer to function.
Base class for information common to all types of variables.
std::string description
Description of what this function does.
VarBase(const std::string &n, const std::string &d, const std::string &g, const VariableDataType &v)
ctor
void extendDescriptionString(const std::string &d)
function to extend the description of the variable
VariableDataType variabletype
data type of variable
std::string group
Associated group.
std::string name
Unique identifier of the function, used as key.
A variable returning a floating-point value for a given Particle.
Var(const std::string &n, FunctionPtr f, const std::string &d, const std::string &g="", const VariableDataType &v=VariableDataType::c_double)
ctor
FunctionPtr function
Pointer to function.