Belle II Software  release-05-02-19
VariableToReturnValueModule.cc
1 /**************************************************************************
2 * BASF2 (Belle Analysis Framework 2) *
3 * Copyright(C) 2013 - Belle II Collaboration *
4 * *
5 * Author: The Belle II Collaboration *
6 * Contributors: Thomas Keck *
7 * *
8 * This software is provided "as is" without any warranty. *
9 **************************************************************************/
10 
11 #include <analysis/modules/VariableToReturnValue/VariableToReturnValueModule.h>
12 
13 #include <analysis/dataobjects/EventExtraInfo.h>
14 #include <framework/datastore/StoreObjPtr.h>
15 #include <framework/logging/Logger.h>
16 
17 #include <cmath>
18 
19 using namespace Belle2;
20 
21 // Register module in the framework
22 REG_MODULE(VariableToReturnValue)
23 
24 
26  Module(), m_function(nullptr)
27 {
28  //Set module properties
29  setDescription("Calculate event-based variable specified by the user and sets return value of the module accordingly.");
30  setPropertyFlags(c_ParallelProcessingCertified);
31 
32  addParam("variable", m_variable,
33  "Variable taken from Variable::Manager, see output of 'basf2 variables.py'.", std::string(""));
34 }
35 
37 {
39  if (!var) {
40  B2ERROR("Variable '" << m_variable << "' is not available in Variable::Manager!");
41  } else {
42  m_function = var->function;
43  }
44 }
45 
47 {
48  this->setReturnValue(static_cast<int>(std::lround(m_function(nullptr))));
49 }
Belle2::VariableToReturnValueModule
Module to calculate variable specified by the user and set return value accordingly.
Definition: VariableToReturnValueModule.h:33
Belle2::Variable::Manager::Var
A variable returning a floating-point value for a given Particle.
Definition: Manager.h:137
Belle2::Variable::Manager::getVariable
const Var * getVariable(std::string name)
Get the variable belonging to the given key.
Definition: Manager.cc:33
Belle2::VariableToReturnValueModule::m_variable
std::string m_variable
variable name (module parameter)
Definition: VariableToReturnValueModule.h:47
REG_MODULE
#define REG_MODULE(moduleName)
Register the given module (without 'Module' suffix) with the framework.
Definition: Module.h:652
Belle2::VariableToReturnValueModule::initialize
virtual void initialize() override
Initialize.
Definition: VariableToReturnValueModule.cc:36
Belle2::Module
Base class for Modules.
Definition: Module.h:74
Belle2::VariableToReturnValueModule::m_function
Variable::Manager::FunctionPtr m_function
function pointer corresponding to given variable.
Definition: VariableToReturnValueModule.h:45
Belle2
Abstract base class for different kinds of events.
Definition: MillepedeAlgorithm.h:19
Belle2::Module::setReturnValue
void setReturnValue(int value)
Sets the return value for this module as integer.
Definition: Module.cc:222
Belle2::VariableToReturnValueModule::event
virtual void event() override
Method called for each event.
Definition: VariableToReturnValueModule.cc:46
Belle2::Variable::Manager::Instance
static Manager & Instance()
get singleton instance.
Definition: Manager.cc:27