Belle II Software development
VariableToReturnValueModule.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <analysis/modules/VariableToReturnValue/VariableToReturnValueModule.h>
10
11#include <framework/logging/Logger.h>
12
13using namespace Belle2;
14
15// Register module in the framework
16REG_MODULE(VariableToReturnValue);
17
18
20 Module(), m_function(nullptr)
21{
22 //Set module properties
23 setDescription("Calculate event-based variable specified by the user and sets return value of the module accordingly.");
25
26 addParam("variable", m_variable,
27 "Variable taken from Variable::Manager, see output of 'basf2 variables.py'.", std::string(""));
28}
29
31{
33 if (!var) {
34 B2ERROR("Variable '" << m_variable << "' is not available in Variable::Manager!");
35 } else {
36 m_function = var->function;
37 }
38}
39
41{
42 int returnValue = 0;
43 if (std::holds_alternative<double>(m_function(nullptr))) {
44 returnValue = std::get<double>(m_function(nullptr));
45 } else if (std::holds_alternative<int>(m_function(nullptr))) {
46 returnValue = std::get<int>(m_function(nullptr));
47 } else if (std::holds_alternative<bool>(m_function(nullptr))) {
48 returnValue = std::get<bool>(m_function(nullptr));
49 }
50 this->setReturnValue(returnValue);
51}
Base class for Modules.
Definition: Module.h:72
void setDescription(const std::string &description)
Sets the description of the module.
Definition: Module.cc:214
void setPropertyFlags(unsigned int propertyFlags)
Sets the flags for the module properties.
Definition: Module.cc:208
void setReturnValue(int value)
Sets the return value for this module as integer.
Definition: Module.cc:220
@ c_ParallelProcessingCertified
This module can be run in parallel processing mode safely (All I/O must be done through the data stor...
Definition: Module.h:80
virtual void initialize() override
Initialize.
virtual void event() override
Method called for each event.
std::string m_variable
variable name (module parameter)
Variable::Manager::FunctionPtr m_function
function pointer corresponding to given variable.
const Var * getVariable(std::string name)
Get the variable belonging to the given key.
Definition: Manager.cc:58
static Manager & Instance()
get singleton instance.
Definition: Manager.cc:26
void addParam(const std::string &name, T &paramVariable, const std::string &description, const T &defaultValue)
Adds a new parameter to the module.
Definition: Module.h:559
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:649
Abstract base class for different kinds of events.
A variable returning a floating-point value for a given Particle.
Definition: Manager.h:145