Belle II Software  release-06-02-00
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 <analysis/dataobjects/EventExtraInfo.h>
12 #include <framework/datastore/StoreObjPtr.h>
13 #include <framework/logging/Logger.h>
14 
15 #include <cmath>
16 
17 using namespace Belle2;
18 
19 // Register module in the framework
20 REG_MODULE(VariableToReturnValue)
21 
22 
24  Module(), m_function(nullptr)
25 {
26  //Set module properties
27  setDescription("Calculate event-based variable specified by the user and sets return value of the module accordingly.");
28  setPropertyFlags(c_ParallelProcessingCertified);
29 
30  addParam("variable", m_variable,
31  "Variable taken from Variable::Manager, see output of 'basf2 variables.py'.", std::string(""));
32 }
33 
35 {
37  if (!var) {
38  B2ERROR("Variable '" << m_variable << "' is not available in Variable::Manager!");
39  } else {
40  m_function = var->function;
41  }
42 }
43 
45 {
46  this->setReturnValue(static_cast<int>(std::lround(m_function(nullptr))));
47 }
Base class for Modules.
Definition: Module.h:72
void setReturnValue(int value)
Sets the return value for this module as integer.
Definition: Module.cc:220
Module to calculate variable specified by the user and set return value accordingly.
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:31
static Manager & Instance()
get singleton instance.
Definition: Manager.cc:25
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:650
Abstract base class for different kinds of events.
A variable returning a floating-point value for a given Particle.
Definition: Manager.h:133